added a swicher on the properties
All checks were successful
Build frontend / build (push) Successful in 46s
All checks were successful
Build frontend / build (push) Successful in 46s
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, getMyRentListings } 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';
|
||||
@ -224,14 +224,22 @@ export default function PropertyDetailsPage() {
|
||||
// Check if current user owns this property via their own listings
|
||||
if (AuthService.isAuthenticated() && AuthService.isOwner()) {
|
||||
try {
|
||||
const myRent = await getMyRentListings();
|
||||
const list = Array.isArray(myRent) ? myRent : (myRent ? [myRent] : []);
|
||||
const [myRent, mySale] = await Promise.allSettled([
|
||||
getMyRentListings(),
|
||||
getMySaleListings(),
|
||||
]);
|
||||
const myPropIds = new Set();
|
||||
list.filter(Boolean).forEach(p => {
|
||||
const info = p.propertyInformation || {};
|
||||
if (info.id) myPropIds.add(Number(info.id));
|
||||
if (p.id) myPropIds.add(Number(p.id));
|
||||
});
|
||||
const collectIds = (result) => {
|
||||
if (result.status !== 'fulfilled' || !result.value) return;
|
||||
const list = Array.isArray(result.value) ? result.value : [result.value];
|
||||
list.filter(Boolean).forEach(p => {
|
||||
const info = p.propertyInformation || {};
|
||||
if (info.id) myPropIds.add(Number(info.id));
|
||||
if (p.id) myPropIds.add(Number(p.id));
|
||||
});
|
||||
};
|
||||
collectIds(myRent);
|
||||
collectIds(mySale);
|
||||
const propInfoId = mapped._raw?.propertyInformation?.id;
|
||||
if (myPropIds.has(Number(mapped.id)) || (propInfoId && myPropIds.has(Number(propInfoId)))) {
|
||||
setIsOwnProperty(true);
|
||||
|
||||
Reference in New Issue
Block a user