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

Development (#480) #481

Merged
merged 1 commit into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion frontend/src/apis/orderApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
32 changes: 25 additions & 7 deletions frontend/src/components/Cart/ShoppinCartDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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();
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -214,7 +223,16 @@ export const ShoppingCartDetails = () => {
{handleCreateOrder.isLoading ? (
"Creating Order..."
) : (
<>{handleCreateOrder.isError ? <div>An error occurred: {handleCreateOrder.error.message}</div> : null}</>
<>
{handleCreateOrder.isError ? (
<div>
An error occurred:{" "}
{handleCreateOrder.error.response.data.message.message?.length
? handleCreateOrder.error.response.data.message.message.join(",")
: handleCreateOrder.error.response.data.message.error}
</div>
) : null}
</>
)}
{handleCreateOrder.isSuccess ? <div>Order processed successfully</div> : null}
</div>
Expand Down
1 change: 0 additions & 1 deletion frontend/src/utility/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Loading