import React from 'react'; import { Controller, useFormContext } from 'react-hook-form'; import FormHelperText from '@mui/material/FormHelperText'; import { Upload } from './upload'; import { UploadBox } from './upload-box'; import { IRHFUploadProps } from '../types'; import { UploadAvatar } from './upload-avatar'; /** * @description {RHFUploadAvatar} - Function for uploading avatar using React Hook Form. * @param {strung} name - The name of the avatar * @param {object} other - Other IRHFUploadProps * @return {JSX.Element} The JSX element for the uploaded avatar */ export const RHFUploadAvatar = ({ name, ...other }: IRHFUploadProps) => { const { control } = useFormContext(); return ( (
{!!error && ( {error.message} )}
)} /> ); }; /** * @description {RHFUploadBox} - RHFUploadBox component for handling file uploads with react-hook-form. * @param {string} name - The name of the upload box * @param {object} other - Other props for the upload box * @return {ReactNode} The rendered upload box component */ export const RHFUploadBox = ({ name, ...other }: IRHFUploadProps) => { const { control } = useFormContext(); return ( ( )} /> ); }; /** * @description {RHFUpload} - Function for RHFUpload component. * @param {string} name - name of the upload * @param {boolean} multiple - whether multiple files can be uploaded * @param {string} helperText - helper text for the upload * @param {...other} other - other props * @return {ReactNode} the rendered RHFUpload component */ export const RHFUpload = ({ name, multiple, helperText, ...other }: IRHFUploadProps) => { const { control } = useFormContext(); return ( multiple ? ( {error ? error?.message : helperText} ) } {...other} /> ) : ( {error ? error?.message : helperText} ) } {...other} /> ) } /> ); };