Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: password reset sending multiple requests #3139

Merged
merged 7 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ui/__test__/login.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ describe('Login Component', () => {
render(<Login />)

expect(
screen.queryByText('Welcome back. Login with your credentials')
screen.queryByText('Welcome back. Login with your credentials.')
).toBeInTheDocument()
expect(
screen.queryByText('or via your identity provider.')
screen.queryByText('or with your identity provider.')
).not.toBeInTheDocument()
})

Expand All @@ -82,7 +82,7 @@ describe('Login Component', () => {

expect(
screen.getByText(
'Welcome back. Login with your credentials or via your identity provider.'
'Welcome back. Login with your credentials or with your identity provider.'
)
).toBeInTheDocument()
})
Expand Down
6 changes: 3 additions & 3 deletions ui/pages/login/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ export default function Login() {
<>
<h1 className='text-base font-bold leading-snug'>Login to Infra</h1>
<h2 className='my-3 max-w-[260px] text-center text-xs text-gray-300'>
Welcome back. Login with your credentials{' '}
{providers?.length > 0 && 'or via your identity provider.'}
Welcome back. Login with your credentials
{providers?.length > 0 && ' or with your identity provider'}.
</h2>
{providers?.length > 0 && (
<>
Expand Down Expand Up @@ -196,7 +196,7 @@ export default function Login() {
</button>
{isEmailConfigured && (
<Link href='/password-reset'>
<a className='text-3xs text-violet-100 hover:border-violet-100'>
<a className='mt-3 text-3xs text-violet-100 hover:border-violet-100'>
I forgot my password
</a>
</Link>
Expand Down
29 changes: 6 additions & 23 deletions ui/pages/password-reset/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ export default function PasswordReset() {
const { token } = router.query

const [email, setEmail] = useState('')
const [error, setError] = useState('')
const [submitted, setSubmitted] = useState(false)

async function onSubmit(e) {
setSubmitted(true)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to set this back to false on error so the user can try again.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call out though but the UI doesn't currently branch on errors. The error state is never set to a non-empty value so I've removed it

e.preventDefault()

try {
Expand All @@ -28,7 +28,6 @@ export default function PasswordReset() {
}

await res.json()
setSubmitted(true)
} catch (e) {
console.error(e)
}
Expand All @@ -41,7 +40,7 @@ export default function PasswordReset() {
{token ? (
<>
<h2 className='my-3 max-w-[260px] text-center text-xs text-gray-300'>
Please set your password
Please set your password.
</h2>
<div className='relative mt-4 w-full'>
<div
Expand All @@ -58,21 +57,13 @@ export default function PasswordReset() {
<h1 className='text-base font-bold leading-snug'>Password Reset</h1>
{submitted ? (
<p className='my-3 max-w-[260px] text-xs text-gray-300'>
Please check your email for the reset link
Please check your email for the reset link.
</p>
) : (
<>
<h2 className='my-3 max-w-[260px] text-center text-xs text-gray-300'>
Please enter your email
Please enter your email.
</h2>
<div className='relative mt-4 w-full'>
<div
className='absolute inset-0 flex items-center'
aria-hidden='true'
>
<div className='w-full border-t border-gray-800' />
</div>
</div>
<form
onSubmit={onSubmit}
className='relative flex w-full max-w-sm flex-col'
Expand All @@ -91,24 +82,16 @@ export default function PasswordReset() {
placeholder='enter your email'
onChange={e => {
setEmail(e.target.value)
setError('')
}}
className={`w-full border-b border-gray-800 bg-transparent px-px py-2 text-2xs placeholder:italic focus:border-b focus:border-gray-200 focus:outline-none ${
error ? 'border-pink-500/60' : ''
}`}
className={`w-full border-b border-gray-800 bg-transparent px-px py-2 text-2xs placeholder:italic focus:border-b focus:border-gray-200 focus:outline-none`}
/>
</div>
<button
disabled={!email}
disabled={!email || submitted}
className='mt-6 mb-2 rounded-lg border border-violet-300 px-4 py-3 text-2xs text-violet-100 hover:border-violet-100 disabled:pointer-events-none disabled:opacity-30'
>
Submit
</button>
{error && (
<p className='absolute -bottom-3.5 mx-auto w-full text-center text-2xs text-pink-400'>
{error}
</p>
)}
</form>
</>
)}
Expand Down