From c374f2214b62c3187cf42a96ac7009b7447c0fea Mon Sep 17 00:00:00 2001 From: Mohammed Al-yaseen Date: Sun, 5 Oct 2025 19:44:56 +0300 Subject: [PATCH] cart refactor code --- .../cart/components/CartDesktopLayout.tsx | 60 +---------- .../components/CartMobileTabletLayout.tsx | 75 +------------- src/pages/cart/components/CouponCard.tsx | 99 +++++++++++++++++++ 3 files changed, 108 insertions(+), 126 deletions(-) create mode 100644 src/pages/cart/components/CouponCard.tsx diff --git a/src/pages/cart/components/CartDesktopLayout.tsx b/src/pages/cart/components/CartDesktopLayout.tsx index 735f933..4d781d3 100644 --- a/src/pages/cart/components/CartDesktopLayout.tsx +++ b/src/pages/cart/components/CartDesktopLayout.tsx @@ -1,5 +1,5 @@ import styles from "pages/cart/cart.module.css"; -import { Row, Col, Button, Card, Input, Divider, Space, message } from "antd"; +import { Row, Col, Button, Card, Divider, Space, message } from "antd"; import ProTitle from "components/ProTitle.tsx"; import { colors, ProBlack2 } from "ThemeConstants.ts"; import ProText from "components/ProText.tsx"; @@ -11,8 +11,7 @@ import CartActionsButtons from "components/CartActionsButtons/CartActionsButtons import { CartItem } from "utils/types/appTypes.ts"; import ProInputCard from "components/ProInputCard/ProInputCard.tsx"; import { EditOutlined } from "@ant-design/icons"; -import DonateIcon from "components/Icons/cart/DonateIcon.tsx"; -import CouponHeartIcon from "components/Icons/cart/CouponHeart.tsx"; + import DonateHandIcon from "components/Icons/cart/DonateHandIcon.tsx"; import ProInModalMultiSelect from "components/ProSelect/ProInModalMultiSelect.tsx"; import { @@ -20,38 +19,27 @@ import { removeTable, selectCart, selectCartTotal, - updateCoupon, updateTip, } from "features/order/orderSlice.ts"; -import { CouponDialog } from "components/CustomBottomSheet/CouponDialog.tsx"; import { TipDialog } from "components/CustomBottomSheet/TipDialog.tsx"; import { useTranslation } from "react-i18next"; import { useAppSelector, useAppDispatch } from "redux/hooks.ts"; import { useState } from "react"; import { getTableOptions } from "pages/cart/page.tsx"; import SpecialRequestCard from "pages/cart/components/SpecialRequestCard.tsx"; +import CouponCard from "pages/cart/components/CouponCard.tsx"; export default function CartDesktopLayout() { const { t } = useTranslation(); const dispatch = useAppDispatch(); const { themeName } = useAppSelector((state) => state.theme); - const { items, coupon, tip, tables } = useAppSelector(selectCart); + const { items, tip, tables } = useAppSelector(selectCart); const subtotal = useAppSelector(selectCartTotal); const tax = subtotal * 0.1; // 10% tax const total = subtotal + tax; - const [isCouponOpen, setIsCouponOpen] = useState(false); const [isTipOpen, setIsTipOpen] = useState(false); - const handleCouponSave = (value: string) => { - dispatch(updateCoupon(value)); - message.success(t("cart.coupon") + " " + t("updatedSuccessfully")); - }; - - const handleCouponClose = () => { - setIsCouponOpen(false); - }; - const handleTipSave = (value: string) => { dispatch(updateTip(value)); message.success(t("cart.tip") + " " + t("updatedSuccessfully")); @@ -203,46 +191,15 @@ export default function CartDesktopLayout() { {/* Sidebar Column */}
- {/* Special Request */}
- {/* Coupon Code */}
- setIsCouponOpen(true)} - > - {t("viewOffers")} - - } - > - - {t("apply")} - - - } - /> - +
{/* Reward Your Waiter */} @@ -402,13 +359,6 @@ export default function CartDesktopLayout() { {/* Desktop Dialogs */} - - state.theme); const orderType = localStorage.getItem("orderType"); - const [isCouponOpen, setIsCouponOpen] = useState(false); const [estimateWay, setEstimateWay] = useState("now"); const [isEstimateTimeOpen, setIsEstimateTimeOpen] = useState(false); const [isTipOpen, setIsTipOpen] = useState(false); - const handleCouponSave = (value: string) => { - dispatch(updateCoupon(value)); - message.success(t("cart.coupon") + " " + t("updatedSuccessfully")); - }; - - const handleCouponClose = () => { - setIsCouponOpen(false); - }; - const handleTipSave = (value: string) => { dispatch(updateTip(value)); message.success(t("cart.tip") + " " + t("updatedSuccessfully")); @@ -257,56 +244,9 @@ export default function CartMobileTabletLayout() { - {/* Mobile/Tablet layout */} - {/* Special Request */} - {/* Coupon Code */} - setIsCouponOpen(true)} - > - - {t("cart.viewOffers")} - - -
- } - > - - {t("cart.apply")} - - - } - /> - + + {/* Car Plate*/} {orderType === "pickup" && ( @@ -541,13 +481,6 @@ export default function CartMobileTabletLayout() { {/* Mobile/Tablet Bottom Sheets */} - - { + dispatch(updateCoupon(value)); + message.success(t("cart.coupon") + " " + t("updatedSuccessfully")); + }; + + const handleCouponClose = () => { + setIsCouponOpen(false); + }; + + return ( + <> + setIsCouponOpen(true)} + > + + {t("cart.viewOffers")} + + + + } + > + + {t("cart.apply")} + + + } + /> + + {isDesktop ? ( + + ) : ( + + )} + + ); +}