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(login): disable sendLoginCode button when mutation is loading #3874

Merged
merged 1 commit into from
Oct 6, 2023
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
13 changes: 9 additions & 4 deletions src/components/Forms/EmailLoginForm/OtherOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ import styles from './styles.module.css'

export const SendLoginCodeButton = ({
sendLoginCode,
disabled,
}: {
sendLoginCode: () => void
disabled?: boolean
}) => (
<section className={styles.option}>
<FormattedMessage
defaultMessage="Forgot password?"
description="src/components/Forms/EmailLoginForm/Buttons.tsx"
/>
<Button aria-haspopup="dialog" onClick={sendLoginCode}>
<Button aria-haspopup="dialog" onClick={sendLoginCode} disabled={disabled}>
<FormattedMessage
defaultMessage="Send login code"
description="src/components/Forms/EmailLoginForm/Buttons.tsx"
Expand All @@ -24,18 +26,21 @@ export const SendLoginCodeButton = ({
)

const OtherOptions = ({
isInPage,
hasSendCode,
sendLoginCode,
disabled,
}: {
isInPage: boolean
hasSendCode: boolean
sendLoginCode?: () => any
disabled?: boolean
}) => {
return (
<section className={styles.otherOptions}>
{!hasSendCode && sendLoginCode && (
<SendLoginCodeButton sendLoginCode={sendLoginCode} />
<SendLoginCodeButton
sendLoginCode={sendLoginCode}
disabled={disabled}
/>
)}
{hasSendCode && (
<section className={styles.hasSendCode}>
Expand Down
11 changes: 4 additions & 7 deletions src/components/Forms/EmailLoginForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,10 @@ export const EmailLoginForm: React.FC<FormProps> = ({

const passwordRef = useRef<HTMLInputElement>(null)

const [sendCode] = useMutation<SendVerificationCodeMutation>(
SEND_CODE,
undefined,
{
const [sendCode, { loading: sendingCode }] =
useMutation<SendVerificationCodeMutation>(SEND_CODE, undefined, {
showToast: false,
}
)
})

const intl = useIntl()
const {
Expand Down Expand Up @@ -307,9 +304,9 @@ export const EmailLoginForm: React.FC<FormProps> = ({
{errorCode !== ERROR_CODES.CODE_EXPIRED &&
!(hasSendCode && errorCode === ERROR_CODES.CODE_INVALID) && (
<OtherOptions
isInPage={isInPage}
sendLoginCode={sendLoginCode}
hasSendCode={hasSendCode}
disabled={sendingCode}
/>
)}
</Form>
Expand Down
Loading