[resumes][feat] update submit page

pull/421/head
Keane Chan 2 years ago
parent 5844c52efe
commit e64d645d36
No known key found for this signature in database
GPG Key ID: 32718398E1E9F87C

@ -14,6 +14,7 @@ import {
CheckboxInput, CheckboxInput,
Dialog, Dialog,
Select, Select,
Spinner,
TextArea, TextArea,
TextInput, TextInput,
} from '@tih/ui'; } from '@tih/ui';
@ -74,6 +75,7 @@ export default function SubmitResumeForm({
const [isDialogShown, setIsDialogShown] = useState(false); const [isDialogShown, setIsDialogShown] = useState(false);
const { data: session, status } = useSession(); const { data: session, status } = useSession();
const isSessionLoading = status === 'loading';
const router = useRouter(); const router = useRouter();
const trpcContext = trpc.useContext(); const trpcContext = trpc.useContext();
const resumeUpsertMutation = trpc.useMutation('resumes.resume.user.upsert'); const resumeUpsertMutation = trpc.useMutation('resumes.resume.user.upsert');
@ -122,12 +124,12 @@ export default function SubmitResumeForm({
// Route user to sign in if not logged in // Route user to sign in if not logged in
useEffect(() => { useEffect(() => {
if (status !== 'loading') { if (isSessionLoading) {
if (session?.user?.id == null) { if (session?.user?.id == null) {
router.push('/api/auth/signin'); router.push('/api/auth/signin');
} }
} }
}, [router, session, status]); }, [isSessionLoading, router, session]);
const onSubmit: SubmitHandler<IFormInput> = async (data) => { const onSubmit: SubmitHandler<IFormInput> = async (data) => {
setIsLoading(true); setIsLoading(true);
@ -221,11 +223,17 @@ export default function SubmitResumeForm({
}, [errors?.file, invalidFileUploadError]); }, [errors?.file, invalidFileUploadError]);
const onValueChange = (section: InputKeys, value: string) => { const onValueChange = (section: InputKeys, value: string) => {
setValue(section, value.trim(), { shouldTouch: false }); setValue(section, value.trim(), { shouldDirty: true });
}; };
return ( return (
<> <>
{isSessionLoading && (
<div className="w-full pt-4">
{' '}
<Spinner display="block" size="lg" />{' '}
</div>
)}
<Head> <Head>
<title>Upload a Resume</title> <title>Upload a Resume</title>
</Head> </Head>
@ -268,12 +276,18 @@ export default function SubmitResumeForm({
</h1> </h1>
{/* Title Section */} {/* Title Section */}
<TextInput <TextInput
{...register('title', { required: true })} {...(register('title', { required: true }), {})}
defaultValue={initFormDetails?.title}
disabled={isLoading} disabled={isLoading}
errorMessage={
errors.title?.message != null
? 'Title cannot be empty'
: undefined
}
label="Title" label="Title"
placeholder={TITLE_PLACEHOLDER} placeholder={TITLE_PLACEHOLDER}
required={true} required={true}
onChange={(val) => setValue('title', val)} onChange={(val) => onValueChange('title', val)}
/> />
<div className="flex gap-8"> <div className="flex gap-8">
<Select <Select
@ -364,7 +378,8 @@ export default function SubmitResumeForm({
)} )}
{/* Additional Info Section */} {/* Additional Info Section */}
<TextArea <TextArea
{...(register('additionalInfo'), {})} {...(register('additionalInfo'),
{ defaultValue: initFormDetails?.additionalInfo })}
disabled={isLoading} disabled={isLoading}
label="Additional Information" label="Additional Information"
placeholder={ADDITIONAL_INFO_PLACEHOLDER} placeholder={ADDITIONAL_INFO_PLACEHOLDER}

Loading…
Cancel
Save