From ffcf7cac34d981ccc1b1b65d732c0b17c8035ab7 Mon Sep 17 00:00:00 2001 From: Andrew Kostka Date: Tue, 30 Jan 2024 09:35:44 +0100 Subject: [PATCH] Request account toggle should send API request (#763) --- .../Pages/ManageWiki/Cards/Registration.vue | 47 +++++++------------ 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/src/components/Pages/ManageWiki/Cards/Registration.vue b/src/components/Pages/ManageWiki/Cards/Registration.vue index 0a496f19..48a316e1 100644 --- a/src/components/Pages/ManageWiki/Cards/Registration.vue +++ b/src/components/Pages/ManageWiki/Cards/Registration.vue @@ -7,17 +7,13 @@ - - - - It may take up to 10 seconds for changes to be reflected on your wiki - - @@ -30,33 +26,26 @@ export default { data () { return { requestAccount: false, - inFlight: false, - error: '' + inFlight: false } }, created () { this.requestAccount = this.$store.state.wikis.currentWikiSettings.wwExtEnableConfirmAccount }, methods: { - doSubmit () { - const wiki = this.wikiId - const promises = [] - - const setting = 'wwExtEnableConfirmAccount' - const value = this.requestAccount - promises.push( - this.$store.dispatch('updateSetting', { wiki, setting, value }) - ) - - Promise.all(promises) - .then(() => { - this.$store.dispatch('setEnableConfirmAccount', value) - alert('Update success!') - }) - .catch(err => { - console.log(err.response) - alert('Something went wrong.') - }) + async toggle (enabled) { + try { + this.inFlight = true + await this.$store.dispatch('updateSetting', { wiki: this.wikiId, setting: 'wwExtEnableConfirmAccount', value: enabled }) + await this.$store.dispatch('setEnableConfirmAccount', enabled) + } catch (error) { + console.log(error.response) + alert('Something went wrong.') + await this.$nextTick() + this.requestAccount = !enabled + } finally { + this.inFlight = false + } } } }