diff --git a/src/components/OrganisationCreation.vue b/src/components/OrganisationCreation.vue index 9f32c487d0d9e071625f2f05e416ccafc68a9465..02b286ff56d79822759fecd775ec850c77ff17c3 100644 --- a/src/components/OrganisationCreation.vue +++ b/src/components/OrganisationCreation.vue @@ -142,12 +142,21 @@ <div class="form-row"> <div class="form-group col-6"> <label>{{ $t('organisationCreation.form.phone') }}</label> - <input - v-model="formData.tel" - class="form-control" - type="text" - placeholder="" + <ValidationProvider + ref="phone_number" + :rules="isFieldRequired('phone_number', formConfig.requiredFields)" + v-slot="{ classes, errors }" > + <div class="control" :class="classes"> + <input + v-model="formData.tel" + class="form-control" + type="text" + placeholder="" + > + <span class="form-errors">{{ errors[0] }}</span> + </div> + </ValidationProvider> </div> </div> @@ -310,8 +319,8 @@ export default { } }, error(newValue) { - if (newValue) { - for (const [key, value] of Object.entries(newValue)) { + if (newValue && newValue.usergroup_roles && newValue.usergroup_roles.length && newValue.usergroup_roles[0].organisation) { + for (const [key, value] of Object.entries(newValue.usergroup_roles[0].organisation)) { if (this.$refs[key]) { this.$refs[key].applyResult({ errors: value, diff --git a/src/services/error-service.js b/src/services/error-service.js index 8e22c1bea607f452e8548f9fde3eaae1128453ce..f1715a37d6bb10a8508726e4ed6e64f744c18a9f 100644 --- a/src/services/error-service.js +++ b/src/services/error-service.js @@ -11,7 +11,6 @@ export class ErrorService { router.push({ name: '403Page'}); } if (response && response.status >= 400 && response.status < 405) { - const errorObj = response.data.detail ? response.data.detail : response.data; const messages = []; function recurse(obj) { diff --git a/src/store/modules/sign-up.store.js b/src/store/modules/sign-up.store.js index 494845bf7b2adfdf6e94dd6f6c916e1a288b0761..29aa557dbe575e79022cbef33be1babfcfa3f08c 100644 --- a/src/store/modules/sign-up.store.js +++ b/src/store/modules/sign-up.store.js @@ -28,26 +28,13 @@ const getters = { 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) => { + POST_SIGNUP: async ({ state, commit }) => { + try { + const resp = await client.signUp(state.form); + if (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 - || i18n.t('messages.error'), - ); - commit('SET_SIGNED', false); - }); } if (state.organisationSpheres && state.organisationSpheres.length > 0) { const data = { @@ -62,53 +49,35 @@ const actions = { parents: state.organisationSpheres.map((el) => { return el.id; }) }; await usergroupsAPI.updateUsergroup(resp.usergroup_roles[0].usergroup.id, data) - .then(() => { - commit('SET_ERROR', undefined); - }) - .catch((error) => { - commit( - 'SET_ERROR', - error.response - || i18n.t('messages.error'), - ); - commit('SET_SIGNED', false); - }); } commit('SET_ERROR', undefined); commit('SET_SIGNED', true); - }, - ) - .catch( - (error) => { - commit( - 'SET_ERROR', - error.response - || i18n.t('messages.error'), - ); - commit('SET_SIGNED', false); - }, + } + } catch (error) { + commit( + 'SET_ERROR', + error.response + || i18n.t('messages.error'), ); + 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) => { + SET_FORM: (state, data) => { state.form = data.form; state.organisationThumbnail = data.thumbnail; state.organisationSpheres = data.spheres; }, - [SET_SIGNED]: (state, value) => { + SET_SIGNED: (state, value) => { if (value === true) { state.signed = true; } else { state.signed = false; } }, - [SET_ERROR]: (state, value) => { + SET_ERROR: (state, value) => { ErrorService.onError(value); state.error = value && value.data ? value.data : value; }, diff --git a/src/store/modules/user.store.js b/src/store/modules/user.store.js index 632050e334ab1f67342a584270f46263240ec1a2..af74b4cabfeb8977c7829313cfb4ded582815914 100644 --- a/src/store/modules/user.store.js +++ b/src/store/modules/user.store.js @@ -3,15 +3,6 @@ import loginAPI from '@/api/loginAPI.js'; import { ErrorService } from '@/services/error-service.js'; import i18n from '@/i18n'; -// MUTATIONS -export const SET_ERROR = 'SET_ERROR'; -export const SET_SUCCESS = 'SET_SUCCESS'; -export const SET_USER_DETAIL = 'SET_USER_DETAIL'; - -// ACTIONS -export const GET_USER_DETAIL = 'GET_USER_DETAIL'; -export const UPDATE_USER_DETAIL = 'UPDATE_USER_DETAIL'; - /**************** STATE *******************/ const state = { userData: null, @@ -27,20 +18,20 @@ const getters = { /*************** MUTATIONS ****************/ const mutations = { - [SET_USER_DETAIL]: (state, payload) => { + SET_USER_DETAIL: (state, payload) => { state.userData = payload; }, - [SET_ERROR]: (state, error) => { + SET_ERROR: (state, error) => { if (error) { ErrorService.onError(error); - state.userError = error.response.data.detail; + state.userError = error.data; } else { state.userError = error; } }, - [SET_SUCCESS]: (state, payload) => { + SET_SUCCESS: (state, payload) => { state.error = null; state.success = payload.message; }, @@ -49,22 +40,21 @@ const mutations = { const actions = { - [GET_USER_DETAIL]: async ({ commit }) => { - await loginAPI.getUserDetail() - .then((resp) => { - if (resp) { - commit('SET_ERROR', null); - commit('SET_USER_DETAIL', resp); + GET_USER_DETAIL: async ({ commit }) => { + try { + const resp = await loginAPI.getUserDetail(); + if (resp) { + commit('SET_ERROR', null); + commit('SET_USER_DETAIL', resp); + } + } catch (error) { + commit('SET_ERROR', error.response); } - }) - .catch((error) => { - commit('SET_ERROR', error); - }); }, - [UPDATE_USER_DETAIL]: async ({ commit }, data) => { - await loginAPI.updateUserDetail(data) - .then((resp) => { + UPDATE_USER_DETAIL: async ({ commit }, data) => { + try { + const resp = await loginAPI.updateUserDetail(data); if (resp) { commit('SET_ERROR', null); commit('SET_SUCCESS', { @@ -72,14 +62,14 @@ const actions = { message: i18n.t('messages.password.success') }); } - }) - .catch((error) => { + } catch(error) { commit('SET_SUCCESS', { response: null, message: null }); - commit('SET_ERROR', error); - }); + commit('SET_ERROR', error.response); + throw new Error(error); + } }, }; diff --git a/src/views/UserProfile.vue b/src/views/UserProfile.vue index dd039639545858480991c53093c176a7f7b643b0..9b5cc6f744dca1363f6e9ef08495e06d7a103b80 100644 --- a/src/views/UserProfile.vue +++ b/src/views/UserProfile.vue @@ -489,7 +489,11 @@ export default { }, computed: { - ...mapState('user', ['userData', 'success']), + ...mapState('user', [ + 'userData', + 'userError', + 'success' + ]), ...mapState('organisations', ['organisationsRoles']), ...mapState('sign-in', [ 'next' @@ -506,6 +510,18 @@ export default { this.$refs.form.validate(); } }, + + userError(newValue) { + if (newValue) { + for (const [key, value] of Object.entries(newValue)) { + this.$refs[key].applyResult({ + errors: value, + valid: false, + failedRules: {} + }); + } + } + } }, created() { @@ -554,19 +570,22 @@ export default { submitUserInformations() { this.loadingUserInformation = true this.UPDATE_USER_DETAIL(this.formUser) - .then(() => { - this.GET_USER_DETAIL() .then(() => { - this.formUser = { - ...this.formUser, - ...this.userData - }; + this.GET_USER_DETAIL() + .then(() => { + this.formUser = { + ...this.formUser, + ...this.userData + }; + this.loadingUserInformation = false; + }) + .catch(() => { + this.loadingUserInformation = false; + }); + }) + .catch(() => { this.loadingUserInformation = false; }); - }) - .catch(() => { - this.loadingUserInformation = false; - }); }, submitNewEmail() {