fixing bugs with item notification radius
This commit is contained in:
@@ -59,7 +59,8 @@ const EditItem: 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,
|
||||
@@ -68,7 +69,9 @@ const EditItem: 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);
|
||||
const [formData, setFormData] = useState<ItemFormData>({
|
||||
name: "",
|
||||
description: "",
|
||||
@@ -255,20 +258,29 @@ const EditItem: React.FC = () => {
|
||||
setError(null);
|
||||
|
||||
// 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, updating item without coordinates:', error);
|
||||
console.warn(
|
||||
"Geocoding failed, updating item without coordinates:",
|
||||
error
|
||||
);
|
||||
}
|
||||
} else {
|
||||
console.warn("No geocoding function available");
|
||||
}
|
||||
|
||||
try {
|
||||
// Use existing image previews (which includes both old and new images)
|
||||
const imageUrls = imagePreviews;
|
||||
|
||||
await itemAPI.updateItem(id!, {
|
||||
const updatePayload = {
|
||||
...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,
|
||||
@@ -289,7 +301,9 @@ const EditItem: React.FC = () => {
|
||||
specifyTimesPerDay: formData.specifyTimesPerDay,
|
||||
weeklyTimes: formData.weeklyTimes,
|
||||
images: imageUrls,
|
||||
});
|
||||
};
|
||||
|
||||
await itemAPI.updateItem(id!, updatePayload);
|
||||
|
||||
// Check if user has other items - only save to user profile if no other items
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user