diff --git a/app/owner/bookings/page.js b/app/owner/bookings/page.js
index 258a884..a19f601 100644
--- a/app/owner/bookings/page.js
+++ b/app/owner/bookings/page.js
@@ -6,7 +6,7 @@ import { useRouter } from "next/navigation";
import { useTranslation } from "react-i18next";
import { Calendar, User, Mail, Phone, CheckCircle, XCircle, Clock, MapPin, Bed, Bath, Square, CalendarDays, ChevronLeft, ChevronRight, Eye, Loader2, Search } from "lucide-react";
import toast, { Toaster } from "react-hot-toast";
-import { getMyRentListings, getOwnerReservationRequests } from "@/app/utils/api";
+import { getRentProperty, getOwnerReservationsByStatuses, getRentProperties } from "@/app/utils/api";
import useAuth from "@/app/hooks/useAuth";
import Loading from "@/app/loading";
@@ -383,22 +383,63 @@ export default function OwnerBookingsPage() {
const fetchData = async () => {
try {
- const response = await getOwnerReservationRequests();
+ const [response, rentProps] = await Promise.all([getOwnerReservationsByStatuses([0, 1, 2, 3, 4]), getRentProperties().catch(() => [])]);
let rawData = response;
+
if (response && response.data) {
rawData = response.data;
}
- // تحويل البيانات إلى مصفوفة وتصفية العناصر الفارغة (null أو undefined)
const rawList = Array.isArray(rawData) ? rawData : rawData ? [rawData] : [];
+
const list = rawList.filter(Boolean);
- const mappedBookings = list.map((item) => {
+ // Rent properties
+ const propsList = Array.isArray(rentProps) ? rentProps : [];
+
+ // مهم: تعريف propMap هون
+ const propMap = {};
+
+ propsList.forEach((rp) => {
+ const info = rp?.propertyInformation ?? {};
+
+ const propertyData = {
+ ...info,
+
+ // إذا كانت موجودة داخل rp
+ dailyRent: rp?.dailyRent,
+ monthlyRent: rp?.monthlyRent,
+ deposit: rp?.deposit,
+
+ allowedPaymentPeriod: rp?.allowedPaymentPeriod,
+ };
+
+ propMap[rp.propertyInformationId] = propertyData;
+ propMap[rp.propertyInformation?.id] = propertyData;
+ });
+
+ console.log("PROP MAP:", propMap);
+
+ // ربط الـ reservation بالعقار عن طريق propertyId
+ const enriched = list.map((item) => {
+ if (item.propertyId && propMap[item.propertyId]) {
+ item._prop = propMap[item.propertyId];
+ }
+
+ return item;
+ });
+
+ console.log("ENRICHED BOOKINGS:", enriched);
+
+ const mappedBookings = enriched.map((item) => {
+ const property = item._prop || {};
+
let parsedDetails = {};
+
try {
- if (item?.propertyInformation?.detailsJSON) {
- parsedDetails = JSON.parse(item.propertyInformation.detailsJSON);
+ if (property?.detailsJSON) {
+ parsedDetails = JSON.parse(property.detailsJSON);
}
} catch (e) {
console.error("Error parsing detailsJSON", e);
@@ -406,31 +447,48 @@ export default function OwnerBookingsPage() {
const statusMap = {
0: "pending",
- 1: "confirmed",
- 2: "completed",
- 3: "cancelled",
+ 1: "pending",
+ 2: "confirmed",
+ 3: "completed",
+ 4: "cancelled",
};
- const statusKey = statusMap[item?.propertyInformation?.status] || "pending";
+ const statusKey = statusMap[item?.status] || "pending";
return {
id: item?.id,
- dailyRent: item?.dailyRent,
- monthlyRent: item?.monthlyRent,
- deposit: item?.deposit,
+
+ propertyId: item?.propertyId,
+
+ // هون صاروا ياخدوا من property
+ dailyRent: property?.dailyRent || 0,
+ monthlyRent: property?.monthlyRent || 0,
+ deposit: property?.deposit || 0,
+
createdAt: item?.createdAt,
- startDate: item?.createdAt?.split("T")[0],
+
+ startDate: item?.startDate?.split("T")[0],
+ endDate: item?.endDate?.split("T")[0],
+
status: statusKey,
- propertyTitle: parsedDetails.description || `${t("property")} #${item?.id}`,
- location: item?.propertyInformation?.address || "",
- images: item?.propertyInformation?.images || [],
+
+ propertyTitle: parsedDetails.description || `${t("property")} #${item?.propertyId}`,
+
+ location: property?.address || "",
+
+ images: property?.images || [],
+
propertyDetails: {
- bedrooms: item?.propertyInformation?.numberOfBedRooms || 0,
- bathrooms: item?.propertyInformation?.numberOfBathRooms || 0,
- salons: item?.propertyInformation?.numberOfSalons || 0,
- area: item?.propertyInformation?.space || 0,
+ bedrooms: property?.numberOfBedRooms || 0,
+ bathrooms: property?.numberOfBathRooms || 0,
+ salons: property?.numberOfSalons || 0,
+ area: property?.space || 0,
},
+
+ propertyInformation: property,
+
parsedDetails,
+
tenantName: item?.tenantName || null,
tenantPhone: item?.tenantPhone || null,
tenantEmail: item?.tenantEmail || null,
@@ -476,9 +534,7 @@ export default function OwnerBookingsPage() {
}, [bookings]);
if (isLoading) {
- return (
-