diff --git a/src/modules/place.module.tsx b/src/modules/place.module.tsx index f19d281..2238e12 100644 --- a/src/modules/place.module.tsx +++ b/src/modules/place.module.tsx @@ -9,202 +9,215 @@ import { TagComponent } from "@/components/tag"; import { Button } from "@/components/ui/button"; import { useDashboardStore } from "@/shared/stores/places.store"; -export const PlaceModule = ({ inputPlace, onSave }: { inputPlace: Place, onSave: (place: Place) => void; }) => { - const [place, setPlace] = useState(inputPlace); +export const PlaceModule = ({ + inputPlace, + onSave, +}: { + inputPlace: Place; + onSave: (place: Place) => void; +}) => { + const [place, setPlace] = useState(inputPlace); - useEffect(() => { - setPlace(inputPlace); - }, [inputPlace]); + useEffect(() => { + setPlace(inputPlace); + }, [inputPlace]); - const { tags } = useDashboardStore(); + const { tags } = useDashboardStore(); - const handleInputChange = useCallback( - (e: React.ChangeEvent) => { - const { name, value } = e.target; - if (!place) return; + const handleInputChange = useCallback( + (e: React.ChangeEvent) => { + const { name, value } = e.target; + if (!place) return; - if (name === "lat" || name === "lon") { - const newLocation = { - ...place.location, - [name]: value, - }; - setPlace({ ...place, location: newLocation }); - } else { - setPlace({ ...place, [name]: value }); - } - }, - [place] - ); + if (name === "lat" || name === "lon") { + const newLocation = { + ...place.location, + [name]: value, + }; + setPlace({ ...place, location: newLocation }); + } else { + setPlace({ ...place, [name]: value }); + } + }, + [place] + ); - const handleAddPhoto = () => { - if (!place) return; - const newPhotoUrl = prompt("Enter the URL of the new photo:"); - if (newPhotoUrl) { - setPlace({ - ...place, - images: [...place.images, newPhotoUrl], - }); - } - }; + const handleAddPhoto = () => { + if (!place) return; + const newPhotoUrl = prompt("Enter the URL of the new photo:"); + if (newPhotoUrl) { + setPlace({ + ...place, + images: [...place.images, newPhotoUrl], + }); + } + }; - const handleRemovePhoto = (index: number) => { - if (!place) return; - const newImages = place.images.filter((_, i) => i !== index); - setPlace({ ...place, images: newImages }); - }; + const handleRemovePhoto = (index: number) => { + if (!place) return; + const newImages = place.images.filter((_, i) => i !== index); + setPlace({ ...place, images: newImages }); + }; - const toggleTag = (tag: Tag) => { - const isTagSelected = place.tags.some(t => t.id === tag.id); - const updatedTags = isTagSelected - ? place.tags.filter(t => t.id !== tag.id) - : [...place.tags, tag]; - handleTagChange(updatedTags); - }; + const toggleTag = (tag: Tag) => { + const isTagSelected = place.tags.some((t) => t.id === tag.id); + const updatedTags = isTagSelected + ? place.tags.filter((t) => t.id !== tag.id) + : [...place.tags, tag]; + handleTagChange(updatedTags); + }; - const handleTagChange = (updatedTags: Tag[]) => { - setPlace(prev => ({ - ...prev, - tags: updatedTags, - })); - }; + const handleTagChange = (updatedTags: Tag[]) => { + setPlace((prev) => ({ + ...prev, + tags: updatedTags, + })); + }; - const handleSave = useCallback(() => { - onSave(place); - }, [place, onSave]); + const handleSave = useCallback(() => { + place.location.lat = Number(place.location.lat); + place.location.lon = Number(place.location.lon); - return place !== null ? ( -
-
-
- {place.images.map((img, index) => ( -
- Place -
handleRemovePhoto(index)} - > - -
-
- ))} -
-
- -
-
-
+ place.priceAvg = Number(place.priceAvg); + + onSave(place); + }, [place, onSave]); + + return place !== null ? ( + +
+
+ {place.images.map((img, index) => ( +
+ Place +
handleRemovePhoto(index)} + > + +
+
+ ))} +
+
+ +
+
+
+
+
+
+
+
+ + +
+
+ +
-
-
-
-
- - -
-
- - -
-
- -