From be627d1726b84e35a2df628a5aea2cd1eb98d69c Mon Sep 17 00:00:00 2001 From: Andrea Vos Date: Sat, 24 Oct 2020 22:32:12 +0200 Subject: [PATCH] #50 pronouns cards - delete --- assets/style.scss | 2 +- components/Account.vue | 5 +- components/Confirm.vue | 94 ++++++++++++++++++++++++++++++++++ components/ProfileOverview.vue | 22 ++++++-- layouts/default.vue | 15 ++++++ locale/pl/translations.suml | 6 +++ server/profile.js | 15 ++++-- 7 files changed, 151 insertions(+), 8 deletions(-) create mode 100644 components/Confirm.vue diff --git a/assets/style.scss b/assets/style.scss index 2da0d651b..70f4be77d 100644 --- a/assets/style.scss +++ b/assets/style.scss @@ -42,7 +42,7 @@ $container-max-widths: ( @import "~bootstrap/scss/list-group"; //@import "~bootstrap/scss/close"; //@import "~bootstrap/scss/toasts"; -//@import "~bootstrap/scss/modal"; +@import "~bootstrap/scss/modal"; //@import "~bootstrap/scss/tooltip"; //@import "~bootstrap/scss/popover"; //@import "~bootstrap/scss/carousel"; diff --git a/components/Account.vue b/components/Account.vue index adb163e57..fc97ac2d7 100644 --- a/components/Account.vue +++ b/components/Account.vue @@ -44,7 +44,7 @@

profile.list:

@@ -96,6 +96,9 @@ this.$store.commit('setToken', null); this.$cookies.removeAll(); }, + setProfiles(profiles) { + this.profiles = profiles; + }, }, } diff --git a/components/Confirm.vue b/components/Confirm.vue new file mode 100644 index 000000000..870b8cd52 --- /dev/null +++ b/components/Confirm.vue @@ -0,0 +1,94 @@ + + + + + diff --git a/components/ProfileOverview.vue b/components/ProfileOverview.vue index ffa9c262d..f10c3376b 100644 --- a/components/ProfileOverview.vue +++ b/components/ProfileOverview.vue @@ -10,9 +10,10 @@ profile.edit - + + - + @@ -28,6 +29,21 @@ props: { profile: { required: true }, locale: { required: true }, - } + }, + data() { + return { + deleting: false, + } + }, + methods: { + async removeProfile() { + await this.$confirm(this.$t('profile.deleteConfirm'), 'danger'); + + this.deleting = true; + const response = await this.$axios.$post(`/profile/delete/${this.config.locale}`, {}, { headers: this.$auth() }); + this.deleting = false; + this.$emit('update', response); + }, + }, } diff --git a/layouts/default.vue b/layouts/default.vue index ff0272aa6..fa5281122 100644 --- a/layouts/default.vue +++ b/layouts/default.vue @@ -8,9 +8,24 @@
+ + + diff --git a/locale/pl/translations.suml b/locale/pl/translations.suml index 276f772be..ad11116cf 100644 --- a/locale/pl/translations.suml +++ b/locale/pl/translations.suml @@ -698,6 +698,7 @@ profile: show: 'Pokaż' edit: 'Edytuj' delete: 'Usuń' + deleteConfirm: 'Czy na pewno chcesz usunąć tę wizytówkę?' editor: header: 'Edytor wizytówki' save: 'Zapisz wizytówkę' @@ -725,3 +726,8 @@ footer: notFound: message: 'Strony nie znaleziono' back: 'Wróć na główną' + +confirm: + header: 'Czy jesteś pewnx?' + yes: 'Tak, na pewno' + no: 'Nie, anuluj' diff --git a/server/profile.js b/server/profile.js index 9b0e8c4d7..c0a21c750 100644 --- a/server/profile.js +++ b/server/profile.js @@ -38,7 +38,7 @@ const buildProfile = profile => { }; }; -const fetchProfile = async (db, res, username, self) => { +const fetchProfiles = async (db, res, username, self) => { const profiles = await db.all(SQL` SELECT profiles.*, users.username, users.email FROM profiles LEFT JOIN users on users.id == profiles.userId WHERE users.username = ${username} @@ -65,7 +65,7 @@ export default async function (req, res, next) { if (req.method === 'GET' && req.url.startsWith('/get/')) { const username = req.url.substring(5); - return await fetchProfile(db, res, username, user && user.authenticated && user.username === username) + return await fetchProfiles(db, res, username, user && user.authenticated && user.username === username) } if (!user || !user.authenticated) { @@ -83,7 +83,16 @@ export default async function (req, res, next) { ${JSON.stringify(req.body.words)}, 1 )`); - return fetchProfile(db, res, user.username, true); + return fetchProfiles(db, res, user.username, true); + } + + if (req.method === 'POST' && req.url.startsWith('/delete/')) { + const locale = req.url.substring(8); + const userId = (await db.get(SQL`SELECT id FROM users WHERE username = ${user.username}`)).id; + + await db.get(SQL`DELETE FROM profiles WHERE userId = ${userId} AND locale = ${locale}`); + + return fetchProfiles(db, res, user.username, true); } return renderJson(res, { error: 'notfound' }, 404);