From d7a56ba9299e90b0dd5482bb939b0bccb9089226 Mon Sep 17 00:00:00 2001 From: Mohammed Al-yaseen Date: Wed, 5 Nov 2025 19:05:10 +0300 Subject: [PATCH] enhance loyalty card --- src/components/LoyaltyCard/LoyaltyCard.tsx | 115 ++++++++++--------- src/components/OrderSummary/OrderSummary.tsx | 31 +++-- src/features/order/orderSlice.ts | 2 +- 3 files changed, 80 insertions(+), 68 deletions(-) diff --git a/src/components/LoyaltyCard/LoyaltyCard.tsx b/src/components/LoyaltyCard/LoyaltyCard.tsx index 7744481..aca8b14 100644 --- a/src/components/LoyaltyCard/LoyaltyCard.tsx +++ b/src/components/LoyaltyCard/LoyaltyCard.tsx @@ -19,6 +19,7 @@ const LoyaltyCard = () => { (restaurant?.customer_loyalty_points || 0) <= 0; + return (
@@ -35,62 +36,64 @@ const LoyaltyCard = () => {
)} - - - - - - - - - {t("menu.loyaltyPoints")} - - - - - {token && - t("menu.loyaltyDescription", { - value: restaurant?.loyalty_stamps ?? 0, - })} - {!token && ( -
- - {t("menu.joinUs")} - - - {t("menu.joinUsDescription")} - -
- )} -
- - - - -
- {token && ( + {!isHasLoyaltyGift && ( + + + + + + + + + {t("menu.loyaltyPoints")} + + + + + {token && + t("menu.loyaltyDescription", { + value: restaurant?.loyalty_stamps ?? 0, + })} + {!token && ( +
+ + {t("menu.joinUs")} + + + {t("menu.joinUsDescription")} + +
+ )} +
+ + + + +
+ )} + {token && !isHasLoyaltyGift && (
diff --git a/src/components/OrderSummary/OrderSummary.tsx b/src/components/OrderSummary/OrderSummary.tsx index 0aced66..5896860 100644 --- a/src/components/OrderSummary/OrderSummary.tsx +++ b/src/components/OrderSummary/OrderSummary.tsx @@ -11,6 +11,7 @@ import { } from "features/order/orderSlice"; import { OrderType } from "pages/checkout/hooks/types"; import { useTranslation } from "react-i18next"; +import { useParams } from "react-router-dom"; import { useGetRestaurantDetailsQuery } from "redux/api/others"; import { useAppDispatch, useAppSelector } from "redux/hooks"; import ProText from "../ProText"; @@ -20,7 +21,8 @@ import styles from "./OrderSummary.module.css"; export default function OrderSummary() { const { t } = useTranslation(); const { useLoyaltyPoints } = useAppSelector(selectCart); - const { data: restaurant } = useGetRestaurantDetailsQuery("595"); + const { subdomain } = useParams(); + const { data: restaurant } = useGetRestaurantDetailsQuery(subdomain); const { orderType } = useAppSelector(selectCart); const dispatch = useAppDispatch(); const subtotal = useAppSelector(selectCartTotal); @@ -53,7 +55,11 @@ export default function OrderSummary() {
{t("cart.discount")}
@@ -69,7 +75,7 @@ export default function OrderSummary() {
- {isHasLoyaltyGift && ( + {isHasLoyaltyGift && restaurant?.is_loyalty_enabled === 1 && ( <>

@@ -90,14 +96,17 @@ export default function OrderSummary() {
)} - {isHasLoyaltyGift && useLoyaltyPoints && highestLoyaltyItem && ( -
- {t("cart.loyaltyDiscountApplied", { - itemName: highestLoyaltyItem.name, - amount: Math.round(highestLoyaltyItem.price || 0).toFixed(2), - })} -
- )} + {isHasLoyaltyGift && + useLoyaltyPoints && + highestLoyaltyItem && + restaurant?.is_loyalty_enabled === 1 && ( +
+ {t("cart.loyaltyDiscountApplied", { + itemName: highestLoyaltyItem.name, + amount: Math.round(highestLoyaltyItem.price || 0).toFixed(2), + })} +
+ )} ); diff --git a/src/features/order/orderSlice.ts b/src/features/order/orderSlice.ts index c02a2a9..f2506a7 100644 --- a/src/features/order/orderSlice.ts +++ b/src/features/order/orderSlice.ts @@ -653,7 +653,7 @@ export const selectGrandTotal = (state: RootState) => { return ( subtotal + taxAmount - - (state.order.useLoyaltyPoints ? loyaltyDiscount : 0) + + (state.order.useLoyaltyPoints && state.order.restaurant?.is_loyalty_enabled === 1 ? loyaltyDiscount : 0) + deliveryFee );};