import { Form, Formik } from "formik"; import FormGroup from "../components/FormGroup"; import type { SoundUploadValue } from "../../../types/types"; import { useSoundContext } from "../../../context/SoundContext"; import { toast } from "sonner"; const SoundUpload = () => { const { dispatch } = useSoundContext(); const initialValues: SoundUploadValue = { name: "", soundFile: null, soundFileName: "", soundUrl: "", }; const handleSubmit = (values: SoundUploadValue) => { if (!values.soundFile) { toast.warning("Please select an audio file"); } else { dispatch({ type: "ADD", payload: values }); toast.success("Sound file upload successfully"); } }; return ( {({ setFieldValue, errors, setFieldError, values }) => (
{ if (e.target?.files && e.target?.files[0]?.type === "audio/mpeg") { const url = URL.createObjectURL(e.target.files[0]); setFieldValue("soundUrl", url); setFieldValue("name", e.target.files[0].name); setFieldValue("soundFileName", e.target.files[0].name); setFieldValue("soundFile", e.target.files[0]); } else { setFieldError("soundFile", "Not an mp3 file"); toast.error("Not an mp3 file"); } }} />
{!values.soundFile && (
No uploaded sound files
)}

Uploaded Sound files will appear in the drop downs once they are uploaded. They can be used for any Sighting,{" "} Hotlist or NPED hits.

{errors.soundFile &&

Not an mp3 file

}
)}
); }; export default SoundUpload;