-
Notifications
You must be signed in to change notification settings - Fork 3
Action bar - order and payment [last subscription cycle] #163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
0eba05a
bc071e3
ce58b8e
0b89fad
5c43099
59c6153
27f073f
907d968
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,11 +43,75 @@ defineMessages({ | |
| changePaymentButton: { | ||
| id: 'details-page.action-bar.button.changePayment', | ||
| }, | ||
| orderDispatchedLabel: { | ||
| id: 'details-page.action-bar.label.orderDispatched', | ||
| }, | ||
| orderDeliveryDateBody: { | ||
| id: 'details-page.action-bar.text.orderDeliveryDate', | ||
| }, | ||
| orderDeliveryDetailBody: { | ||
| id: 'details-page.action-bar.text.orderDeliveryDetail', | ||
| }, | ||
| trackOrderButton: { | ||
| id: 'details-page.action-bar.button.trackOrder', | ||
| }, | ||
| viewOrderButton: { | ||
| id: 'details-page.action-bar.button.viewOrder', | ||
| }, | ||
| nextPurchaseLabel: { | ||
| id: 'details-page.action-bar.label.nextPurchase', | ||
| }, | ||
| nextPurchaseText: { | ||
| id: 'details-page.action-bar.text.nextPurchase', | ||
| }, | ||
| nextPurchaseButton: { | ||
| id: 'details-page.action-bar.button.nextPurchase', | ||
| }, | ||
| printBankSlipLabel: { | ||
| id: 'details-page.action-bar.label.printBankSlip', | ||
| }, | ||
| printBankSlipText: { | ||
| id: 'details-page.action-bar.text.printBankSlip', | ||
| }, | ||
| printBankSlipButton: { | ||
| id: 'details-page.action-bar.button.printBankSlip', | ||
| }, | ||
| }) | ||
|
|
||
| class ActionBarContainer extends Component<Props> { | ||
| private calculateDaysUntilSpecificDate = (specificDate: string) => { | ||
| const today = new Date() | ||
| const diffTime = Math.abs(+new Date(specificDate) - +today) | ||
| const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)) | ||
|
|
||
| return diffDays | ||
| } | ||
|
|
||
| private getOrderDispatchedAction = ( | ||
| deliveryDate: string | undefined, | ||
| trackingUrl: string | undefined | ||
| ) => { | ||
| const orderDispatchedBody = deliveryDate | ||
| ? 'orderDeliveryDate' | ||
| : 'orderDeliveryDetail' | ||
| const orderDispatchedButton = trackingUrl ? 'trackOrder' : 'viewOrder' | ||
|
|
||
| return { body: orderDispatchedBody, button: orderDispatchedButton } | ||
| } | ||
|
|
||
| private getSuggestedAction = () => { | ||
| const { status, address, isSkipped, payment, onUpdateAction } = this.props | ||
| const { | ||
| status, | ||
| address, | ||
| isSkipped, | ||
| payment, | ||
| orderStatus, | ||
| orderDeliveryDate, | ||
| orderTrackingUrl, | ||
| nextPurchaseDate, | ||
| bankSlipUrl, | ||
| onUpdateAction, | ||
| } = this.props | ||
|
|
||
| let action: SubscriptionAction | null = null | ||
| let buttonVariation: 'primary' | 'secondary' = 'primary' | ||
|
|
@@ -57,11 +121,18 @@ class ActionBarContainer extends Component<Props> { | |
| action = 'restore' | ||
| } else if (!address) { | ||
| action = 'changeAddress' | ||
| } else if (!payment) { | ||
| } else if (!payment || orderStatus === 'payment-denied') { | ||
| action = 'changePayment' | ||
| } else if (isSkipped) { | ||
| action = 'unskip' | ||
| buttonVariation = 'secondary' | ||
| } else if (!!orderDeliveryDate || !!orderTrackingUrl) { | ||
| action = 'orderDispatched' | ||
| } else if (bankSlipUrl) { | ||
| action = 'printBankSlip' | ||
| } else if (nextPurchaseDate) { | ||
| action = 'nextPurchase' | ||
| buttonVariation = 'secondary' | ||
| } | ||
|
|
||
| if (action === 'changeAddress' || action === 'changePayment') { | ||
|
|
@@ -71,7 +142,15 @@ class ActionBarContainer extends Component<Props> { | |
| let onClick | ||
| if ( | ||
| action && | ||
| ['restore', 'unskip', 'changeAddress', 'changePayment'].includes(action) | ||
| [ | ||
| 'restore', | ||
| 'unskip', | ||
| 'changeAddress', | ||
| 'changePayment', | ||
| 'orderDispatched', | ||
| 'nextPurchase', | ||
| 'printBankSlip', | ||
| ].includes(action) | ||
| ) { | ||
| onClick = () => onUpdateAction(action as SubscriptionAction) | ||
| } | ||
|
|
@@ -97,12 +176,30 @@ class ActionBarContainer extends Component<Props> { | |
| displayDanger ? 'c-danger fw5' : 'c-muted-1' | ||
| }`} | ||
| > | ||
| <FormattedMessage id={`details-page.action-bar.label.${action}`} /> | ||
| <FormattedMessage | ||
| id={`details-page.action-bar.label.${action}`} | ||
| values={{ | ||
| numberOfDaysNextPurchase: | ||
| this.props.nextPurchaseDate && | ||
| this.calculateDaysUntilSpecificDate( | ||
| this.props.nextPurchaseDate | ||
| ), | ||
| }} | ||
| /> | ||
| </div> | ||
| <div className="flex items-center flex-wrap justify-between"> | ||
| <div className="t-heading-4 w-100 w-60-ns"> | ||
| <FormattedMessage | ||
| id={`details-page.action-bar.text.${action}`} | ||
| id={ | ||
| action === 'orderDispatched' | ||
| ? `details-page.action-bar.text.${ | ||
| this.getOrderDispatchedAction( | ||
| this.props.orderDeliveryDate, | ||
| this.props.orderTrackingUrl | ||
| ).body | ||
| }` | ||
| : `details-page.action-bar.text.${action}` | ||
| } | ||
| values={{ | ||
| day: ( | ||
| <FormattedDate | ||
|
|
@@ -111,13 +208,35 @@ class ActionBarContainer extends Component<Props> { | |
| day="2-digit" | ||
| /> | ||
| ), | ||
| nextPurchaseDate: ( | ||
| <FormattedDate | ||
| value={this.props.nextPurchaseDate} | ||
| month="long" | ||
| day="2-digit" | ||
| weekday="long" | ||
| /> | ||
| ), | ||
| numberOfDaysNextDelivery: | ||
| this.props.orderDeliveryDate && | ||
| this.calculateDaysUntilSpecificDate( | ||
| this.props.orderDeliveryDate | ||
| ), | ||
| }} | ||
| /> | ||
| </div> | ||
| <div className="mw5-ns w-100 mt4 w-40-ns mt0-ns pl0 pl6-ns"> | ||
| <Button variation={buttonVariation} onClick={onClick} block> | ||
| <FormattedMessage | ||
| id={`details-page.action-bar.button.${action}`} | ||
| id={ | ||
| action === 'orderDispatched' | ||
| ? `details-page.action-bar.button.${ | ||
| this.getOrderDispatchedAction( | ||
| this.props.orderDeliveryDate, | ||
| this.props.orderTrackingUrl | ||
| ).button | ||
| }` | ||
| : `details-page.action-bar.button.${action}` | ||
| } | ||
| /> | ||
| </Button> | ||
| </div> | ||
|
|
@@ -134,6 +253,10 @@ type Props = { | |
| nextPurchaseDate: string | ||
| address: Subscription['shippingAddress'] | ||
| payment: Subscription['purchaseSettings']['paymentMethod'] | ||
| orderStatus: string | undefined | ||
| orderDeliveryDate: string | undefined | ||
| orderTrackingUrl: string | undefined | ||
| bankSlipUrl: string | undefined | ||
|
Comment on lines
+256
to
+259
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe passing the full order to this guy is a better approach instead of multiple props.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. checking DetailsPage, the there are conditions in some parameters.. do you think it's better this way or passes the entire subscription object to handle it inside the action bar? |
||
| onUpdateAction: (action: SubscriptionAction) => void | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -96,9 +96,34 @@ class SubscriptionsDetailsContainer extends Component<Props, State> { | |
| } | ||
|
|
||
| private handleUpdateAction = (action: SubscriptionAction) => { | ||
| const { history, subscription } = this.props | ||
|
|
||
| const orderPackages = | ||
| subscription?.lastExecution?.order?.packageAttachment.packages | ||
| const orderTrackingUrl = | ||
| orderPackages.length > 0 && orderPackages[0].trackingUrl | ||
|
|
||
| const orderTransactions = | ||
| subscription?.lastExecution?.order?.paymentData.transactions | ||
| const orderPayments = | ||
| orderTransactions.length > 0 && orderTransactions[0].payments | ||
| const bankSlipUrl = orderPayments.length > 0 && orderPayments[0].url | ||
|
|
||
| if (action === 'changeAddress' || action === 'changePayment') { | ||
| this.setState({ isEditMode: true }) | ||
| goToElement({ id: PREFERENCES_ID }) | ||
| } else if (action === 'orderDispatched' && !!orderTrackingUrl) { | ||
| window.open(orderTrackingUrl) | ||
|
Comment on lines
+115
to
+116
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Displaying an anchor tag is a better approach instead of calling through javascript and you can do it on the ActionBar component itself instead of doing it on the parent component
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm I get it.. but based on the generic structure defined in this |
||
| } else if ( | ||
| action === 'orderDispatched' && | ||
| !orderTrackingUrl && | ||
| subscription?.lastExecution?.order?.orderId | ||
| ) { | ||
| history.push(`/orders/${subscription.lastExecution.order.orderId}`) | ||
| } else if (action === 'nextPurchase') { | ||
| this.handleChangeEdit(true) | ||
|
Comment on lines
+123
to
+124
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this do? |
||
| } else if (action === 'printBankSlip' && !!bankSlipUrl) { | ||
| window.open(bankSlipUrl) | ||
| } else { | ||
| this.setState({ isModalOpen: true, actionType: action }) | ||
| } | ||
|
|
@@ -189,6 +214,13 @@ class SubscriptionsDetailsContainer extends Component<Props, State> { | |
| errorMessage, | ||
| }) | ||
|
|
||
| const orderPackages = | ||
| subscription.lastExecution?.order?.packageAttachment.packages | ||
| const orderLogisticsInfo = | ||
| subscription.lastExecution?.order?.shippingData.logisticsInfo | ||
| const orderTransactions = | ||
| subscription?.lastExecution?.order?.paymentData?.transactions | ||
|
|
||
| return ( | ||
| <div id={DETAILS_ID}> | ||
| <History | ||
|
|
@@ -219,6 +251,19 @@ class SubscriptionsDetailsContainer extends Component<Props, State> { | |
| payment={subscription.purchaseSettings.paymentMethod} | ||
| onUpdateAction={this.handleUpdateAction} | ||
| nextPurchaseDate={subscription.nextPurchaseDate} | ||
| orderStatus={subscription.lastExecution?.order?.status} | ||
| orderDeliveryDate={ | ||
| subscription.lastExecution?.order?.status === 'invoiced' | ||
| ? orderLogisticsInfo.length > 0 && | ||
| orderLogisticsInfo[0].shippingEstimateDate | ||
| : undefined | ||
| } | ||
| orderTrackingUrl={ | ||
| subscription.lastExecution?.order?.status === 'invoiced' | ||
| ? orderPackages.length > 0 && orderPackages[0].trackingUrl | ||
| : undefined | ||
| } | ||
| bankSlipUrl={orderTransactions?.[0].payments?.[0]?.url} | ||
| /> | ||
| <Products | ||
| subscriptionId={subscription.id} | ||
|
|
@@ -275,7 +320,8 @@ type Props = { | |
| updateStatus: (args: Variables<UpdateStatusArgs>) => Promise<MutationResult> | ||
| } & InjectedRuntimeContext & | ||
| WrappedComponentProps & | ||
| ChildProps | ||
| ChildProps & | ||
| RouteComponentProps | ||
|
|
||
| type InputProps = RouteComponentProps<{ subscriptionId: string }> | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.