diff --git a/app/owner/reservations/page.js b/app/owner/reservations/page.js index 0293ab8..9d41bb0 100644 --- a/app/owner/reservations/page.js +++ b/app/owner/reservations/page.js @@ -664,7 +664,7 @@ import { } from 'lucide-react'; import toast, { Toaster } from 'react-hot-toast'; import AuthService from '../../services/AuthService'; -import { getRentProperty } from '../../utils/api'; +import { getRentProperties } from '../../utils/api'; const API_BASE = process.env.NEXT_PUBLIC_API_URL || 'https://45.93.137.91.nip.io/api'; @@ -756,8 +756,14 @@ async function enrich(r) { } } -const pAddr = (p) => p?.address ?? ''; -const pImgs = (p) => (Array.isArray(p?.images) ? p.images : []); +const pAddr = (p, r) => p?.address ?? r?.propertyAddress ?? ''; +const pImgs = (p, r) => { + if (p?.images && Array.isArray(p.images)) return p.images; + if (r?.property?.images && Array.isArray(r.property.images)) return r.property.images; + if (r?.propertyInfo?.images && Array.isArray(r.propertyInfo.images)) return r.propertyInfo.images; + if (r?.propertyImage) return [r.propertyImage]; + return []; +}; const pBeds = (p) => p?.numberOfBedRooms ?? 0; const pBaths = (p) => p?.numberOfBathRooms ?? 0; @@ -893,9 +899,9 @@ function OwnerCard({ }) { const { t } = useTranslation(); const p = r._prop; - const imgs = pImgs(p); + const imgs = pImgs(p, r); const img = imgs.length > 0 ? buildImageUrl(imgs[0]) : null; - const addr = pAddr(p); + const addr = pAddr(p, r); const isPending = Number(r.status) === 0; const isActionLoading = actionLoadingId === r.id; const isReporting = reportingId === r.id; @@ -1035,6 +1041,7 @@ function DetailsModal({ r, isOpen, onClose, onReport, reportingId }) { const p = r._prop; const isReporting = reportingId === r.id; + const imgs = pImgs(p, r); return (
+ {imgs.length > 0 && ( +
+ +
+ )} + {p && (

@@ -1075,7 +1088,7 @@ function DetailsModal({ r, isOpen, onClose, onReport, reportingId }) {

{t('address')}{' '} - {pAddr(p) || '—'} + {pAddr(p, r) || '—'}

{(pBeds(p) || pBaths(p)) && ( @@ -1249,28 +1262,44 @@ export default function OwnerReservationRequestsPage() { const token = AuthService.getToken(); - const res = await fetch( - `${API_BASE}/Reservations/GetOwnerResevationRequests`, - { - method: 'GET', - headers: { - Authorization: `Bearer ${token}`, - 'Content-Type': 'application/json', - }, + const [resResult, rentProps] = await Promise.all([ + fetch( + `${API_BASE}/Reservations/GetOwnerResevationRequests`, + { + method: 'GET', + headers: { + Authorization: `Bearer ${token}`, + 'Content-Type': 'application/json', + }, + } + ).then(async (res) => { + if (!res.ok) { + const errorText = await res.text(); + throw new Error(errorText || `HTTP ${res.status}`); + } + const json = await res.json(); + let list = json.data || json || []; + if (!Array.isArray(list)) list = []; + return list; + }), + getRentProperties().catch(() => []), + ]); + + const propsList = Array.isArray(rentProps) ? rentProps : []; + const propMap = {}; + propsList.forEach(rp => { + const info = rp?.propertyInformation ?? {}; + if (rp?.allowedPaymentPeriod) info.allowedPaymentPeriod = rp.allowedPaymentPeriod; + propMap[rp.propertyInformationId] = info; + if (rp?.propertyInformation?.id) propMap[rp.propertyInformation.id] = info; + }); + + const enriched = resResult.map(r => { + if (r.propertyId && propMap[r.propertyId]) { + r._prop = propMap[r.propertyId]; } - ); - - if (!res.ok) { - const errorText = await res.text(); - throw new Error(errorText || `HTTP ${res.status}`); - } - - const json = await res.json(); - - let list = json.data || json || []; - if (!Array.isArray(list)) list = []; - - const enriched = await Promise.all(list.map(enrich)); + return r; + }); setReservations(enriched); setFiltered(enriched); @@ -1305,7 +1334,7 @@ export default function OwnerReservationRequestsPage() { result = result.filter( (x) => - pAddr(x._prop).toLowerCase().includes(q) || String(x.id).includes(q) + pAddr(x._prop, x).toLowerCase().includes(q) || String(x.id).includes(q) ); }