Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzhang1618 committed May 10, 2024
1 parent 187c9eb commit 7c1c18e
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/components/admin/store/PickupOrdersPrepareDisplay/index.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { Typography } from '@/components/common';
import { PublicOrderItemWithQuantity, PublicOrderWithItems } from '@/lib/types/apiResponses';
import { getOrderItemQuantities } from '@/lib/utils';
import { PublicOrderWithItems } from '@/lib/types/apiResponses';
import { OrderItemQuantity, getOrderItemQuantities } from '@/lib/utils';
import { useMemo } from 'react';
import styles from './style.module.scss';

interface PickupOrdersDisplayPrepareProps {
orders: PublicOrderWithItems[];
}

const itemToString = (item: PublicOrderItemWithQuantity): string => {
const itemToString = (item: OrderItemQuantity): 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 PickupOrdersPrepareDisplay = ({ orders }: PickupOrdersDisplayPrepareProps) => {
const itemBreakdown: PublicOrderItemWithQuantity[] = useMemo(() => {
const itemBreakdown: OrderItemQuantity[] = useMemo(() => {
// Concatenate all items together into one large order to display the item breakdown.
const allItems = orders.flatMap(a => a.items);
return getOrderItemQuantities({ items: allItems, ignoreFulfilled: true });
return getOrderItemQuantities(allItems);
}, [orders]);

return (
Expand All @@ -34,7 +34,7 @@ const PickupOrdersPrepareDisplay = ({ orders }: PickupOrdersDisplayPrepareProps)
</th>
{itemBreakdown.map(item => {
return (
<tr key={item.uuid}>
<tr key={item.uuids[0]}>
<td>
<Typography variant="h5/regular">{item.quantity}</Typography>
</td>
Expand All @@ -56,9 +56,7 @@ const PickupOrdersPrepareDisplay = ({ orders }: PickupOrdersDisplayPrepareProps)
<Typography variant="h4/bold">Items</Typography>
</th>
{orders.map(order => {
const itemQuantities = getOrderItemQuantities({
items: order.items,
});
const itemQuantities = getOrderItemQuantities(order.items);
return (
<tr key={order.uuid}>
<td>
Expand All @@ -67,7 +65,7 @@ const PickupOrdersPrepareDisplay = ({ orders }: PickupOrdersDisplayPrepareProps)
<td>
<ul className={styles.itemList}>
{itemQuantities.map(item => (
<li key={item.uuid}>
<li key={item.uuids[0]}>
<Typography variant="h5/regular">{`${item.fulfilled ? '✅' : '❌'} ${
item.quantity
} x ${itemToString(item)}`}</Typography>
Expand Down

0 comments on commit 7c1c18e

Please sign in to comment.