update booking confirmation
This commit is contained in:
@@ -170,6 +170,19 @@ const Booking = () => {
|
|||||||
setForm((prev) => ({ ...prev, [key]: e.target.value }));
|
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 = () => {
|
const validateBeforeSubmit = () => {
|
||||||
if (form.checkInDate && form.checkOutDate) {
|
if (form.checkInDate && form.checkOutDate) {
|
||||||
const inD = new Date(form.checkInDate);
|
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 adults = Number(form.adults);
|
||||||
const children = Number(form.children || 0);
|
const children = Number(form.children || 0);
|
||||||
|
|
||||||
@@ -194,7 +221,7 @@ const Booking = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = async (e) => {
|
const handleSubmit = async (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -219,8 +246,8 @@ const Booking = () => {
|
|||||||
roomCategoryId: selectedOption?.kind === 'category' ? form.roomId : undefined,
|
roomCategoryId: selectedOption?.kind === 'category' ? form.roomId : undefined,
|
||||||
roomCategory: selectedOption?.name || undefined,
|
roomCategory: selectedOption?.name || undefined,
|
||||||
requestedRoomType: selectedOption?.name || undefined,
|
requestedRoomType: selectedOption?.name || undefined,
|
||||||
checkInDate: form.checkInDate,
|
checkInDate: toEndOfDayISO(form.checkInDate),
|
||||||
checkOutDate: form.checkOutDate,
|
checkOutDate: toEndOfDayISO(form.checkOutDate),
|
||||||
numberOfGuests: {
|
numberOfGuests: {
|
||||||
adults: Number(form.adults),
|
adults: Number(form.adults),
|
||||||
children: Number(form.children || 0)
|
children: Number(form.children || 0)
|
||||||
|
|||||||
@@ -5,11 +5,9 @@ import { useLocation, Link } from 'react-router-dom';
|
|||||||
const BookingConfirmation = () => {
|
const BookingConfirmation = () => {
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
|
||||||
// نتوقع إنه صفحة الحجز تبعتنا رح تعمل navigate وتبعت state فيه request
|
|
||||||
const request = location.state?.request || null;
|
const request = location.state?.request || null;
|
||||||
|
|
||||||
const WA_NUMBER = useMemo(() => {
|
const WA_NUMBER = useMemo(() => {
|
||||||
// إذا عندك رقم ثابت حاليا
|
|
||||||
return '963986105010';
|
return '963986105010';
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -36,7 +34,6 @@ const BookingConfirmation = () => {
|
|||||||
|
|
||||||
const WA_LINK = useMemo(() => `https://wa.me/${WA_NUMBER}?text=${waText}`, [WA_NUMBER, waText]);
|
const WA_LINK = useMemo(() => `https://wa.me/${WA_NUMBER}?text=${waText}`, [WA_NUMBER, waText]);
|
||||||
|
|
||||||
// خيار: تفتح واتساب أوتوماتيك بعد نجاح الإرسال
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (request?.autoOpenWhatsApp) {
|
if (request?.autoOpenWhatsApp) {
|
||||||
window.open(WA_LINK, '_blank', 'noopener,noreferrer');
|
window.open(WA_LINK, '_blank', 'noopener,noreferrer');
|
||||||
|
|||||||
Reference in New Issue
Block a user