fix
This commit is contained in:
@@ -58,7 +58,7 @@ const Header = () => {
|
|||||||
return () => window.removeEventListener('scroll', handleScroll);
|
return () => window.removeEventListener('scroll', handleScroll);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const lightHeaderRoutes = ['/facilities', '/contact'];
|
const lightHeaderRoutes = ['/facilities', '/contact', '/booking'];
|
||||||
const forceLightHeader = lightHeaderRoutes.some(
|
const forceLightHeader = lightHeaderRoutes.some(
|
||||||
(r) => location.pathname === r || location.pathname.startsWith(r + '/')
|
(r) => location.pathname === r || location.pathname.startsWith(r + '/')
|
||||||
);
|
);
|
||||||
@@ -119,7 +119,6 @@ const Header = () => {
|
|||||||
</ListItem>
|
</ListItem>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
{/* ✅ بدل واتساب: يروح على صفحة /booking */}
|
|
||||||
<ListItem disablePadding>
|
<ListItem disablePadding>
|
||||||
<ListItemButton
|
<ListItemButton
|
||||||
component={Link}
|
component={Link}
|
||||||
@@ -228,7 +227,6 @@ const Header = () => {
|
|||||||
<LanguageIcon />
|
<LanguageIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
|
||||||
{/* ✅ بدل واتساب: يروح على صفحة /booking */}
|
|
||||||
<motion.div
|
<motion.div
|
||||||
initial={{ opacity: 0, scale: 0.9 }}
|
initial={{ opacity: 0, scale: 0.9 }}
|
||||||
animate={{ opacity: 1, scale: 1 }}
|
animate={{ opacity: 1, scale: 1 }}
|
||||||
|
|||||||
@@ -39,7 +39,18 @@ const Booking = () => {
|
|||||||
const loadRooms = async () => {
|
const loadRooms = async () => {
|
||||||
try {
|
try {
|
||||||
const res = await api.get('/api/rooms?limit=100');
|
const res = await api.get('/api/rooms?limit=100');
|
||||||
const fetched = res?.data?.data?.rooms || [];
|
|
||||||
|
const rawRooms =
|
||||||
|
res?.data?.data?.rooms ||
|
||||||
|
res?.data?.data ||
|
||||||
|
res?.data?.rooms ||
|
||||||
|
[];
|
||||||
|
|
||||||
|
const fetched = (Array.isArray(rawRooms) ? rawRooms : []).filter((r) => {
|
||||||
|
const status = String(r?.status || '').toLowerCase();
|
||||||
|
return !status || status === 'active';
|
||||||
|
});
|
||||||
|
|
||||||
if (mounted) setRooms(fetched);
|
if (mounted) setRooms(fetched);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (mounted) setMessage({ type: 'error', text: 'Failed to load rooms' });
|
if (mounted) setMessage({ type: 'error', text: 'Failed to load rooms' });
|
||||||
@@ -108,15 +119,13 @@ const Booking = () => {
|
|||||||
specialRequests: form.specialRequests
|
specialRequests: form.specialRequests
|
||||||
};
|
};
|
||||||
|
|
||||||
// ✅ هذا لازم يكون موجود بالـ CMS: POST /api/bookings/request
|
|
||||||
const res = await api.post('/api/bookings/request', payload);
|
const res = await api.post('/api/bookings/request', payload);
|
||||||
|
|
||||||
const booking = res?.data?.data?.booking || null;
|
const booking = res?.data?.data?.booking || null;
|
||||||
const bookingNumber = booking?.bookingNumber || res?.data?.data?.bookingNumber || null;
|
const bookingNumber = booking?.bookingNumber || res?.data?.data?.bookingNumber || null;
|
||||||
|
|
||||||
const selectedRoom = rooms.find(r => r._id === form.roomId);
|
const selectedRoom = rooms.find(r => String(r._id || r.id) === String(form.roomId));
|
||||||
|
|
||||||
// ✅ معلومات نبعثها لصفحة BookingConfirmation
|
|
||||||
const requestForConfirmation = {
|
const requestForConfirmation = {
|
||||||
fullName: `${form.firstName} ${form.lastName}`.trim(),
|
fullName: `${form.firstName} ${form.lastName}`.trim(),
|
||||||
phone: form.phone,
|
phone: form.phone,
|
||||||
@@ -125,13 +134,12 @@ const Booking = () => {
|
|||||||
checkOutDate: form.checkOutDate,
|
checkOutDate: form.checkOutDate,
|
||||||
adults: Number(form.adults),
|
adults: Number(form.adults),
|
||||||
children: Number(form.children || 0),
|
children: Number(form.children || 0),
|
||||||
roomCategory: selectedRoom?.name || '',
|
roomCategory: selectedRoom?.name || selectedRoom?.title || '',
|
||||||
message: form.specialRequests || '',
|
message: form.specialRequests || '',
|
||||||
bookingNumber: bookingNumber || '',
|
bookingNumber: bookingNumber || '',
|
||||||
autoOpenWhatsApp: true // إذا صفحة الـ Confirmation عندك بتفتح واتساب تلقائيًا
|
autoOpenWhatsApp: true
|
||||||
};
|
};
|
||||||
|
|
||||||
// ✅ روح على صفحة التأكيد (بدون ما نظل هون)
|
|
||||||
navigate('/booking/confirmation', { state: { request: requestForConfirmation } });
|
navigate('/booking/confirmation', { state: { request: requestForConfirmation } });
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -182,11 +190,19 @@ const Booking = () => {
|
|||||||
onChange={handleChange('roomId')}
|
onChange={handleChange('roomId')}
|
||||||
required
|
required
|
||||||
>
|
>
|
||||||
{rooms.map(r => (
|
{rooms.length === 0 ? (
|
||||||
<MenuItem key={r._id} value={r._id}>
|
<MenuItem disabled value="">
|
||||||
{r.name} (#{r.roomNumber}) - ${r.basePrice}/night
|
No rooms available
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
))}
|
) : (
|
||||||
|
rooms.map((r) => (
|
||||||
|
<MenuItem key={r._id || r.id} value={r._id || r.id}>
|
||||||
|
{(r.name || r.title || 'Room')}
|
||||||
|
{r.roomNumber ? ` (#${r.roomNumber})` : ''}
|
||||||
|
{(r.basePrice ?? r.price) != null ? ` - $${r.basePrice ?? r.price}/night` : ''}
|
||||||
|
</MenuItem>
|
||||||
|
))
|
||||||
|
)}
|
||||||
</TextField>
|
</TextField>
|
||||||
|
|
||||||
<TextField
|
<TextField
|
||||||
|
|||||||
Reference in New Issue
Block a user