mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2025-07-28 20:52:00 +08:00
[resumes][chore] remove resumeFile state
This commit is contained in:
@ -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();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user