From fc35e2ececa4a4ae4ad645ea8e05ff264b621df0 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Thu, 1 Apr 2021 03:16:56 +0200 Subject: [PATCH] [user] Fixed avatar upload --- .../components/settings/MainUserSettings.vue | 18 ++++++++++-------- src/plugins/user/store.ts | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/plugins/user/components/settings/MainUserSettings.vue b/src/plugins/user/components/settings/MainUserSettings.vue index d59e519..20e5123 100644 --- a/src/plugins/user/components/settings/MainUserSettings.vue +++ b/src/plugins/user/components/settings/MainUserSettings.vue @@ -135,7 +135,7 @@ export default defineComponent({ const password = ref(''); const newPassword = ref(''); - const avatar = ref([]); + const avatar = ref(); const userModel = ref(props.user); const canSetRoles = computed(() => hasPermission('users_set_roles')); @@ -157,7 +157,7 @@ export default defineComponent({ progress: true, actions: [{ icon: 'mdi-close', color: 'white' }], }); - avatar.value = []; + avatar.value = undefined; } function save() { @@ -174,12 +174,14 @@ export default defineComponent({ emit('update:user', changed); - if (avatar.value && (avatar.value.length > 0 || avatar.value instanceof File)) - userStore.uploadAvatar(changed, avatar.value[0]).catch((response: Response) => { - if (response && response.status == 400) { - onAvatarRejected(); - } - }); + if (avatar.value) + userStore + .uploadAvatar(changed, avatar.value instanceof File ? avatar.value : avatar.value[0]) + .catch((response: Response) => { + if (response && response.status == 400) { + onAvatarRejected(); + } + }); reset(); } diff --git a/src/plugins/user/store.ts b/src/plugins/user/store.ts index 3a02c31..a09500b 100644 --- a/src/plugins/user/store.ts +++ b/src/plugins/user/store.ts @@ -64,7 +64,7 @@ export const useUserStore = defineStore({ return data; }, - async uploadAvatar(user: FG.User, file: string) { + async uploadAvatar(user: FG.User, file: string | File) { const formData = new FormData(); formData.append('file', file); await api.post(`/users/${user.userid}/avatar`, formData, {