editing the add rent property mouaz is the best in the west
All checks were successful
Build frontend / build (push) Successful in 44s

This commit is contained in:
mouazkh
2026-05-25 23:18:03 +03:00
parent 8d48fcae99
commit 2c4a163cdb

View File

@ -100,6 +100,10 @@ export default function AddPropertyPage() {
bedrooms: 1,
bathrooms: 1,
livingRooms: 1,
floorNumber: '',
salons: '',
balconies: '',
space: '',
services: {
[PropertyService.ELECTRICITY]: false,
@ -123,6 +127,7 @@ export default function AddPropertyPage() {
dailyPrice: '',
monthlyPrice: '',
deposit: '',
city: '',
district: '',
@ -132,7 +137,31 @@ export default function AddPropertyPage() {
description: '',
images: []
images: [],
nearbySchool: '',
nearbyHospital: '',
nearbyRestaurant: '',
nearbyUniversity: '',
nearbyPark: '',
nearbyMall: '',
roomAreaType: 'Private room',
roomPeopleAllowed: '',
roomFurniture: '',
roomEntrance: 'Shared entrance',
roomBathroom: 'Shared',
roomKitchen: 'Not available',
roomRestrictedAreas: false,
roomResidents: '',
roomGender: 'Family',
roomLanguage: '',
roomChildren: false,
roomPets: false,
roomDedicatedTo: 'Everyone',
roomVisitors: true,
roomQuietTimes: false,
roomQuietTimesDetails: '',
});
const [imagePreviews, setImagePreviews] = useState([]);
@ -559,44 +588,63 @@ const handleMapClick = async (coords) => {
.filter(([, v]) => v)
.map(([k]) => k);
const detailsJSON = JSON.stringify({
const details = {
description: formData.description || '',
services: selectedServices,
serviceDetails: selectedServices.reduce((acc, s) => ({ ...acc, [s]: 'in general' }), {}),
terms: selectedTerms,
serviceDetails: selectedServices.reduce((acc, s) => ({ ...acc, [s]: formData.serviceDetails[s] || 'in general' }), {}),
terms: selectedTerms.reduce((acc, k) => ({ ...acc, [k]: true }), {}),
displayType: formData.offerType === 'both' ? 'Both' : formData.offerType === 'daily' ? 'Daily' : 'Monthly',
propertyCondition: formData.furnished ? 'Furnished' : 'Unfurnished',
photos: imagePreviews.map((_, i) => `photo_${i}.jpg`),
room: {
areaType: formData.propertyType === 'room' ? 'Shared room' : 'Private room',
peopleAllowed: String(formData.bedrooms),
entranceType: formData.propertyType === 'room' ? 'Shared entrance' : 'Private entrance',
bathroomType: formData.bathrooms > 1 ? 'Private' : 'Shared',
kitchenType: 'Not available',
hasRestrictedOwnerAreas: false,
languageDialect: '',
hasChildren: false,
hasPets: false,
dedicatedTo: 'Everyone',
visitorsAllowed: true,
quietTimesEnabled: false,
quietTimes: '',
}
});
propertyCondition: formData.furnished ? 'WithFurniture' : 'WithoutFurniture',
floorNumber: parseInt(formData.floorNumber) || 0,
numberOfSalons: parseInt(formData.salons) || 0,
numberOfBalconies: parseInt(formData.balconies) || 0,
nearbyDistances: {
school: formData.nearbySchool || '',
hospital: formData.nearbyHospital || '',
restaurant: formData.nearbyRestaurant || '',
university: formData.nearbyUniversity || '',
park: formData.nearbyPark || '',
mall: formData.nearbyMall || '',
},
};
if (formData.propertyType === 'room') {
details.room = {
areaType: formData.roomAreaType || 'Private room',
peopleAllowed: formData.roomPeopleAllowed || String(formData.bedrooms),
furnitureDetails: formData.roomFurniture || '',
entranceType: formData.roomEntrance || 'Shared entrance',
bathroomType: formData.roomBathroom || 'Shared',
kitchenType: formData.roomKitchen || 'Not available',
hasRestrictedOwnerAreas: formData.roomRestrictedAreas || false,
homeResidentsCount: formData.roomResidents || '',
currentPopulationGender: formData.roomGender || 'Family',
languageDialect: formData.roomLanguage || '',
hasChildren: formData.roomChildren || false,
hasPets: formData.roomPets || false,
dedicatedTo: formData.roomDedicatedTo || 'Everyone',
visitorsAllowed: formData.roomVisitors ?? true,
quietTimesEnabled: formData.roomQuietTimes ?? false,
quietTimes: formData.roomQuietTimesDetails || '',
};
}
const detailsJSON = JSON.stringify(details);
const propInfo = {
cordsX: formData.lat ? String(formData.lat) : '',
cordsY: formData.lng ? String(formData.lng) : '',
images: uploadedImagePaths,
address: `${formData.city} - ${formData.district} - ${formData.address}`.trim(),
description: formData.description || '',
numberOfBathRooms: formData.bathrooms || 0,
numberOfRooms: (formData.bedrooms || 0) + (formData.livingRooms || 0),
numberOfRooms: formData.bedrooms || 0,
numberOfBedRooms: formData.bedrooms || 0,
space: parseFloat(formData.space) || 0,
detailsJSON,
buildingType: buildingTypeMap[formData.propertyType] ?? BuildingType.APARTMENT,
status: 0,
propertyType: formData.furnished ? RentPropertyCondition.WITH_FURNITURE : RentPropertyCondition.WITHOUT_FURNITURE,
images: uploadedImagePaths,
};
try {
@ -617,13 +665,11 @@ const handleMapClick = async (coords) => {
deposit: parseFloat(formData.deposit) || 0,
monthlyRent: parseFloat(formData.monthlyPrice) || 0,
dailyRent: parseFloat(formData.dailyPrice) || 0,
rating: 0,
rating: 1,
currencyId: selectedCurrencyId,
rentType: rentTypeMap[formData.offerType] ?? RentType.MONTHLY,
isSmokeAllow: !formData.terms[PropertyTerm.NO_SMOKING],
specializedFor: false,
isVisitorAllow: !formData.terms[PropertyTerm.NO_PARTIES],
type: formData.furnished ? RentPropertyType.FURNISHED : RentPropertyType.UNFURNISHED,
allowedPaymentPeriod: '01:00:00:00',
};
console.log('[AddProperty] Rent payload:', JSON.stringify(payload, null, 2));
const res = await addRentProperty(payload);
@ -786,7 +832,23 @@ const handleMapClick = async (coords) => {
<p className="text-gray-600">أدخل التفاصيل والخدمات المتاحة</p>
</div>
<div className="grid grid-cols-1 md:grid-cols-3 gap-6">
<div className="grid grid-cols-1 md:grid-cols-4 gap-6">
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">
المساحة (م²)
</label>
<div className="relative">
<Square className="absolute right-3 top-1/2 transform -translate-y-1/2 w-4 h-4 text-gray-400" />
<input
type="number"
value={formData.space}
onChange={(e) => setFormData({...formData, space: e.target.value})}
className="w-full pr-10 pl-3 py-3 border border-gray-300 rounded-xl focus:outline-none focus:ring-2 focus:ring-amber-500"
placeholder="مثال: 120"
/>
</div>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">
عدد الغرف <span className="text-red-500">*</span>
@ -872,6 +934,39 @@ const handleMapClick = async (coords) => {
</div>
</div>
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">رقم الطابق</label>
<input
type="number"
value={formData.floorNumber}
onChange={(e) => setFormData({...formData, floorNumber: e.target.value})}
className="w-full px-4 py-3 border border-gray-300 rounded-xl focus:outline-none focus:ring-2 focus:ring-amber-500"
placeholder="مثال: 3"
/>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">عدد الصالونات</label>
<input
type="number"
value={formData.salons}
onChange={(e) => setFormData({...formData, salons: e.target.value})}
className="w-full px-4 py-3 border border-gray-300 rounded-xl focus:outline-none focus:ring-2 focus:ring-amber-500"
placeholder="مثال: 1"
/>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">عدد البلكونات</label>
<input
type="number"
value={formData.balconies}
onChange={(e) => setFormData({...formData, balconies: e.target.value})}
className="w-full px-4 py-3 border border-gray-300 rounded-xl focus:outline-none focus:ring-2 focus:ring-amber-500"
placeholder="مثال: 1"
/>
</div>
</div>
<div>
<h3 className="text-lg font-bold text-gray-900 mb-4">الخدمات المتوفرة <span className="text-red-500">*</span></h3>
<div className="space-y-3">