Skip to content
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

Hotfix for partially fulfilled events #252

Merged
merged 4 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ? '✅' : '❌'} ${
alexzhang1618 marked this conversation as resolved.
Show resolved Hide resolved
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) {
alexzhang1618 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading