[resumes][chore] remove resumeFile state

This commit is contained in:
Keane Chan
2022-10-15 11:07:10 +08:00
parent fa13f19b4c
commit 510e3d3227

View File

@ -79,7 +79,6 @@ export default function SubmitResumeForm({
initFormDetails, initFormDetails,
onClose = () => undefined, onClose = () => undefined,
}: Props) { }: Props) {
const [resumeFile, setResumeFile] = useState<File | null>(null);
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const [invalidFileUploadError, setInvalidFileUploadError] = useState< const [invalidFileUploadError, setInvalidFileUploadError] = useState<
string | null string | null
@ -96,6 +95,7 @@ export default function SubmitResumeForm({
handleSubmit, handleSubmit,
setValue, setValue,
reset, reset,
watch,
formState: { errors, isDirty, dirtyFields }, formState: { errors, isDirty, dirtyFields },
} = useForm<IFormInput>({ } = useForm<IFormInput>({
defaultValues: { defaultValues: {
@ -104,11 +104,12 @@ export default function SubmitResumeForm({
}, },
}); });
const resumeFile = watch('file');
const onFileDrop = useCallback( const onFileDrop = useCallback(
(acceptedFiles: Array<File>, fileRejections: Array<FileRejection>) => { (acceptedFiles: Array<File>, fileRejections: Array<FileRejection>) => {
if (fileRejections.length === 0) { if (fileRejections.length === 0) {
setInvalidFileUploadError(''); setInvalidFileUploadError('');
setResumeFile(acceptedFiles[0]);
setValue('file', acceptedFiles[0], { setValue('file', acceptedFiles[0], {
shouldDirty: true, shouldDirty: true,
}); });
@ -147,7 +148,6 @@ export default function SubmitResumeForm({
const fileName = keyAndFileName.substring(keyAndFileName.indexOf('-') + 1); const fileName = keyAndFileName.substring(keyAndFileName.indexOf('-') + 1);
const file = new File([data], fileName); const file = new File([data], fileName);
setResumeFile(file);
setValue('file', file, { setValue('file', file, {
shouldDirty: false, shouldDirty: false,
}); });
@ -168,9 +168,6 @@ export default function SubmitResumeForm({
}, [fetchFilePdf]); }, [fetchFilePdf]);
const onSubmit: SubmitHandler<IFormInput> = async (data) => { const onSubmit: SubmitHandler<IFormInput> = async (data) => {
if (resumeFile == null) {
return;
}
setIsLoading(true); setIsLoading(true);
let fileUrl = initFormDetails?.url ?? ''; let fileUrl = initFormDetails?.url ?? '';
@ -228,16 +225,12 @@ export default function SubmitResumeForm({
onClose(); onClose();
setIsDialogShown(false); setIsDialogShown(false);
reset(); reset();
setResumeFile(null);
setInvalidFileUploadError(null); setInvalidFileUploadError(null);
}; };
const onClickDownload = async ( const onClickDownload = async (
event: React.MouseEvent<HTMLParagraphElement, MouseEvent>, event: React.MouseEvent<HTMLParagraphElement, MouseEvent>,
) => { ) => {
if (resumeFile == null) {
return;
}
// Prevent click event from propagating up to dropzone // Prevent click event from propagating up to dropzone
event.stopPropagation(); event.stopPropagation();