Skip to content

Commit

Permalink
Hotfix for partially fulfilled events
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzhang1618 committed May 9, 2024
1 parent 958f5e5 commit a74906c
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 47 deletions.
12 changes: 7 additions & 5 deletions src/components/admin/store/PickupOrdersPrepareDisplay/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const PickupOrdersPrepareDisplay = ({ orders }: PickupOrdersDisplayPrepareProps)
const itemBreakdown: PublicOrderItemWithQuantity[] = useMemo(() => {
// Concatenate all items together into one large order to display the item breakdown.
const allItems = orders.flatMap(a => a.items);
return getOrderItemQuantities(allItems);
return getOrderItemQuantities({ items: allItems, ignoreFulfilled: true });
}, [orders]);

return (
Expand Down Expand Up @@ -56,7 +56,9 @@ const PickupOrdersPrepareDisplay = ({ orders }: PickupOrdersDisplayPrepareProps)
<Typography variant="h4/bold">Items</Typography>
</th>
{orders.map(order => {
const itemQuantities = getOrderItemQuantities(order.items);
const itemQuantities = getOrderItemQuantities({
items: order.items,
});
return (
<tr key={order.uuid}>
<td>
Expand All @@ -66,9 +68,9 @@ const PickupOrdersPrepareDisplay = ({ orders }: PickupOrdersDisplayPrepareProps)
<ul className={styles.itemList}>
{itemQuantities.map(item => (
<li key={item.uuid}>
<Typography variant="h5/regular">{`${item.quantity} x ${itemToString(
item
)}`}</Typography>
<Typography variant="h5/regular">{`${item.fulfilled ? '✅' : '❌'} ${
item.quantity
} x ${itemToString(item)}`}</Typography>
</li>
))}
</ul>
Expand Down
89 changes: 48 additions & 41 deletions src/components/store/OrderSummary/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ const isOrderActionable = (status: OrderStatus, pickupEvent: PublicOrderPickupEv
const now = new Date();
const eventStart = new Date(pickupEvent.start);
eventStart.setDate(eventStart.getDate() - 2);
if (
now > eventStart &&
status !== OrderStatus.PICKUP_MISSED &&
status !== OrderStatus.PICKUP_CANCELLED
) {
if (status === OrderStatus.PLACED && now > eventStart) {
return false;
}
return true;
Expand All @@ -48,7 +44,7 @@ const OrderSummary = ({
reschedulePickupEvent,
cancelOrder,
}: OrderSummaryProps) => {
const items = getOrderItemQuantities(order.items);
const items = getOrderItemQuantities({ items: order.items });

const totalCostWithoutDiscount = items.reduce((cost, item) => {
return cost + item.quantity * item.option.price;
Expand All @@ -73,45 +69,56 @@ const OrderSummary = ({
onClose={() => setCancelModalOpen(false)}
cancelOrder={cancelOrder}
/>
{items.map(item => (
<Link
href={`${config.store.itemRoute}${item.option.item.uuid}`}
key={item.uuid}
className={styles.itemInfo}
>
<div className={styles.image}>
<Image
src={getDefaultOrderItemPhoto(item)}
style={{ objectFit: 'cover' }}
sizes="9.375rem"
alt="Store item picture"
fill
/>
</div>
<div className={styles.itemSummary}>
<Typography variant="h4/bold">{item.option.item.itemName}</Typography>
<div className={styles.label}>
<Typography variant="h5/bold">Price: </Typography>
<Diamonds
count={item.option.price * item.quantity}
discount={item.salePriceAtPurchase}
{items.map(item => {
if (item.fulfilled && orderStatus === OrderStatus.PLACED) {
return undefined;
}

const itemName =
orderStatus === OrderStatus.PARTIALLY_FULFILLED
? `${item.option.item.itemName} ${item.fulfilled ? '✅' : '❌'}`
: item.option.item.itemName;

return (
<Link
href={`${config.store.itemRoute}${item.option.item.uuid}`}
key={item.uuid}
className={styles.itemInfo}
>
<div className={styles.image}>
<Image
src={getDefaultOrderItemPhoto(item)}
style={{ objectFit: 'cover' }}
sizes="9.375rem"
alt="Store item picture"
fill
/>
</div>
<div className={styles.label}>
<Typography variant="h5/bold">Quantity: </Typography>
<Typography variant="h5/regular">{item.quantity}</Typography>
</div>
{item.option.metadata ? (
<div className={styles.itemSummary}>
<Typography variant="h4/bold">{itemName}</Typography>
<div className={styles.label}>
<Typography variant="h5/bold">{`${capitalize(
item.option.metadata.type
)}: `}</Typography>
<Typography variant="h5/regular">{item.option.metadata.value}</Typography>
<Typography variant="h5/bold">Price: {`${item.fulfilled}`}</Typography>
<Diamonds
count={item.option.price * item.quantity}
discount={item.salePriceAtPurchase}
/>
</div>
) : null}
</div>
</Link>
))}
<div className={styles.label}>
<Typography variant="h5/bold">Quantity: </Typography>
<Typography variant="h5/regular">{item.quantity}</Typography>
</div>
{item.option.metadata ? (
<div className={styles.label}>
<Typography variant="h5/bold">{`${capitalize(
item.option.metadata.type
)}: `}</Typography>
<Typography variant="h5/regular">{item.option.metadata.value}</Typography>
</div>
) : null}
</div>
</Link>
);
})}
<hr className={styles.divider} />
<div className={styles.footer}>
<div className={styles.buttons}>
Expand Down
12 changes: 11 additions & 1 deletion src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,13 +385,23 @@ export const isOrderPickupEvent = (
event: PublicOrderPickupEvent | PublicEvent
): event is PublicOrderPickupEvent => 'status' in event;

interface getOrderItemQuantitiesParams {
items: PublicOrderItem[];
ignoreFulfilled?: boolean;
}
/**
* Condenses a list of ordered items into unique items with quantities.
*/
export const getOrderItemQuantities = (items: PublicOrderItem[]): PublicOrderItemWithQuantity[] => {
export const getOrderItemQuantities = ({
items,
ignoreFulfilled,
}: getOrderItemQuantitiesParams): PublicOrderItemWithQuantity[] => {
const itemMap = new Map<string, PublicOrderItemWithQuantity>();

items.forEach(item => {
if (ignoreFulfilled && item.fulfilled) {
return;
}
const existingItem = itemMap.get(item.option.uuid);
if (existingItem) {
existingItem.quantity += 1;
Expand Down

0 comments on commit a74906c

Please sign in to comment.