added the descption
All checks were successful
Build frontend / build (push) Successful in 42s

This commit is contained in:
mouazkh
2026-05-26 19:18:49 +03:00
parent 9979877e1c
commit c53a8eeb6d

View File

@ -15,7 +15,7 @@ import {
TreePine, Building, GraduationCap, ExternalLink, TreePine, Building, GraduationCap, ExternalLink,
Smile, Ban, Wine, Dog, CassetteTape, Info Smile, Ban, Wine, Dog, CassetteTape, Info
} from 'lucide-react'; } from 'lucide-react';
import { getRentProperty, getSaleProperty, getSalePropertyById, bookReservation, getAvailableDateRanges, getOwnerContactInformation, getMyRentListings, getMySaleListings, getOwnerByUserId } from '../../utils/api'; import { getRentProperty, getSaleProperty, getSalePropertyById, bookReservation, getAvailableDateRanges, getOwnerContactInformation, getMyRentListings } from '../../utils/api';
import AuthService from '../../services/AuthService'; import AuthService from '../../services/AuthService';
import { useFavorites } from '@/app/contexts/FavoritesContext'; import { useFavorites } from '@/app/contexts/FavoritesContext';
import { BuildingTypeKeys, PropertyStatusKeys, extractCity } from '../../enums'; import { BuildingTypeKeys, PropertyStatusKeys, extractCity } from '../../enums';
@ -221,53 +221,20 @@ export default function PropertyDetailsPage() {
console.warn('Failed to fetch date ranges', e); console.warn('Failed to fetch date ranges', e);
} }
} }
// Check if current user owns this property // Check if current user owns this property via their own listings
if (AuthService.isAuthenticated() && AuthService.isOwner()) { if (AuthService.isAuthenticated() && AuthService.isOwner()) {
try { try {
const authUser = AuthService.getUser(); const myRent = await getMyRentListings();
const rawInfo = (mapped._raw || {}).propertyInformation || {}; const list = Array.isArray(myRent) ? myRent : (myRent ? [myRent] : []);
let owned = false; const myPropIds = new Set(list.map(p => {
// Check 1: Fetch owner profile to get DB id, then compare with propertyInformation.ownerId
if (authUser?.id) {
try {
const ownerProfile = await getOwnerByUserId(authUser.id);
if (ownerProfile?.id && mapped.ownerId && Number(ownerProfile.id) === Number(mapped.ownerId)) {
owned = true;
}
} catch (e) {
console.warn('[OwnerCheck] getOwnerByUserId failed:', e);
}
}
// Check 2: Fallback via managed property IDs (like Flutter ManagedPropertiesService)
if (!owned) {
const [myRent, mySale] = await Promise.allSettled([
getMyRentListings(),
getMySaleListings(),
]);
const myPropIds = new Set();
const collectIds = (result) => {
if (result.status !== 'fulfilled' || !result.value) return;
const list = Array.isArray(result.value) ? result.value : [result.value];
list.forEach(p => {
const info = p.propertyInformation || {}; const info = p.propertyInformation || {};
if (info.id) myPropIds.add(Number(info.id)); return Number(info.id || p.id);
if (p.id) myPropIds.add(Number(p.id)); }));
}); if (myPropIds.has(Number(mapped._raw?.propertyInformation?.id || mapped.id))) {
}; setIsOwnProperty(true);
collectIds(myRent);
collectIds(mySale);
const checkId = mapped.id ? Number(mapped.id) : null;
const checkInfoId = rawInfo.id ? Number(rawInfo.id) : null;
if ((checkId && myPropIds.has(checkId)) || (checkInfoId && myPropIds.has(checkInfoId))) {
owned = true;
} }
}
setIsOwnProperty(owned);
} catch (e) { } catch (e) {
console.error('[OwnerCheck] error:', e); console.warn('[OwnerCheck] failed:', e);
} }
} }
} }
@ -831,9 +798,6 @@ export default function PropertyDetailsPage() {
<summary className="cursor-pointer font-bold">🔍 Owner Debug</summary> <summary className="cursor-pointer font-bold">🔍 Owner Debug</summary>
<div className="mt-1 space-y-0.5"> <div className="mt-1 space-y-0.5">
<p>isOwnProperty: <b>{String(isOwnProperty)}</b></p> <p>isOwnProperty: <b>{String(isOwnProperty)}</b></p>
<p>prop ownerId: <b>{String(property.ownerId ?? 'null')}</b></p>
<p>user id (JWT): <b>{String(AuthService.getUser()?.id ?? 'null')}</b></p>
<p>user name: <b>{String(AuthService.getUser()?.name ?? 'null')}</b></p>
<p>authenticated: <b>{String(AuthService.isAuthenticated())}</b> | isOwner: <b>{String(AuthService.isOwner())}</b></p> <p>authenticated: <b>{String(AuthService.isAuthenticated())}</b> | isOwner: <b>{String(AuthService.isOwner())}</b></p>
</div> </div>
</details> </details>