This commit is contained in:
@ -9,7 +9,7 @@ import {
|
||||
} from 'lucide-react';
|
||||
import toast, { Toaster } from 'react-hot-toast';
|
||||
import AuthService from '../services/AuthService';
|
||||
import { getRentProperty, getUserReservations, payDeposit } from '../utils/api';
|
||||
import { getRentProperties, getUserReservations, payDeposit } from '../utils/api';
|
||||
|
||||
const API_BASE = process.env.NEXT_PUBLIC_API_URL || 'https://45.93.137.91.nip.io/api';
|
||||
|
||||
@ -37,17 +37,6 @@ function StatusBadge({ code }) {
|
||||
);
|
||||
}
|
||||
|
||||
async function enrich(reservation) {
|
||||
if (!reservation.propertyId) return reservation;
|
||||
try {
|
||||
const prop = await getRentProperty(reservation.propertyId);
|
||||
const info = prop?.propertyInformation ?? prop ?? {};
|
||||
if (prop?.allowedPaymentPeriod) info.allowedPaymentPeriod = prop.allowedPaymentPeriod;
|
||||
reservation._prop = info;
|
||||
} catch { /* skip */ }
|
||||
return reservation;
|
||||
}
|
||||
|
||||
const propAddr = (p, r) => p?.address ?? r?.propertyAddress ?? '';
|
||||
const propImages = (p, r) => {
|
||||
if (p?.images && Array.isArray(p.images)) return p.images;
|
||||
@ -248,9 +237,23 @@ export default function UserReservationsPage() {
|
||||
|
||||
const loadReservations = useCallback(async () => {
|
||||
try {
|
||||
const data = await getUserReservations();
|
||||
const [data, rentProps] = await Promise.all([
|
||||
getUserReservations(),
|
||||
getRentProperties().catch(() => []),
|
||||
]);
|
||||
const list = Array.isArray(data) ? data : [];
|
||||
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;
|
||||
propMap[rp.propertyInformation?.id] = info;
|
||||
});
|
||||
const enriched = list.map(r => {
|
||||
if (r.propertyId && propMap[r.propertyId]) r._prop = propMap[r.propertyId];
|
||||
return r;
|
||||
});
|
||||
setReservations(enriched);
|
||||
setFiltered(enriched);
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user