Skip to content
Snippets Groups Projects
Commit 17244b6d authored by m431m's avatar m431m :speech_balloon:
Browse files

Merge branch 'redmine-issues/16667' into 'develop'

REDMINE_ISSUE-16667

See merge request onegeo-suite/sites/onegeo-suite-site-login-vuejs!39
parents 025ad0fe f8484d0d
No related branches found
No related tags found
No related merge requests found
Pipeline #13334 passed with warnings
......@@ -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,
......
......@@ -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) {
......
......@@ -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;
},
......
......@@ -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);
}
},
};
......
......@@ -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() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment