From 13a0649806b1d47a5bc005ce0eb2e1398abed6b6 Mon Sep 17 00:00:00 2001 From: mouazkh Date: Tue, 26 May 2026 17:31:01 +0300 Subject: [PATCH] added the descption --- app/property/[id]/PropertyDetail.js | 42 ++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/app/property/[id]/PropertyDetail.js b/app/property/[id]/PropertyDetail.js index 7d9f950..65be139 100644 --- a/app/property/[id]/PropertyDetail.js +++ b/app/property/[id]/PropertyDetail.js @@ -15,7 +15,7 @@ import { TreePine, Building, GraduationCap, ExternalLink, Smile, Ban, Wine, Dog, CassetteTape, Info } from 'lucide-react'; -import { getRentProperty, getSaleProperty, getSalePropertyById, bookReservation, getAvailableDateRanges, getOwnerContactInformation } from '../../utils/api'; +import { getRentProperty, getSaleProperty, getSalePropertyById, bookReservation, getAvailableDateRanges, getOwnerContactInformation, getMyRentListings, getMySaleListings } from '../../utils/api'; import AuthService from '../../services/AuthService'; import { useFavorites } from '@/app/contexts/FavoritesContext'; import { BuildingTypeKeys, PropertyStatusKeys, extractCity } from '../../enums'; @@ -185,6 +185,7 @@ export default function PropertyDetailsPage() { const [calendarMonth, setCalendarMonth] = useState(() => new Date().getMonth()); const [calendarYear, setCalendarYear] = useState(() => new Date().getFullYear()); const [pricingMode, setPricingMode] = useState('daily'); + const [isOwnProperty, setIsOwnProperty] = useState(false); const [favLoading, setFavLoading] = useState(false); const [avgRating, setAvgRating] = useState(null); const [showRatingForm, setShowRatingForm] = useState(false); @@ -219,6 +220,30 @@ export default function PropertyDetailsPage() { console.warn('Failed to fetch date ranges', e); } } + // Check if current user owns this property + if (AuthService.isAuthenticated() && AuthService.isOwner()) { + try { + const [myRent, mySale] = await Promise.allSettled([ + getMyRentListings(), + getMySaleListings(), + ]); + const myPropIds = new Set(); + const addIds = (items) => { + if (!Array.isArray(items)) return; + items.forEach(p => { + const info = p.propertyInformation || {}; + if (info.id) myPropIds.add(info.id); + if (p.id) myPropIds.add(p.id); + }); + }; + if (myRent.status === 'fulfilled') addIds(myRent.value); + if (mySale.status === 'fulfilled') addIds(mySale.value); + const propInfoId = mapped._raw?.propertyInformationId || mapped.id; + if (myPropIds.has(propInfoId) || myPropIds.has(mapped.id)) { + setIsOwnProperty(true); + } + } catch {} + } } } catch (err) { console.error('[PropertyDetail] Failed:', err); @@ -777,12 +802,15 @@ export default function PropertyDetailsPage() { {/* Booking Card */} {property.isRent && ( -
- -

حجز العقار

-
- - {bookingSuccess ? ( + {isOwnProperty ? ( +
+
+ +
+

هذا عقارك

+

لا يمكنك حجز عقارك الخاص

+
+ ) : bookingSuccess ? (