-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusers.js
More file actions
50 lines (43 loc) · 1.19 KB
/
users.js
File metadata and controls
50 lines (43 loc) · 1.19 KB
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
import usersApi from "../../api/users";
import * as types from "../mutation-types";
const getDefaultState = () => {
return { error: null, loading: false };
};
export default {
state: getDefaultState(),
actions: {
async createUser({ commit }, payload) {
try {
commit(types.USER_CREATE_REQUEST, { loading: true });
const response = await usersApi.registerEmployee(payload);
commit(types.USER_CREATE_SUCCESS, {
loading: false,
});
commit(types.USER_CREATE_RESET);
return response.data;
} catch (error) {
commit(types.USER_CREATE_FAILURE, {
loading: false,
error: error.response.data,
});
throw new Error(error.response.data);
}
},
},
mutations: {
[types.USER_CREATE_REQUEST](state, { loading }) {
state.loading = loading;
},
[types.USER_CREATE_SUCCESS](state, { loading }) {
state.loading = loading;
},
[types.USER_CREATE_FAILURE](state, { loading, error }) {
state.loading = loading;
state.error = error;
},
[types.USER_CREATE_RESET](state) {
Object.assign(state, getDefaultState());
},
},
getters: {},
};