import DescriptionOutlinedIcon from '@mui/icons-material/DescriptionOutlined'; import { Box, Typography } from '@mui/material'; import { type FormikValues, useFormikContext } from 'formik'; import { path, split } from 'ramda'; import { useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import FileDropZone, { transformFileListToArray } from '../../FileDropZone'; import type { InputPropsWithoutGroup } from './models'; const File = ({ fieldName, file, change, dataTestId, label }: InputPropsWithoutGroup): JSX.Element => { const { t } = useTranslation(); const { values, setFieldValue, setFieldTouched } = useFormikContext(); const fieldNamePath = split('.', fieldName); const files = useMemo( () => path(fieldNamePath, values), [values, fieldNamePath] ) as FileList; const filesArray = transformFileListToArray(files); const changeFiles = (newFiles: FileList | null): void => { if (change) { change({ setFieldTouched, setFieldValue, value: newFiles } as Parameters< NonNullable >[0]); return; } setFieldValue(fieldName, newFiles); }; return ( {t(label)} undefined} /> {filesArray.map((file) => ( {file.name} ))} ); }; export default File;