diff --git a/src/presentation/pages/login/login.tsx b/src/presentation/pages/login/login.tsx index bc4a8fb..cb4ace2 100644 --- a/src/presentation/pages/login/login.tsx +++ b/src/presentation/pages/login/login.tsx @@ -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, @@ -23,9 +23,10 @@ import { type LoginProps = { validation: Validation; authentication: Authentication; + display: Display; }; -const Login: React.FC = ({validation, authentication}) => { +const Login: React.FC = ({validation, authentication, display}) => { const theme = useTheme(); const initialValues: LoginFormValues = {email: '', password: ''}; @@ -38,12 +39,21 @@ const Login: React.FC = ({validation, authentication}) => { }; const onSubmit = async (values: LoginFormValues): Promise => { - 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 (