[resumes][feat] skip upload of file if not changed ()

pull/381/head
Keane Chan 2 years ago committed by GitHub
parent 8a4a627f80
commit 50ea8ddc1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -101,7 +101,7 @@ export default function ResumeReviewPage() {
return ( return (
<> <>
{(detailsQuery.isError || detailsQuery.data === null) && ErrorPage} {(detailsQuery.isError || detailsQuery.data === null) && ErrorPage}
{detailsQuery.isLoading && ( {detailsQuery.isFetching && (
<div className="w-full pt-4"> <div className="w-full pt-4">
{' '} {' '}
<Spinner display="block" size="lg" />{' '} <Spinner display="block" size="lg" />{' '}

@ -96,7 +96,7 @@ export default function SubmitResumeForm({
handleSubmit, handleSubmit,
setValue, setValue,
reset, reset,
formState: { errors, isDirty }, formState: { errors, isDirty, dirtyFields },
} = useForm<IFormInput>({ } = useForm<IFormInput>({
defaultValues: { defaultValues: {
isChecked: false, isChecked: false,
@ -170,7 +170,10 @@ export default function SubmitResumeForm({
return; return;
} }
setIsLoading(true); setIsLoading(true);
let fileUrl = initFormDetails?.url ?? '';
// Only update file in fs when it changes
if (dirtyFields.file) {
const formData = new FormData(); const formData = new FormData();
formData.append('key', RESUME_STORAGE_KEY); formData.append('key', RESUME_STORAGE_KEY);
formData.append('file', resumeFile); formData.append('file', resumeFile);
@ -180,7 +183,8 @@ export default function SubmitResumeForm({
'Content-Type': 'multipart/form-data', 'Content-Type': 'multipart/form-data',
}, },
}); });
const { url } = res.data; fileUrl = res.data.url;
}
resumeUpsertMutation.mutate( resumeUpsertMutation.mutate(
{ {
@ -190,7 +194,7 @@ export default function SubmitResumeForm({
location: data.location, location: data.location,
role: data.role, role: data.role,
title: data.title, title: data.title,
url, url: fileUrl,
}, },
{ {
onError(error) { onError(error) {

Loading…
Cancel
Save