This commit is contained in:
@ -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 && (
|
||||
<motion.div initial={{ opacity: 0, x: 20 }} animate={{ opacity: 1, x: 0 }} className="bg-white rounded-2xl p-5 shadow-sm border border-gray-200 sticky top-6">
|
||||
<div className="flex items-center gap-2 mb-3">
|
||||
<Calendar className="w-4 h-4 text-amber-500" />
|
||||
<h3 className="font-bold text-gray-900">حجز العقار</h3>
|
||||
</div>
|
||||
|
||||
{bookingSuccess ? (
|
||||
{isOwnProperty ? (
|
||||
<div className="text-center py-3">
|
||||
<div className="w-14 h-14 bg-gray-100 rounded-full flex items-center justify-center mx-auto mb-2">
|
||||
<Home className="w-7 h-7 text-gray-400" />
|
||||
</div>
|
||||
<h4 className="font-bold text-gray-700 text-sm mb-1">هذا عقارك</h4>
|
||||
<p className="text-xs text-gray-500">لا يمكنك حجز عقارك الخاص</p>
|
||||
</div>
|
||||
) : bookingSuccess ? (
|
||||
<div className="text-center py-3">
|
||||
<div className="w-14 h-14 bg-green-100 rounded-full flex items-center justify-center mx-auto mb-2">
|
||||
<Check className="w-7 h-7 text-green-600" />
|
||||
|
||||
Reference in New Issue
Block a user