import { Path } from 'react-hook-form'; import { UnpackNestedValue, UseFormSetValue } from 'react-hook-form/dist/types/form'; import { FieldPathValue } from 'react-hook-form/dist/types/path'; import { FieldValues } from 'react-hook-form/dist/types/fields'; import { FileType } from '../models/file'; import { Dispatch, SetStateAction } from 'react'; export default class FileUploadLib { public static onRemoveFile (file: FileType, id: string, setFile: Dispatch>, setValue: UseFormSetValue, onFileRemove: () => void) { if (file?.id) { setValue( `${id}[_destroy]` as Path, true as UnpackNestedValue>> ); } setValue( `${id}[attachment_files]` as Path, null as UnpackNestedValue>> ); setFile(null); if (typeof onFileRemove === 'function') { onFileRemove(); } } public static hasFile (file: FileType): boolean { return !!file?.attachment_name; } }