From 0b7c6feeb33770e660336be373be6941e5d6dcbd Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Wed, 18 Nov 2020 03:11:34 +0100 Subject: [PATCH] Fixed issue with avatar upload --- .../components/settings/MainUserSettings.vue | 53 ++++++++----------- src/plugins/user/store/user.ts | 1 - 2 files changed, 22 insertions(+), 32 deletions(-) diff --git a/src/plugins/user/components/settings/MainUserSettings.vue b/src/plugins/user/components/settings/MainUserSettings.vue index 1abf68c..373243f 100644 --- a/src/plugins/user/components/settings/MainUserSettings.vue +++ b/src/plugins/user/components/settings/MainUserSettings.vue @@ -1,8 +1,5 @@ @@ -127,7 +114,7 @@ import { computed, defineComponent, ref, - onBeforeMount, + onBeforeMount } from '@vue/composition-api'; import { Store } from 'vuex'; import { StateInterface } from 'src/store'; @@ -145,17 +132,17 @@ export default defineComponent({ components: { IsoDateInput: IsoDateInput }, props: { user: { - required: true, + required: true }, newUser: { - default: false, - }, + default: false + } }, setup(props: Props, { root, emit }) { const store = >root.$store; onBeforeMount(() => { - store.dispatch('user/getRoles', false).catch((error) => { + store.dispatch('user/getRoles', false).catch(error => { console.warn(error); }); }); @@ -169,7 +156,7 @@ export default defineComponent({ const oldUser = computed(() => { if (isCurrentUser.value) return store.state.user.currentUser; else - return store.state.user.users.filter((user) => { + return store.state.user.users.filter(user => { user.userid === props.user?.userid; })[0]; }); @@ -182,13 +169,13 @@ export default defineComponent({ message: 'Datei zu groß oder keine gültige Bilddatei.', timeout: 10000, progress: true, - actions: [{ icon: 'mdi-close', color: 'white' }], + actions: [{ icon: 'mdi-close', color: 'white' }] }); avatar.value = []; } const allRoles = computed(() => - store.state.user.roles.map((role) => role.name) + store.state.user.roles.map(role => role.name) ); const password = ref(''); const new_password = ref(''); @@ -199,20 +186,24 @@ export default defineComponent({ if (typeof changed.birthday === 'string') changed.birthday = new Date(changed.birthday); changed = Object.assign(changed, { - password: password.value, + password: password.value }); if (new_password.value != '') { changed = Object.assign(changed, { - new_password: new_password.value, + new_password: new_password.value }); } emit('update:user', changed); - if (avatar.value && avatar.value.length > 0) + + if ( + avatar.value && + (avatar.value.length > 0 || avatar.value instanceof File) + ) store .dispatch('user/uploadAvatar', { user: changed, - file: avatar.value, + file: avatar.value }) .catch((response: Response) => { if (response && response.status == 400) { @@ -270,8 +261,8 @@ export default defineComponent({ notEmpty, isUseridUsed, save, - reset, + reset }; - }, + } }); diff --git a/src/plugins/user/store/user.ts b/src/plugins/user/store/user.ts index c1bc397..3c813f4 100644 --- a/src/plugins/user/store/user.ts +++ b/src/plugins/user/store/user.ts @@ -34,7 +34,6 @@ const mutations: MutationTree = { setCurrentUser(state, data: FG.User) { if (typeof data.birthday === 'string') data.birthday = new Date(data.birthday); - console.warn(data.birthday); SessionStorage.set('currentUser', data); state.currentUser = data; },