Skip to content

Commit

Permalink
fix: review
Browse files Browse the repository at this point in the history
  • Loading branch information
dougfabris committed Sep 19, 2023
1 parent 1dd9a31 commit 7d9c0c3
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions packages/web-ui-registration/src/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,12 @@ export const LoginForm = ({ setLoginRoute }: { setLoginRoute: DispatchLoginRoute
},
onError: (error: any) => {
if ([error.error, error.errorType].includes('error-invalid-email')) {
setError('username', { type: 'invalid-email', message: t('registration.page.login.errors.invalidEmail') });
return setError('username', { type: 'invalid-email', message: t('registration.page.login.errors.invalidEmail') });
}

if ('error' in error && error.error !== 403) {
setErrorOnSubmit(error.error);
return;
return setErrorOnSubmit(error.error);
}

setErrorOnSubmit('user-not-found');
},
});

Expand All @@ -93,11 +90,15 @@ export const LoginForm = ({ setLoginRoute }: { setLoginRoute: DispatchLoginRoute
if (loginFormRef.current) {
loginFormRef.current.focus();
}
}, [errorOnSubmit]);
}, []);

const renderErrorOnSubmit = (error: LoginErrors) => {
const { type, i18n } = LOGIN_SUBMIT_ERRORS[error];
return <Callout type={type}>{t(i18n)}</Callout>;
return (
<Callout id={`${usernameId}-${passwordId}-error`} aria-live='assertive' type={type}>
{t(i18n)}
</Callout>
);
};

if (errors.username?.type === 'invalid-email') {
Expand Down Expand Up @@ -131,7 +132,7 @@ export const LoginForm = ({ setLoginRoute }: { setLoginRoute: DispatchLoginRoute
placeholder={usernameOrEmailPlaceholder || t('registration.component.form.emailPlaceholder')}
error={errors.username?.message}
aria-invalid={errors.username || errorOnSubmit ? 'true' : 'false'}
aria-describedby={`${usernameId}-error`}
aria-describedby={`${usernameId}-error ${usernameId}-${passwordId}-error`}
id={usernameId}
/>
</Field.Row>
Expand All @@ -153,7 +154,7 @@ export const LoginForm = ({ setLoginRoute }: { setLoginRoute: DispatchLoginRoute
placeholder={passwordPlaceholder}
error={errors.password?.message}
aria-invalid={errors.password || errorOnSubmit ? 'true' : 'false'}
aria-describedby={`${passwordId}-error`}
aria-describedby={`${passwordId}-error ${usernameId}-${passwordId}-error`}
id={passwordId}
/>
</Field.Row>
Expand All @@ -177,11 +178,7 @@ export const LoginForm = ({ setLoginRoute }: { setLoginRoute: DispatchLoginRoute
)}
</Field>
</FieldGroup>
{errorOnSubmit && (
<FieldGroup disabled={loginMutation.isLoading} id={`${usernameId}-error`} aria-live='assertive'>
{renderErrorOnSubmit(errorOnSubmit)}
</FieldGroup>
)}
{errorOnSubmit && <FieldGroup disabled={loginMutation.isLoading}>{renderErrorOnSubmit(errorOnSubmit)}</FieldGroup>}
</Form.Container>
<Form.Footer>
<ButtonGroup stretch>
Expand Down

0 comments on commit 7d9c0c3

Please sign in to comment.