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');
{ setIsLoading(false);
id: 1, return;
title: 'فيلا فاخرة في المزة', }
propertyType: 'villa',
purpose: 'rent', try {
rentType: 'both', console.log('[OwnerProperties] Fetching listings for user:', userId);
dailyPrice: 500000, const data = await getMyRentListings(userId);
monthlyPrice: 15000000, const list = Array.isArray(data) ? data : (data ? [data] : []);
location: 'دمشق، المزة', console.log('[OwnerProperties] API returned:', list.length, 'properties');
bedrooms: 5,
bathrooms: 4, const mapped = list.map((item) => {
area: 450, const info = item.propertyInformation || {};
livingRooms: 3, const details = (() => {
status: 'available', try { return JSON.parse(info.detailsJSON || '{}'); } catch { return {}; }
images: ['/villa1.jpg'], })();
createdAt: new Date().toISOString(),
furnished: true, return {
description: 'فيلا فاخرة مع حديقة خاصة ومسبح', id: item.id,
address: 'شارع المزة - فيلات غربية', title: info.address || `عقار #${item.id}`,
city: 'دمشق', propertyType: { 0: 'apartment', 1: 'villa', 2: 'house' }[info.buildingType] || 'apartment',
district: 'المزة', purpose: 'rent',
services: { rentType: { 0: 'daily', 1: 'weekly', 2: 'monthly' }[item.rentType] || 'daily',
electricity: true, dailyPrice: item.dailyRent || 0,
internet: true, monthlyPrice: item.monthlyRent || 0,
heating: true, deposit: item.deposit || 0,
water: true, location: info.address || '',
airConditioning: true, bedrooms: info.numberOfBedRooms || 0,
parking: true, bathrooms: info.numberOfBathRooms || 0,
elevator: false area: info.space || 0,
}, livingRooms: details.livingRooms || 0,
terms: { status: { 0: 'available', 1: 'booked', 2: 'maintenance' }[info.status] || 'available',
noSmoking: true, images: ['/property-placeholder.jpg'],
noPets: false, createdAt: item.createdAt || new Date().toISOString(),
noParties: true, furnished: details.furnished || false,
noAlcohol: false, description: info.description || '',
suitableForChildren: true, address: info.address || '',
suitableForElderly: true city: '',
} district: '',
} services: details.services || {},
]; terms: details.terms || {},
setProperties(mockProperties); rating: item.rating || 0,
localStorage.setItem('ownerProperties', JSON.stringify(mockProperties)); currencyId: item.currencyId,
_raw: item,
};
});
setProperties(mapped);
} catch (err) {
console.error('[OwnerProperties] Failed to load properties:', err);
toast.error('فشل في تحميل العقارات');
} finally {
setIsLoading(false);
} }
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', {