From f0e8dde10210f19c0059c57fd55faef29ac43a6a Mon Sep 17 00:00:00 2001 From: Jonas Rittershofer Date: Sun, 10 May 2020 14:13:44 +0200 Subject: [PATCH] Redirect on deleting form Signed-off-by: Jonas Rittershofer --- src/Forms.vue | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Forms.vue b/src/Forms.vue index ed085e2..636c732 100644 --- a/src/Forms.vue +++ b/src/Forms.vue @@ -32,7 +32,7 @@ - + {{ t('forms', 'Loading forms …') }} @@ -102,16 +102,16 @@ export default { return this.forms && this.forms.length === 0 }, - hash() { + routeHash() { return this.$route.params.hash }, selectedForm: { get() { - return this.forms.find(form => form.hash === this.hash) + return this.forms.find(form => form.hash === this.routeHash) }, set(form) { - const index = this.forms.findIndex(search => search.hash === this.hash) + const index = this.forms.findIndex(search => search.hash === this.routeHash) if (index > -1) { this.$set(this.forms, index, form) } @@ -163,7 +163,14 @@ export default { */ async onDeleteForm(id) { const formIndex = this.forms.findIndex(form => form.id === id) + const deletedHash = this.forms[formIndex].hash + this.forms.splice(formIndex, 1) + + // Redirect if current form has been deleted + if (deletedHash === this.routeHash) { + this.$router.push({ name: 'root' }) + } }, }, }