it must be fixed
All checks were successful
Build frontend / build (push) Successful in 1m28s

This commit is contained in:
mouazkh
2026-07-20 22:12:51 +03:00
parent ca6b12bfb9
commit 4166a5d652

View File

@ -664,7 +664,7 @@ import {
} from 'lucide-react'; } from 'lucide-react';
import toast, { Toaster } from 'react-hot-toast'; import toast, { Toaster } from 'react-hot-toast';
import AuthService from '../../services/AuthService'; import AuthService from '../../services/AuthService';
import { getRentProperty } from '../../utils/api'; import { getRentProperties } from '../../utils/api';
const API_BASE = const API_BASE =
process.env.NEXT_PUBLIC_API_URL || 'https://45.93.137.91.nip.io/api'; 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 pAddr = (p, r) => p?.address ?? r?.propertyAddress ?? '';
const pImgs = (p) => (Array.isArray(p?.images) ? p.images : []); 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 pBeds = (p) => p?.numberOfBedRooms ?? 0;
const pBaths = (p) => p?.numberOfBathRooms ?? 0; const pBaths = (p) => p?.numberOfBathRooms ?? 0;
@ -893,9 +899,9 @@ function OwnerCard({
}) { }) {
const { t } = useTranslation(); const { t } = useTranslation();
const p = r._prop; const p = r._prop;
const imgs = pImgs(p); const imgs = pImgs(p, r);
const img = imgs.length > 0 ? buildImageUrl(imgs[0]) : null; 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 isPending = Number(r.status) === 0;
const isActionLoading = actionLoadingId === r.id; const isActionLoading = actionLoadingId === r.id;
const isReporting = reportingId === r.id; const isReporting = reportingId === r.id;
@ -1035,6 +1041,7 @@ function DetailsModal({ r, isOpen, onClose, onReport, reportingId }) {
const p = r._prop; const p = r._prop;
const isReporting = reportingId === r.id; const isReporting = reportingId === r.id;
const imgs = pImgs(p, r);
return ( return (
<motion.div <motion.div
@ -1066,6 +1073,12 @@ function DetailsModal({ r, isOpen, onClose, onReport, reportingId }) {
</div> </div>
<div className="p-6 space-y-6"> <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 && ( {p && (
<div className="bg-gray-50 p-4 rounded-xl"> <div className="bg-gray-50 p-4 rounded-xl">
<h3 className="font-bold text-gray-900 mb-3 flex items-center gap-2"> <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> <p>
<span className="text-gray-500">{t('address')}</span>{' '} <span className="text-gray-500">{t('address')}</span>{' '}
{pAddr(p) || '—'} {pAddr(p, r) || '—'}
</p> </p>
{(pBeds(p) || pBaths(p)) && ( {(pBeds(p) || pBaths(p)) && (
@ -1249,28 +1262,44 @@ export default function OwnerReservationRequestsPage() {
const token = AuthService.getToken(); const token = AuthService.getToken();
const res = await fetch( const [resResult, rentProps] = await Promise.all([
`${API_BASE}/Reservations/GetOwnerResevationRequests`, fetch(
{ `${API_BASE}/Reservations/GetOwnerResevationRequests`,
method: 'GET', {
headers: { method: 'GET',
Authorization: `Bearer ${token}`, headers: {
'Content-Type': 'application/json', 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];
} }
); return r;
});
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));
setReservations(enriched); setReservations(enriched);
setFiltered(enriched); setFiltered(enriched);
@ -1305,7 +1334,7 @@ export default function OwnerReservationRequestsPage() {
result = result.filter( result = result.filter(
(x) => (x) =>
pAddr(x._prop).toLowerCase().includes(q) || String(x.id).includes(q) pAddr(x._prop, x).toLowerCase().includes(q) || String(x.id).includes(q)
); );
} }