Skip to content

Commit

Permalink
feat(LoginForm): add setError prop to handle error state and improve …
Browse files Browse the repository at this point in the history
…resend code functionality
  • Loading branch information
Chisomchima committed Feb 27, 2025
1 parent 44bb0b9 commit d679c5f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/pages/login/InnerLoginForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,27 @@ export const InnerLoginForm = ({
setFormUserName,
setIsResetButtonPressed,
}) => {
const [isResendDisabled, setIsResendDisabled] = useState(true)
const [isResendDisabled, setIsResendDisabled] = useState(false)

useEffect(() => {
setIsResendDisabled(true)
const timer = setTimeout(() => {
setIsResendDisabled(false)
}, 30000)
return () => clearTimeout(timer)
}, [])

const resendCode = () => {
const resendCode = async() => {
setIsResetButtonPressed(true)
setIsResendDisabled(true)
form.change('twoFA', undefined)
setIsResetButtonPressed(true)
handleSubmit()

await handleSubmit()
setTimeout(() => {
setIsResendDisabled(false)
}, 30000)
}

const verify = () => {
setIsResetButtonPressed(false)
handleSubmit()
Expand Down Expand Up @@ -118,9 +121,14 @@ export const InnerLoginForm = ({
secondary
disabled={isResendDisabled || loading}
onClick={resendCode}
loading={loading}
>
{isResendDisabled ? (
<Tooltip content={'You must wait 30 seconds before requesting a new code'}>
<Tooltip
content={
'You must wait 30 seconds before requesting a new code'
}
>
{i18n.t('Resend Code', { lngs })}
</Tooltip>
) : (
Expand Down
1 change: 1 addition & 0 deletions src/pages/login/LoginForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const LoginForm = ({
passwordResetEnabled,
unknownStatus,
error,
setError,

Check failure on line 20 in src/pages/login/LoginForm.js

View workflow job for this annotation

GitHub Actions / lint / lint

'setError' is missing in props validation

Check failure on line 20 in src/pages/login/LoginForm.js

View workflow job for this annotation

GitHub Actions / lint / lint

'setError' is defined but never used
loading,
setFormUserName,
lngs,
Expand Down

0 comments on commit d679c5f

Please sign in to comment.