diff --git a/app/owner/properties/add/page.js b/app/owner/properties/add/page.js index 372bfaf..bfc1923 100644 --- a/app/owner/properties/add/page.js +++ b/app/owner/properties/add/page.js @@ -51,7 +51,7 @@ import { Move } from 'lucide-react'; import toast, { Toaster } from 'react-hot-toast'; -import { addRentProperty } from '../../../utils/api'; +import { addRentProperty, getCurrencies } 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 }); @@ -127,6 +127,8 @@ export default function AddPropertyPage() { const [mapZoom, setMapZoom] = useState(13); const [searchQuery, setSearchQuery] = useState(''); const [mapLoaded, setMapLoaded] = useState(false); + const [currencies, setCurrencies] = useState([]); + const [selectedCurrencyId, setSelectedCurrencyId] = useState(1); const [errors, setErrors] = useState({}); @@ -178,6 +180,17 @@ export default function AddPropertyPage() { }); } setMapLoaded(true); + + // Fetch available currencies + getCurrencies().then((data) => { + if (Array.isArray(data) && data.length > 0) { + setCurrencies(data); + setSelectedCurrencyId(data[0].id); + console.log('[AddProperty] Currencies loaded:', data); + } + }).catch((err) => { + console.warn('[AddProperty] Failed to load currencies:', err); + }); }, []); const handleSearch = async () => { @@ -537,7 +550,7 @@ const handleMapClick = async (coords) => { MonthlyRent: parseFloat(formData.monthlyPrice) || 0, DailyRent: parseFloat(formData.dailyPrice) || 0, Rating: 0, - CurrencyId: 1, + CurrencyId: selectedCurrencyId, RentType: rentTypeMap[formData.offerType] ?? 0, IsSmokeAllow: !formData.terms?.noSmoking, SpecializedFor: false, @@ -908,6 +921,43 @@ function MapClickHandler({ onMapClick }) { + {/* Currency dropdown */} + {currencies.length > 0 && ( +
+ + +
+ )} + + {/* Deposit field */} +
+ +
+ + setFormData({...formData, deposit: e.target.value})} + className="w-full pr-12 pl-4 py-3 border border-gray-300 rounded-xl focus:outline-none focus:ring-2 focus:ring-amber-500" + placeholder="مثال: 500000" + /> +
+
+ {(formData.offerType === 'daily' || formData.offerType === 'both') && (