-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move order row to separate component
- Loading branch information
1 parent
4aa2379
commit 7629d92
Showing
7 changed files
with
117 additions
and
88 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,69 @@ | ||
import { Button, Typography } from '@/components/common'; | ||
import { OrderStatusIndicator } from '@/components/store'; | ||
import { StoreAPI } from '@/lib/api'; | ||
import { PublicOrderItemWithQuantity, PublicOrderWithItems } from '@/lib/types/apiResponses'; | ||
import { OrderStatus } from '@/lib/types/enums'; | ||
import { getOrderItemQuantities, reportError } from '@/lib/utils'; | ||
import styles from './style.module.scss'; | ||
|
||
interface PickupOrderProps { | ||
token: string; | ||
canFulfill: boolean; | ||
order: PublicOrderWithItems; | ||
onOrderUpdate: (orders: PublicOrderWithItems) => void; | ||
} | ||
|
||
const itemToString = (item: PublicOrderItemWithQuantity): string => { | ||
if (item.option.metadata !== null) | ||
return `${item.option.item.itemName} (${item.option.metadata.type}: ${item.option.metadata.value})`; | ||
return item.option.item.itemName; | ||
}; | ||
|
||
const PickupOrder = ({ token, canFulfill, order, onOrderUpdate }: PickupOrderProps) => { | ||
const showFulfill = canFulfill && order.status === OrderStatus.PLACED; | ||
const itemQuantities = getOrderItemQuantities(order.items); | ||
return ( | ||
<tr className={styles.row}> | ||
<td> | ||
<Typography variant="h5/regular">{`${order.user.firstName} ${order.user.lastName}`}</Typography> | ||
<OrderStatusIndicator orderStatus={order.status} /> | ||
{showFulfill && itemQuantities.length > 1 ? ( | ||
<Button | ||
size="small" | ||
onClick={async () => { | ||
try { | ||
const newOrder = await StoreAPI.fulfillOrderPickup(token, order.uuid, order.items); | ||
const itemUuids = order.items.map(item => item.uuid); | ||
onOrderUpdate({ | ||
...newOrder, | ||
items: order.items.map(item => | ||
itemUuids.includes(item.uuid) ? { ...item, fulfilled: true } : item | ||
), | ||
}); | ||
} catch (error: unknown) { | ||
reportError('Failed to fulfill order', error); | ||
} | ||
}} | ||
> | ||
Fulfill | ||
</Button> | ||
) : null} | ||
</td> | ||
<td> | ||
<ul className={styles.itemList}> | ||
{itemQuantities.map(item => { | ||
return ( | ||
<li key={item.uuid}> | ||
<Typography variant="h5/regular">{`${item.quantity} x ${itemToString( | ||
item | ||
)}`}</Typography> | ||
</li> | ||
); | ||
})} | ||
</ul> | ||
</td> | ||
</tr> | ||
); | ||
}; | ||
|
||
export default PickupOrder; |
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,18 @@ | ||
.row { | ||
border-top: 1px solid var(--theme-accent-line-2); | ||
|
||
td { | ||
padding: 1.5rem; | ||
} | ||
|
||
.itemList { | ||
list-style-type: disc; | ||
|
||
li { | ||
align-items: center; | ||
display: flex; | ||
flex-wrap: wrap; | ||
gap: 10px; | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/components/admin/store/PickupOrder/style.module.scss.d.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export type Styles = { | ||
itemList: string; | ||
row: string; | ||
}; | ||
|
||
export type ClassNames = keyof Styles; | ||
|
||
declare const styles: Styles; | ||
|
||
export default styles; |
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: 0 additions & 1 deletion
1
src/components/admin/store/PickupOrdersPrepareDisplay/style.module.scss.d.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
export type Styles = { | ||
breakdown: string; | ||
container: string; | ||
itemList: string; | ||
table: string; | ||
}; | ||
|
||
|
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