Newer
Older
import client from '@/api/loginAPI.js';
import { ErrorService } from '@/services/error-service.js';
import Swal from "sweetalert2";
import "sweetalert2/dist/sweetalert2.min.css";
import router from '@/router';
const state = {
error: null,
success: null
};
const getters = {
};
export const REQUEST_FORGOTTEN_PASSWORD = 'REQUEST_FORGOTTEN_PASSWORD';
export const CONFIRM_NEW_PASSWORD = 'CONFIRM_NEW_PASSWORD';
const actions = {
[REQUEST_FORGOTTEN_PASSWORD]: async ({ commit }, data) => {
const response = await client.forgottenPasswordRequest(data);
if (response.status === 200) {
Swal.fire({
position: 'center',
heightAuto: false,
icon: 'success',
showConfirmButton: true,
confirmButtonText: 'OK',
confirmButtonColor: '#187CC6'
}).then((result) => {
if (result.isConfirmed) {
router.push({ name: 'SignIn' });
}
});
}
if (response.status === 404) {
commit('SET_ERROR', {
response: response,
});
}
},
[CONFIRM_NEW_PASSWORD]: async ({ commit }, data) => {
const response = await client.forgottenPasswordConfirm(data);
if (response.status === 200) {
Swal.fire({
position: 'center',
heightAuto: false,
icon: 'success',
showConfirmButton: true,
confirmButtonText: 'OK',
confirmButtonColor: '#187CC6'
}).then((result) => {
if (result.isConfirmed) {
router.push({ name: 'SignIn' });
}
});
} else if (response.status === 400) {
Swal.fire({
position: 'center',
heightAuto: false,
icon: 'error',
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
showConfirmButton: true,
confirmButtonText: 'OK',
confirmButtonColor: '#187CC6'
}).then((result) => {
if (result.isConfirmed) {
router.push({ name: 'SignIn' });
}
});
}
}
};
export const SET_ERROR = 'SET_ERROR';
export const SET_SUCCESS = 'SET_SUCCESS';
const mutations = {
[SET_ERROR]: (state, payload) => {
state.success = null;
ErrorService.onError(payload.response);
state.error = payload.message;
},
[SET_SUCCESS]: (state, payload) => {
state.error = null;
state.success = payload.message;
},
};
export default {
namespaced: true,
state,
getters,
actions,
mutations,
};