the best in the west is mouaz
All checks were successful
Build frontend / build (push) Successful in 55s

This commit is contained in:
mouazkh
2026-05-25 21:27:39 +03:00
parent a5577765ed
commit 00ccf5f262
35 changed files with 4876 additions and 2433 deletions

View File

@ -46,7 +46,7 @@ import {
} from 'lucide-react';
import toast, { Toaster } from 'react-hot-toast';
import AuthService from '../../services/AuthService';
import { getMyRentListings } from '../../utils/api';
import { getMyRentListings, getMySaleListings, editRentProperty } from '../../utils/api';
const DeleteConfirmationModal = ({ isOpen, onClose, onConfirm, propertyTitle }) => {
if (!isOpen) return null;
@ -721,24 +721,31 @@ export default function OwnerPropertiesPage() {
try {
console.log('[OwnerProperties] Fetching listings for user:', userId);
const data = await getMyRentListings();
const list = Array.isArray(data) ? data : (data ? [data] : []);
console.log('[OwnerProperties] API returned:', list.length, 'properties');
const mapped = list.map((item) => {
const [rentData, saleData] = await Promise.allSettled([
getMyRentListings(),
getMySaleListings(),
]);
const rentList = rentData.status === 'fulfilled' ? (Array.isArray(rentData.value) ? rentData.value : (rentData.value ? [rentData.value] : [])) : [];
const saleList = saleData.status === 'fulfilled' ? (Array.isArray(saleData.value) ? saleData.value : (saleData.value ? [saleData.value] : [])) : [];
console.log('[OwnerProperties] Rent:', rentList.length, 'Sale:', saleList.length);
const mappedRent = rentList.map((item) => {
const info = item.propertyInformation || {};
const details = (() => {
try { return JSON.parse(info.detailsJSON || '{}'); } catch { return {}; }
})();
const details = (() => { try { return JSON.parse(info.detailsJSON || '{}'); } catch { return {}; } })();
const apiBase = typeof window !== 'undefined' ? (process.env.NEXT_PUBLIC_API_URL || 'https://45.93.137.91.nip.io/api') : '';
const raw = Array.isArray(info.images) ? info.images : [];
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',
rentType: { 0: 'daily', 1: 'monthly' }[item.rentType] || 'daily',
dailyPrice: item.dailyRent || 0,
monthlyPrice: item.monthlyRent || 0,
salePrice: item.price || 0,
deposit: item.deposit || 0,
location: info.address || '',
bedrooms: info.numberOfBedRooms || 0,
@ -746,11 +753,7 @@ export default function OwnerPropertiesPage() {
area: info.space || 0,
livingRooms: details.livingRooms || 0,
status: { 0: 'available', 1: 'booked', 2: 'maintenance' }[info.status] || 'available',
images: (() => {
const apiBase = typeof window !== 'undefined' ? (process.env.NEXT_PUBLIC_API_URL || 'https://45.93.137.91.nip.io/api') : '';
const raw = Array.isArray(info.images) ? info.images : [];
return raw.length > 0 ? raw.map(img => img.startsWith('http') ? img : `${apiBase}${img.startsWith('/') ? '' : '/Pictures/'}${img}`) : ['/property-placeholder.jpg'];
})(),
images: raw.length > 0 ? raw.map(img => img.startsWith('http') ? img : `${apiBase}${img.startsWith('/') ? '' : '/Pictures/'}${img}`) : ['/property-placeholder.jpg'],
createdAt: item.createdAt || new Date().toISOString(),
furnished: details.furnished || false,
description: info.description || '',
@ -765,7 +768,42 @@ export default function OwnerPropertiesPage() {
};
});
setProperties(mapped);
const mappedSale = saleList.map((item) => {
const info = item.propertyInformation || {};
const details = (() => { try { return JSON.parse(info.detailsJSON || '{}'); } catch { return {}; } })();
const apiBase = typeof window !== 'undefined' ? (process.env.NEXT_PUBLIC_API_URL || 'https://45.93.137.91.nip.io/api') : '';
const raw = Array.isArray(info.images) ? info.images : [];
return {
id: item.id,
title: info.address || `عقار للبيع #${item.id}`,
propertyType: { 0: 'apartment', 1: 'villa', 2: 'house' }[info.buildingType] || 'apartment',
purpose: 'sale',
dailyPrice: 0,
monthlyPrice: 0,
salePrice: item.price || 0,
deposit: 0,
location: info.address || '',
bedrooms: info.numberOfBedRooms || 0,
bathrooms: info.numberOfBathRooms || 0,
area: info.space || 0,
livingRooms: details.livingRooms || 0,
status: 'available',
images: raw.length > 0 ? raw.map(img => img.startsWith('http') ? img : `${apiBase}${img.startsWith('/') ? '' : '/Pictures/'}${img}`) : ['/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([...mappedRent, ...mappedSale]);
} catch (err) {
console.error('[OwnerProperties] Failed to load properties:', err);
toast.error('فشل في تحميل العقارات');
@ -788,12 +826,58 @@ export default function OwnerPropertiesPage() {
}
};
const handleSaveEdit = (updatedProperty) => {
const newProperties = properties.map(p =>
p.id === updatedProperty.id ? updatedProperty : p
);
updatePropertiesInStorage(newProperties);
setEditModal({ isOpen: false, property: null });
const handleSaveEdit = async (updatedProperty) => {
try {
if (updatedProperty.purpose === 'rent' && updatedProperty._raw) {
const buildingTypeMap = { apartment: 0, villa: 1, sweet: 2, room: 3, studio: 4, office: 5, farms: 6, shop: 7, warehouse: 8 };
const raw = updatedProperty._raw;
const rentTypeMap = { daily: 1, monthly: 0, both: 0 };
const detailsJSON = JSON.stringify({
services: updatedProperty.services || {},
terms: updatedProperty.terms || {},
furnished: updatedProperty.furnished,
});
const payload = {
propertyInformation: {
cordsX: raw.propertyInformation?.cordsX || '',
cordsY: raw.propertyInformation?.cordsY || '',
address: updatedProperty.address || raw.propertyInformation?.address || '',
description: updatedProperty.description || raw.propertyInformation?.description || '',
numberOfBathRooms: updatedProperty.bathrooms || raw.propertyInformation?.numberOfBathRooms || 0,
numberOfRooms: (updatedProperty.bedrooms || 0) + (updatedProperty.livingRooms || 0),
numberOfBedRooms: updatedProperty.bedrooms || raw.propertyInformation?.numberOfBedRooms || 0,
space: parseFloat(updatedProperty.area) || raw.propertyInformation?.space || 0,
detailsJSON,
buildingType: buildingTypeMap[updatedProperty.propertyType] ?? 0,
status: updatedProperty.status === 'available' ? 0 : 1,
propertyType: updatedProperty.furnished ? 0 : 1,
images: raw.propertyInformation?.images || [],
},
deposit: parseFloat(updatedProperty.deposit) || raw.deposit || 0,
monthlyRent: parseFloat(updatedProperty.monthlyPrice) || raw.monthlyRent || 0,
dailyRent: parseFloat(updatedProperty.dailyPrice) || raw.dailyRent || 0,
rating: updatedProperty.rating || 0,
currencyId: updatedProperty.currencyId || raw.currencyId || 1,
rentType: rentTypeMap[updatedProperty.rentType] ?? 0,
isSmokeAllow: !updatedProperty.terms?.NoSmoking,
isVisitorAllow: !updatedProperty.terms?.NoParties,
type: updatedProperty.furnished ? 0 : 1,
};
await editRentProperty(updatedProperty.id, payload);
}
const newProperties = properties.map(p =>
p.id === updatedProperty.id ? updatedProperty : p
);
updatePropertiesInStorage(newProperties);
setEditModal({ isOpen: false, property: null });
toast.success('تم تحديث العقار بنجاح');
} catch (err) {
console.error('[OwnerProperties] Edit failed:', err);
toast.error('فشل تحديث العقار');
}
};
const fadeInUp = {