-
+ {img &&
}
+
-
-
-
- {property && (
-
-
- {property.address || 'عقار'}
-
- )}
+
+ {addr &&
{addr}
}
-
- {reservation.totalPrice?.toLocaleString() || '—'}
-
+
{r.totalPrice?.toLocaleString() ?? '—'}
السعر الإجمالي
-
- {property?.images?.length > 0 && (
-
-

-
- )}
-
+ {(beds||baths) &&
{beds>0&&{beds} غرف}{baths>0&&{baths} حمامات}
}
-
-
من
-
- {new Date(reservation.startDate).toLocaleDateString('ar')}
-
+
من
+
{new Date(r.startDate).toLocaleDateString('ar')}
-
-
إلى
-
- {new Date(reservation.endDate).toLocaleDateString('ar')}
-
+
إلى
+
{new Date(r.endDate).toLocaleDateString('ar')}
-
-
@@ -115,83 +96,43 @@ function ReservationCard({ reservation, onViewDetails }) {
);
}
-function DetailsModal({ reservation, isOpen, onClose }) {
- if (!isOpen || !reservation) return null;
- const property = reservation.property || reservation.propertyInformation;
+function DetailsModal({ r, isOpen, onClose }) {
+ if (!isOpen || !r) return null;
+ const p = r._prop;
return (
-
- e.stopPropagation()}
- >
+
+ e.stopPropagation()}>
تفاصيل الحجز
-
-
-
+
-
رقم الحجز: #{reservation.id}
+
رقم الحجز: #{r.id}
-
- {property && (
-
-
- معلومات العقار
-
-
العنوان: {property.address || '—'}
- {property.numberOfBedRooms && (
-
- {property.numberOfBedRooms} غرف
- {property.numberOfBathRooms} حمامات
-
- )}
-
- )}
-
+ {p &&
+
معلومات العقار
+
العنوان: {propAddr(p)||'—'}
+ {(propBeds(p)||propBaths(p)) &&
+ {propBeds(p)>0&&{propBeds(p)} غرف}
+ {propBaths(p)>0&&{propBaths(p)} حمامات}
+
}
+
}
-
- تفاصيل الحجز
-
+
تفاصيل الحجز
-
-
تاريخ البداية
-
{new Date(reservation.startDate).toLocaleDateString('ar')}
-
-
-
تاريخ النهاية
-
{new Date(reservation.endDate).toLocaleDateString('ar')}
-
-
-
-
تاريخ الإنشاء
-
{new Date(reservation.createdAt).toLocaleDateString('ar')}
-
+
تاريخ البداية
{new Date(r.startDate).toLocaleDateString('ar')}
+
تاريخ النهاية
{new Date(r.endDate).toLocaleDateString('ar')}
+
+
تاريخ الإنشاء
{new Date(r.createdAt).toLocaleDateString('ar')}
-
-
- المعلومات المالية
-
-
- الإجمالي
- {reservation.totalPrice?.toLocaleString() || '—'}
-
+
المعلومات المالية
+
الإجمالي{r.totalPrice?.toLocaleString()??'—'}
@@ -208,129 +149,75 @@ export default function UserReservationsPage() {
const [filterStatus, setFilterStatus] = useState('all');
const [searchTerm, setSearchTerm] = useState('');
- useEffect(() => {
- const user = AuthService.getUser();
- if (!user) {
- router.push('/login');
- return;
- }
- loadReservations();
- }, [router]);
+ useEffect(() => { if (!AuthService.getUser()) { router.push('/login'); return; } loadReservations(); }, [router]);
- const loadReservations = async () => {
+ const loadReservations = useCallback(async () => {
try {
- const token = AuthService.getToken();
const res = await fetch(`${API_BASE}/Reservations/GetUserResevations`, {
- headers: { Authorization: `Bearer ${token}` },
+ headers: { Authorization: `Bearer ${AuthService.getToken()}` },
});
-
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const json = await res.json();
-
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?.propertyInformation || propRes?.data || propRes || null;
- } catch (e) {
- console.warn('Failed to load property', r.propertyId);
- }
- }
- return r;
- })
- );
-
+ const enriched = await Promise.all(list.map(enrich));
setReservations(enriched);
setFiltered(enriched);
} catch (err) {
- console.error('Failed to load reservations:', err);
+ console.error(err);
toast.error('فشل تحميل الحجوزات');
setReservations([]);
setFiltered([]);
}
setLoading(false);
- };
+ }, []);
useEffect(() => {
- let result = reservations;
- if (filterStatus !== 'all') result = result.filter(r => r.status === filterStatus);
- if (searchTerm) {
- const q = searchTerm.toLowerCase();
- result = result.filter(r => {
- const addr = (r.property?.address || '').toLowerCase();
- const sid = String(r.id).toLowerCase();
- return addr.includes(q) || sid.includes(q);
- });
- }
- setFiltered(result);
+ let r = reservations;
+ if (filterStatus !== 'all') r = r.filter(x => STATUS_MAP[x.status] === filterStatus);
+ if (searchTerm) { const q = searchTerm.toLowerCase(); r = r.filter(x => propAddr(x._prop).toLowerCase().includes(q) || String(x.id).includes(q)); }
+ setFiltered(r);
}, [reservations, filterStatus, searchTerm]);
- const statuses = ['all', ...new Set(reservations.map(r => r.status))];
- const statusCounts = {
- all: reservations.length,
- ...Object.fromEntries(
- [...new Set(reservations.map(r => r.status))].map(s => [s, reservations.filter(r => r.status === s).length])
- ),
- };
+ const allStatuses = [...new Set(reservations.map(r => STATUS_MAP[r.status]))];
+ const counts = { all: reservations.length, ...Object.fromEntries(allStatuses.map(s => [s, reservations.filter(r => STATUS_MAP[r.status] === s).length])) };
- if (loading) return
;
+ if (loading) return
;
return (
-
setSelected(null)} />
-
+ setSelected(null)} />
-
- router.back()} className="flex items-center gap-2 text-gray-600 hover:text-amber-600 mb-4">
- الرجوع
-
+
+ router.back()} className="flex items-center gap-2 text-gray-600 hover:text-amber-600 mb-4"> الرجوع
حجوزاتي
لديك {reservations.length} حجز
-
- {Object.entries(statusCounts).map(([status, count]) => (
-
setFilterStatus(status)}
- >
- {count}
- {status === 'all' ? 'الكل' : (statusConfig[status]?.label || status)}
+ {Object.entries(counts).map(([s, c]) => (
+ setFilterStatus(s)}>
+ {c}
+ {s==='all'?'الكل':(STATUS_UI[s]?.label||s)}
))}
-
-
- setSearchTerm(e.target.value)}
- className="w-full pl-10 pr-4 py-3 border border-gray-300 rounded-xl focus:outline-none focus:ring-2 focus:ring-amber-500"
- />
+
+ setSearchTerm(e.target.value)}
+ className="w-full pl-10 pr-4 py-3 border border-gray-300 rounded-xl focus:outline-none focus:ring-2 focus:ring-amber-500"/>
-
{filtered.length === 0 ? (
-
+
لا توجد حجوزات
لم تقم بأي حجز حتى الآن
) : (
- {filtered.map((r) => (
-
- ))}
+ {filtered.map(r => )}
)}