Skip to content

Commit

Permalink
feat: ensure Login calls Display to show errors if Authentication fails
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorverasm committed Jan 25, 2021
1 parent 6f179eb commit 3e55a4d
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/presentation/pages/login/login.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Authentication} from '@/domain/usecases';
import {DefaultI18n, LoginI18n, translate} from '@/locale';
import {Validation} from '@/presentation/protocols/validation';
import {Display, Validation} from '@/presentation/protocols';
import {LoginFormValues} from '@/presentation/types';
import {
Button,
Expand All @@ -23,9 +23,10 @@ import {
type LoginProps = {
validation: Validation<LoginFormValues>;
authentication: Authentication;
display: Display;
};

const Login: React.FC<LoginProps> = ({validation, authentication}) => {
const Login: React.FC<LoginProps> = ({validation, authentication, display}) => {
const theme = useTheme();

const initialValues: LoginFormValues = {email: '', password: ''};
Expand All @@ -38,12 +39,21 @@ const Login: React.FC<LoginProps> = ({validation, authentication}) => {
};

const onSubmit = async (values: LoginFormValues): Promise<void> => {
if (loading) {
return;
try {
if (loading) {
return;
}
console.log(values);
setLoading(true);
await authentication.auth({
email: values.email,
password: values.password,
});
} catch (error) {
console.log('trow error', error.message);
setLoading(false);
display.show({title: 'Oops!', description: error.message});
}
console.log(values);
setLoading(true);
await authentication.auth({email: values.email, password: values.password});
};

return (
Expand Down

0 comments on commit 3e55a4d

Please sign in to comment.