-
Notifications
You must be signed in to change notification settings - Fork 78
/
LoginForm.js
54 lines (52 loc) · 1.4 KB
/
LoginForm.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// import { required, email } from 'vuelidate/lib/validators';
import { required, email } from '@vuelidate/validators';
import useVuelidate from '@vuelidate/core';
import ServerError from 'presentation/components/ServerError/ServerError.vue';
import BaseForm from 'presentation/components/BaseForm/BaseForm.vue';
import BaseInput from 'presentation/components/BaseInput/BaseInput.vue';
import { useI18n } from 'vue-i18n';
import useCustomerTools from 'hooks/useCustomerTools';
import { ref } from 'vue';
import useAccessRules from 'hooks/useAccessRules';
function Rules() {
this.password = { required };
this.email = {
required,
email,
};
}
export default {
components: {
BaseForm,
BaseInput,
ServerError,
// LoadingButton,
},
props: {},
setup() {
const { showResetPassword } = useAccessRules();
const { t } = useI18n();
const form = ref({
email: '',
password: '',
});
const rules = new Rules(form);
const v = useVuelidate(rules, form);
const tools = useCustomerTools();
const customerSignMeIn = () =>
tools.login(form.value.email, form.value.password);
const getErrorMessage = ({ code }) => {
if (code === 'InvalidCredentials') {
return t('invalidCredentials');
}
return t('unknownError');
};
return {
v,
customerSignMeIn,
t,
getErrorMessage,
showResetPassword,
};
},
};