Skip to content

Commit

Permalink
Update user-facing style to be aligned with Amy's design
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzhang1618 committed May 10, 2024
1 parent 1395354 commit 187c9eb
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 67 deletions.
168 changes: 103 additions & 65 deletions src/components/store/OrderSummary/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@ import PickupEventPreviewModal from '@/components/store/PickupEventPreviewModal'
import { config } from '@/lib';
import { PublicOrderPickupEvent, PublicOrderWithItems } from '@/lib/types/apiResponses';
import { OrderStatus } from '@/lib/types/enums';
import { capitalize, getDefaultOrderItemPhoto, getOrderItemQuantities } from '@/lib/utils';
import {
OrderItemQuantity,
capitalize,
getDefaultOrderItemPhoto,
getOrderItemQuantities,
} from '@/lib/utils';
import Image from 'next/image';
import Link from 'next/link';
import { useState } from 'react';
import styles from './style.module.scss';

interface OrderSummaryProps {
order: PublicOrderWithItems;
orderStatus: OrderStatus;
futurePickupEvents: PublicOrderPickupEvent[];
pickupEvent: PublicOrderPickupEvent;
reschedulePickupEvent: (pickup: PublicOrderPickupEvent) => Promise<void>;
cancelOrder: () => Promise<void>;
}

const isOrderActionable = (status: OrderStatus, pickupEvent: PublicOrderPickupEvent): boolean => {
if (status === OrderStatus.CANCELLED || status === OrderStatus.FULFILLED) {
// If the order is cancelled by the user or fulfilled, no further action can be taken.
Expand All @@ -36,6 +32,102 @@ const isOrderActionable = (status: OrderStatus, pickupEvent: PublicOrderPickupEv
return true;
};

interface OrderItemPreviewProps {
item: OrderItemQuantity;
orderStatus: OrderStatus;
}

const OrderItemPreview = ({ item, orderStatus }: OrderItemPreviewProps) => {
if (item.fulfilled && orderStatus === OrderStatus.PLACED) {
/*
* When a partially fulfilled order is rescheduled,
* the status is changed to PLACED, but all items remain (some as fulfilled).
* These items should be hidden.
*/
return null;
}

return (
<Link href={`${config.store.itemRoute}${item.option.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} />
</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.label}>
<Typography variant="h5/bold">{`${capitalize(
item.option.metadata.type
)}: `}</Typography>
<Typography variant="h5/regular">{item.option.metadata.value}</Typography>
</div>
) : null}
</div>
</Link>
);
};

interface OrderItemsSummaryProps {
items: OrderItemQuantity[];
orderStatus: OrderStatus;
}

const OrderItemsSummary = ({ items, orderStatus }: OrderItemsSummaryProps) => {
if (orderStatus !== OrderStatus.PARTIALLY_FULFILLED) {
return (
<>
{items.map(item => (
<OrderItemPreview item={item} orderStatus={orderStatus} key={item.uuids[0]} />
))}
</>
);
}
const pickedUpItems = items.filter(item => item.fulfilled);
const notPickedUpItems = items.filter(item => !item.fulfilled);

return (
<div>
<Typography variant="h3/bold" className={styles.partiallyFulfilledText}>
Items Picked Up:
</Typography>
{pickedUpItems.map(item => (
<OrderItemPreview item={item} orderStatus={orderStatus} key={item.uuids[0]} />
))}

<hr className={styles.divider} />
<Typography variant="h3/bold" className={styles.partiallyFulfilledText}>
Awaiting Pickup:
</Typography>
{notPickedUpItems.map(item => (
<OrderItemPreview item={item} orderStatus={orderStatus} key={item.uuids[0]} />
))}
</div>
);
};

interface OrderSummaryProps {
order: PublicOrderWithItems;
orderStatus: OrderStatus;
futurePickupEvents: PublicOrderPickupEvent[];
pickupEvent: PublicOrderPickupEvent;
reschedulePickupEvent: (pickup: PublicOrderPickupEvent) => Promise<void>;
cancelOrder: () => Promise<void>;
}

const OrderSummary = ({
order,
orderStatus,
Expand Down Expand Up @@ -69,61 +161,7 @@ const OrderSummary = ({
onClose={() => setCancelModalOpen(false)}
cancelOrder={cancelOrder}
/>
{items.map(item => {
if (item.fulfilled && orderStatus === OrderStatus.PLACED) {
/*
* When a partially fulfilled order is rescheduled,
* the status is changed to PLACED, but all items remain (some as fulfilled).
* These items should be hidden.
*/
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.uuids[0]}
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">{itemName}</Typography>
<div className={styles.label}>
<Typography variant="h5/bold">Price: </Typography>
<Diamonds
count={item.option.price * item.quantity}
discount={item.salePriceAtPurchase}
/>
</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.label}>
<Typography variant="h5/bold">{`${capitalize(
item.option.metadata.type
)}: `}</Typography>
<Typography variant="h5/regular">{item.option.metadata.value}</Typography>
</div>
) : null}
</div>
</Link>
);
})}
<OrderItemsSummary items={items} orderStatus={orderStatus} />
<hr className={styles.divider} />
<div className={styles.footer}>
<div className={styles.buttons}>
Expand Down
7 changes: 5 additions & 2 deletions src/components/store/OrderSummary/style.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
.container {
margin-top: 0.75rem;

.partiallyFulfilledText {
padding: 0.75rem 1.5rem;
}

.itemInfo {
display: flex;
flex-direction: row;
Expand Down Expand Up @@ -36,8 +40,7 @@
.divider {
border-top: 1px solid var(--theme-elevated-stroke);
height: 0.1rem;
margin: 0 1rem;
margin-top: 0.75rem;
margin: 0.75rem 1rem;
width: auto;
}

Expand Down
1 change: 1 addition & 0 deletions src/components/store/OrderSummary/style.module.scss.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type Styles = {
itemInfo: string;
itemSummary: string;
label: string;
partiallyFulfilledText: string;
totalDiamonds: string;
totalPrice: string;
};
Expand Down

0 comments on commit 187c9eb

Please sign in to comment.