edited the edit property and need to test
All checks were successful
Build frontend / build (push) Successful in 1m36s
All checks were successful
Build frontend / build (push) Successful in 1m36s
This commit is contained in:
@ -64,47 +64,29 @@ import {
|
|||||||
updateRentPropertyStatus,
|
updateRentPropertyStatus,
|
||||||
updateSalePropertyStatus,
|
updateSalePropertyStatus,
|
||||||
} from "../../utils/api";
|
} from "../../utils/api";
|
||||||
|
import { PropertyService } from "../../enums/PropertyService";
|
||||||
|
import { PropertyTerm } from "../../enums/PropertyTerm";
|
||||||
|
|
||||||
const serviceI18nKeys = {
|
const serviceI18nKeys = {
|
||||||
Electricity: "propertyService.electricity",
|
[PropertyService.ELECTRICITY]: "propertyService.electricity",
|
||||||
Internet: "propertyService.internet",
|
[PropertyService.INTERNET]: "propertyService.internet",
|
||||||
Heating: "propertyService.heating",
|
[PropertyService.HEATING]: "propertyService.heating",
|
||||||
Water: "propertyService.water",
|
[PropertyService.WATER]: "propertyService.water",
|
||||||
Pool: "propertyService.pool",
|
[PropertyService.POOL]: "propertyService.pool",
|
||||||
PrivateGarden: "propertyService.privateGarden",
|
[PropertyService.PRIVATE_GARDEN]: "propertyService.privateGarden",
|
||||||
Parking: "propertyService.parking",
|
[PropertyService.PARKING]: "propertyService.parking",
|
||||||
Security247: "propertyService.security247",
|
[PropertyService.SECURITY_247]: "propertyService.security247",
|
||||||
CentralHeating: "propertyService.centralHeating",
|
[PropertyService.CENTRAL_HEATING]: "propertyService.centralHeating",
|
||||||
CentralAirConditioning: "propertyService.centralAirConditioning",
|
[PropertyService.CENTRAL_AIR_CONDITIONING]: "propertyService.centralAirConditioning",
|
||||||
EquippedKitchen: "propertyService.equippedKitchen",
|
[PropertyService.EQUIPPED_KITCHEN]: "propertyService.equippedKitchen",
|
||||||
MaidsRoom: "propertyService.maidsRoom",
|
[PropertyService.MAIDS_ROOM]: "propertyService.maidsRoom",
|
||||||
Elevator: "propertyService.elevator",
|
[PropertyService.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",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const termI18nKeys = {
|
const termI18nKeys = {
|
||||||
NoSmoking: "propertyTerm.noSmoking",
|
[PropertyTerm.NO_SMOKING]: "propertyTerm.noSmoking",
|
||||||
NoAnimals: "propertyTerm.noAnimals",
|
[PropertyTerm.NO_ANIMALS]: "propertyTerm.noAnimals",
|
||||||
NoParties: "propertyTerm.noParties",
|
[PropertyTerm.NO_PARTIES]: "propertyTerm.noParties",
|
||||||
NoAlcohol: "propertyTerm.noAlcohol",
|
|
||||||
SuitableForChildren: "propertyTerm.suitableForChildren",
|
|
||||||
SuitableForFamilies: "propertyTerm.suitableForFamilies",
|
|
||||||
SuitableForStudents: "propertyTerm.suitableForStudents",
|
|
||||||
SuitableForElderly: "propertyTerm.suitableForElderly",
|
|
||||||
OnlyFemales: "propertyTerm.onlyFemales",
|
|
||||||
OnlyMales: "propertyTerm.onlyMales",
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const proximityI18nKeys = {
|
const proximityI18nKeys = {
|
||||||
@ -616,6 +598,7 @@ const PropertyEditModal = ({ isOpen, onClose, property, onSave }) => {
|
|||||||
floor: 0,
|
floor: 0,
|
||||||
salons: 0,
|
salons: 0,
|
||||||
balconies: 0,
|
balconies: 0,
|
||||||
|
livingRooms: 0,
|
||||||
area: 0,
|
area: 0,
|
||||||
services: {},
|
services: {},
|
||||||
serviceDetails: {},
|
serviceDetails: {},
|
||||||
@ -656,6 +639,7 @@ const PropertyEditModal = ({ isOpen, onClose, property, onSave }) => {
|
|||||||
const propServices = property.services || {};
|
const propServices = property.services || {};
|
||||||
const services = {};
|
const services = {};
|
||||||
const serviceDetails = {};
|
const serviceDetails = {};
|
||||||
|
|
||||||
Object.keys(serviceI18nKeys).forEach((key) => {
|
Object.keys(serviceI18nKeys).forEach((key) => {
|
||||||
const val = propServices[key];
|
const val = propServices[key];
|
||||||
if (val && typeof val === 'string') {
|
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 propTerms = property.terms || {};
|
||||||
const terms = {};
|
const terms = {};
|
||||||
Object.keys(termI18nKeys).forEach((key) => {
|
Object.keys(termI18nKeys).forEach((key) => {
|
||||||
terms[key] = !!propTerms[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 || {};
|
const prox = property.proximity || details.nearbyDistances || {};
|
||||||
|
|
||||||
@ -691,17 +690,18 @@ const PropertyEditModal = ({ isOpen, onClose, property, onSave }) => {
|
|||||||
details.numberOfBalconies ??
|
details.numberOfBalconies ??
|
||||||
details.balconies ??
|
details.balconies ??
|
||||||
0,
|
0,
|
||||||
|
livingRooms: property.livingRooms ?? details.numberOfLivingRooms ?? details.livingRooms ?? 0,
|
||||||
area: property.area || 0,
|
area: property.area || 0,
|
||||||
services,
|
services,
|
||||||
serviceDetails,
|
serviceDetails,
|
||||||
terms,
|
terms,
|
||||||
customTerms: details.customTerms || [],
|
customTerms: details.customTerms || [],
|
||||||
nearbySchool: prox.School ?? prox.school ?? '',
|
nearbySchool: prox.School ?? prox.school ?? prox.nearbySchool ?? '',
|
||||||
nearbyHospital: prox.Hospital ?? prox.hospital ?? '',
|
nearbyHospital: prox.Hospital ?? prox.hospital ?? prox.nearbyHospital ?? '',
|
||||||
nearbyRestaurant: prox.Restaurant ?? prox.restaurant ?? '',
|
nearbyRestaurant: prox.Restaurant ?? prox.restaurant ?? prox.nearbyRestaurant ?? '',
|
||||||
nearbyUniversity: prox.University ?? prox.university ?? '',
|
nearbyUniversity: prox.University ?? prox.university ?? prox.nearbyUniversity ?? '',
|
||||||
nearbyPark: prox.Park ?? prox.park ?? '',
|
nearbyPark: prox.Park ?? prox.park ?? prox.nearbyPark ?? '',
|
||||||
nearbyMall: prox.Mall ?? prox.mall ?? '',
|
nearbyMall: prox.Mall ?? prox.mall ?? prox.nearbyMall ?? '',
|
||||||
purpose: property.purpose || 'rent',
|
purpose: property.purpose || 'rent',
|
||||||
currencyId: property.currencyId || 1,
|
currencyId: property.currencyId || 1,
|
||||||
...(property.purpose === 'rent'
|
...(property.purpose === 'rent'
|
||||||
@ -763,6 +763,22 @@ const PropertyEditModal = ({ isOpen, onClose, property, onSave }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSave = async () => {
|
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);
|
setIsSaving(true);
|
||||||
try {
|
try {
|
||||||
await onSave(formData);
|
await onSave(formData);
|
||||||
@ -880,6 +896,7 @@ const PropertyEditModal = ({ isOpen, onClose, property, onSave }) => {
|
|||||||
{[
|
{[
|
||||||
{ id: 'bedrooms', label: t('bedroomsCount') },
|
{ id: 'bedrooms', label: t('bedroomsCount') },
|
||||||
{ id: 'bathrooms', label: t('bathroomsCount') },
|
{ id: 'bathrooms', label: t('bathroomsCount') },
|
||||||
|
{ id: 'livingRooms', label: t('livingRoomsCount') },
|
||||||
{ id: 'floor', label: t('floorLabel') },
|
{ id: 'floor', label: t('floorLabel') },
|
||||||
{ id: 'salons', label: t('salonsCount') },
|
{ id: 'salons', label: t('salonsCount') },
|
||||||
{ id: 'balconies', label: t('balconiesCount') },
|
{ id: 'balconies', label: t('balconiesCount') },
|
||||||
@ -1541,6 +1558,7 @@ export default function OwnerPropertiesPage() {
|
|||||||
floorNumber: parseInt(formData.floor) || 0,
|
floorNumber: parseInt(formData.floor) || 0,
|
||||||
numberOfSalons: parseInt(formData.salons) || 0,
|
numberOfSalons: parseInt(formData.salons) || 0,
|
||||||
numberOfBalconies: parseInt(formData.balconies) || 0,
|
numberOfBalconies: parseInt(formData.balconies) || 0,
|
||||||
|
numberOfLivingRooms: parseInt(formData.livingRooms) || 0,
|
||||||
nearbyDistances: {
|
nearbyDistances: {
|
||||||
school: formData.nearbySchool || '',
|
school: formData.nearbySchool || '',
|
||||||
hospital: formData.nearbyHospital || '',
|
hospital: formData.nearbyHospital || '',
|
||||||
|
|||||||
Reference in New Issue
Block a user