update booking confirmation
This commit is contained in:
@@ -170,6 +170,19 @@ const Booking = () => {
|
||||
setForm((prev) => ({ ...prev, [key]: e.target.value }));
|
||||
};
|
||||
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
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);
|
||||
@@ -180,6 +193,20 @@ const Booking = () => {
|
||||
}
|
||||
}
|
||||
|
||||
// ✅ 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;
|
||||
}
|
||||
}
|
||||
|
||||
const adults = Number(form.adults);
|
||||
const children = Number(form.children || 0);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user