Skip to content

Commit

Permalink
Request account toggle should send API request (#763)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewKostka authored Jan 30, 2024
1 parent 4e270cd commit ffcf7ca
Showing 1 changed file with 18 additions and 29 deletions.
47 changes: 18 additions & 29 deletions src/components/Pages/ManageWiki/Cards/Registration.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@
<v-switch
v-model="requestAccount"
label="Accounts must be requested"
hide-details="auto"
@change="toggle"
:loading="inFlight"
:disabled="inFlight"
>
</v-switch>
</v-card-text>
<v-card-actions>
<v-tooltip top>
<template v-slot:activator="{ on, attrs }">
<v-btn v-bind="attrs" v-on="on" @click="doSubmit">Set Options</v-btn>
</template>
<span>It may take up to 10 seconds for changes to be reflected on your wiki</span>
</v-tooltip>
</v-card-actions>
</v-card>
</template>

Expand All @@ -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
}
}
}
}
Expand Down

0 comments on commit ffcf7ca

Please sign in to comment.