From 9f6492cf418b5a814b51ef71b8485354d494165a Mon Sep 17 00:00:00 2001 From: mouazkh Date: Tue, 26 May 2026 00:20:20 +0300 Subject: [PATCH] fixed the details --- app/contexts/FavoritesContext.js | 6 ++- app/owner/properties/page.js | 84 +++++++++++++++++++++++++++-- app/property/[id]/PropertyDetail.js | 25 ++++++++- app/property/[id]/page.js | 8 ++- 4 files changed, 115 insertions(+), 8 deletions(-) diff --git a/app/contexts/FavoritesContext.js b/app/contexts/FavoritesContext.js index afdfcfe..b136d5b 100644 --- a/app/contexts/FavoritesContext.js +++ b/app/contexts/FavoritesContext.js @@ -17,7 +17,11 @@ export const useFavorites = () => { function mapApiFavorite(item) { const info = item.propertyInformation || {}; let details = {}; - try { details = JSON.parse(info.detailsJSON || '{}'); } catch {} + if (typeof info.detailsJSON === 'object' && info.detailsJSON) { + details = info.detailsJSON; + } else { + try { details = JSON.parse(info.detailsJSON || '{}'); } catch {} + } const price = item.monthlyRent || item.dailyRent || 0; const priceUnit = item.monthlyRent ? 'monthly' : 'daily'; diff --git a/app/owner/properties/page.js b/app/owner/properties/page.js index ef6f41f..d1f2f81 100644 --- a/app/owner/properties/page.js +++ b/app/owner/properties/page.js @@ -46,6 +46,11 @@ import { Star, Ban, Check, + School, + Hospital, + Store, + GraduationCap, + TreePine, } from "lucide-react"; import toast, { Toaster } from "react-hot-toast"; import AuthService from "../../services/AuthService"; @@ -153,6 +158,21 @@ const termLabels = { OnlyMales: "ذكور فقط", }; +const proximityLabels = { + School: "مدرسة", + Hospital: "مستشفى", + Restaurant: "مطعم", + University: "جامعة", + Park: "حديقة", + Mall: "مركز تسوق", + Supermarket: "سوبر ماركت", + Pharmacy: "صيدلية", + Mosque: "مسجد", + Bank: "بنك", + Airport: "مطار", + BusStation: "موقف باص", +}; + const PropertyViewModal = ({ isOpen, onClose, property }) => { if (!isOpen || !property) return null; @@ -220,6 +240,30 @@ const PropertyViewModal = ({ isOpen, onClose, property }) => { {property.propertyTypeLabel || "عقار"}

+

+ نوع العرض: + + {property.displayType === "Daily rent" + ? "إيجار يومي" + : property.displayType === "Monthly rent" + ? "إيجار شهري" + : property.displayType === "Both" + ? "يومي وشهري" + : property.displayType === "For sale" + ? "للبيع" + : property.rentType === "daily" + ? "إيجار يومي" + : property.rentType === "monthly" + ? "إيجار شهري" + : (property.dailyPrice > 0 && property.monthlyPrice > 0) + ? "يومي وشهري" + : property.monthlyPrice > 0 + ? "إيجار شهري" + : property.dailyPrice > 0 + ? "إيجار يومي" + : property.purpose === "sale" ? "للبيع" : "عرض"} + +

{property.purpose === "rent" && (

حالة التأثيث: @@ -355,9 +399,39 @@ const PropertyViewModal = ({ isOpen, onClose, property }) => { ); })} - - )} + + )} + + {property.proximity && Object.keys(property.proximity).length > 0 && ( +

+

القرب من الخدمات

+
+ {Object.entries(property.proximity).map(([key, val]) => { + if (!val) return null; + const dist = typeof val === "object" ? val.distance : val; + return ( +
+ {key === "School" && } + {key === "Hospital" && } + {key === "Restaurant" && } + {key === "University" && } + {key === "Park" && } + {key === "Mall" && } + {!["School","Hospital","Restaurant","University","Park","Mall"].includes(key) && } +
+ {proximityLabels[key] || key} + {dist} {typeof dist === "number" ? "كم" : ""} +
+
+ ); + })} +
+
+ )} {property.terms && Object.keys(property.terms).length > 0 && (
@@ -956,7 +1030,7 @@ export default function OwnerPropertiesPage() { const mappedRent = rentList.map((item) => { const info = item.propertyInformation || {}; - const details = (() => { + const details = typeof info.detailsJSON === 'object' && info.detailsJSON ? info.detailsJSON : (() => { try { return JSON.parse(info.detailsJSON || "{}"); } catch { @@ -1037,6 +1111,7 @@ export default function OwnerPropertiesPage() { : ["/property-placeholder.jpg"], createdAt: item.createdAt || new Date().toISOString(), furnished: details.furnished || false, + displayType: details.displayType || (item.dailyRent && item.monthlyRent ? 'Both' : item.monthlyRent ? 'Monthly rent' : item.dailyRent ? 'Daily rent' : 'Both'), description: info.description || "", address: info.address || "", city: "", @@ -1052,7 +1127,7 @@ export default function OwnerPropertiesPage() { const mappedSale = saleList.map((item) => { const info = item.propertyInformation || {}; - const details = (() => { + const details = typeof info.detailsJSON === 'object' && info.detailsJSON ? info.detailsJSON : (() => { try { return JSON.parse(info.detailsJSON || "{}"); } catch { @@ -1125,6 +1200,7 @@ export default function OwnerPropertiesPage() { : ["/property-placeholder.jpg"], createdAt: item.createdAt || new Date().toISOString(), furnished: details.furnished || false, + displayType: details.displayType || 'For sale', description: info.description || "", address: info.address || "", city: "", diff --git a/app/property/[id]/PropertyDetail.js b/app/property/[id]/PropertyDetail.js index 6c6bf3a..b402d77 100644 --- a/app/property/[id]/PropertyDetail.js +++ b/app/property/[id]/PropertyDetail.js @@ -75,7 +75,7 @@ const proximityLabels = { function mapApiDetail(item) { if (!item) return null; const info = item.propertyInformation || {}; - const details = (() => { try { return JSON.parse(info.detailsJSON || '{}'); } catch { return {}; } })(); + const details = typeof info.detailsJSON === 'object' && info.detailsJSON ? info.detailsJSON : (() => { try { return JSON.parse(info.detailsJSON || '{}'); } catch { return {}; } })(); const isRent = item.dailyRent != null || item.monthlyRent != null; const dailyPrice = item.dailyRent || 0; @@ -117,6 +117,10 @@ function mapApiDetail(item) { }); const roomDetails = details.room || details.roomDetails || {}; + const displayType = details.displayType || (isRent ? (monthlyPrice && dailyPrice ? 'Both' : monthlyPrice ? 'Monthly' : 'Daily') : 'Sale'); + const propertyCondition = details.propertyCondition || ''; + const furnished = propertyCondition.toLowerCase().includes('furniture') ? propertyCondition.toLowerCase() === 'withfurniture' : !!item.isFurnished; + return { id: item.id, propertyInformationId: info.id, @@ -128,6 +132,9 @@ function mapApiDetail(item) { priceUnit, priceDisplay: { daily: dailyPrice, monthly: monthlyPrice, sale: salePrice }, isRent, + displayType, + propertyCondition, + furnished, location: { city: extractCity(info.address) || 'دمشق', address: info.address || '', @@ -374,9 +381,23 @@ export default function PropertyDetailsPage() {
-
+
{property.typeLabel} {property.statusLabel} + {property.isRent && property.displayType && ( + + {(() => { + const dt = property.displayType.toLowerCase(); + if (dt === 'both' || dt.includes('both')) return 'يومي وشهري'; + if (dt.includes('daily')) return 'يومي'; + if (dt.includes('monthly')) return 'شهري'; + return dt; + })()} + + )} + + {property.furnished ? 'مفروش' : 'غير مفروش'} +

{property.title}

diff --git a/app/property/[id]/page.js b/app/property/[id]/page.js index 2c1191f..91be01f 100644 --- a/app/property/[id]/page.js +++ b/app/property/[id]/page.js @@ -19,7 +19,13 @@ async function fetchPropertyForMeta(id) { function mapProperty(item) { const info = item.propertyInformation || item.PropertyInformation || {}; let details = {}; - try { details = JSON.parse(info.detailsJSON || info.DetailsJSON || '{}'); } catch {} + if (typeof info.detailsJSON === 'object' && info.detailsJSON) { + details = info.detailsJSON; + } else if (typeof info.DetailsJSON === 'object' && info.DetailsJSON) { + details = info.DetailsJSON; + } else { + try { details = JSON.parse(info.detailsJSON || info.DetailsJSON || '{}'); } catch {} + } const price = item.monthlyRent || item.MonthlyRent || item.dailyRent || item.DailyRent || 0; const priceUnit = item.monthlyRent || item.MonthlyRent ? 'monthly' : 'daily';