From 925982d700e063da595a698ca0a2b429b0a9c24f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Tue, 27 Oct 2020 13:49:45 +0100 Subject: [PATCH] User kann eigene Einstellungen updaten --- src/plugins/user/components/settings/Main.vue | 81 ++++++++++++++++--- src/plugins/user/store/user.ts | 66 +++++++++------ 2 files changed, 112 insertions(+), 35 deletions(-) diff --git a/src/plugins/user/components/settings/Main.vue b/src/plugins/user/components/settings/Main.vue index bfd5521..8ebefc1 100644 --- a/src/plugins/user/components/settings/Main.vue +++ b/src/plugins/user/components/settings/Main.vue @@ -4,15 +4,13 @@ + + + + diff --git a/src/plugins/user/store/user.ts b/src/plugins/user/store/user.ts index c6f6b43..977d790 100644 --- a/src/plugins/user/store/user.ts +++ b/src/plugins/user/store/user.ts @@ -35,22 +35,22 @@ const state: UserStateInterface = { }; const mutations: MutationTree = { - setUser (state, data: FG.User) { + setUser(state, data: FG.User) { state.user = data; }, - setSession (state, data: FG.Session) { + setSession(state, data: FG.Session) { state.session = data; }, - setLoginLoading (state, data: boolean) { + setLoginLoading(state, data: boolean) { state.loginLoading = data; }, - showState (state) { + showState(state) { console.log(state); } }; const actions: ActionTree = { - login ({ commit }, data: LoginData) { + login({ commit }, data: LoginData) { commit('setLoginLoading', true); Loading.show({ message: 'Du wirst eingeloggt' }); void axios @@ -73,7 +73,7 @@ const actions: ActionTree = { Loading.hide(); }); }, - logout ({ commit }, token) { + logout({ commit }, token) { void axios.delete(`/auth/${token}`).then(() => { commit('setUser', { display_name: '', @@ -92,45 +92,61 @@ const actions: ActionTree = { }); }); }, - loadFromLocalStorage ({ commit }) { + updateUser({ commit, getters }, data) { + commit('setLoginLoading', true); + axios + .put(`/users/${getters.user.userid}`, data) + .catch(error => { + console.log(error); + }) + .finally(() => { + commit('setLoginLoading', false); + }); + }, + loadFromLocalStorage({ commit }) { console.log('load from store'); let data = LocalStorage.getItem('user'); - commit('setUser', data ? data : { - display_name: '', - firstname: '', - lastname: '', - mail: '', - roles: [], - userid: '' - }); + commit( + 'setUser', + data + ? data + : { + display_name: '', + firstname: '', + lastname: '', + mail: '', + roles: [], + userid: '' + } + ); data = LocalStorage.getItem('session'); commit( 'setSession', data ? data : { - browser: '', - expires: new Date(), - lifetime: -1, - platform: '', - token: '' - } + browser: '', + expires: new Date(), + lifetime: -1, + platform: '', + token: '' + } ); commit('showState'); } }; const getters: GetterTree = { - user ({ user }) { + user({ user }) { return user; }, - displayName ({ user }) { + displayName({ user }) { return user.display_name; }, - session ({ session }) { + session({ session }) { return session; }, - loginLoading ({ loginLoading }) { + loginLoading({ loginLoading }) { return loginLoading; } };