diff --git a/client/src/pages/Booking.js b/client/src/pages/Booking.js index ec05fe9..ec4805c 100644 --- a/client/src/pages/Booking.js +++ b/client/src/pages/Booking.js @@ -170,31 +170,58 @@ const Booking = () => { setForm((prev) => ({ ...prev, [key]: e.target.value })); }; - const validateBeforeSubmit = () => { - if (form.checkInDate && form.checkOutDate) { - const inD = new Date(form.checkInDate); - const outD = new Date(form.checkOutDate); - if (inD >= outD) { - setMessage({ type: 'error', text: 'Check-out date must be after check-in date' }); - return false; - } - } - const adults = Number(form.adults); - const children = Number(form.children || 0); + const toLocalStartOfDay = (dateStr) => { + if (!dateStr) return null; + const d = new Date(`${dateStr}T00:00:00`); // local start + d.setHours(0, 0, 0, 0); + return d; +}; - if (!Number.isFinite(adults) || adults < 1) { - setMessage({ type: 'error', text: 'Adults must be at least 1' }); +const toEndOfDayISO = (dateStr) => { + if (!dateStr) return dateStr; + return `${dateStr}T23:59:59`; +}; + + const validateBeforeSubmit = () => { + if (form.checkInDate && form.checkOutDate) { + const inD = new Date(form.checkInDate); + const outD = new Date(form.checkOutDate); + if (inD >= outD) { + setMessage({ type: 'error', text: 'Check-out date must be after check-in date' }); return false; } + } - if (!Number.isFinite(children) || children < 0) { - setMessage({ type: 'error', text: 'Children cannot be negative' }); + // ✅ Allow booking starting today (disallow only past days) + if (form.checkInDate) { + const today = new Date(); + today.setHours(0, 0, 0, 0); + + const inDay = new Date(`${form.checkInDate}T00:00:00`); + inDay.setHours(0, 0, 0, 0); + + if (inDay < today) { + setMessage({ type: 'error', text: 'Check-in date cannot be in the past' }); return false; } + } - return true; - }; + const adults = Number(form.adults); + const children = Number(form.children || 0); + + if (!Number.isFinite(adults) || adults < 1) { + setMessage({ type: 'error', text: 'Adults must be at least 1' }); + return false; + } + + if (!Number.isFinite(children) || children < 0) { + setMessage({ type: 'error', text: 'Children cannot be negative' }); + return false; + } + + return true; +}; const handleSubmit = async (e) => { e.preventDefault(); @@ -219,8 +246,8 @@ const Booking = () => { roomCategoryId: selectedOption?.kind === 'category' ? form.roomId : undefined, roomCategory: selectedOption?.name || undefined, requestedRoomType: selectedOption?.name || undefined, - checkInDate: form.checkInDate, - checkOutDate: form.checkOutDate, + checkInDate: toEndOfDayISO(form.checkInDate), + checkOutDate: toEndOfDayISO(form.checkOutDate), numberOfGuests: { adults: Number(form.adults), children: Number(form.children || 0) diff --git a/client/src/pages/BookingConfirmation.js b/client/src/pages/BookingConfirmation.js index c9cc181..123374e 100644 --- a/client/src/pages/BookingConfirmation.js +++ b/client/src/pages/BookingConfirmation.js @@ -5,11 +5,9 @@ import { useLocation, Link } from 'react-router-dom'; const BookingConfirmation = () => { const location = useLocation(); - // نتوقع إنه صفحة الحجز تبعتنا رح تعمل navigate وتبعت state فيه request const request = location.state?.request || null; const WA_NUMBER = useMemo(() => { - // إذا عندك رقم ثابت حاليا return '963986105010'; }, []); @@ -36,7 +34,6 @@ const BookingConfirmation = () => { const WA_LINK = useMemo(() => `https://wa.me/${WA_NUMBER}?text=${waText}`, [WA_NUMBER, waText]); - // خيار: تفتح واتساب أوتوماتيك بعد نجاح الإرسال useEffect(() => { if (request?.autoOpenWhatsApp) { window.open(WA_LINK, '_blank', 'noopener,noreferrer');