This commit is contained in:
@ -161,7 +161,7 @@ function mapApiDetail(item) {
|
|||||||
isSmokeAllow: item.isSmokeAllow,
|
isSmokeAllow: item.isSmokeAllow,
|
||||||
isVisitorAllow: item.isVisitorAllow,
|
isVisitorAllow: item.isVisitorAllow,
|
||||||
specializedFor: item.specializedFor,
|
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,
|
_raw: item,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -221,19 +221,18 @@ 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 (Flutter approach)
|
||||||
if (AuthService.isAuthenticated()) {
|
if (AuthService.isAuthenticated()) {
|
||||||
const currentUserId = AuthService.getUserId();
|
const currentUserId = AuthService.getUserId();
|
||||||
const raw = mapped._raw || {};
|
const rawInfo = (mapped._raw || {}).propertyInformation || {};
|
||||||
const rawInfo = raw.propertyInformation || {};
|
|
||||||
console.log('[OwnerCheck] currentUserId:', currentUserId);
|
console.log('[OwnerCheck] currentUserId:', currentUserId);
|
||||||
console.log('[OwnerCheck] raw keys:', Object.keys(raw));
|
console.log('[OwnerCheck] mapped.ownerId:', mapped.ownerId, 'rawInfo.ownerId:', rawInfo.ownerId);
|
||||||
console.log('[OwnerCheck] rawInfo keys:', Object.keys(rawInfo));
|
// Check 1: Direct ownerId match (like Flutter: property.ownerId == currentUserId)
|
||||||
console.log('[OwnerCheck] raw.userId:', raw.userId, 'raw.ownerId:', raw.ownerId, 'rawInfo.userId:', rawInfo.userId, 'rawInfo.ownerId:', rawInfo.ownerId);
|
if (mapped.ownerId != null && currentUserId != null && Number(mapped.ownerId) === Number(currentUserId)) {
|
||||||
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))) {
|
|
||||||
setIsOwnProperty(true);
|
setIsOwnProperty(true);
|
||||||
} else if (AuthService.isOwner()) {
|
}
|
||||||
|
// Check 2: ManagedPropertiesService fallback (owner only)
|
||||||
|
else if (AuthService.isOwner()) {
|
||||||
try {
|
try {
|
||||||
const [myRent, mySale] = await Promise.allSettled([
|
const [myRent, mySale] = await Promise.allSettled([
|
||||||
getMyRentListings(),
|
getMyRentListings(),
|
||||||
@ -253,7 +252,6 @@ export default function PropertyDetailsPage() {
|
|||||||
collectIds(mySale);
|
collectIds(mySale);
|
||||||
const checkId = mapped.id ? Number(mapped.id) : null;
|
const checkId = mapped.id ? Number(mapped.id) : null;
|
||||||
const checkInfoId = rawInfo.id ? Number(rawInfo.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))) {
|
if ((checkId && myPropIds.has(checkId)) || (checkInfoId && myPropIds.has(checkInfoId))) {
|
||||||
setIsOwnProperty(true);
|
setIsOwnProperty(true);
|
||||||
}
|
}
|
||||||
@ -815,6 +813,17 @@ export default function PropertyDetailsPage() {
|
|||||||
|
|
||||||
{/* Sidebar */}
|
{/* Sidebar */}
|
||||||
<div className="space-y-4">
|
<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 */}
|
{/* Booking Card */}
|
||||||
{property.isRent && (
|
{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">
|
<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">
|
||||||
|
|||||||
Reference in New Issue
Block a user