diff --git a/src/assets/locals/ar.json b/src/assets/locals/ar.json index 2371950..b1dea44 100644 --- a/src/assets/locals/ar.json +++ b/src/assets/locals/ar.json @@ -170,7 +170,15 @@ "justXMorePurchasesToUnlockYourFREEItem": "فقط {{cups}} أكثر للفتح الوجبة المجانية!", "youreJustXCupsAwayFromYourNextReward": "🎉 أنت فقط {{cups}} أكثر للحصول على المكافأة التالية!", "callWaiter": "اتصل بالرادير", - "balance": "الرصيد" + "balance": "الرصيد", + "closed": "مغلق", + "sunday": "الأحد", + "monday": "الإثنين", + "tuesday": "الثلاثاء", + "wednesday": "الأربعاء", + "thursday": "الخميس", + "friday": "الجمعة", + "saturday": "السبت" }, "cart": { "addSpecialRequestOptional": "إضافة طلب خاص (اختياري)", diff --git a/src/assets/locals/en.json b/src/assets/locals/en.json index d6215fb..43996f4 100644 --- a/src/assets/locals/en.json +++ b/src/assets/locals/en.json @@ -182,7 +182,15 @@ "justXMorePurchasesToUnlockYourFREEItem": "Just {{cups}} more purchases to unlock your FREE item!", "youreJustXCupsAwayFromYourNextReward": "🎉 You're just {{cups}} stamps away from your next reward!", "callWaiter": "Call Waiter", - "balance": "Balance" + "balance": "Balance", + "closed": "Closed", + "sunday": "Sunday", + "monday": "Monday", + "tuesday": "Tuesday", + "wednesday": "Wednesday", + "thursday": "Thursday", + "friday": "Friday", + "saturday": "Saturday" }, "cart": { "remainingToPay": "Remaining to Pay", diff --git a/src/components/CustomBottomSheet/OpeningTimesBottomSheet.tsx b/src/components/CustomBottomSheet/OpeningTimesBottomSheet.tsx index 2167847..5ddf76a 100644 --- a/src/components/CustomBottomSheet/OpeningTimesBottomSheet.tsx +++ b/src/components/CustomBottomSheet/OpeningTimesBottomSheet.tsx @@ -4,19 +4,70 @@ import { ProBottomSheet } from "../ProBottomSheet/ProBottomSheet"; import ProText from "components/ProText"; import ProTitle from "components/ProTitle"; import { useAppSelector } from "redux/hooks"; +import { useGetOpeningTimesQuery } from "redux/api/others"; +import { useMemo } from "react"; interface OpeningTimesBottomSheetProps { isOpen: boolean; onClose: () => void; } -const textStyle: React.CSSProperties = { +const dayTextStyle: React.CSSProperties = { fontWeight: 400, fontStyle: "Regular", fontSize: 14, lineHeight: "140%", letterSpacing: "0%", - marginBottom: 4, +}; + +const todayTextStyle: React.CSSProperties = { + fontWeight: 700, + fontStyle: "Bold", + fontSize: 14, + lineHeight: "140%", + letterSpacing: "0%", +}; + +// Helper function to format time (HH:mm to 12h format) +const formatTime = (time: string | null | undefined): string => { + if (!time) return ""; + + // If already in 12h format (contains AM/PM), return as is + if (time.includes("AM") || time.includes("PM")) { + return time; + } + + // Parse 24h format (HH:mm) + const [hours, minutes] = time.split(":"); + const hour24 = parseInt(hours, 10); + + if (isNaN(hour24)) return time; + + const hour12 = hour24 % 12 || 12; + const ampm = hour24 >= 12 ? "PM" : "AM"; + return `${hour12}:${minutes} ${ampm}`; +}; + +// Helper function to get time ranges for a day +const getDayTimes = ( + openingTimes: any, + dayIndex: number, +): { shift1: string | null; shift2: string | null } => { + if (!openingTimes) { + return { shift1: null, shift2: null }; + } + + const from1 = openingTimes[`${dayIndex}_from` as keyof typeof openingTimes]; + const to1 = openingTimes[`${dayIndex}_to` as keyof typeof openingTimes]; + const from2 = openingTimes[`2_${dayIndex}_from` as keyof typeof openingTimes]; + const to2 = openingTimes[`2_${dayIndex}_to` as keyof typeof openingTimes]; + + const shift1 = + from1 && to1 ? `${formatTime(from1)} - ${formatTime(to1)}` : null; + const shift2 = + from2 && to2 ? `${formatTime(from2)} - ${formatTime(to2)}` : null; + + return { shift1, shift2 }; }; export function OpeningTimesBottomSheet({ @@ -26,6 +77,12 @@ export function OpeningTimesBottomSheet({ const { t } = useTranslation(); const { isRTL } = useAppSelector((state) => state.locale); const { restaurant } = useAppSelector((state) => state.order); + const { data: openingTimes } = useGetOpeningTimesQuery( + restaurant?.restautantId, + { + skip: !restaurant?.restautantId, + }, + ); const days = [ "sunday", @@ -37,7 +94,11 @@ export function OpeningTimesBottomSheet({ "saturday", ]; const todayIndex = new Date().getDay(); - const todayDay = days[todayIndex]; + + // Memoize day times to avoid recalculating on every render + const dayTimes = useMemo(() => { + return days.map((_, index) => getDayTimes(openingTimes, index)); + }, [openingTimes]); return (
- {t("menu.address")} - - {isRTL ? restaurant?.addressAR : restaurant?.address} - + {/* Address Section */} +
+ + {t("menu.address")} + + + {isRTL ? restaurant?.addressAR : restaurant?.address} + +
- {t("menu.openingTimes")} -
- + + {t("menu.openingTimes")} + +
- sunday - - - 10:00 AM to 10:00 PM - -
-
- - monday - - - 10:00 AM to 10:00 PM - -
-
- - tuesday - - - 10:00 AM to 10:00 PM - -
-
- - wednesday - - - 10:00 AM to 10:00 PM - -
-
- - thursday - - - 10:00 AM to 10:00 PM - -
-
- - friday - - - 10:00 AM to 10:00 PM - -
-
- - saturday - - - 10:00 AM to 10:00 PM - + {days.map((day, index) => { + const isToday = index === todayIndex; + const { shift1, shift2 } = dayTimes[index]; + const hasShifts = shift1 || shift2; + const timeDisplay = shift2 + ? `${shift1}, ${shift2}` + : shift1 || t("menu.closed"); + + return ( +
+ + {t(`menu.${day}`)} + + + {timeDisplay} + +
+ ); + })} +
-
); } diff --git a/src/pages/product/components/ExtraGroupsContainer.tsx b/src/pages/product/components/ExtraGroupsContainer.tsx index 9165167..f9a7a0e 100644 --- a/src/pages/product/components/ExtraGroupsContainer.tsx +++ b/src/pages/product/components/ExtraGroupsContainer.tsx @@ -14,7 +14,6 @@ export default function ExtraGroupsContainer({ selectedExtrasByGroup: Record; setSelectedExtrasByGroup: Dispatch>>; }) { - return ( <> {groupsList.length > 0 && ( diff --git a/src/pages/product/page.tsx b/src/pages/product/page.tsx index a796da7..31937ac 100644 --- a/src/pages/product/page.tsx +++ b/src/pages/product/page.tsx @@ -214,6 +214,8 @@ export default function ProductDetailPage({ ); } + console.log(product.theExtrasGroups); + return (
)} - {product.theExtrasGroups.length === 0 && - getExtras()?.length > 0 && ( - - )} + {getExtras()?.length > 0 && ( + + )}
)} diff --git a/src/redux/api/others.ts b/src/redux/api/others.ts index dea70c5..cd0d4dc 100644 --- a/src/redux/api/others.ts +++ b/src/redux/api/others.ts @@ -13,6 +13,7 @@ import { REDEEM_DETAILS_URL, LOYALTY_HISTORY_URL, CREATE_GIFT_AMOUNT_URL, + OPENING_TIMES_URL, } from "utils/constants"; import { OrderDetails } from "pages/checkout/hooks/types"; @@ -25,6 +26,7 @@ import { import { baseApi } from "./apiSlice"; import { EGiftCard } from "pages/EGiftCards/type"; import { RedeemResponse } from "pages/redeem/types"; +import { OpeningTimeResponse } from "./types"; export const branchApi = baseApi.injectEndpoints({ endpoints: (builder) => ({ @@ -210,6 +212,15 @@ export const branchApi = baseApi.injectEndpoints({ body, }), }), + getOpeningTimes: builder.query({ + query: (restaurantId: string) => ({ + url: OPENING_TIMES_URL +"/"+ restaurantId, + method: "GET", + }), + transformResponse: (response: any) => { + return response.result; + }, + }), }), }); export const { @@ -227,4 +238,5 @@ export const { useGetRedeemDetailsQuery, useGetLoyaltyHistoryQuery, useCreateGiftAmountMutation, + useGetOpeningTimesQuery, } = branchApi; diff --git a/src/redux/api/types.ts b/src/redux/api/types.ts new file mode 100644 index 0000000..7fff4dc --- /dev/null +++ b/src/redux/api/types.ts @@ -0,0 +1,34 @@ +export interface OpeningTimeResponse { + id: number; + created_at: string; + updated_at: string; + "0_from": string; + "0_to": string; + "1_from": string; + "1_to": string; + "2_from": string; + "2_to": string; + "3_from": string; + "3_to": string; + "4_from": string; + "4_to": string; + "5_from": string; + "5_to": string; + "6_from": string; + "6_to": string; + restorant_id: number; + "2_0_from": any; + "2_0_to": any; + "2_1_from": any; + "2_1_to": any; + "2_2_from": any; + "2_2_to": any; + "2_3_from": any; + "2_3_to": any; + "2_4_from": any; + "2_4_to": any; + "2_5_from": any; + "2_5_to": any; + "2_6_from": any; + "2_6_to": any; +} diff --git a/src/utils/constants.ts b/src/utils/constants.ts index f82102b..612eb01 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -111,4 +111,5 @@ export const DISCOUNT_URL = `${BASE_URL}getDiscount`; export const EGIFT_CARDS_URL = `${BASE_URL}gift/cards`; export const REDEEM_DETAILS_URL = `${BASE_URL}gift/getGiftOrderByVoucherCode`; export const LOYALTY_HISTORY_URL = `${BASE_URL}loyaltyHistory`; -export const CREATE_GIFT_AMOUNT_URL = `${BASE_URL}gift/addGiftAmount`; \ No newline at end of file +export const CREATE_GIFT_AMOUNT_URL = `${BASE_URL}gift/addGiftAmount`; +export const OPENING_TIMES_URL = `${BASE_URL}restaurant/getWorkingHours`; \ No newline at end of file