Add property form submits to API as RentPropertyDto
All checks were successful
Build frontend / build (push) Successful in 43s
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:
@ -51,6 +51,7 @@ import {
|
|||||||
Move
|
Move
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import toast, { Toaster } from 'react-hot-toast';
|
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 MapContainer = dynamic(() => import('react-leaflet').then(mod => mod.MapContainer), { ssr: false });
|
||||||
const TileLayer = dynamic(() => import('react-leaflet').then(mod => mod.TileLayer), { 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;
|
if (!validateStep()) return;
|
||||||
|
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
console.log('[AddProperty] Building RentPropertyDto payload...');
|
||||||
|
|
||||||
setTimeout(() => {
|
// Map UI BuildingType to API enum: 0=Apartment, 1=Villa, 2=House
|
||||||
console.log('Property Data:', formData);
|
const buildingTypeMap = { apartment: 0, villa: 1, suite: 0, room: 0 };
|
||||||
setIsLoading(false);
|
// 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('تم إضافة العقار بنجاح!');
|
toast.success('تم إضافة العقار بنجاح!');
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
router.push('/owner/properties');
|
router.push('/owner/properties');
|
||||||
}, 1500);
|
}, 1500);
|
||||||
}, 2000);
|
} catch (err) {
|
||||||
|
console.error('[AddProperty] API error:', err);
|
||||||
|
toast.error(err.message || 'فشل في إضافة العقار');
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const fadeInUp = {
|
const fadeInUp = {
|
||||||
|
|||||||
@ -169,6 +169,16 @@ export async function getOwnerByUserId(userId) {
|
|||||||
return apiFetch(`/Owner/GetByUserId/${userId}`);
|
return apiFetch(`/Owner/GetByUserId/${userId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ─── Properties ───
|
||||||
|
|
||||||
|
export async function addRentProperty(data) {
|
||||||
|
console.log('[API] Adding rent property:', data.PropertyInformation?.Address);
|
||||||
|
return apiFetch('/RentProperties/AddRentProperty', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// ─── Auth: Registration ───
|
// ─── Auth: Registration ───
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user