-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add shipments
type to ResourceLineItem
component
#445
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably there is no need to re-define the props since you are extending them from
DisplayStatus
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right note.. I'd like to share the same question to you all because we made the same thing for all other dictionaries.. We should review them all..