Skip to content

Commit

Permalink
chore: remove order trigger attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomontalbano committed Nov 16, 2023
1 parent 767c8e5 commit 8322e8a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 68 deletions.
82 changes: 16 additions & 66 deletions packages/app-elements/src/dictionaries/orders.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,14 @@
import type { TriggerAttribute } from '#helpers/resources'
import type { IconProps } from '#ui/atoms/Icon'
import type { Order, OrderUpdate } from '@commercelayer/sdk'
import type { Order } from '@commercelayer/sdk'
import type { DisplayStatus } from './types'

type UITriggerAttributes =
| Extract<
TriggerAttribute<OrderUpdate>,
| '_approve'
| '_cancel'
| '_capture'
| '_refund'
| '_archive'
| '_unarchive'
>
| '_return'
export interface OrderDisplayStatus extends DisplayStatus {
label: string
icon: IconProps['name']
color: IconProps['background']
task?: string
triggerAttributes: UITriggerAttributes[]
}

export function getOrderDisplayStatus(order: Order): OrderDisplayStatus {
const archiveTriggerAttribute: Extract<
UITriggerAttributes,
'_archive' | '_unarchive'
> = order.archived_at == null ? '_archive' : '_unarchive'

const combinedStatus =
`${order.status}:${order.payment_status}:${order.fulfillment_status}` as const

Expand All @@ -36,8 +17,7 @@ export function getOrderDisplayStatus(order: Order): OrderDisplayStatus {
label: 'Editing',
icon: 'pencilSimple',
color: 'orange',
task: 'Editing',
triggerAttributes: []
task: 'Editing'
}
}

Expand All @@ -54,17 +34,15 @@ export function getOrderDisplayStatus(order: Order): OrderDisplayStatus {
label: 'Placed',
icon: 'arrowDown',
color: 'orange',
task: 'Awaiting approval',
triggerAttributes: ['_approve', '_cancel']
task: 'Awaiting approval'
}

case 'placed:unpaid:unfulfilled':
return {
label: 'Placed',
icon: 'x',
color: 'red',
task: 'Error to cancel',
triggerAttributes: ['_cancel']
task: 'Error to cancel'
}

case 'approved:authorized:unfulfilled':
Expand All @@ -73,8 +51,7 @@ export function getOrderDisplayStatus(order: Order): OrderDisplayStatus {
label: 'Approved',
icon: 'creditCard',
color: 'orange',
task: 'Payment to capture',
triggerAttributes: ['_capture']
task: 'Payment to capture'
}

case 'approved:paid:in_progress':
Expand All @@ -83,59 +60,52 @@ export function getOrderDisplayStatus(order: Order): OrderDisplayStatus {
label: 'In progress',
icon: 'arrowClockwise',
color: 'orange',
task: 'Fulfillment in progress',
triggerAttributes: ['_refund']
task: 'Fulfillment in progress'
}

case 'approved:authorized:in_progress':
return {
label: 'In progress (Manual)',
icon: 'arrowClockwise',
color: 'orange',
task: 'Fulfillment in progress',
triggerAttributes: ['_capture']
task: 'Fulfillment in progress'
}

case 'approved:paid:fulfilled':
return {
label: 'Fulfilled',
icon: 'check',
color: 'green',
triggerAttributes: ['_refund', '_return', archiveTriggerAttribute]
color: 'green'
}

// TODO: This could be a gift-card and what If i do return?
case 'approved:free:fulfilled':
return {
label: 'Fulfilled',
icon: 'check',
color: 'green',
triggerAttributes: ['_return', archiveTriggerAttribute]
color: 'green'
}

case 'approved:paid:not_required':
case 'approved:partially_refunded:not_required':
return {
label: 'Approved',
icon: 'check',
color: 'green',
triggerAttributes: ['_refund', archiveTriggerAttribute]
color: 'green'
}

case 'approved:free:not_required':
return {
label: 'Approved',
icon: 'check',
color: 'green',
triggerAttributes: [archiveTriggerAttribute]
color: 'green'
}

case 'approved:partially_refunded:fulfilled':
return {
label: 'Part. refunded',
icon: 'check',
color: 'green',
triggerAttributes: ['_refund', '_return', archiveTriggerAttribute]
color: 'green'
}

case 'cancelled:voided:unfulfilled':
Expand All @@ -146,16 +116,14 @@ export function getOrderDisplayStatus(order: Order): OrderDisplayStatus {
return {
label: 'Cancelled',
icon: 'x',
color: 'gray',
triggerAttributes: [archiveTriggerAttribute]
color: 'gray'
}

case 'cancelled:refunded:fulfilled':
return {
label: 'Cancelled',
icon: 'x',
color: 'gray',
triggerAttributes: ['_return', archiveTriggerAttribute]
color: 'gray'
}

case 'pending:unpaid:unfulfilled':
Expand All @@ -164,16 +132,14 @@ export function getOrderDisplayStatus(order: Order): OrderDisplayStatus {
return {
label: 'Pending',
icon: 'shoppingBag',
color: 'white',
triggerAttributes: []
color: 'white'
}

default:
return {
label: `Not handled: (${combinedStatus})`,
icon: 'warning',
color: 'white',
triggerAttributes: []
color: 'white'
}
}
}
Expand Down Expand Up @@ -235,19 +201,3 @@ export function getOrderFulfillmentStatusName(

return dictionary[status]
}

export function getOrderTriggerAttributeName(
triggerAttribute: UITriggerAttributes
): string {
const dictionary: Record<typeof triggerAttribute, string> = {
_approve: 'Approve',
_archive: 'Archive',
_cancel: 'Cancel',
_capture: 'Capture payment',
_refund: 'Refund',
_return: 'Return',
_unarchive: 'Unarchive'
}

return dictionary[triggerAttribute]
}
3 changes: 1 addition & 2 deletions packages/app-elements/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,7 @@ export {
getOrderFulfillmentStatusName,
getOrderPaymentStatusName,
getOrderStatusName,
getOrderTransactionPastTense,
getOrderTriggerAttributeName
getOrderTransactionPastTense
} from '#dictionaries/orders'
export {
getReturnDisplayStatus,
Expand Down

0 comments on commit 8322e8a

Please sign in to comment.