'use client' import { ChangeEventHandler, FC, useRef } from 'react' import { useNotification } from '@baseapp-frontend/utils' import { Button, Input } from '@mui/material' import { Controller } from 'react-hook-form' import { FileUploadButtonProps } from './types' const FileUploadButton: FC = (props) => { const fileRef = useRef(undefined) const { sendToast } = useNotification() const { accept, maxSize, ...fileUploadProps } = props const { control, label, name, setFile } = fileUploadProps return ( <> { const handleOnChange: ChangeEventHandler = ( event, ) => { const { files } = event.target as HTMLInputElement if (files![0] && maxSize && files![0].size > maxSize) { sendToast(`This file is too large (max ${maxSize / 1024 / 1024}MB).`, { type: 'error', }) } else { field.onChange(files![0]) setFile(name, files![0], { shouldValidate: false, shouldDirty: true, shouldTouch: true, }) } } return ( ) }} /> ) } export default FileUploadButton