[resumes][feat] remove updating of pdf on edit (#385)

* [resumes][feat] remove updating of pdf on edit

* [resumes][fix] remove nit
pull/386/head
Keane Chan 2 years ago committed by GitHub
parent 9f24e0bcca
commit b885e3445f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -124,28 +124,6 @@ export default function SubmitResumeForm({
onDrop: onFileDrop, onDrop: onFileDrop,
}); });
const fetchFilePdf = useCallback(async () => {
const fileUrl = initFormDetails?.url;
if (fileUrl == null) {
return;
}
const data = await axios
.get(fileUrl, {
responseType: 'blob',
})
.then((res) => res.data);
const keyAndFileName = fileUrl.substring(fileUrl.indexOf('resumes'));
const fileName = keyAndFileName.substring(keyAndFileName.indexOf('-') + 1);
const file = new File([data], fileName);
setValue('file', file, {
shouldDirty: false,
});
}, [initFormDetails?.url, setValue]);
// Route user to sign in if not logged in // Route user to sign in if not logged in
useEffect(() => { useEffect(() => {
if (status !== 'loading') { if (status !== 'loading') {
@ -155,11 +133,6 @@ export default function SubmitResumeForm({
} }
}, [router, session, status]); }, [router, session, status]);
// Fetch initial file PDF for edit form
useEffect(() => {
fetchFilePdf();
}, [fetchFilePdf]);
const onSubmit: SubmitHandler<IFormInput> = async (data) => { const onSubmit: SubmitHandler<IFormInput> = async (data) => {
setIsLoading(true); setIsLoading(true);
let fileUrl = initFormDetails?.url ?? ''; let fileUrl = initFormDetails?.url ?? '';
@ -313,71 +286,78 @@ export default function SubmitResumeForm({
/> />
</div> </div>
))} ))}
{/* Upload Resume Section */} {/* Upload resume form */}
<p className="text-sm font-medium text-slate-700"> {isNewForm && (
Upload resume (PDF format) <>
<span aria-hidden="true" className="text-danger-500"> <p className="text-sm font-medium text-slate-700">
{' '} Upload resume (PDF format)
* <span aria-hidden="true" className="text-danger-500">
</span> {' '}
</p> *
{/* Upload Resume Box */} </span>
<div className="mb-4"> </p>
<div <div className="mb-4">
{...getRootProps()} <div
className={clsx( {...getRootProps()}
fileUploadError ? 'border-danger-600' : 'border-gray-300', className={clsx(
'mt-2 flex justify-center rounded-md border-2 border-dashed px-6 pt-5 pb-6', fileUploadError
)}> ? 'border-danger-600'
<div className="space-y-1 text-center"> : 'border-gray-300',
<div className="flex gap-2"> 'mt-2 flex justify-center rounded-md border-2 border-dashed px-6 pt-5 pb-6',
{resumeFile == null ? ( )}>
<PaperClipIcon className="m-auto h-8 w-8 text-gray-600" /> <div className="space-y-1 text-center">
) : (
<div className="flex gap-2"> <div className="flex gap-2">
<p {resumeFile == null ? (
className="cursor-pointer underline underline-offset-1 hover:text-indigo-600" <PaperClipIcon className="m-auto h-8 w-8 text-gray-600" />
onClick={onClickDownload}> ) : (
{resumeFile.name} <div className="flex gap-2">
</p> <p
className="cursor-pointer underline underline-offset-1 hover:text-indigo-600"
onClick={onClickDownload}>
{resumeFile.name}
</p>
</div>
)}
</div> </div>
)} <div className="flex justify-center text-sm">
</div> <label
<div className="flex justify-center text-sm"> className="rounded-md focus-within:outline-none focus-within:ring-2 focus-within:ring-indigo-500 focus-within:ring-offset-2"
<label htmlFor="file-upload">
className="rounded-md focus-within:outline-none focus-within:ring-2 focus-within:ring-indigo-500 focus-within:ring-offset-2" <div className="flex gap-1 ">
htmlFor="file-upload"> <p className="cursor-pointer font-medium text-indigo-600 hover:text-indigo-400">
<div className="flex gap-1 "> {resumeFile == null
<p className="cursor-pointer font-medium text-indigo-600 hover:text-indigo-400"> ? 'Upload a file'
{resumeFile == null : 'Replace file'}
? 'Upload a file' </p>
: 'Replace file'} <span className="text-gray-500">
</p> or drag and drop
<span className="text-gray-500"> </span>
or drag and drop </div>
</span> <input
{...register('file', { required: true })}
{...getInputProps()}
accept="application/pdf"
className="sr-only"
disabled={isLoading}
id="file-upload"
name="file-upload"
type="file"
/>
</label>
</div> </div>
<input <p className="text-xs text-gray-500">
{...register('file', { required: true })} PDF up to {FILE_SIZE_LIMIT_MB}MB
{...getInputProps()} </p>
accept="application/pdf" </div>
className="sr-only"
disabled={isLoading}
id="file-upload"
name="file-upload"
type="file"
/>
</label>
</div> </div>
<p className="text-xs text-gray-500"> {fileUploadError && (
PDF up to {FILE_SIZE_LIMIT_MB}MB <p className="text-danger-600 text-sm">
</p> {fileUploadError}
</p>
)}
</div> </div>
</div> </>
{fileUploadError && ( )}
<p className="text-danger-600 text-sm">{fileUploadError}</p>
)}
</div>
{/* Additional Info Section */} {/* Additional Info Section */}
<div className="mb-8"> <div className="mb-8">
<TextArea <TextArea

Loading…
Cancel
Save