Newer
Older
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 client from '@/api/loginAPI.js';
import organisationAPI from '@/api/organisationsAPI.js';
import usergroupsAPI from '@/api/usergroupsAPI.js';
import { ErrorService } from '@/services/error-service.js';
const state = {
form: {
first_name: null,
last_name: null,
email: null,
phone_number: null,
comments: null,
username: null,
password1: null,
password2: null
},
organisationThumbnail: null,
organisationSpheres: [],
signed: false,
error: null,
};
const getters = {
getForm: state => state.form,
getSigned: state => state.signed,
getError: state => state.error,
};
export const POST_SIGNUP = 'POST_SIGNUP';
const actions = {
[POST_SIGNUP]: async ({ state, commit }) => {
await client.signUp(state.form)
.then(
async (resp) => {
if (state.organisationThumbnail) {
await organisationAPI.setOrganisationThumbnail(resp.usergroup_roles[0].organisation.id, state.organisationThumbnail)
.then(() => {
commit('SET_ERROR', undefined);
})
.catch((error) => {
commit(
'SET_ERROR',
error.response
|| 'Une erreur est survenue',
);
commit('SET_SIGNED', false);
});
}
if (state.organisationSpheres && state.organisationSpheres.length > 0) {
...resp.usergroup_roles[0].usergroup,
usergroup_type: {
id: resp.usergroup_roles[0].usergroup.usergroup_type,
codename: 'organisation',
description: 'Organisation',
display_name: 'Organisation',
display_name_plural: 'Organisations',
},
parents: state.organisationSpheres.map((el) => { return el.id; })
};
await usergroupsAPI.updateUsergroup(resp.usergroup_roles[0].usergroup.id, data)
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
.then(() => {
commit('SET_ERROR', undefined);
})
.catch((error) => {
commit(
'SET_ERROR',
error.response
|| 'Une erreur est survenue',
);
commit('SET_SIGNED', false);
});
}
commit('SET_ERROR', undefined);
commit('SET_SIGNED', true);
},
)
.catch(
(error) => {
commit(
'SET_ERROR',
error.response
|| 'Une erreur est survenue',
);
commit('SET_SIGNED', false);
},
);
},
};
export const SET_FORM = 'SET_FORM';
export const SET_SIGNED = 'SET_SIGNED';
export const SET_ERROR = 'SET_ERROR';
const mutations = {
[SET_FORM]: (state, data) => {
state.form = data.form;
state.organisationThumbnail = data.thumbnail;
state.organisationSpheres = data.spheres;
},
[SET_SIGNED]: (state, value) => {
if (value === true) {
state.signed = true;
} else {
state.signed = false;
}
},
[SET_ERROR]: (state, value) => {
ErrorService.onError(value);
state.error = value && value.data ? value.data : value;
},
};
export default {
namespaced: true,
state,
getters,
actions,
mutations,
};