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

This commit is contained in:
mouazkh
2026-05-26 18:43:47 +03:00
parent bf044cef45
commit 9fda2618c8

View File

@ -161,7 +161,7 @@ function mapApiDetail(item) {
isSmokeAllow: item.isSmokeAllow,
isVisitorAllow: item.isVisitorAllow,
specializedFor: item.specializedFor,
ownerId: item.userId || item.ownerId || info.userId || info.ownerId || null,
ownerId: info.ownerId ?? info.userId ?? item.ownerId ?? item.userId ?? null,
_raw: item,
};
}
@ -221,19 +221,18 @@ export default function PropertyDetailsPage() {
console.warn('Failed to fetch date ranges', e);
}
}
// Check if current user owns this property
// Check if current user owns this property (Flutter approach)
if (AuthService.isAuthenticated()) {
const currentUserId = AuthService.getUserId();
const raw = mapped._raw || {};
const rawInfo = raw.propertyInformation || {};
const rawInfo = (mapped._raw || {}).propertyInformation || {};
console.log('[OwnerCheck] currentUserId:', currentUserId);
console.log('[OwnerCheck] raw keys:', Object.keys(raw));
console.log('[OwnerCheck] rawInfo keys:', Object.keys(rawInfo));
console.log('[OwnerCheck] raw.userId:', raw.userId, 'raw.ownerId:', raw.ownerId, 'rawInfo.userId:', rawInfo.userId, 'rawInfo.ownerId:', rawInfo.ownerId);
const possibleOwnerFields = [raw.userId, raw.ownerId, rawInfo.userId, rawInfo.ownerId, raw.userID, raw.ownerID, rawInfo.userID, rawInfo.ownerID].filter(Boolean);
if (possibleOwnerFields.some(id => String(id) === String(currentUserId))) {
console.log('[OwnerCheck] mapped.ownerId:', mapped.ownerId, 'rawInfo.ownerId:', rawInfo.ownerId);
// Check 1: Direct ownerId match (like Flutter: property.ownerId == currentUserId)
if (mapped.ownerId != null && currentUserId != null && Number(mapped.ownerId) === Number(currentUserId)) {
setIsOwnProperty(true);
} else if (AuthService.isOwner()) {
}
// Check 2: ManagedPropertiesService fallback (owner only)
else if (AuthService.isOwner()) {
try {
const [myRent, mySale] = await Promise.allSettled([
getMyRentListings(),
@ -253,7 +252,6 @@ export default function PropertyDetailsPage() {
collectIds(mySale);
const checkId = mapped.id ? Number(mapped.id) : null;
const checkInfoId = rawInfo.id ? Number(rawInfo.id) : null;
console.log('[OwnerCheck] myPropIds:', [...myPropIds], 'checkId:', checkId, 'checkInfoId:', checkInfoId);
if ((checkId && myPropIds.has(checkId)) || (checkInfoId && myPropIds.has(checkInfoId))) {
setIsOwnProperty(true);
}
@ -815,6 +813,17 @@ export default function PropertyDetailsPage() {
{/* Sidebar */}
<div className="space-y-4">
{/* Debug: Owner Check Info */}
{typeof window !== 'undefined' && (
<details className="bg-red-50 p-2 rounded-xl text-[10px] text-red-700 border border-red-200">
<summary className="cursor-pointer font-bold">🔍 Owner Debug</summary>
<div className="mt-1 space-y-0.5">
<p>isOwnProperty: <b>{String(isOwnProperty)}</b></p>
<p>ownerId: <b>{String(property.ownerId ?? 'null')}</b></p>
<p>rawInfo keys: <b>{Object.keys((property._raw||{}).propertyInformation||{}).join(', ') || 'none'}</b></p>
</div>
</details>
)}
{/* 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">