[resumes][fix] fix unauthenticated issue on submit form

pull/422/head
Keane Chan 2 years ago
parent 8e50cc7313
commit 70b102f87e
No known key found for this signature in database
GPG Key ID: 32718398E1E9F87C

@ -74,8 +74,7 @@ export default function SubmitResumeForm({
>(null); >(null);
const [isDialogShown, setIsDialogShown] = useState(false); const [isDialogShown, setIsDialogShown] = useState(false);
const { data: session, status } = useSession(); const { 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');
@ -124,12 +123,10 @@ 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 (isSessionLoading) { if (status === 'unauthenticated') {
if (session?.user?.id == null) {
router.push('/api/auth/signin'); router.push('/api/auth/signin');
} }
} }, [router, status]);
}, [isSessionLoading, router, session]);
const onSubmit: SubmitHandler<IFormInput> = async (data) => { const onSubmit: SubmitHandler<IFormInput> = async (data) => {
setIsLoading(true); setIsLoading(true);
@ -228,15 +225,16 @@ export default function SubmitResumeForm({
return ( return (
<> <>
{isSessionLoading && ( <Head>
<title>Upload a Resume</title>
</Head>
{status === 'loading' && (
<div className="w-full pt-4"> <div className="w-full pt-4">
{' '} {' '}
<Spinner display="block" size="lg" />{' '} <Spinner display="block" size="lg" />{' '}
</div> </div>
)} )}
<Head> {status === 'authenticated' && (
<title>Upload a Resume</title>
</Head>
<main className="h-[calc(100vh-4rem)] flex-1 overflow-y-auto"> <main className="h-[calc(100vh-4rem)] flex-1 overflow-y-auto">
<section <section
aria-labelledby="primary-heading" aria-labelledby="primary-heading"
@ -332,7 +330,9 @@ export default function SubmitResumeForm({
<div <div
{...getRootProps()} {...getRootProps()}
className={clsx( className={clsx(
fileUploadError ? 'border-danger-600' : 'border-slate-300', fileUploadError
? 'border-danger-600'
: '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',
)}> )}>
<div className="space-y-1 text-center"> <div className="space-y-1 text-center">
@ -352,7 +352,9 @@ export default function SubmitResumeForm({
<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 ? 'Select file' : 'Replace file'} {resumeFile == null
? 'Select file'
: 'Replace file'}
</span> </span>
<input <input
{...register('file', { required: true })} {...register('file', { required: true })}
@ -418,6 +420,7 @@ export default function SubmitResumeForm({
</form> </form>
</section> </section>
</main> </main>
)}
</> </>
); );
} }

Loading…
Cancel
Save