feat: enrich reservation pages with property details via GetRentPropertyById
All checks were successful
Build frontend / build (push) Successful in 43s
All checks were successful
Build frontend / build (push) Successful in 43s
This commit is contained in:
@ -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('فشل تحميل طلبات الحجز');
|
||||
|
||||
@ -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('فشل تحميل الحجوزات');
|
||||
|
||||
Reference in New Issue
Block a user