This commit is contained in:
yotakii
2026-02-23 14:40:19 +03:00
parent ee0024adbc
commit 724bcc8f10
2 changed files with 30 additions and 16 deletions

View File

@@ -58,7 +58,7 @@ const Header = () => {
return () => window.removeEventListener('scroll', handleScroll);
}, []);
const lightHeaderRoutes = ['/facilities', '/contact'];
const lightHeaderRoutes = ['/facilities', '/contact', '/booking'];
const forceLightHeader = lightHeaderRoutes.some(
(r) => location.pathname === r || location.pathname.startsWith(r + '/')
);
@@ -119,7 +119,6 @@ const Header = () => {
</ListItem>
))}
{/* ✅ بدل واتساب: يروح على صفحة /booking */}
<ListItem disablePadding>
<ListItemButton
component={Link}
@@ -228,7 +227,6 @@ const Header = () => {
<LanguageIcon />
</IconButton>
{/* ✅ بدل واتساب: يروح على صفحة /booking */}
<motion.div
initial={{ opacity: 0, scale: 0.9 }}
animate={{ opacity: 1, scale: 1 }}

View File

@@ -39,7 +39,18 @@ const Booking = () => {
const loadRooms = async () => {
try {
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);
} catch (e) {
if (mounted) setMessage({ type: 'error', text: 'Failed to load rooms' });
@@ -108,15 +119,13 @@ const Booking = () => {
specialRequests: form.specialRequests
};
// ✅ هذا لازم يكون موجود بالـ CMS: POST /api/bookings/request
const res = await api.post('/api/bookings/request', payload);
const booking = res?.data?.data?.booking || 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 = {
fullName: `${form.firstName} ${form.lastName}`.trim(),
phone: form.phone,
@@ -125,13 +134,12 @@ const Booking = () => {
checkOutDate: form.checkOutDate,
adults: Number(form.adults),
children: Number(form.children || 0),
roomCategory: selectedRoom?.name || '',
roomCategory: selectedRoom?.name || selectedRoom?.title || '',
message: form.specialRequests || '',
bookingNumber: bookingNumber || '',
autoOpenWhatsApp: true // إذا صفحة الـ Confirmation عندك بتفتح واتساب تلقائيًا
autoOpenWhatsApp: true
};
// ✅ روح على صفحة التأكيد (بدون ما نظل هون)
navigate('/booking/confirmation', { state: { request: requestForConfirmation } });
} catch (error) {
@@ -182,11 +190,19 @@ const Booking = () => {
onChange={handleChange('roomId')}
required
>
{rooms.map(r => (
<MenuItem key={r._id} value={r._id}>
{r.name} (#{r.roomNumber}) - ${r.basePrice}/night
{rooms.length === 0 ? (
<MenuItem disabled value="">
No rooms available
</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