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, }; 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 }) => (
{ if ( e.target?.files && e.target?.files[0]?.type === "audio/mpeg" ) { setFieldValue("name", e.target.files[0].name); setFieldValue("soundFile", e.target.files[0]); } else { setFieldError("soundFile", "Not an mp3 file"); toast.error("Not an mp3 file"); } }} /> {errors.soundFile && (

Not an mp3 file

)}
)}
); }; export default SoundUpload;