fixing add property

This commit is contained in:
Beilin-b
2026-07-16 10:56:59 -07:00
parent 2374e80380
commit ca6b12bfb9
2 changed files with 69 additions and 170 deletions

View File

@ -227,7 +227,6 @@ export default function AddPropertyPage() {
};
useEffect(() => {
// Fetch available currencies
getCurrencies().then((data) => {
if (Array.isArray(data) && data.length > 0) {
setCurrencies(data);
@ -278,7 +277,7 @@ export default function AddPropertyPage() {
};
const handleGeolocation = () => {
if (!navigator.geolocation) {
if (!navigator.geolocation) {
toast.error(t('toast.geolocationNotSupported'));
return;
}
@ -291,7 +290,7 @@ if (!navigator.geolocation) {
setMapCenter([latitude, longitude]);
setMapZoom(18);
try {
try {
const response = await fetch(
`https://nominatim.openstreetmap.org/reverse?format=json&lat=${latitude}&lon=${longitude}&accept-language=ar`
);
@ -319,57 +318,59 @@ try {
);
};
const handleMapClick = async (coords) => {
try {
const [lat, lng] = coords;
toast.loading(t('addProperty.locationSelecting'), { id: 'location' });
const response = await fetch(
`https://nominatim.openstreetmap.org/reverse?format=json&lat=${lat}&lon=${lng}&accept-language=ar`
);
const data = await response.json();
setSelectedLocation({
lat: lat,
lng: lng,
const handleMapClick = async (coords) => {
try {
const [lat, lng] = coords;
toast.loading(t('addProperty.locationSelecting'), { id: 'location' });
const response = await fetch(
`https://nominatim.openstreetmap.org/reverse?format=json&lat=${lat}&lon=${lng}&accept-language=ar`
);
const data = await response.json();
setSelectedLocation({
lat: lat,
lng: lng,
address: data.display_name || t('addProperty.defaultAddress')
});
setMapZoom(18);
toast.success(t('toast.locationSelectedSuccess'), { id: 'location' });
} catch (error) {
console.error(t('addProperty.locationError'), error);
const [lat, lng] = coords;
setSelectedLocation({
lat: lat,
lng: lng,
address: t('addProperty.defaultAddress')
});
setMapZoom(18);
toast.success(t('toast.locationConfirmed'), { id: 'location' });
}
};
const handleMarkerDragEnd = async (lat, lng) => {
try {
const response = await fetch(
`https://nominatim.openstreetmap.org/reverse?format=json&lat=${lat}&lon=${lng}&accept-language=ar`
);
const data = await response.json();
setSelectedLocation({
lat,
lng,
address: data.display_name || t('addProperty.defaultAddress')
});
setMapZoom(18);
toast.success(t('toast.locationSelectedSuccess'), { id: 'location' });
} catch (error) {
console.error(t('addProperty.locationError'), error);
const [lat, lng] = coords;
setSelectedLocation({
lat: lat,
lng: lng,
address: t('addProperty.defaultAddress')
});
setMapZoom(18);
toast.success(t('toast.locationConfirmed'), { id: 'location' });
}
};
const handleMarkerDragEnd = async (lat, lng) => {
try {
const response = await fetch(
`https://nominatim.openstreetmap.org/reverse?format=json&lat=${lat}&lon=${lng}&accept-language=ar`
);
const data = await response.json();
setSelectedLocation({
lat,
lng,
address: data.display_name || t('addProperty.defaultAddress')
});
} catch (error) {
setSelectedLocation({
lat,
lng,
address: t('addProperty.defaultAddress')
});
}
};
});
} catch (error) {
setSelectedLocation({
lat,
lng,
address: t('addProperty.defaultAddress')
});
}
};
const confirmLocation = () => {
if (selectedLocation) {
setFormData({
@ -414,7 +415,6 @@ const handleMarkerDragEnd = async (lat, lng) => {
continue;
}
// Show preview
const reader = new FileReader();
reader.onloadend = () => {
setImagePreviews(prev => [...prev, reader.result]);
@ -426,7 +426,6 @@ const handleMarkerDragEnd = async (lat, lng) => {
images: [...prev.images, file]
}));
// Upload to server immediately
try {
const path = await uploadPicture(file);
setUploadedImagePaths(prev => [...prev, path]);
@ -648,7 +647,6 @@ const handleMarkerDragEnd = async (lat, lng) => {
return;
}
// Map UI property type to API BuildingType enum
const buildingTypeMap = { apartment: BuildingType.APARTMENT, villa: BuildingType.VILLA, sweet: BuildingType.SWEET, suite: BuildingType.SWEET, room: BuildingType.ROOM, studio: BuildingType.STUDIO, office: BuildingType.OFFICE, farms: BuildingType.FARMS, shop: BuildingType.SHOP, warehouse: BuildingType.WAREHOUSE };
const selectedServices = Object.entries(formData.services)
@ -750,7 +748,7 @@ const handleMarkerDragEnd = async (lat, lng) => {
currencyId: selectedCurrencyId,
rentType: rentTypeMap[formData.offerType] ?? RentType.MONTHLY,
type: formData.furnished ? RentPropertyType.FURNISHED : RentPropertyType.UNFURNISHED,
allowedPaymentPeriod: formData.allowedPaymentPeriod || '',
allowedPaymentPeriod: formData.allowedPaymentPeriod || '1.00:00:00',
});
const res = await addRentProperty(payload);
toast.success(t('toast.rentPropertySuccess'));
@ -787,7 +785,7 @@ const handleMarkerDragEnd = async (lat, lng) => {
)}
<div className="mb-8">
<div className="flex items-center justify-between mb-4">
<Link
<Link
href="/owner/properties"
className="flex items-center gap-2 text-gray-600 hover:text-amber-600 transition-colors group"
>
@ -838,7 +836,7 @@ const handleMarkerDragEnd = async (lat, lng) => {
</div>
<div>
<label className="block text-sm font-medium text-gray-700 mb-3">
<label className="block text-sm font-medium text-gray-700 mb-3">
{t('addProperty.propertyTypeLabel')} <span className="text-red-500">*</span>
</label>
<div className="grid grid-cols-2 md:grid-cols-4 gap-3">
@ -1226,7 +1224,6 @@ const handleMarkerDragEnd = async (lat, lng) => {
})}
</div>
{/* Custom Terms */}
<div className="mt-4 p-4 border border-dashed border-gray-300 rounded-xl">
<p className="text-sm font-medium text-gray-700 mb-2">{t('addProperty.customTermsTitle')}</p>
<div className="flex gap-2">
@ -1360,7 +1357,6 @@ const handleMarkerDragEnd = async (lat, lng) => {
</div>
</div>
{/* Currency dropdown */}
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">
{t('addProperty.currencyLabel')} <span className="text-red-500">*</span>
@ -1375,7 +1371,6 @@ const handleMarkerDragEnd = async (lat, lng) => {
</select>
</div>
{/* Price and deposit fields - conditional on offerType */}
{errors.offerType && (
<p className="text-red-500 text-sm mt-1">{errors.offerType}</p>
)}