Add property form submits to API as RentPropertyDto
All checks were successful
Build frontend / build (push) Successful in 43s

- Added addRentProperty() API function for POST /RentProperties/AddRentProperty
- handleSubmit builds correct RentPropertyDto with nested PropertyInformation
- Maps UI fields to API enums (BuildingType, RentType, RentPropertyType, PropertyStatus)
- Services/terms stored in DetailsJSON as JSON string
- Console logs the full payload before sending
This commit is contained in:
Claw AI
2026-03-28 18:00:44 +00:00
parent da0c36727f
commit d94b32a670
2 changed files with 65 additions and 5 deletions

View File

@ -51,6 +51,7 @@ import {
Move
} from 'lucide-react';
import toast, { Toaster } from 'react-hot-toast';
import { addRentProperty } from '../../../utils/api';
const MapContainer = dynamic(() => import('react-leaflet').then(mod => mod.MapContainer), { ssr: false });
const TileLayer = dynamic(() => import('react-leaflet').then(mod => mod.TileLayer), { ssr: false });
@ -499,16 +500,65 @@ const handleMapClick = async (coords) => {
if (!validateStep()) return;
setIsLoading(true);
console.log('[AddProperty] Building RentPropertyDto payload...');
setTimeout(() => {
console.log('Property Data:', formData);
setIsLoading(false);
// Map UI BuildingType to API enum: 0=Apartment, 1=Villa, 2=House
const buildingTypeMap = { apartment: 0, villa: 1, suite: 0, room: 0 };
// Map UI offerType to API RentType: 0=day, 1=week, 2=month
const rentTypeMap = { daily: 0, monthly: 2, both: 2, sale: 2 };
// Map UI propertyType to API RentPropertyType: 0=Family, 1=Person
const rentPropertyType = formData.terms?.suitableForChildren ? 0 : 1;
// Services/terms go into DetailsJSON
const detailsJSON = JSON.stringify({
services: formData.services,
terms: formData.terms,
furnished: formData.furnished,
livingRooms: formData.livingRooms,
});
const payload = {
PropertyInformation: {
CordsX: formData.lat ? String(formData.lat) : '',
CordsY: formData.lng ? String(formData.lng) : '',
Address: `${formData.city} - ${formData.district} - ${formData.address}`.trim(),
Description: formData.description || '',
NumberOfBathRooms: formData.bathrooms || 0,
NumberOfRooms: (formData.bedrooms || 0) + (formData.livingRooms || 0),
NumberOfBedRooms: formData.bedrooms || 0,
Space: parseFloat(formData.space) || 0,
DetailsJSON: detailsJSON,
BuildingType: buildingTypeMap[formData.propertyType] ?? 0,
Status: 0,
PropertyType: formData.offerType === 'sale' ? 1 : 0,
},
Deposit: parseFloat(formData.deposit) || 0,
MonthlyRent: parseFloat(formData.monthlyPrice) || 0,
DailyRent: parseFloat(formData.dailyPrice) || 0,
Rating: 0,
CurrencyId: 1,
RentType: rentTypeMap[formData.offerType] ?? 0,
IsSmokeAllow: !formData.terms?.noSmoking,
SpecializedFor: false,
IsVisitorAllow: !formData.terms?.noParties,
Type: rentPropertyType,
};
console.log('[AddProperty] Payload:', JSON.stringify(payload, null, 2));
try {
const res = await addRentProperty(payload);
console.log('[AddProperty] API response:', res);
toast.success('تم إضافة العقار بنجاح!');
setTimeout(() => {
router.push('/owner/properties');
}, 1500);
}, 2000);
} catch (err) {
console.error('[AddProperty] API error:', err);
toast.error(err.message || 'فشل في إضافة العقار');
} finally {
setIsLoading(false);
}
};
const fadeInUp = {