import { Field, FieldArray, Form, Formik } from "formik"; import FormGroup from "../components/FormGroup"; import type { FormValues, Hotlist } from "../../../types/types"; import { useSoundContext } from "../../../context/SoundContext"; import { useCameraBlackboard } from "../../../hooks/useCameraBlackboard"; import { toast } from "sonner"; const SoundSettingsFields = () => { const { state, dispatch } = useSoundContext(); const { mutation } = useCameraBlackboard(); const hotlists: Hotlist[] = state.hotlists; const soundOptions = state?.soundOptions?.map((soundOption) => ({ value: soundOption?.name, label: soundOption?.name, })); const initialValues: FormValues = { sightingSound: state.sightingSound ?? "switch", NPEDsound: state.NPEDsound ?? "popup", hotlists, }; const handleSubmit = async (values: FormValues) => { dispatch({ type: "UPDATE", payload: values }); const result = await mutation.mutateAsync({ operation: "INSERT", path: "soundSettings", value: values, }); if (result.reason !== "OK") { toast.error("Cannot update sound settings"); } else { toast.success("Sound Settings successfully updated"); } }; return ( {({ values }) => (
{soundOptions?.map(({ value, label }) => { return ( ); })} {soundOptions?.map(({ value, label }) => ( ))}

Hotlist Sounds

(
{values?.hotlists?.length > 0 ? ( values?.hotlists?.map((hotlist, index) => (
{soundOptions?.map(({ value, label }) => ( ))}
)) ) : (

No hotlists yet, Add one

)}
)} />
)}
); }; export default SoundSettingsFields;