From fb590eb8f20302e913202a3852edd926434ff949 Mon Sep 17 00:00:00 2001 From: Mohammed Al-yaseen Date: Sat, 15 Nov 2025 22:48:32 +0300 Subject: [PATCH] when users try to navigate to a past date, they'll see a warning message and the date won't change --- src/assets/locals/ar.json | 5 +++- src/assets/locals/en.json | 5 +++- .../cart/components/timeEstimate/Content.tsx | 23 +++++++++++++------ 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/assets/locals/ar.json b/src/assets/locals/ar.json index a8c0238..7e87d55 100644 --- a/src/assets/locals/ar.json +++ b/src/assets/locals/ar.json @@ -244,7 +244,10 @@ "couponInvalid": "رمز القسيمة غير صالح", "couponExpired": "رمز القسيمة منتهي الصلاحية", "couponAlreadyUsed": "رمز القسيمة مستخدم بالفعل", - "couponNotApplicable": "رمز القسيمة غير مطبق" + "couponNotApplicable": "رمز القسيمة غير مطبق", + "am": "ص", + "pm": "م", + "cannotSelectPastDate": "لا يمكنك اختيار تاريخ سابق. يرجى اختيار اليوم أو تاريخ مستقبلي." }, "checkout": { "title": "الدفع", diff --git a/src/assets/locals/en.json b/src/assets/locals/en.json index 82d1526..1b3d289 100644 --- a/src/assets/locals/en.json +++ b/src/assets/locals/en.json @@ -254,7 +254,10 @@ "couponInvalid": "Invalid coupon code", "couponExpired": "Coupon expired", "couponAlreadyUsed": "Coupon already used", - "couponNotApplicable": "Coupon not applicable" + "couponNotApplicable": "Coupon not applicable", + "am": "AM", + "pm": "PM", + "cannotSelectPastDate": "You cannot select a past date. Please select today or a future date." }, "checkout": { "title": "Checkout", diff --git a/src/pages/cart/components/timeEstimate/Content.tsx b/src/pages/cart/components/timeEstimate/Content.tsx index 482f9a2..cf1f703 100644 --- a/src/pages/cart/components/timeEstimate/Content.tsx +++ b/src/pages/cart/components/timeEstimate/Content.tsx @@ -1,4 +1,4 @@ -import { Button, Divider } from "antd"; +import { Button, Divider, message } from "antd"; import BackIcon from "components/Icons/BackIcon.tsx"; import NextIcon from "components/Icons/NextIcon.tsx"; import dayjs from "dayjs"; @@ -30,7 +30,7 @@ interface EstimateTimeContentProps { export default function Content({ onSave, onClose }: EstimateTimeContentProps) { const { t } = useTranslation(); - const [selectedDate, setSelectedDate] = useState(Date()); + const [selectedDate, setSelectedDate] = useState(dayjs().format(SERVER_DATE_FORMAT)); const [selectedTime, setSelectedTime] = useState(); const [isAM, setIsAM] = useState(true); const { isRTL } = useAppSelector((state) => state.locale); @@ -45,6 +45,15 @@ export default function Content({ onSave, onClose }: EstimateTimeContentProps) { const goToPreviousDay = () => { const newDate = dayjs(selectedDate).subtract(1, "d"); + const today = dayjs().startOf("day"); + const newDateStart = newDate.startOf("day"); + + // Check if the new date would be before today + if (newDateStart.isBefore(today)) { + message.warning(t("cart.cannotSelectPastDate")); + return; + } + setSelectedDate(newDate.format(SERVER_DATE_FORMAT)); }; @@ -105,7 +114,7 @@ export default function Content({ onSave, onClose }: EstimateTimeContentProps) { ) } - onClick={goToPreviousDay} + onClick={isRTL ? goToNextDay : goToPreviousDay} style={{ display: "flex", alignItems: "center", @@ -141,7 +150,7 @@ export default function Content({ onSave, onClose }: EstimateTimeContentProps) { ) } - onClick={goToNextDay} + onClick={isRTL ? goToPreviousDay : goToNextDay} style={{ display: "flex", alignItems: "center", @@ -157,7 +166,7 @@ export default function Content({ onSave, onClose }: EstimateTimeContentProps) {
setIsAM(true)} className={styles.toggleButton + " " + (isAM ? styles.active : "")} > - AM + {t("cart.am")}