Skip to content

Commit

Permalink
fix: fix saving behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
dati18 committed Jan 11, 2024
1 parent cde17ae commit fb1de61
Showing 1 changed file with 33 additions and 27 deletions.
60 changes: 33 additions & 27 deletions src/components/Pages/ManageWiki/Cards/QuestyCaptcha.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
</template>

<script>
export default {
name: 'QuestyCaptcha',
props: [
Expand Down Expand Up @@ -143,37 +144,42 @@ export default {
saveForm () {
for (let i = 0; i < this.questionsFromStore.length; i++) {
const entry = this.questionsFromStore[i]
if (!entry.question.trim() && !entry.answers && this.questionsFromStore.length > 1) {
const noQuestion = entry.question.trim() === ''
const noAnswer = entry.answers && entry.answers.length === 0
if (noQuestion && noAnswer && this.questionsFromStore.length > 1) {
this.questionsFromStore.splice(i, 1)
}
}
if (!this.$refs.questyForm.validate()) {
return
}
const wiki = this.wikiId
const promises = []
const captchaEnabledSetting = 'wwUseQuestyCaptcha'
const captchaQuestionsSetting = 'wwCaptchaQuestions'
const enableValue = this.captchaActivate
const questions = {}
this.questionsFromStore.forEach(item => {
questions[item.question] = item.answers
})
const JSONQuestions = JSON.stringify(questions)
promises.push(
this.$store.dispatch('updateSetting', { wiki, setting: captchaEnabledSetting, value: enableValue }),
this.$store.dispatch('updateSetting', { wiki, setting: captchaQuestionsSetting, value: JSONQuestions })
)
Promise.all(promises)
.then(() => {
this.$store.dispatch('setEnabledQuestyCaptcha', enableValue)
this.$store.dispatch('setQuestyCaptchaQuestions', this.questionsFromStore)
this.successMessage = true
})
.catch(err => {
console.log(err.response)
this.errorMessage = true
this.$nextTick(() => {
if (!this.$refs.questyForm.validate()) {
console.log('validation failss')
return
}
const wiki = this.wikiId
const promises = []
const captchaEnabledSetting = 'wwUseQuestyCaptcha'
const captchaQuestionsSetting = 'wwCaptchaQuestions'
const enableValue = this.captchaActivate
const questions = {}
this.questionsFromStore.forEach(item => {
questions[item.question] = item.answers
})
const JSONQuestions = JSON.stringify(questions)
promises.push(
this.$store.dispatch('updateSetting', { wiki, setting: captchaEnabledSetting, value: enableValue }),
this.$store.dispatch('updateSetting', { wiki, setting: captchaQuestionsSetting, value: JSONQuestions })
)
Promise.all(promises)
.then(() => {
this.$store.dispatch('setEnabledQuestyCaptcha', enableValue)
this.$store.dispatch('setQuestyCaptchaQuestions', this.questionsFromStore)
this.successMessage = true
})
.catch(err => {
console.log(err.response)
this.errorMessage = true
})
})
},
recoverDefaultQuestions () {
const recoveredDefaultQuestions = this.$store.state.wikis.currentWikiSettings.defaultQuestions
Expand Down

0 comments on commit fb1de61

Please sign in to comment.