From 70b102f87e99fc66c43462b44909b48f99843f27 Mon Sep 17 00:00:00 2001 From: Keane Chan Date: Mon, 24 Oct 2022 14:59:24 +0800 Subject: [PATCH] [resumes][fix] fix unauthenticated issue on submit form --- apps/portal/src/pages/resumes/submit.tsx | 357 ++++++++++++----------- 1 file changed, 180 insertions(+), 177 deletions(-) diff --git a/apps/portal/src/pages/resumes/submit.tsx b/apps/portal/src/pages/resumes/submit.tsx index f664836c..c851cafa 100644 --- a/apps/portal/src/pages/resumes/submit.tsx +++ b/apps/portal/src/pages/resumes/submit.tsx @@ -74,8 +74,7 @@ export default function SubmitResumeForm({ >(null); const [isDialogShown, setIsDialogShown] = useState(false); - const { data: session, status } = useSession(); - const isSessionLoading = status === 'loading'; + const { status } = useSession(); const router = useRouter(); const trpcContext = trpc.useContext(); const resumeUpsertMutation = trpc.useMutation('resumes.resume.user.upsert'); @@ -124,12 +123,10 @@ export default function SubmitResumeForm({ // Route user to sign in if not logged in useEffect(() => { - if (isSessionLoading) { - if (session?.user?.id == null) { - router.push('/api/auth/signin'); - } + if (status === 'unauthenticated') { + router.push('/api/auth/signin'); } - }, [isSessionLoading, router, session]); + }, [router, status]); const onSubmit: SubmitHandler = async (data) => { setIsLoading(true); @@ -228,196 +225,202 @@ export default function SubmitResumeForm({ return ( <> - {isSessionLoading && ( + + Upload a Resume + + {status === 'loading' && (
{' '} {' '}
)} - - Upload a Resume - -
-
- {/* Reset Dialog component */} - - } - secondaryButton={ - -
-

- {isNewForm ? 'Upload a resume' : 'Update details'} -

- {/* Title Section */} - +
+ {/* Reset Dialog component */} + } - label="Title" - placeholder={TITLE_PLACEHOLDER} - required={true} - onChange={(val) => onValueChange('title', val)} - /> -
- setValue('role', val)} + /> + setValue('experience', val)} + onChange={(val) => setValue('location', val)} /> -
- + + +

+ PDF up to {FILE_SIZE_LIMIT_MB}MB

- )} -
-
-

- PDF up to {FILE_SIZE_LIMIT_MB}MB -

+ {fileUploadError && ( +

{fileUploadError}

+ )} - {fileUploadError && ( -

{fileUploadError}

- )} - - )} - {/* Additional Info Section */} -