diff --git a/packages/client/lib/components/BottomNav/BottomNav.jsx b/packages/client/lib/components/BottomNav/BottomNav.jsx index 20b8e14..6eff19f 100644 --- a/packages/client/lib/components/BottomNav/BottomNav.jsx +++ b/packages/client/lib/components/BottomNav/BottomNav.jsx @@ -1,5 +1,5 @@ import { useState } from 'react'; -import useFormStore from '../../../store/formStore.js'; +import { useFormStoreActions } from '../../../store/formStore.js'; import { SVGIcon } from '../common/icons/SVGIcon.jsx'; import BottomNavItem from './BottomNavItem.jsx'; @@ -27,7 +27,7 @@ const RIGHT_NAV_ITEMS = BOTTOM_NAV_ITEMS.slice(2, 4); const BottomNav = () => { const [active, setActive] = useState(0); - const setShowForm = useFormStore((state) => state.setShowForm); + const { setShowForm } = useFormStoreActions(); const handleActive = (name) => { setActive(name); diff --git a/packages/client/lib/components/LocationSearch.jsx b/packages/client/lib/components/LocationSearch.jsx index b96ee01..90dc64d 100644 --- a/packages/client/lib/components/LocationSearch.jsx +++ b/packages/client/lib/components/LocationSearch.jsx @@ -1,5 +1,4 @@ import { useRef, useState } from 'react'; -import { useMainStoreActions } from '../../store/store'; import useOnClickOutside from '../hooks/useOnClickOutside'; import { SVGIcon } from './common/icons/SVGIcon'; @@ -22,12 +21,15 @@ const getSearchLocationData = async (searchText) => { } }; -const LocationSearch = () => { +/** + * @property {({ lat, lng }) => void} setLocationData + * @returns {JSX.Element} + */ +const LocationSearch = ({ setLocationData }) => { const [isOpen, setIsOpen] = useState(false); const [value, setValue] = useState(''); const [results, setResults] = useState([]); const searchRef = useRef(null); - const { setGeoData } = useMainStoreActions(); let debounceTimerRef = useRef(null); @@ -52,7 +54,7 @@ const LocationSearch = () => { console.log('Clicked on item:', name, lat, lng); setValue(name); setIsOpen(false); - setGeoData({ lat, lng }); + setLocationData({ lat, lng }); }; const hideSearch = () => { diff --git a/packages/client/lib/components/Map.jsx b/packages/client/lib/components/Map.jsx index f40be76..935f68b 100644 --- a/packages/client/lib/components/Map.jsx +++ b/packages/client/lib/components/Map.jsx @@ -8,7 +8,7 @@ import { ZoomControl, useMap, } from 'react-leaflet'; -import useFormStore from '../../store/formStore'; +import { useFormStoreActions } from '../../store/formStore'; import useMainStore from '../../store/store'; /** @@ -19,7 +19,7 @@ import useMainStore from '../../store/store'; */ const SetViewOnUserLocation = () => { const geoData = useMainStore((state) => state.geoData); - const setLocation = useFormStore((state) => state.setLocation); + const { setLocation } = useFormStoreActions(); const isMounted = useRef(false); const map = useMap(); diff --git a/packages/client/lib/components/ReportForm/FormViews/CategoryView.jsx b/packages/client/lib/components/ReportForm/FormViews/CategoryView.jsx index d0721dc..b94e29c 100644 --- a/packages/client/lib/components/ReportForm/FormViews/CategoryView.jsx +++ b/packages/client/lib/components/ReportForm/FormViews/CategoryView.jsx @@ -1,4 +1,4 @@ -import useFormStore from '../../../../store/formStore'; +import { useFormStore, useFormStoreActions } from '../../../../store/formStore'; const categoryOptions = [ 'Lost/Missing Pet', @@ -12,8 +12,8 @@ const categoryOptions = [ const CategoryView = () => { const category = useFormStore((state) => state.category); - const setCategory = useFormStore((state) => state.setCategory); const formErrorState = useFormStore((state) => state.error); + const { setCategory } = useFormStoreActions(); const handleChange = ({ target }) => { setCategory(target.value); diff --git a/packages/client/lib/components/ReportForm/FormViews/LocationView.jsx b/packages/client/lib/components/ReportForm/FormViews/LocationView.jsx index 300d669..1cbeba0 100644 --- a/packages/client/lib/components/ReportForm/FormViews/LocationView.jsx +++ b/packages/client/lib/components/ReportForm/FormViews/LocationView.jsx @@ -1,10 +1,19 @@ -import useFormStore from '../../../../store/formStore'; +import { latLngToString } from '@/lib/helpers/helpers'; +import useMainStore from '@/store/store'; +import { useFormStore, useFormStoreActions } from '../../../../store/formStore'; import { SVGIcon } from '../../common/icons/SVGIcon'; const LocationView = () => { + const { setStep } = useFormStoreActions(); + const geoData = useMainStore((state) => state.geoData); const location = useFormStore((state) => state.location); - const setLocation = useFormStore((state) => state.setLocation); - const setStep = useFormStore((state) => state.setStep); + + const handleClick = () => { + setStep(5); // this is the step where the map is shown + }; + + // use the location from the form if it exists, otherwise use the geolocation data + const locationCoordinates = latLngToString(location ?? geoData); return (
@@ -14,22 +23,19 @@ const LocationView = () => { e.g. {'"'}Example Road, City{'"'} or {'"'}-8.54, 115.24{'"'} setLocation(e.target.value)} + id="location" name="location" - value={`${location.lat}, ${location.lng}`} placeholder="Provide a location or coordinates" - className="text-foreground border-border bg-background focus:ring-primary focus:border-primary block w-full rounded-lg border p-2 shadow-md" + type="text" + value={locationCoordinates} />
); diff --git a/packages/client/lib/components/ReportForm/NavigationButtons/FormButtons.jsx b/packages/client/lib/components/ReportForm/NavigationButtons/FormButtons.jsx index 1e82d26..5ae463e 100644 --- a/packages/client/lib/components/ReportForm/NavigationButtons/FormButtons.jsx +++ b/packages/client/lib/components/ReportForm/NavigationButtons/FormButtons.jsx @@ -1,15 +1,11 @@ -import useFormStore from '../../../../store/formStore'; +import { useFormStore, useFormStoreActions } from '../../../../store/formStore'; import { Button } from '../../common/Button'; import { SVGIcon } from '../../common/icons/SVGIcon'; import SubmitReportForm from './SubmitReportForm.jsx'; const FormButtons = () => { const step = useFormStore((state) => state.step); - const setStep = useFormStore((state) => state.setStep); - const setError = useFormStore((state) => state.setError); - - const resetForm = useFormStore((state) => state.resetForm); - const setShowForm = useFormStore((state) => state.setShowForm); + const { resetForm, setError, setShowForm, setStep } = useFormStoreActions(); const handleCancel = () => { resetForm(); diff --git a/packages/client/lib/components/ReportForm/NavigationButtons/SubmitReportForm.jsx b/packages/client/lib/components/ReportForm/NavigationButtons/SubmitReportForm.jsx index 02446a8..8f5f927 100644 --- a/packages/client/lib/components/ReportForm/NavigationButtons/SubmitReportForm.jsx +++ b/packages/client/lib/components/ReportForm/NavigationButtons/SubmitReportForm.jsx @@ -1,12 +1,10 @@ -import useFormStore from '../../../../store/formStore'; +import { useFormStoreActions } from '../../../../store/formStore'; import { useMainStoreActions } from '../../../../store/store'; import { Button } from '../../common/Button'; const SubmitReportForm = () => { const { setMarkers } = useMainStoreActions(); - const getFormData = useFormStore((state) => state.getFormData); - const resetForm = useFormStore((state) => state.resetForm); - const setShowForm = useFormStore((state) => state.setShowForm); + const { getFormData, resetForm, setShowForm } = useFormStoreActions(); const handleSubmit = (e) => { e.preventDefault(); @@ -18,9 +16,9 @@ const SubmitReportForm = () => { return (