From fc12930471bdddec142a81428b4719bac06cc807 Mon Sep 17 00:00:00 2001 From: Burak Civan Date: Fri, 21 May 2021 14:34:05 +0300 Subject: [PATCH] 'Delete function code refactor' --- resources/assets/js/mixins/spa-global.js | 12 ++++++++++++ resources/assets/js/views/wizard/Currencies.vue | 12 +----------- resources/assets/js/views/wizard/Taxes.vue | 11 +---------- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/resources/assets/js/mixins/spa-global.js b/resources/assets/js/mixins/spa-global.js index 5656be8bc..64d710cba 100644 --- a/resources/assets/js/mixins/spa-global.js +++ b/resources/assets/js/mixins/spa-global.js @@ -155,6 +155,18 @@ export default { this.onFailError(error) }, this); }, + onDeleteEvent(event, form_list, event_id) { + form_list.forEach(function (item, index) { + if (item.id == event_id) { + form_list.splice(index, 1); + return; + } + }, this); + + this.component = ""; + + this.onSuccessDelete(event); + }, onFailError(error) { this.error_field_name = error.response.data.errors; } diff --git a/resources/assets/js/views/wizard/Currencies.vue b/resources/assets/js/views/wizard/Currencies.vue index 11688b2da..906fc427a 100644 --- a/resources/assets/js/views/wizard/Currencies.vue +++ b/resources/assets/js/views/wizard/Currencies.vue @@ -371,7 +371,6 @@ export default { }, }) .then((response) => { - debugger; data.rate = response.data.rate; data.precision = response.data.precision; data.symbol = response.data.symbol; @@ -402,16 +401,7 @@ export default { }, deleteCurrency(event) { - this.currencies.forEach(function (currency, index) { - if (currency.id == event.currency_id) { - this.currencies.splice(index, 1); - return; - } - }, this); - - this.component = ""; - - this.onSuccessDelete(event); + this.onDeleteEvent(event, this.currencies, event.currency_id); }, }, }; diff --git a/resources/assets/js/views/wizard/Taxes.vue b/resources/assets/js/views/wizard/Taxes.vue index 4c9a9ee88..e2dfa48c8 100644 --- a/resources/assets/js/views/wizard/Taxes.vue +++ b/resources/assets/js/views/wizard/Taxes.vue @@ -285,16 +285,7 @@ export default { this.onSubmitEvent("POST", url + "/wizard/taxes", "type", this.taxes); }, deleteCurrency(event) { - this.taxes.forEach(function (tax, index) { - if (tax.id == event.tax_id) { - this.taxes.splice(index, 1); - return; - } - }, this); - - this.component = ""; - - this.onSuccessDelete(event); + this.onDeleteEvent(event, this.taxes, event.tax_id); }, }, };