From 0657f9e72d4af81eb785cd6bf09479b5e13a86aa Mon Sep 17 00:00:00 2001 From: Oyinlola Olasunkanmi Raymond <60177090+olasunkanmi-SE@users.noreply.github.com> Date: Sat, 20 Jan 2024 16:24:33 +0800 Subject: [PATCH] Development (#480) * include restaurant information as part of the menu response (#471) * include restaurant information as part of the menu response * fix build errors * fix build errors --------- Co-authored-by: Olasunkanmi Oyinlola * 349 place order (#473) * include restaurant information as part of the menu response * fix build errors * fix build errors * fix the create order flow, from frontend to backend --------- Co-authored-by: Olasunkanmi Oyinlola * 349 place order (#476) * 349 place order (#478) * include restaurant information as part of the menu response * fix build errors * fix build errors * fix the create order flow, from frontend to backend * place order, add success animation and clear local storage if the cart has been filled for an hr and more * fix build errors * fix build errors * move the implementation of adding expiry to cart to addItemToCart handler * fix issues with creating notes when none was passwd * npm audit to upgrade packages with issues --------- Co-authored-by: Olasunkanmi Oyinlola * display api error message * display api error message --------- Co-authored-by: Olasunkanmi Oyinlola --- frontend/src/apis/orderApi.ts | 1 - .../components/Cart/ShoppinCartDetails.tsx | 32 +++++++++++++++---- frontend/src/utility/utils.ts | 1 - 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/frontend/src/apis/orderApi.ts b/frontend/src/apis/orderApi.ts index a80a509f..73611089 100644 --- a/frontend/src/apis/orderApi.ts +++ b/frontend/src/apis/orderApi.ts @@ -43,7 +43,6 @@ export const OrderApi = () => { return totalSelectedItemsPrice; }; - const cartItemsMapper = (orderSummary: OrderSummary[]): IcartItems[] => { const menus = orderSummary.flatMap((summary) => summary.menus); const cartItems = menus.map((menu) => { diff --git a/frontend/src/components/Cart/ShoppinCartDetails.tsx b/frontend/src/components/Cart/ShoppinCartDetails.tsx index c70a7bfb..10308100 100644 --- a/frontend/src/components/Cart/ShoppinCartDetails.tsx +++ b/frontend/src/components/Cart/ShoppinCartDetails.tsx @@ -5,7 +5,13 @@ import { useNavigate } from "react-router-dom"; import { CONSTANTS } from "../../constants/constant"; import { useShoppingCart } from "../../hooks/UseShoppingCart"; import { OrderSummary } from "../../reducers"; -import { calculateServiceCharge, calculateTotalOrderAmount, setLocalStorageData, wordWrap } from "../../utility/utils"; +import { + calculateServiceCharge, + calculateTotalOrderAmount, + clearStorage, + setLocalStorageData, + wordWrap, +} from "../../utility/utils"; import { QtyButton } from "../MenuItems/addItemButton"; import { CallToAction } from "../Utilities/modal"; import { CartSelectedItems } from "./CartSelectedItems"; @@ -14,9 +20,6 @@ import { OrderApi } from "../../apis/orderApi"; import useAxiosPrivate from "../../hooks/useAxiosPrivate"; import { useMutation } from "react-query"; import { ICreateOrderDTO } from "../../dto/order"; -import Lottie from "lottie-react"; -import groovyWalkAnimation from "../../assets/animations/1704611321528.json"; -import success from "../../assets/animations/1704612008454.json"; export const ShoppingCartDetails = () => { const navigate = useNavigate(); @@ -88,8 +91,14 @@ export const ShoppingCartDetails = () => { mutationFn: async (order: ICreateOrderDTO) => { return await axios.post("orders/create", order); }, - onSuccess: (data, variables, context) => {}, - onError: (data, variables, context) => {}, + onSuccess: (data) => { + if (data.data.isSuccess) { + resetCart(); + clearStorage(); + closeCart(); + navigate("/"); + } + }, }); return ( @@ -214,7 +223,16 @@ export const ShoppingCartDetails = () => { {handleCreateOrder.isLoading ? ( "Creating Order..." ) : ( - <>{handleCreateOrder.isError ?
An error occurred: {handleCreateOrder.error.message}
: null} + <> + {handleCreateOrder.isError ? ( +
+ An error occurred:{" "} + {handleCreateOrder.error.response.data.message.message?.length + ? handleCreateOrder.error.response.data.message.message.join(",") + : handleCreateOrder.error.response.data.message.error} +
+ ) : null} + )} {handleCreateOrder.isSuccess ?
Order processed successfully
: null} diff --git a/frontend/src/utility/utils.ts b/frontend/src/utility/utils.ts index 5a6bb96f..0ea1856f 100644 --- a/frontend/src/utility/utils.ts +++ b/frontend/src/utility/utils.ts @@ -81,6 +81,5 @@ export const cartExpiry = (date: string): boolean => { const specifiedDate: Date = new Date(date); const timeDifferenceMs: number = new Date().getTime() - specifiedDate.getTime(); const hoursDifference: number = timeDifferenceMs / (1000 * 60 * 60); - console.log(hoursDifference); return hoursDifference > 1; };