diff --git a/app/owner/reservations/page.js b/app/owner/reservations/page.js index 5f12658..1cf4b2c 100644 --- a/app/owner/reservations/page.js +++ b/app/owner/reservations/page.js @@ -22,6 +22,7 @@ import { } from 'lucide-react'; import toast, { Toaster } from 'react-hot-toast'; import AuthService from '../../services/AuthService'; +import { getRentProperty } from '../../utils/api'; const API_BASE = process.env.NEXT_PUBLIC_API_URL || 'https://45.93.137.91.nip.io/api'; @@ -266,9 +267,26 @@ export default function OwnerReservationRequestsPage() { if (!res.ok) throw new Error(`HTTP ${res.status}`); const json = await res.json(); - const list = json.data || json || []; - setReservations(Array.isArray(list) ? list : []); - setFiltered(Array.isArray(list) ? list : []); + let list = json.data || json || []; + if (!Array.isArray(list)) list = []; + + // Enrich each reservation with property details + const enriched = await Promise.all( + list.map(async (r) => { + if (!r.property && r.propertyId) { + try { + const propRes = await getRentProperty(r.propertyId); + r.property = propRes?.data || propRes || null; + } catch (e) { + console.warn('Failed to load property', r.propertyId); + } + } + return r; + }) + ); + + setReservations(enriched); + setFiltered(enriched); } catch (err) { console.error('Failed to load owner reservations:', err); toast.error('فشل تحميل طلبات الحجز'); diff --git a/app/reservations/page.js b/app/reservations/page.js index 24f9c7a..f2cd398 100644 --- a/app/reservations/page.js +++ b/app/reservations/page.js @@ -19,6 +19,7 @@ import { } from 'lucide-react'; import toast, { Toaster } from 'react-hot-toast'; import AuthService from '../services/AuthService'; +import { getRentProperty } from '../utils/api'; const API_BASE = process.env.NEXT_PUBLIC_API_URL || 'https://45.93.137.91.nip.io/api'; @@ -226,9 +227,26 @@ export default function UserReservationsPage() { if (!res.ok) throw new Error(`HTTP ${res.status}`); const json = await res.json(); - const list = json.data || json || []; - setReservations(Array.isArray(list) ? list : []); - setFiltered(Array.isArray(list) ? list : []); + let list = json.data || json || []; + if (!Array.isArray(list)) list = []; + + // Enrich each reservation with property details + const enriched = await Promise.all( + list.map(async (r) => { + if (!r.property && r.propertyId) { + try { + const propRes = await getRentProperty(r.propertyId); + r.property = propRes?.data || propRes || null; + } catch (e) { + console.warn('Failed to load property', r.propertyId); + } + } + return r; + }) + ); + + setReservations(enriched); + setFiltered(enriched); } catch (err) { console.error('Failed to load reservations:', err); toast.error('فشل تحميل الحجوزات');