fixing bugs with item notification radius
This commit is contained in:
@@ -83,7 +83,8 @@ const CreateItem: React.FC = () => {
|
||||
const [selectedAddressId, setSelectedAddressId] = useState<string>("");
|
||||
const [addressesLoading, setAddressesLoading] = useState(true);
|
||||
const [selectedPricingUnit, setSelectedPricingUnit] = useState<string>("day");
|
||||
const [showAdvancedPricing, setShowAdvancedPricing] = useState<boolean>(false);
|
||||
const [showAdvancedPricing, setShowAdvancedPricing] =
|
||||
useState<boolean>(false);
|
||||
const [enabledPricingTiers, setEnabledPricingTiers] = useState({
|
||||
hour: false,
|
||||
day: false,
|
||||
@@ -92,7 +93,9 @@ const CreateItem: React.FC = () => {
|
||||
});
|
||||
|
||||
// Reference to LocationForm geocoding function
|
||||
const geocodeLocationRef = useRef<(() => Promise<boolean>) | null>(null);
|
||||
const geocodeLocationRef = useRef<
|
||||
(() => Promise<{ latitude: number; longitude: number } | null>) | null
|
||||
>(null);
|
||||
|
||||
useEffect(() => {
|
||||
fetchUserAddresses();
|
||||
@@ -161,11 +164,15 @@ const CreateItem: React.FC = () => {
|
||||
setError("");
|
||||
|
||||
// Try to geocode the address before submitting
|
||||
let geocodedCoordinates = null;
|
||||
if (geocodeLocationRef.current) {
|
||||
try {
|
||||
await geocodeLocationRef.current();
|
||||
geocodedCoordinates = await geocodeLocationRef.current();
|
||||
} catch (error) {
|
||||
console.warn('Geocoding failed, creating item without coordinates:', error);
|
||||
console.warn(
|
||||
"Geocoding failed, creating item without coordinates:",
|
||||
error
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,6 +195,9 @@ const CreateItem: React.FC = () => {
|
||||
|
||||
const response = await api.post("/items", {
|
||||
...formData,
|
||||
// Use geocoded coordinates if available, otherwise fall back to formData
|
||||
latitude: geocodedCoordinates?.latitude ?? formData.latitude,
|
||||
longitude: geocodedCoordinates?.longitude ?? formData.longitude,
|
||||
pricePerDay: formData.pricePerDay
|
||||
? parseFloat(formData.pricePerDay.toString())
|
||||
: undefined,
|
||||
@@ -221,8 +231,8 @@ const CreateItem: React.FC = () => {
|
||||
state: formData.state,
|
||||
zipCode: formData.zipCode,
|
||||
country: formData.country,
|
||||
latitude: formData.latitude,
|
||||
longitude: formData.longitude,
|
||||
latitude: geocodedCoordinates?.latitude ?? formData.latitude,
|
||||
longitude: geocodedCoordinates?.longitude ?? formData.longitude,
|
||||
isPrimary: true,
|
||||
});
|
||||
} catch (addressError) {
|
||||
|
||||
Reference in New Issue
Block a user