[resumes][feat] add error message to submit form

pull/424/head
Keane Chan 2 years ago
parent b52f15a937
commit 64670923e1
No known key found for this signature in database
GPG Key ID: 32718398E1E9F87C

@ -86,10 +86,16 @@ export default function SubmitResumeForm({
setValue, setValue,
reset, reset,
watch, watch,
clearErrors,
formState: { errors, isDirty, dirtyFields }, formState: { errors, isDirty, dirtyFields },
} = useForm<IFormInput>({ } = useForm<IFormInput>({
defaultValues: { defaultValues: {
additionalInfo: '',
experience: '',
isChecked: false, isChecked: false,
location: '',
role: '',
title: '',
...initFormDetails, ...initFormDetails,
}, },
}); });
@ -296,7 +302,7 @@ export default function SubmitResumeForm({
options={ROLES} options={ROLES}
placeholder=" " placeholder=" "
required={true} required={true}
onChange={(val) => setValue('role', val)} onChange={(val) => onValueChange('role', val)}
/> />
<Select <Select
{...register('experience', { required: true })} {...register('experience', { required: true })}
@ -305,7 +311,7 @@ export default function SubmitResumeForm({
options={EXPERIENCES} options={EXPERIENCES}
placeholder=" " placeholder=" "
required={true} required={true}
onChange={(val) => setValue('experience', val)} onChange={(val) => onValueChange('experience', val)}
/> />
</div> </div>
<Select <Select
@ -315,7 +321,7 @@ export default function SubmitResumeForm({
options={LOCATIONS} options={LOCATIONS}
placeholder=" " placeholder=" "
required={true} required={true}
onChange={(val) => setValue('location', val)} onChange={(val) => onValueChange('location', val)}
/> />
{/* Upload resume form */} {/* Upload resume form */}
{isNewForm && ( {isNewForm && (
@ -335,6 +341,16 @@ export default function SubmitResumeForm({
: 'border-slate-300', : 'border-slate-300',
'flex cursor-pointer justify-center rounded-md border-2 border-dashed bg-slate-100 py-4', 'flex cursor-pointer justify-center rounded-md border-2 border-dashed bg-slate-100 py-4',
)}> )}>
<input
{...register('file', { required: true })}
{...getInputProps()}
accept="application/pdf"
className="sr-only"
disabled={isLoading}
id="file-upload"
name="file-upload"
type="file"
/>
<div className="space-y-1 text-center"> <div className="space-y-1 text-center">
{resumeFile == null ? ( {resumeFile == null ? (
<ArrowUpCircleIcon className="text-primary-500 m-auto h-10 w-10" /> <ArrowUpCircleIcon className="text-primary-500 m-auto h-10 w-10" />
@ -345,29 +361,15 @@ export default function SubmitResumeForm({
{resumeFile.name} {resumeFile.name}
</p> </p>
)} )}
<div className="flex items-center text-sm">
<label <label
className="focus-within:ring-primary-500 rounded-md focus-within:outline-none focus-within:ring-2 focus-within:ring-offset-2" className="focus-within:ring-primary-500 flex items-center rounded-md text-sm focus-within:outline-none focus-within:ring-2 focus-within:ring-offset-2"
htmlFor="file-upload"> htmlFor="file-upload">
<span className="font-medium">Drop file here</span> <span className="font-medium">Drop file here</span>
<span className="mr-1 ml-1 font-light">or</span> <span className="mr-1 ml-1 font-light">or</span>
<span className="text-primary-600 hover:text-primary-400 cursor-pointer font-medium"> <span className="text-primary-600 hover:text-primary-400 cursor-pointer font-medium">
{resumeFile == null {resumeFile == null ? 'Select file' : 'Replace file'}
? 'Select file'
: 'Replace file'}
</span> </span>
<input
{...register('file', { required: true })}
{...getInputProps()}
accept="application/pdf"
className="sr-only"
disabled={isLoading}
id="file-upload"
name="file-upload"
type="file"
/>
</label> </label>
</div>
<p className="text-xs text-slate-500"> <p className="text-xs text-slate-500">
PDF up to {FILE_SIZE_LIMIT_MB}MB PDF up to {FILE_SIZE_LIMIT_MB}MB
</p> </p>
@ -394,8 +396,18 @@ export default function SubmitResumeForm({
<CheckboxInput <CheckboxInput
{...register('isChecked', { required: true })} {...register('isChecked', { required: true })}
disabled={isLoading} disabled={isLoading}
errorMessage={
!errors.file && errors.isChecked
? 'Please tick the checkbox after reading through the guidelines.'
: undefined
}
label="I have read and will follow the guidelines stated." label="I have read and will follow the guidelines stated."
onChange={(val) => setValue('isChecked', val)} onChange={(val) => {
if (val) {
clearErrors('isChecked');
}
setValue('isChecked', val);
}}
/> />
</> </>
)} )}

Loading…
Cancel
Save