mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2025-07-28 12:43:12 +08:00
[resumes][fix] fix unauthenticated issue on submit form
This commit is contained in:
@ -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) {
|
||||
if (status === 'unauthenticated') {
|
||||
router.push('/api/auth/signin');
|
||||
}
|
||||
}
|
||||
}, [isSessionLoading, router, session]);
|
||||
}, [router, status]);
|
||||
|
||||
const onSubmit: SubmitHandler<IFormInput> = async (data) => {
|
||||
setIsLoading(true);
|
||||
@ -228,15 +225,16 @@ export default function SubmitResumeForm({
|
||||
|
||||
return (
|
||||
<>
|
||||
{isSessionLoading && (
|
||||
<Head>
|
||||
<title>Upload a Resume</title>
|
||||
</Head>
|
||||
{status === 'loading' && (
|
||||
<div className="w-full pt-4">
|
||||
{' '}
|
||||
<Spinner display="block" size="lg" />{' '}
|
||||
</div>
|
||||
)}
|
||||
<Head>
|
||||
<title>Upload a Resume</title>
|
||||
</Head>
|
||||
{status === 'authenticated' && (
|
||||
<main className="h-[calc(100vh-4rem)] flex-1 overflow-y-auto">
|
||||
<section
|
||||
aria-labelledby="primary-heading"
|
||||
@ -332,7 +330,9 @@ export default function SubmitResumeForm({
|
||||
<div
|
||||
{...getRootProps()}
|
||||
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',
|
||||
)}>
|
||||
<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="mr-1 ml-1 font-light">or</span>
|
||||
<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>
|
||||
<input
|
||||
{...register('file', { required: true })}
|
||||
@ -418,6 +420,7 @@ export default function SubmitResumeForm({
|
||||
</form>
|
||||
</section>
|
||||
</main>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user