Owner properties page fetches from API via GetMyRentListings
All checks were successful
Build frontend / build (push) Successful in 41s

- Calls /RentProperties/GetMyRentListings/{userId} with user ID from JWT
- Maps API response (nested propertyInformation + detailsJSON) to UI format
- Removed mock data and localStorage fallback
This commit is contained in:
Claw AI
2026-03-29 22:17:49 +00:00
parent 6245965c1c
commit 0c3b454015
2 changed files with 64 additions and 49 deletions

View File

@ -46,6 +46,7 @@ import {
} from 'lucide-react'; } from 'lucide-react';
import toast, { Toaster } from 'react-hot-toast'; import toast, { Toaster } from 'react-hot-toast';
import AuthService from '../../services/AuthService'; import AuthService from '../../services/AuthService';
import { getMyRentListings } from '../../utils/api';
const DeleteConfirmationModal = ({ isOpen, onClose, onConfirm, propertyTitle }) => { const DeleteConfirmationModal = ({ isOpen, onClose, onConfirm, propertyTitle }) => {
if (!isOpen) return null; if (!isOpen) return null;
@ -708,56 +709,65 @@ export default function OwnerPropertiesPage() {
const loadProperties = () => { const loadProperties = async () => {
const storedProperties = localStorage.getItem('ownerProperties'); const authUser = AuthService.getUser();
if (storedProperties) { const userId = authUser?.id;
setProperties(JSON.parse(storedProperties));
} else { if (!userId) {
const mockProperties = [ console.warn('[OwnerProperties] No user ID found');
{
id: 1,
title: 'فيلا فاخرة في المزة',
propertyType: 'villa',
purpose: 'rent',
rentType: 'both',
dailyPrice: 500000,
monthlyPrice: 15000000,
location: 'دمشق، المزة',
bedrooms: 5,
bathrooms: 4,
area: 450,
livingRooms: 3,
status: 'available',
images: ['/villa1.jpg'],
createdAt: new Date().toISOString(),
furnished: true,
description: 'فيلا فاخرة مع حديقة خاصة ومسبح',
address: 'شارع المزة - فيلات غربية',
city: 'دمشق',
district: 'المزة',
services: {
electricity: true,
internet: true,
heating: true,
water: true,
airConditioning: true,
parking: true,
elevator: false
},
terms: {
noSmoking: true,
noPets: false,
noParties: true,
noAlcohol: false,
suitableForChildren: true,
suitableForElderly: true
}
}
];
setProperties(mockProperties);
localStorage.setItem('ownerProperties', JSON.stringify(mockProperties));
}
setIsLoading(false); setIsLoading(false);
return;
}
try {
console.log('[OwnerProperties] Fetching listings for user:', userId);
const data = await getMyRentListings(userId);
const list = Array.isArray(data) ? data : (data ? [data] : []);
console.log('[OwnerProperties] API returned:', list.length, 'properties');
const mapped = list.map((item) => {
const info = item.propertyInformation || {};
const details = (() => {
try { return JSON.parse(info.detailsJSON || '{}'); } catch { return {}; }
})();
return {
id: item.id,
title: info.address || `عقار #${item.id}`,
propertyType: { 0: 'apartment', 1: 'villa', 2: 'house' }[info.buildingType] || 'apartment',
purpose: 'rent',
rentType: { 0: 'daily', 1: 'weekly', 2: 'monthly' }[item.rentType] || 'daily',
dailyPrice: item.dailyRent || 0,
monthlyPrice: item.monthlyRent || 0,
deposit: item.deposit || 0,
location: info.address || '',
bedrooms: info.numberOfBedRooms || 0,
bathrooms: info.numberOfBathRooms || 0,
area: info.space || 0,
livingRooms: details.livingRooms || 0,
status: { 0: 'available', 1: 'booked', 2: 'maintenance' }[info.status] || 'available',
images: ['/property-placeholder.jpg'],
createdAt: item.createdAt || new Date().toISOString(),
furnished: details.furnished || false,
description: info.description || '',
address: info.address || '',
city: '',
district: '',
services: details.services || {},
terms: details.terms || {},
rating: item.rating || 0,
currencyId: item.currencyId,
_raw: item,
};
});
setProperties(mapped);
} catch (err) {
console.error('[OwnerProperties] Failed to load properties:', err);
toast.error('فشل في تحميل العقارات');
} finally {
setIsLoading(false);
}
}; };
const updatePropertiesInStorage = (newProperties) => { const updatePropertiesInStorage = (newProperties) => {

View File

@ -177,6 +177,11 @@ export async function getOwnerByUserId(userId) {
// ─── Properties ─── // ─── Properties ───
export async function getMyRentListings(userId) {
console.log('[API] Fetching my rent listings for user:', userId);
return apiFetch(`/RentProperties/GetMyRentListings/${userId}`);
}
export async function addRentProperty(data) { export async function addRentProperty(data) {
console.log('[API] Adding rent property:', data.PropertyInformation?.Address); console.log('[API] Adding rent property:', data.PropertyInformation?.Address);
return apiFetch('/RentProperties/AddRentProperty', { return apiFetch('/RentProperties/AddRentProperty', {