cart refactor code
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import styles from "pages/cart/cart.module.css";
|
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 ProTitle from "components/ProTitle.tsx";
|
||||||
import { colors, ProBlack2 } from "ThemeConstants.ts";
|
import { colors, ProBlack2 } from "ThemeConstants.ts";
|
||||||
import ProText from "components/ProText.tsx";
|
import ProText from "components/ProText.tsx";
|
||||||
@@ -11,8 +11,7 @@ import CartActionsButtons from "components/CartActionsButtons/CartActionsButtons
|
|||||||
import { CartItem } from "utils/types/appTypes.ts";
|
import { CartItem } from "utils/types/appTypes.ts";
|
||||||
import ProInputCard from "components/ProInputCard/ProInputCard.tsx";
|
import ProInputCard from "components/ProInputCard/ProInputCard.tsx";
|
||||||
import { EditOutlined } from "@ant-design/icons";
|
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 DonateHandIcon from "components/Icons/cart/DonateHandIcon.tsx";
|
||||||
import ProInModalMultiSelect from "components/ProSelect/ProInModalMultiSelect.tsx";
|
import ProInModalMultiSelect from "components/ProSelect/ProInModalMultiSelect.tsx";
|
||||||
import {
|
import {
|
||||||
@@ -20,38 +19,27 @@ import {
|
|||||||
removeTable,
|
removeTable,
|
||||||
selectCart,
|
selectCart,
|
||||||
selectCartTotal,
|
selectCartTotal,
|
||||||
updateCoupon,
|
|
||||||
updateTip,
|
updateTip,
|
||||||
} from "features/order/orderSlice.ts";
|
} from "features/order/orderSlice.ts";
|
||||||
import { CouponDialog } from "components/CustomBottomSheet/CouponDialog.tsx";
|
|
||||||
import { TipDialog } from "components/CustomBottomSheet/TipDialog.tsx";
|
import { TipDialog } from "components/CustomBottomSheet/TipDialog.tsx";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useAppSelector, useAppDispatch } from "redux/hooks.ts";
|
import { useAppSelector, useAppDispatch } from "redux/hooks.ts";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { getTableOptions } from "pages/cart/page.tsx";
|
import { getTableOptions } from "pages/cart/page.tsx";
|
||||||
import SpecialRequestCard from "pages/cart/components/SpecialRequestCard.tsx";
|
import SpecialRequestCard from "pages/cart/components/SpecialRequestCard.tsx";
|
||||||
|
import CouponCard from "pages/cart/components/CouponCard.tsx";
|
||||||
|
|
||||||
export default function CartDesktopLayout() {
|
export default function CartDesktopLayout() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const { themeName } = useAppSelector((state) => state.theme);
|
const { themeName } = useAppSelector((state) => state.theme);
|
||||||
const { items, coupon, tip, tables } = useAppSelector(selectCart);
|
const { items, tip, tables } = useAppSelector(selectCart);
|
||||||
const subtotal = useAppSelector(selectCartTotal);
|
const subtotal = useAppSelector(selectCartTotal);
|
||||||
const tax = subtotal * 0.1; // 10% tax
|
const tax = subtotal * 0.1; // 10% tax
|
||||||
const total = subtotal + tax;
|
const total = subtotal + tax;
|
||||||
|
|
||||||
const [isCouponOpen, setIsCouponOpen] = useState(false);
|
|
||||||
const [isTipOpen, setIsTipOpen] = 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) => {
|
const handleTipSave = (value: string) => {
|
||||||
dispatch(updateTip(value));
|
dispatch(updateTip(value));
|
||||||
message.success(t("cart.tip") + " " + t("updatedSuccessfully"));
|
message.success(t("cart.tip") + " " + t("updatedSuccessfully"));
|
||||||
@@ -203,46 +191,15 @@ export default function CartDesktopLayout() {
|
|||||||
{/* Sidebar Column */}
|
{/* Sidebar Column */}
|
||||||
<Col xs={24} lg={8} xl={7}>
|
<Col xs={24} lg={8} xl={7}>
|
||||||
<div className={styles.desktopSidebar}>
|
<div className={styles.desktopSidebar}>
|
||||||
{/* Special Request */}
|
|
||||||
<div className={styles.desktopSidebarCard}>
|
<div className={styles.desktopSidebarCard}>
|
||||||
<SpecialRequestCard />
|
<SpecialRequestCard />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Coupon Code */}
|
|
||||||
<div
|
<div
|
||||||
className={styles.desktopSidebarCard}
|
className={styles.desktopSidebarCard}
|
||||||
style={{ "--animation-order": 1 } as React.CSSProperties}
|
style={{ "--animation-order": 1 } as React.CSSProperties}
|
||||||
>
|
>
|
||||||
<ProInputCard
|
<CouponCard />
|
||||||
title={t("couponCode")}
|
|
||||||
titleRight={
|
|
||||||
<Button
|
|
||||||
type="link"
|
|
||||||
style={{ color: colors.primary, padding: 0 }}
|
|
||||||
onClick={() => setIsCouponOpen(true)}
|
|
||||||
>
|
|
||||||
{t("viewOffers")} <DonateIcon />
|
|
||||||
</Button>
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<Input
|
|
||||||
placeholder={t("couponCodePlaceholder")}
|
|
||||||
size="large"
|
|
||||||
autoFocus={false}
|
|
||||||
suffix={
|
|
||||||
<Button
|
|
||||||
type="primary"
|
|
||||||
style={{
|
|
||||||
borderRadius: "100px",
|
|
||||||
backgroundColor: colors.primary,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t("apply")}
|
|
||||||
<CouponHeartIcon className={styles.couponApplyIcon} />
|
|
||||||
</Button>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</ProInputCard>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Reward Your Waiter */}
|
{/* Reward Your Waiter */}
|
||||||
@@ -402,13 +359,6 @@ export default function CartDesktopLayout() {
|
|||||||
|
|
||||||
{/* Desktop Dialogs */}
|
{/* Desktop Dialogs */}
|
||||||
|
|
||||||
<CouponDialog
|
|
||||||
isOpen={isCouponOpen}
|
|
||||||
onClose={handleCouponClose}
|
|
||||||
initialValue={coupon}
|
|
||||||
onSave={handleCouponSave}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<TipDialog
|
<TipDialog
|
||||||
isOpen={isTipOpen}
|
isOpen={isTipOpen}
|
||||||
onClose={handleTipClose}
|
onClose={handleTipClose}
|
||||||
|
|||||||
@@ -11,14 +11,11 @@ import ImageWithFallback from "components/ImageWithFallback";
|
|||||||
import CartActionsButtons from "components/CartActionsButtons/CartActionsButtons.tsx";
|
import CartActionsButtons from "components/CartActionsButtons/CartActionsButtons.tsx";
|
||||||
import YouMightAlsoLike from "pages/cart/components/YouMightAlsoLike.tsx";
|
import YouMightAlsoLike from "pages/cart/components/YouMightAlsoLike.tsx";
|
||||||
import ProInputCard from "components/ProInputCard/ProInputCard.tsx";
|
import ProInputCard from "components/ProInputCard/ProInputCard.tsx";
|
||||||
import DonateIcon from "components/Icons/cart/DonateIcon.tsx";
|
|
||||||
import CouponHeartIcon from "components/Icons/cart/CouponHeart.tsx";
|
|
||||||
import ProRatioGroups from "components/ProRatioGroups/ProRatioGroups.tsx";
|
import ProRatioGroups from "components/ProRatioGroups/ProRatioGroups.tsx";
|
||||||
import {
|
import {
|
||||||
updateCollectionMethod,
|
updateCollectionMethod,
|
||||||
updateTables,
|
updateTables,
|
||||||
removeTable,
|
removeTable,
|
||||||
updateCoupon,
|
|
||||||
updateTip,
|
updateTip,
|
||||||
updateEstimateTime,
|
updateEstimateTime,
|
||||||
selectCart,
|
selectCart,
|
||||||
@@ -27,7 +24,6 @@ import DonateHandIcon from "components/Icons/cart/DonateHandIcon.tsx";
|
|||||||
import EditIcon from "components/Icons/EditIcon.tsx";
|
import EditIcon from "components/Icons/EditIcon.tsx";
|
||||||
import ProInModalMultiSelect from "components/ProSelect/ProInModalMultiSelect.tsx";
|
import ProInModalMultiSelect from "components/ProSelect/ProInModalMultiSelect.tsx";
|
||||||
import OrderSummary from "components/OrderSummary/OrderSummary.tsx";
|
import OrderSummary from "components/OrderSummary/OrderSummary.tsx";
|
||||||
import { CouponBottomSheet } from "components/CustomBottomSheet/CouponBottomSheet.tsx";
|
|
||||||
import { TipBottomSheet } from "components/CustomBottomSheet/TipBottomSheet.tsx";
|
import { TipBottomSheet } from "components/CustomBottomSheet/TipBottomSheet.tsx";
|
||||||
import { EstimateTimeBottomSheet } from "components/CustomBottomSheet/EstimateTimeBottomSheet.tsx";
|
import { EstimateTimeBottomSheet } from "components/CustomBottomSheet/EstimateTimeBottomSheet.tsx";
|
||||||
import { getTableOptions } from "pages/cart/page.tsx";
|
import { getTableOptions } from "pages/cart/page.tsx";
|
||||||
@@ -36,11 +32,12 @@ import { useState } from "react";
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import SpecialRequestCard from "pages/cart/components/SpecialRequestCard.tsx";
|
import SpecialRequestCard from "pages/cart/components/SpecialRequestCard.tsx";
|
||||||
import useBreakPoint from "hooks/useBreakPoint.ts";
|
import useBreakPoint from "hooks/useBreakPoint.ts";
|
||||||
|
import CouponCard from "pages/cart/components/CouponCard.tsx";
|
||||||
|
|
||||||
export default function CartMobileTabletLayout() {
|
export default function CartMobileTabletLayout() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const { items, coupon, tip, tables, estimateTimeDate, collectionMethod } =
|
const { items, tip, tables, estimateTimeDate, collectionMethod } =
|
||||||
useAppSelector(selectCart);
|
useAppSelector(selectCart);
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
|
|
||||||
@@ -51,20 +48,10 @@ export default function CartMobileTabletLayout() {
|
|||||||
const { themeName } = useAppSelector((state) => state.theme);
|
const { themeName } = useAppSelector((state) => state.theme);
|
||||||
const orderType = localStorage.getItem("orderType");
|
const orderType = localStorage.getItem("orderType");
|
||||||
|
|
||||||
const [isCouponOpen, setIsCouponOpen] = useState(false);
|
|
||||||
const [estimateWay, setEstimateWay] = useState("now");
|
const [estimateWay, setEstimateWay] = useState("now");
|
||||||
const [isEstimateTimeOpen, setIsEstimateTimeOpen] = useState(false);
|
const [isEstimateTimeOpen, setIsEstimateTimeOpen] = useState(false);
|
||||||
const [isTipOpen, setIsTipOpen] = 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) => {
|
const handleTipSave = (value: string) => {
|
||||||
dispatch(updateTip(value));
|
dispatch(updateTip(value));
|
||||||
message.success(t("cart.tip") + " " + t("updatedSuccessfully"));
|
message.success(t("cart.tip") + " " + t("updatedSuccessfully"));
|
||||||
@@ -257,56 +244,9 @@ export default function CartMobileTabletLayout() {
|
|||||||
|
|
||||||
<YouMightAlsoLike />
|
<YouMightAlsoLike />
|
||||||
|
|
||||||
{/* Mobile/Tablet layout */}
|
|
||||||
{/* Special Request */}
|
|
||||||
<SpecialRequestCard />
|
<SpecialRequestCard />
|
||||||
{/* Coupon Code */}
|
|
||||||
<ProInputCard
|
<CouponCard />
|
||||||
title={t("cart.couponCode")}
|
|
||||||
titleRight={
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: "flex",
|
|
||||||
flexDirection: "row",
|
|
||||||
alignItems: "center",
|
|
||||||
gap: 10,
|
|
||||||
}}
|
|
||||||
onClick={() => setIsCouponOpen(true)}
|
|
||||||
>
|
|
||||||
<ProText
|
|
||||||
style={{
|
|
||||||
color: colors.primary,
|
|
||||||
fontSize: 14,
|
|
||||||
cursor: "pointer",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t("cart.viewOffers")}
|
|
||||||
</ProText>
|
|
||||||
<DonateIcon />
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<Input
|
|
||||||
placeholder={t("cart.couponCode")}
|
|
||||||
size="large"
|
|
||||||
autoFocus={false}
|
|
||||||
style={{ padding: "7px 11px", height: 50 }}
|
|
||||||
suffix={
|
|
||||||
<Button
|
|
||||||
style={{
|
|
||||||
width: 100,
|
|
||||||
height: 32,
|
|
||||||
borderRadius: 100,
|
|
||||||
backgroundColor: "black",
|
|
||||||
color: "white",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t("cart.apply")}
|
|
||||||
<CouponHeartIcon className={styles.couponApplyIcon} />
|
|
||||||
</Button>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</ProInputCard>
|
|
||||||
|
|
||||||
{/* Car Plate*/}
|
{/* Car Plate*/}
|
||||||
{orderType === "pickup" && (
|
{orderType === "pickup" && (
|
||||||
@@ -541,13 +481,6 @@ export default function CartMobileTabletLayout() {
|
|||||||
|
|
||||||
{/* Mobile/Tablet Bottom Sheets */}
|
{/* Mobile/Tablet Bottom Sheets */}
|
||||||
|
|
||||||
<CouponBottomSheet
|
|
||||||
isOpen={isCouponOpen}
|
|
||||||
onClose={handleCouponClose}
|
|
||||||
initialValue={coupon}
|
|
||||||
onSave={handleCouponSave}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<TipBottomSheet
|
<TipBottomSheet
|
||||||
isOpen={isTipOpen}
|
isOpen={isTipOpen}
|
||||||
onClose={handleTipClose}
|
onClose={handleTipClose}
|
||||||
|
|||||||
99
src/pages/cart/components/CouponCard.tsx
Normal file
99
src/pages/cart/components/CouponCard.tsx
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
import { CouponBottomSheet } from "components/CustomBottomSheet/CouponBottomSheet.tsx";
|
||||||
|
import { useAppSelector, useAppDispatch } from "redux/hooks.ts";
|
||||||
|
import { selectCart, updateCoupon } from "features/order/orderSlice.ts";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { message, Input, Button } from "antd";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import ProInputCard from "components/ProInputCard/ProInputCard.tsx";
|
||||||
|
import ProText from "components/ProText.tsx";
|
||||||
|
import { colors } from "ThemeConstants.ts";
|
||||||
|
import DonateIcon from "components/Icons/cart/DonateIcon.tsx";
|
||||||
|
import CouponHeartIcon from "components/Icons/cart/CouponHeart.tsx";
|
||||||
|
import styles from "pages/cart/cart.module.css";
|
||||||
|
import { CouponDialog } from "components/CustomBottomSheet/CouponDialog.tsx";
|
||||||
|
import useBreakPoint from "hooks/useBreakPoint.ts";
|
||||||
|
|
||||||
|
type Props = {};
|
||||||
|
export default function CouponCard({}: Props) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
|
const { coupon } = useAppSelector(selectCart);
|
||||||
|
const { isDesktop } = useBreakPoint();
|
||||||
|
|
||||||
|
const [isCouponOpen, setIsCouponOpen] = useState(false);
|
||||||
|
|
||||||
|
const handleCouponSave = (value: string) => {
|
||||||
|
dispatch(updateCoupon(value));
|
||||||
|
message.success(t("cart.coupon") + " " + t("updatedSuccessfully"));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleCouponClose = () => {
|
||||||
|
setIsCouponOpen(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<ProInputCard
|
||||||
|
title={t("cart.couponCode")}
|
||||||
|
titleRight={
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: 10,
|
||||||
|
}}
|
||||||
|
onClick={() => setIsCouponOpen(true)}
|
||||||
|
>
|
||||||
|
<ProText
|
||||||
|
style={{
|
||||||
|
color: colors.primary,
|
||||||
|
fontSize: 14,
|
||||||
|
cursor: "pointer",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("cart.viewOffers")}
|
||||||
|
</ProText>
|
||||||
|
<DonateIcon />
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Input
|
||||||
|
placeholder={t("cart.couponCode")}
|
||||||
|
size="large"
|
||||||
|
autoFocus={false}
|
||||||
|
style={{ padding: "7px 11px", height: 50 }}
|
||||||
|
suffix={
|
||||||
|
<Button
|
||||||
|
style={{
|
||||||
|
width: 100,
|
||||||
|
height: 32,
|
||||||
|
borderRadius: 100,
|
||||||
|
backgroundColor: "black",
|
||||||
|
color: "white",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("cart.apply")}
|
||||||
|
<CouponHeartIcon className={styles.couponApplyIcon} />
|
||||||
|
</Button>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</ProInputCard>
|
||||||
|
{isDesktop ? (
|
||||||
|
<CouponDialog
|
||||||
|
isOpen={isCouponOpen}
|
||||||
|
onClose={handleCouponClose}
|
||||||
|
initialValue={coupon}
|
||||||
|
onSave={handleCouponSave}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<CouponBottomSheet
|
||||||
|
isOpen={isCouponOpen}
|
||||||
|
onClose={handleCouponClose}
|
||||||
|
initialValue={coupon}
|
||||||
|
onSave={handleCouponSave}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user