-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ResourceLineItem of type shipments
- Loading branch information
Showing
8 changed files
with
256 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import { type IconProps } from '#ui/atoms/Icon' | ||
import type { Shipment } from '@commercelayer/sdk' | ||
import type { DisplayStatus } from './types' | ||
|
||
export interface ShipmentDisplayStatus extends DisplayStatus { | ||
label: string | ||
icon: IconProps['name'] | ||
color: IconProps['background'] | ||
task?: string | ||
} | ||
|
||
export function getShipmentDisplayStatus( | ||
shipment: Shipment, | ||
awaitingStockTransfer: boolean = false | ||
): ShipmentDisplayStatus { | ||
const shipmentStatus = awaitingStockTransfer | ||
? 'awaiting_stock_transfer' | ||
: shipment.status | ||
|
||
switch (shipmentStatus) { | ||
case 'upcoming': | ||
return { | ||
label: 'Upcoming', | ||
icon: 'truck', | ||
color: 'gray' | ||
} | ||
|
||
case 'cancelled': | ||
return { | ||
label: 'Cancelled', | ||
icon: 'x', | ||
color: 'gray' | ||
} | ||
|
||
case 'draft': | ||
return { | ||
label: 'Draft', | ||
icon: 'minus', | ||
color: 'gray' | ||
} | ||
|
||
case 'on_hold': | ||
return { | ||
label: 'On hold', | ||
icon: 'hourglass', | ||
color: 'orange', | ||
task: 'On hold' | ||
} | ||
|
||
case 'packing': | ||
return { | ||
label: 'Packing', | ||
icon: 'package', | ||
color: 'orange', | ||
task: 'Packing' | ||
} | ||
|
||
case 'picking': | ||
return { | ||
label: 'Picking', | ||
icon: 'arrowDown', | ||
color: 'orange', | ||
task: 'Picking' | ||
} | ||
|
||
case 'ready_to_ship': | ||
return { | ||
label: 'Ready to ship', | ||
icon: 'arrowUpRight', | ||
color: 'orange', | ||
task: 'Ready to ship' | ||
} | ||
|
||
case 'shipped': | ||
return { | ||
label: 'Shipped', | ||
icon: 'check', | ||
color: 'green' | ||
} | ||
|
||
case 'awaiting_stock_transfer': | ||
return { | ||
label: 'Awaiting stock transfers', | ||
icon: 'hourglass', | ||
color: 'orange', | ||
task: 'Awaiting stock transfers' | ||
} | ||
|
||
default: | ||
return { | ||
label: `Not handled: (${shipment.status})`, | ||
icon: 'warning', | ||
color: 'white' | ||
} | ||
} | ||
} | ||
|
||
export function getShipmentStatusName(status: Shipment['status']): string { | ||
const dictionary: Record<typeof status, string> = { | ||
draft: 'Draft', | ||
on_hold: 'On hold', | ||
upcoming: 'Upcoming', | ||
packing: 'Packing', | ||
picking: 'Picking', | ||
ready_to_ship: 'Ready to ship', | ||
shipped: 'Shipped', | ||
cancelled: 'Cancelled' | ||
} | ||
|
||
return dictionary[status] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/app-elements/src/ui/resources/ResourceListItem/transformers/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export { customerToProps } from './customers' | ||
export { orderToProps } from './orders' | ||
export { returnToProps } from './returns' | ||
export { shipmentToProps } from './shipments' | ||
export { stockTransferToProps } from './stockTransfers' |
42 changes: 42 additions & 0 deletions
42
packages/app-elements/src/ui/resources/ResourceListItem/transformers/shipments.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { getShipmentDisplayStatus } from '#dictionaries/shipments' | ||
import { RadialProgress } from '#ui/atoms/RadialProgress' | ||
import { | ||
ListItemDescription, | ||
ListItemIcon | ||
} from '#ui/resources/ResourceListItem/common' | ||
import type { Shipment } from '@commercelayer/sdk' | ||
import { type ResourceToProps } from '../types' | ||
|
||
export const shipmentToProps: ResourceToProps<Shipment> = ({ | ||
resource, | ||
user | ||
}) => { | ||
const awaitingStockTransfer = | ||
resource.stock_transfers != null && resource.stock_transfers.length > 0 | ||
const displayStatus = getShipmentDisplayStatus( | ||
resource, | ||
awaitingStockTransfer | ||
) | ||
const returnStockLocationName = | ||
resource.stock_location?.name != null | ||
? `From ${resource.stock_location.name} ` | ||
: '' | ||
const number = resource.number != null ? `#${resource.number}` : '' | ||
|
||
return { | ||
name: `Shipment ${number}`, | ||
description: ( | ||
<ListItemDescription | ||
displayStatus={displayStatus} | ||
date={resource.updated_at} | ||
additionalInfos={returnStockLocationName} | ||
/> | ||
), | ||
icon: | ||
!awaitingStockTransfer && resource.status === 'upcoming' ? ( | ||
<RadialProgress icon='truck' /> | ||
) : ( | ||
<ListItemIcon icon={displayStatus.icon} color={displayStatus.color} /> | ||
) | ||
} | ||
} |
15 changes: 13 additions & 2 deletions
15
packages/app-elements/src/ui/resources/ResourceListItem/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters