Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { ActionTree } from "vuex";
- import RestService from "@/api/rest";
- import { State } from "../types/state";
- import { RootState } from "@/store/interfaces/root.state";
- export const actions: ActionTree<State, RootState> = {
- recoverPassword({ commit, dispatch, state, rootState }) {
- return new Promise((resolve, reject) => {
- const isEmpetyEmail = state.email.trim() === "";
- const isEmpetyPhone = state.phone.trim() === "";
- if (isEmpetyEmail && isEmpetyPhone) {
- reject("Укажите email или телефон");
- } else {
- RestService.recoverPassword(state.email.trim())
- .then((res: any) => {
- if (res.message) {
- reject(res.message);
- }
- resolve(res);
- })
- .catch((e: any) => {
- reject(e);
- });
- }
- });
- },
- setPhone({ commit, dispatch, state, rootState }, phone: string) {
- state.phone = phone;
- state.validationMessage.phone = "";
- phone && dispatch("setPhoneValidationMessage", phone);
- },
- setEmail({ commit, dispatch, state, rootState }, email: string) {
- state.email = email;
- state.validationMessage.email = "";
- email && dispatch("setEmailValidationMessage", email);
- },
- setPhoneValidationMessage(
- { commit, dispatch, state, rootState },
- phone: string
- ) {
- RestService.checkPhone(phone).then(data => {
- state.validationMessage.phone = data ? "такой телефон не найден" : "";
- });
- },
- setEmailValidationMessage(
- { commit, dispatch, state, rootState },
- email: string
- ) {
- RestService.checkEmail(email).then(data => {
- state.validationMessage.email = data ? "такой email не найден" : "";
- });
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement