This commit is contained in:
@ -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 (
|
||||
<motion.div
|
||||
@ -1066,6 +1073,12 @@ function DetailsModal({ r, isOpen, onClose, onReport, reportingId }) {
|
||||
</div>
|
||||
|
||||
<div className="p-6 space-y-6">
|
||||
{imgs.length > 0 && (
|
||||
<div className="w-full h-56 rounded-xl overflow-hidden">
|
||||
<img src={buildImageUrl(imgs[0])} alt="" className="w-full h-full object-cover" />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{p && (
|
||||
<div className="bg-gray-50 p-4 rounded-xl">
|
||||
<h3 className="font-bold text-gray-900 mb-3 flex items-center gap-2">
|
||||
@ -1075,7 +1088,7 @@ function DetailsModal({ r, isOpen, onClose, onReport, reportingId }) {
|
||||
|
||||
<p>
|
||||
<span className="text-gray-500">{t('address')}</span>{' '}
|
||||
{pAddr(p) || '—'}
|
||||
{pAddr(p, r) || '—'}
|
||||
</p>
|
||||
|
||||
{(pBeds(p) || pBaths(p)) && (
|
||||
@ -1249,7 +1262,8 @@ export default function OwnerReservationRequestsPage() {
|
||||
|
||||
const token = AuthService.getToken();
|
||||
|
||||
const res = await fetch(
|
||||
const [resResult, rentProps] = await Promise.all([
|
||||
fetch(
|
||||
`${API_BASE}/Reservations/GetOwnerResevationRequests`,
|
||||
{
|
||||
method: 'GET',
|
||||
@ -1258,19 +1272,34 @@ export default function OwnerReservationRequestsPage() {
|
||||
'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 enriched = await Promise.all(list.map(enrich));
|
||||
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];
|
||||
}
|
||||
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)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user