From 3c4be9a81b999753778b46d4f85a99ecacd0ff71 Mon Sep 17 00:00:00 2001 From: Sean Date: Mon, 29 Apr 2024 03:12:06 -0700 Subject: [PATCH] Add fulfill button --- .../PickupOrdersFulfillDisplay/index.tsx | 36 +++++++++++++++++-- src/lib/api/StoreAPI.ts | 21 +++++++++++ src/pages/admin/store/pickup/[uuid].tsx | 16 +++++++-- 3 files changed, 68 insertions(+), 5 deletions(-) diff --git a/src/components/admin/store/PickupOrdersFulfillDisplay/index.tsx b/src/components/admin/store/PickupOrdersFulfillDisplay/index.tsx index 7f759795..9a63a731 100644 --- a/src/components/admin/store/PickupOrdersFulfillDisplay/index.tsx +++ b/src/components/admin/store/PickupOrdersFulfillDisplay/index.tsx @@ -1,16 +1,48 @@ -import { Typography } from '@/components/common'; +import { Button, Typography } from '@/components/common'; +import { StoreAPI } from '@/lib/api'; import { PublicOrderWithItems } from '@/lib/types/apiResponses'; +import { OrderStatus } from '@/lib/types/enums'; +import { reportError } from '@/lib/utils'; interface PickupOrdersFulfillDisplayProps { + token: string; orders: PublicOrderWithItems[]; + onOrderUpdate: (orders: PublicOrderWithItems[]) => void; } -const PickupOrdersFulfillDisplay = ({ orders }: PickupOrdersFulfillDisplayProps) => { +const PickupOrdersFulfillDisplay = ({ + token, + orders, + onOrderUpdate, +}: PickupOrdersFulfillDisplayProps) => { return (
{orders.map(order => (
{`${order.user.firstName} ${order.user.lastName} (${order.status})`} + {order.status === OrderStatus.PLACED || + order.status === OrderStatus.PARTIALLY_FULFILLED ? ( + + ) : null}
))}
diff --git a/src/lib/api/StoreAPI.ts b/src/lib/api/StoreAPI.ts index d1a0eda9..8fa7e963 100644 --- a/src/lib/api/StoreAPI.ts +++ b/src/lib/api/StoreAPI.ts @@ -6,11 +6,13 @@ import { CreateMerchItemRequest, EditMerchCollectionRequest, EditMerchItemRequest, + FulfillMerchOrderRequest, MerchCollection, MerchCollectionEdit, MerchItem, MerchItemEdit, MerchItemOption, + OrderItemFulfillmentUpdate, PlaceMerchOrderRequest, RescheduleOrderPickupRequest, } from '@/lib/types/apiRequests'; @@ -25,6 +27,7 @@ import type { DeleteMerchItemResponse, EditMerchCollectionResponse, EditMerchItemResponse, + FulfillMerchOrderResponse, GetAllMerchCollectionsResponse, GetMerchOrdersResponse, GetOneMerchCollectionResponse, @@ -429,6 +432,24 @@ export const getPastOrderPickupEvents = async ( return response.data.pickupEvents; }; +export const fulfillOrderPickup = async ( + token: string, + order: UUID, + items: OrderItemFulfillmentUpdate[] +): Promise => { + const requestUrl = `${config.api.baseUrl}${config.api.endpoints.store.order}/${order}/fulfill`; + + const requestBody: FulfillMerchOrderRequest = { items }; + + const response = await axios.post(requestUrl, requestBody, { + headers: { + Authorization: `Bearer ${token}`, + }, + }); + + return response.data.order; +}; + export const rescheduleOrderPickup = async ( token: string, order: string, diff --git a/src/pages/admin/store/pickup/[uuid].tsx b/src/pages/admin/store/pickup/[uuid].tsx index 2dcea7a8..852fd693 100644 --- a/src/pages/admin/store/pickup/[uuid].tsx +++ b/src/pages/admin/store/pickup/[uuid].tsx @@ -27,15 +27,25 @@ interface PickupEventDetailsPageProps { } const PickupEventDetailsPage = ({ pickupEvent, token }: PickupEventDetailsPageProps) => { - const { uuid, status, title, start, end, orderLimit, description, linkedEvent, orders } = - pickupEvent; + const { + uuid, + status, + title, + start, + end, + orderLimit, + description, + linkedEvent, + orders: initOrders, + } = pickupEvent; + const [orders, setOrders] = useState(initOrders); const [ordersView, setOrdersView] = useState<'fulfill' | 'prepare'>('fulfill'); let ordersComponent; if (orders && orders.length > 0) ordersComponent = ordersView === 'fulfill' ? ( - + ) : ( );