/
registration.vue
183 lines (168 loc) · 6.05 KB
/
registration.vue
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<template>
<form-wrapper>
<h2 class="mb-3">{{ header }}</h2>
<div class="slider">
<v-scroll-x-reverse-transition>
<mode-step-registration v-show="showMode" @next="enterData"/>
</v-scroll-x-reverse-transition>
<v-scroll-x-reverse-transition>
<data-step-registration v-show="showData" @next="enterData"/>
</v-scroll-x-reverse-transition>
<v-scroll-x-reverse-transition>
<password-step-registration v-show="showPassword" ref="passwordStepFormRef" @next="enterData"/>
</v-scroll-x-reverse-transition>
<v-scroll-x-reverse-transition>
<confirm-step-registration v-show="showConfirm" ref="confirmStepFormRef" @next="enterData"
@resend="sendRegData"/>
</v-scroll-x-reverse-transition>
<v-scroll-x-reverse-transition>
<success-step-registration v-show="showSuccess"/>
</v-scroll-x-reverse-transition>
</div>
<div class="bottom-container">
<div v-if="showBackBtn" class="link" @click="backStep">Назад</div>
<div v-if="showLoginBtn" class="link" @click="goToLogin">На страницу входа</div>
</div>
</form-wrapper>
</template>
<script>
import FormWrapper from '../components/form-wrapper';
import DataStepRegistration from "./forms/data-step-registration";
import PasswordStepRegistration from "./forms/password-step-registration";
import ConfirmStepRegistration from "./forms/confirm-step-registration";
import SuccessStepRegistration from "./forms/success-step-registration";
import RegistrationService from "./service/registration-service";
export default {
name: "register-form",
components: {
FormWrapper,
DataStepRegistration,
PasswordStepRegistration,
ConfirmStepRegistration,
SuccessStepRegistration
}
}
</script>
<script setup>
import {computed, ref, defineExpose} from "vue";
import {RegistrationModel} from "./service/models";
import {useStore} from "vuex";
import {STEPS} from "./forms/constants";
import {useRouter} from "vue-router";
import ModeStepRegistration from "@/views/sign-view/registration/forms/mode-step-registration";
const store = useStore();
const router = useRouter();
// refs
const passwordStepFormRef = ref(null);
const confirmStepFormRef = ref(null);
defineExpose({passwordStepFormRef, confirmStepFormRef});
// data
let infoUser = new RegistrationModel();
// computed
let step = computed(() => store.getters.getRegistrationStep);
let header = computed(() => {
if (step.value === STEPS.CHOSE_MODE) {
return "Зарегистрироваться через";
}
if (step.value === STEPS.DATA) {
return "Регистрация";
}
if (step.value === STEPS.PASSWORD) {
return "Придумайте пароль";
}
if (step.value === STEPS.CONFIRM) {
return "Подтверждение";
}
if (step.value === STEPS.SUCCESS) {
return "";
}
});
let showMode = computed(() => step.value === STEPS.CHOSE_MODE);
let showData = computed(() => step.value === STEPS.DATA);
let showPassword = computed(() => step.value === STEPS.PASSWORD);
let showConfirm = computed(() => step.value === STEPS.CONFIRM);
let showSuccess = computed(() => step.value === STEPS.SUCCESS);
let showBackBtn = computed(() => [STEPS.PASSWORD, STEPS.DATA].includes(step.value));
let showLoginBtn = computed(() => [STEPS.DATA, STEPS.PASSWORD, STEPS.CONFIRM, STEPS.CHOSE_MODE].includes(step.value));
// methods
let nextStep = () => {
store.dispatch('nextRegistrationStep');
};
let backStep = () => {
store.dispatch('backRegistrationStep');
};
let goToLogin = () => {
router.replace({name: "login"});
};
let sendRegData = () => {
let data = store.getters.getRegistrationData;
return RegistrationService.sendRegistrationData(RegistrationModel.build(data));
};
let enterData = (dataForm) => {
if (showMode.value) {
nextStep();
return;
}
if (showData.value) {
store.dispatch('setRegistrationData', dataForm);
nextStep();
return;
}
if (showPassword.value) {
let data = store.getters.getRegistrationData;
if (!data || !data.email || !data.firstName) {
store.dispatch('setRegistrationData', null);
backStep();
return;
}
data.password = dataForm.password;
data.repeatedPassword = dataForm.repeatedPassword;
store.dispatch('setRegistrationData', data);
sendRegData()
.then(() => {
nextStep();
})
.catch(() => {
passwordStepFormRef.value.resetState();
});
return;
}
if (showConfirm.value) {
RegistrationService.sendConfirm(dataForm)
.then(() => {
nextStep();
store.dispatch('setRegistrationData', null);
})
.catch(() => {
confirmStepFormRef.value.resetState();
});
return;
}
};
</script>
<style lang="scss" scoped>
.slider {
display: flex;
align-items: center;
justify-content: center;
position: relative;
width: 100%;
}
.bottom-container {
position: absolute;
bottom: 20px;
.link {
align-self: center;
margin: 5px auto 15px auto;
cursor: pointer;
font-size: 12px;
opacity: 0.5;
transition: opacity .3s ease-out;
width: fit-content;
font-style: italic;
&:hover {
opacity: 1;
}
}
}
</style>