Check if router is ready (#17)

This commit is contained in:
Aswin V 2022-03-04 17:21:24 +05:30 committed by GitHub
parent 1129e3e022
commit 0a5069ba7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,6 +6,7 @@ import { useEffect, useRef, useState } from 'react';
export default function Login() { export default function Login() {
const router = useRouter(); const router = useRouter();
const { id, audience, acsUrl, providerName, relayState } = router.query; const { id, audience, acsUrl, providerName, relayState } = router.query;
const isRouteReady = router.isReady;
const [state, setState] = useState({ const [state, setState] = useState({
username: 'jackson', username: 'jackson',
@ -25,7 +26,7 @@ export default function Login() {
acsUrlInp.current.focus(); acsUrlInp.current.focus();
acsUrlInp.current.select(); acsUrlInp.current.select();
} }
}, []); }, [acsUrl]);
const handleChange = (e: FormEvent<HTMLInputElement | HTMLSelectElement>): void => { const handleChange = (e: FormEvent<HTMLInputElement | HTMLSelectElement>): void => {
const { name, value } = e.currentTarget; const { name, value } = e.currentTarget;
@ -75,41 +76,43 @@ export default function Login() {
<div className='relative top-20 mx-auto w-[465px] max-w-[90%] rounded-md border p-10 text-[#145698]'> <div className='relative top-20 mx-auto w-[465px] max-w-[90%] rounded-md border p-10 text-[#145698]'>
<h2 className='mb-3 text-center text-3xl font-bold'>Login</h2> <h2 className='mb-3 text-center text-3xl font-bold'>Login</h2>
<form onSubmit={handleSubmit}> <form onSubmit={handleSubmit}>
{acsUrl ? null : ( {isRouteReady ? (
<div> acsUrl ? null : (
<div className='mt-5'> <div>
<label htmlFor='acsUrl' className='mb-2 block'> <div className='mt-5'>
ACS URL <sup>(This is where we&apos;ll post the SAML Response)</sup> <label htmlFor='acsUrl' className='mb-2 block'>
</label> ACS URL <sup>(This is where we&apos;ll post the SAML Response)</sup>
<input </label>
name='acsUrl' <input
id='acsUrl' name='acsUrl'
ref={acsUrlInp} id='acsUrl'
autoComplete='off' ref={acsUrlInp}
type='text' autoComplete='off'
placeholder='https://jackson-demo.boxyhq.com/api/oauth/saml' type='text'
value={state.acsUrl} placeholder='https://jackson-demo.boxyhq.com/api/oauth/saml'
onChange={handleChange} value={state.acsUrl}
className='input w-full' onChange={handleChange}
/> className='input w-full'
/>
</div>
<div className='mt-5'>
<label htmlFor='audience' className='mb-2 block'>
Audience
</label>
<input
name='audience'
id='audience'
autoComplete='off'
type='text'
placeholder='https://saml.boxyhq.com'
value={state.audience}
onChange={handleChange}
className='input w-full'
/>
</div>
</div> </div>
<div className='mt-5'> )
<label htmlFor='audience' className='mb-2 block'> ) : null}
Audience
</label>
<input
name='audience'
id='audience'
autoComplete='off'
type='text'
placeholder='https://saml.boxyhq.com'
value={state.audience}
onChange={handleChange}
className='input w-full'
/>
</div>
</div>
)}
<div className='mt-5 flex items-end gap-x-1'> <div className='mt-5 flex items-end gap-x-1'>
<div> <div>
<label htmlFor='username' className='mb-2 block'> <label htmlFor='username' className='mb-2 block'>