From 3ee4a9336515f58982356d8a234d4ad2d2cef096 Mon Sep 17 00:00:00 2001 From: mouazkh Date: Sat, 25 Jul 2026 12:48:37 +0300 Subject: [PATCH] edited the edit property and need to test --- app/owner/properties/page.js | 102 ++++++++++++++++++++--------------- 1 file changed, 60 insertions(+), 42 deletions(-) diff --git a/app/owner/properties/page.js b/app/owner/properties/page.js index ccf5a32..75b1d69 100644 --- a/app/owner/properties/page.js +++ b/app/owner/properties/page.js @@ -64,47 +64,29 @@ import { updateRentPropertyStatus, updateSalePropertyStatus, } from "../../utils/api"; +import { PropertyService } from "../../enums/PropertyService"; +import { PropertyTerm } from "../../enums/PropertyTerm"; const serviceI18nKeys = { - Electricity: "propertyService.electricity", - Internet: "propertyService.internet", - Heating: "propertyService.heating", - Water: "propertyService.water", - Pool: "propertyService.pool", - PrivateGarden: "propertyService.privateGarden", - Parking: "propertyService.parking", - Security247: "propertyService.security247", - CentralHeating: "propertyService.centralHeating", - CentralAirConditioning: "propertyService.centralAirConditioning", - EquippedKitchen: "propertyService.equippedKitchen", - MaidsRoom: "propertyService.maidsRoom", - Elevator: "propertyService.elevator", - Gym: "propertyService.gym", - Sauna: "propertyService.sauna", - Jacuzzi: "propertyService.jacuzzi", - Balcony: "propertyService.balcony", - Rooftop: "propertyService.rooftop", - Furnished: "rentCondition.furnished", - AirConditioning: "propertyService.airConditioning", - SatelliteTV: "propertyService.satelliteTV", - Fireplace: "propertyService.fireplace", - StudyRoom: "propertyService.studyRoom", - Storage: "propertyService.storage", - Laundry: "propertyService.laundry", - SmartHome: "propertyService.smartHome", + [PropertyService.ELECTRICITY]: "propertyService.electricity", + [PropertyService.INTERNET]: "propertyService.internet", + [PropertyService.HEATING]: "propertyService.heating", + [PropertyService.WATER]: "propertyService.water", + [PropertyService.POOL]: "propertyService.pool", + [PropertyService.PRIVATE_GARDEN]: "propertyService.privateGarden", + [PropertyService.PARKING]: "propertyService.parking", + [PropertyService.SECURITY_247]: "propertyService.security247", + [PropertyService.CENTRAL_HEATING]: "propertyService.centralHeating", + [PropertyService.CENTRAL_AIR_CONDITIONING]: "propertyService.centralAirConditioning", + [PropertyService.EQUIPPED_KITCHEN]: "propertyService.equippedKitchen", + [PropertyService.MAIDS_ROOM]: "propertyService.maidsRoom", + [PropertyService.ELEVATOR]: "propertyService.elevator", }; const termI18nKeys = { - NoSmoking: "propertyTerm.noSmoking", - NoAnimals: "propertyTerm.noAnimals", - NoParties: "propertyTerm.noParties", - NoAlcohol: "propertyTerm.noAlcohol", - SuitableForChildren: "propertyTerm.suitableForChildren", - SuitableForFamilies: "propertyTerm.suitableForFamilies", - SuitableForStudents: "propertyTerm.suitableForStudents", - SuitableForElderly: "propertyTerm.suitableForElderly", - OnlyFemales: "propertyTerm.onlyFemales", - OnlyMales: "propertyTerm.onlyMales", + [PropertyTerm.NO_SMOKING]: "propertyTerm.noSmoking", + [PropertyTerm.NO_ANIMALS]: "propertyTerm.noAnimals", + [PropertyTerm.NO_PARTIES]: "propertyTerm.noParties", }; const proximityI18nKeys = { @@ -616,6 +598,7 @@ const PropertyEditModal = ({ isOpen, onClose, property, onSave }) => { floor: 0, salons: 0, balconies: 0, + livingRooms: 0, area: 0, services: {}, serviceDetails: {}, @@ -656,6 +639,7 @@ const PropertyEditModal = ({ isOpen, onClose, property, onSave }) => { const propServices = property.services || {}; const services = {}; const serviceDetails = {}; + Object.keys(serviceI18nKeys).forEach((key) => { const val = propServices[key]; if (val && typeof val === 'string') { @@ -670,11 +654,26 @@ const PropertyEditModal = ({ isOpen, onClose, property, onSave }) => { } }); + const rawSvcArray = Array.isArray(details.services) ? details.services : []; + rawSvcArray.forEach((key) => { + if (!(key in services)) { + services[key] = true; + serviceDetails[key] = details.serviceDetails?.[key] || ''; + } + }); + const propTerms = property.terms || {}; const terms = {}; Object.keys(termI18nKeys).forEach((key) => { terms[key] = !!propTerms[key]; }); + if (details.terms && typeof details.terms === 'object') { + Object.entries(details.terms).forEach(([key, val]) => { + if (val && !(key in terms)) { + terms[key] = true; + } + }); + } const prox = property.proximity || details.nearbyDistances || {}; @@ -691,17 +690,18 @@ const PropertyEditModal = ({ isOpen, onClose, property, onSave }) => { details.numberOfBalconies ?? details.balconies ?? 0, + livingRooms: property.livingRooms ?? details.numberOfLivingRooms ?? details.livingRooms ?? 0, area: property.area || 0, services, serviceDetails, terms, customTerms: details.customTerms || [], - nearbySchool: prox.School ?? prox.school ?? '', - nearbyHospital: prox.Hospital ?? prox.hospital ?? '', - nearbyRestaurant: prox.Restaurant ?? prox.restaurant ?? '', - nearbyUniversity: prox.University ?? prox.university ?? '', - nearbyPark: prox.Park ?? prox.park ?? '', - nearbyMall: prox.Mall ?? prox.mall ?? '', + nearbySchool: prox.School ?? prox.school ?? prox.nearbySchool ?? '', + nearbyHospital: prox.Hospital ?? prox.hospital ?? prox.nearbyHospital ?? '', + nearbyRestaurant: prox.Restaurant ?? prox.restaurant ?? prox.nearbyRestaurant ?? '', + nearbyUniversity: prox.University ?? prox.university ?? prox.nearbyUniversity ?? '', + nearbyPark: prox.Park ?? prox.park ?? prox.nearbyPark ?? '', + nearbyMall: prox.Mall ?? prox.mall ?? prox.nearbyMall ?? '', purpose: property.purpose || 'rent', currencyId: property.currencyId || 1, ...(property.purpose === 'rent' @@ -763,6 +763,22 @@ const PropertyEditModal = ({ isOpen, onClose, property, onSave }) => { }; const handleSave = async () => { + const errors = []; + if (!formData.description?.trim()) errors.push(t('descriptionRequired') || 'الوصف مطلوب'); + if (formData.bedrooms < 1) errors.push(t('bedroomsRequired') || 'يجب أن يكون عدد الغرف على الأقل 1'); + if (formData.bathrooms < 1) errors.push(t('bathroomsRequired') || 'يجب أن يكون عدد الحمامات على الأقل 1'); + if (!formData.area || formData.area <= 0) errors.push(t('areaRequired') || 'المساحة مطلوبة'); + if (formData.purpose === 'rent') { + if ((!formData.dailyPrice || formData.dailyPrice <= 0) && (!formData.monthlyPrice || formData.monthlyPrice <= 0)) { + errors.push(t('priceRequired') || 'يجب إدخال سعر الأجر الشهري أو اليومي'); + } + } else if (formData.purpose === 'sale') { + if (!formData.salePrice || formData.salePrice <= 0) errors.push(t('priceRequired') || 'السعر مطلوب'); + } + if (errors.length > 0) { + toast.error(errors[0]); + return; + } setIsSaving(true); try { await onSave(formData); @@ -880,6 +896,7 @@ const PropertyEditModal = ({ isOpen, onClose, property, onSave }) => { {[ { id: 'bedrooms', label: t('bedroomsCount') }, { id: 'bathrooms', label: t('bathroomsCount') }, + { id: 'livingRooms', label: t('livingRoomsCount') }, { id: 'floor', label: t('floorLabel') }, { id: 'salons', label: t('salonsCount') }, { id: 'balconies', label: t('balconiesCount') }, @@ -1541,6 +1558,7 @@ export default function OwnerPropertiesPage() { floorNumber: parseInt(formData.floor) || 0, numberOfSalons: parseInt(formData.salons) || 0, numberOfBalconies: parseInt(formData.balconies) || 0, + numberOfLivingRooms: parseInt(formData.livingRooms) || 0, nearbyDistances: { school: formData.nearbySchool || '', hospital: formData.nearbyHospital || '',