From f282b19028cd692cf9ebe0daeef39a0732167279 Mon Sep 17 00:00:00 2001 From: Chan Wen Xu Date: Sun, 19 Feb 2023 03:55:17 +0800 Subject: [PATCH] fix: Add pending payment notice on order summary --- src/pages/Checkout/StripeForm.tsx | 12 +-- src/pages/OrderSummary/OrderSummary.tsx | 123 ++++++++++++++++-------- src/typings/order.tsx | 8 +- src/utils/constants/order-status.ts | 18 ++-- 4 files changed, 99 insertions(+), 62 deletions(-) diff --git a/src/pages/Checkout/StripeForm.tsx b/src/pages/Checkout/StripeForm.tsx index 30a0cb1..e314081 100644 --- a/src/pages/Checkout/StripeForm.tsx +++ b/src/pages/Checkout/StripeForm.tsx @@ -49,17 +49,17 @@ const PaymentForm = () => { status:'error', isClosable: true, }); - return; + return; } - if (result.paymentIntent.status === "requires_payment_method") { - toast({ + if (result.paymentIntent.status === "requires_payment_method") { + toast({ title:'Error', description: "Payment was not successful. Please try again.", status:'error', isClosable: true, - }); - return; - } + }); + return; + } setIsLoading(true); const checkoutCart = await api.postCheckoutCart(cartState.items, cartState.billingEmail, cartState.voucher) const payload : CartAction = { diff --git a/src/pages/OrderSummary/OrderSummary.tsx b/src/pages/OrderSummary/OrderSummary.tsx index 59bb928..0497907 100644 --- a/src/pages/OrderSummary/OrderSummary.tsx +++ b/src/pages/OrderSummary/OrderSummary.tsx @@ -31,7 +31,6 @@ export const OrderSummary: FC = () => { const isMobile: boolean = useBreakpointValue({ base: true, md: false }) || false; const { slug: orderSlug = "" } = useParams(); - const [showThankYou, setShowThankYou] = useState(false); const [orderState, setOrderState] = useState(null); // TODO: Fetch subtotal and total from server. const [total, setTotal] = useState(0); @@ -48,7 +47,6 @@ export const OrderSummary: FC = () => { return item.price * item.quantity + acc; }, 0) ); - setShowThankYou(true); }, } ); @@ -56,7 +54,12 @@ export const OrderSummary: FC = () => { const renderThankYouMessage = () => ( <> THANK YOU - Thank you for your purchase. We have received your order. + + Thank you for your purchase. + {orderState?.status === OrderStatusType.PAYMENT_COMPLETED + ? " We have received your order." + : " Your order has been collected."} + + + + + ); + + const renderStatusMessage = () => { + if (!orderState) return null; + switch (orderState?.status) { + case OrderStatusType.PAYMENT_COMPLETED: + case OrderStatusType.ORDER_COMPLETED: + return renderThankYouMessage(); + case OrderStatusType.PENDING_PAYMENT: + return renderPendingMessage(); + default: + return null; + } + }; + + const renderCollectionQR = () => + + {/* TODO: QR Code generator based on Param. */} + + + Please screenshot this QR code and show it at SCSE Lounge to collect + your order. Alternatively, show the email receipt you have received. + + + For any assistance, please contact our email address: + merch@ntuscse.com + + + const renderOrderSummary = () => ( <> - {showThankYou && renderThankYouMessage()} + {orderState && renderStatusMessage()} { - - {renderOrderStatus(orderState?.status ?? OrderStatusType.DELAY)} + {renderOrderStatus(orderState?.status ?? OrderStatusType.PENDING_PAYMENT)} Order Number @@ -116,12 +181,12 @@ export const OrderSummary: FC = () => { Order Number - - {renderOrderStatus(orderState?.status ?? OrderStatusType.DELAY)} + {renderOrderStatus(orderState?.status ?? OrderStatusType.PENDING_PAYMENT)} @@ -168,33 +233,7 @@ export const OrderSummary: FC = () => { - - {/* TODO: QR Code generator based on Param. */} - - - Please screenshot this QR code and show it at SCSE Lounge to collect your order. - Alternatively, show the email receipt you have received. - - - For any assistance, please contact our email address: - merch@ntuscse.com - - + {orderState?.status === OrderStatusType.PAYMENT_COMPLETED && renderCollectionQR()} ); diff --git a/src/typings/order.tsx b/src/typings/order.tsx index 7d5278e..5f67591 100644 --- a/src/typings/order.tsx +++ b/src/typings/order.tsx @@ -1,10 +1,8 @@ // eslint-disable-next-line no-shadow export enum OrderStatusType { - RECEIVED, - PROCESSING, - READY_TO_COLLECT, - DELAY, - COLLECTED, + PENDING_PAYMENT = 1, + PAYMENT_COMPLETED, + ORDER_COMPLETED, } export type OrderItemType = { diff --git a/src/utils/constants/order-status.ts b/src/utils/constants/order-status.ts index e0c57c1..07837b0 100644 --- a/src/utils/constants/order-status.ts +++ b/src/utils/constants/order-status.ts @@ -2,12 +2,12 @@ import { OrderStatusType } from "../../typings/order"; export const renderOrderStatus = (status: OrderStatusType) => { switch (status) { - case OrderStatusType.COLLECTED: - return "Order Collected"; - case OrderStatusType.PROCESSING: - return "Processing"; - case OrderStatusType.RECEIVED: - return "Order Received"; + case OrderStatusType.PENDING_PAYMENT: + return "Pending Payment"; + case OrderStatusType.PAYMENT_COMPLETED: + return "Payment Completed"; + case OrderStatusType.ORDER_COMPLETED: + return "Order Delivered"; default: return "Item Delayed"; } @@ -15,11 +15,11 @@ export const renderOrderStatus = (status: OrderStatusType) => { export const getOrderStatusColor = (status: OrderStatusType) => { switch (status) { - case OrderStatusType.COLLECTED: + case OrderStatusType.ORDER_COMPLETED: return "green.500"; - case OrderStatusType.PROCESSING: + case OrderStatusType.PAYMENT_COMPLETED: return "primary.400"; - case OrderStatusType.RECEIVED: + case OrderStatusType.PENDING_PAYMENT: return "primary.600"; default: return "red.500";