From bc5f6c90015fe512af7cd56efccc8d91a386304d Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Mon, 26 Sep 2022 16:09:10 +0200 Subject: Manager avatar --- pages/settings.vue | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'pages') diff --git a/pages/settings.vue b/pages/settings.vue index 6535dd6..fc08199 100644 --- a/pages/settings.vue +++ b/pages/settings.vue @@ -6,6 +6,27 @@ form.mt-3(v-if="me") .overflow-hidden.shadow(class="sm:rounded-md") .space-y-6.bg-white.px-4.py-5(class="sm:p-6") + div + label.block.text-sm.font-medium.text-gray-700 Avatar + span.text-green-500.text-xs(v-if="avatarChanged") Avatar changed. Reload this page and/or clear your browser cache. + .mt-1.flex.items-center + user-avatar(:data="me") + input(type="file" hidden id="avatar" @change="editAvatar" accept="image/*") + label( + for="avatar" + class="ml-5 cursor-pointer rounded-md border border-gray-300 bg-white py-2 px-3 text-sm font-medium leading-4 text-gray-700 shadow-sm hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2" + ) Change + button( + type="button" + class="ml-5 cursor-pointer rounded-md border border-red-600 flex bg-red-600 py-2 px-3 text-sm font-medium leading-4 text-white shadow-sm hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2" + @click="deleteAvatar" + v-if="me.avatar" + ) + + + + | Delete + div label.block.text-sm.font-medium.text-gray-700(for="name") Name .mt-1 @@ -62,6 +83,7 @@ export default { data() { return { form: {}, + avatarChanged: false, }; }, created() { @@ -73,6 +95,31 @@ export default { }, }, methods: { + editAvatar(event) { + const file = event.target.files[0]; + this.$store + .dispatch("users/editAvatar", { id: this.me.id, file }) + .then((response) => { + if (response.status == 200) { + this.$toast.success(`Avatar has been uploaded`); + this.avatarChanged = true; + } else { + this.$toast.error(`Error uploading '${file.name}'`); + } + }); + }, + deleteAvatar() { + this.$store + .dispatch("users/deleteAvatar", this.me.id) + .then((response) => { + if (response.status == 200) { + this.$toast.success("Avatar has been removed"); + this.avatarChanged = true; + } else { + this.$toast.error("Error removing"); + } + }); + }, save(event) { const f = this.form; -- cgit v1.2.3-18-g5258