Created
December 6, 2019 22:14
-
-
Save gsasouza/7e8c7f814f9ca0df14765bbc33e5b7c3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Login = withFormik<{}, FormValues>({ | |
mapPropsToValues: () => ({ | |
password: '', | |
email: '', | |
remember: true | |
}), | |
validationSchema: Yup.object().shape({ | |
email: Yup.string().required('Usuário é obrigatório'), | |
password: Yup.string().required('Senha é obrigatório'), | |
}), | |
handleSubmit: async (values: FormValues, { setSubmitting, setStatus }) => { | |
try { | |
const { email, password, remember } = values | |
const response = await http.post('/auth/token', { email, password }) | |
await login(response.data.token, remember) | |
setStatus({ message: 'Login realizado com sucesso', type: 'success' }) | |
await navigate('/dashboard/simulator') | |
} catch (e) { | |
//eslint-disable-next-line | |
console.error(`Auth: ${e}`) | |
setStatus({ message: 'Verifique e-mail e senha', type: 'error' }) | |
setSubmitting(false) | |
} | |
setSubmitting(false) | |
}, | |
})(LoginScreenInnerForm) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment