From ea58c197c457d09e9a85b7af389b0f9178815768 Mon Sep 17 00:00:00 2001 From: Victor Felder Date: Tue, 23 Apr 2019 16:26:57 +0200 Subject: [PATCH] fix(proposal): show toast error for proposal submit failures --- pages/proposal/class.vue | 42 +++++++++++++++++++------------------ pages/proposal/property.vue | 42 ++++++++++++++++++++----------------- 2 files changed, 45 insertions(+), 39 deletions(-) diff --git a/pages/proposal/class.vue b/pages/proposal/class.vue index d609deb7..85cb394e 100644 --- a/pages/proposal/class.vue +++ b/pages/proposal/class.vue @@ -147,6 +147,7 @@ import discardDraft from '@/apollo/mutations/discardDraft' import ClassForm from '@/components/proposal/ClassForm' import ProgressionBox from '@/components/proposal/ProgressionBox' import Loader from '@/components/layout/Loader' +import { toastClose } from '@/libs/utils' import { SAVE, SUBMIT, NEW, LOAD } from '@/store/action-types' @@ -265,6 +266,15 @@ export default { this.$store.dispatch('drafts/LOAD') this.$router.push({ name: 'proposal-id', params: { id: this.success } }) } + }, + error () { + if (this.error && !this.success) { + this.$vuexSet('class.clss.isDraft', true) + this.autosaveDraft().then(() => { + this.isLoading = false + this.$toast.error(`Error: ${this.error}`, toastClose) + }) + } } }, methods: { @@ -275,27 +285,19 @@ export default { load: LOAD }), async sendProposal () { - try { - // Send splash screen - this.isLoading = true - // remove draft status from the json proposalObject - this.$vuexSet('class.clss.isDraft', false) - // save the changes - await this.autosaveDraft() - this.stopAutosave() + // Send splash screen + this.isLoading = true + // remove draft status from the json proposalObject + this.$vuexSet('class.clss.isDraft', false) + // save the changes + await this.autosaveDraft() + this.stopAutosave() - const token = this.$apolloHelpers.getToken() - // create the PR etc - await this.submit(token) - // submit will commit success or error to the store, - // see this page's `watch`ers - } - catch (err) { - this.$vuexSet('class.clss.isDraft', true) - // save the changes - await this.autosaveDraft() - this.isLoading = false - } + const token = this.$apolloHelpers.getToken() + // create the PR etc + await this.submit(token) + // submit will commit success or error to the store, + // see this page's `watch`ers }, stopAutosave () { clearInterval(this.saveInterval) diff --git a/pages/proposal/property.vue b/pages/proposal/property.vue index 87dc7514..12fb635b 100644 --- a/pages/proposal/property.vue +++ b/pages/proposal/property.vue @@ -147,6 +147,8 @@ import discardDraft from '@/apollo/mutations/discardDraft' import PropertyForm from '@/components/proposal/PropertyForm' import ProgressionBox from '@/components/proposal/ProgressionBox' import Loader from '@/components/layout/Loader' +import { toastClose } from '@/libs/utils' + import { SAVE, SUBMIT, NEW, LOAD } from '@/store/action-types' const { @@ -263,6 +265,15 @@ export default { this.$store.dispatch('drafts/LOAD') this.$router.push({ name: 'proposal-id', params: { id: this.success } }) } + }, + error () { + if (this.error && !this.success) { + this.$vuexSet('prop.prop.isDraft', true) + this.autosaveDraft().then(() => { + this.isLoading = false + this.$toast.error(`Error: ${this.error}`, toastClose) + }) + } } }, methods: { @@ -273,26 +284,19 @@ export default { load: LOAD }), async sendProposal () { - try { - // Send splash screen - this.isLoading = true - // remove draft status from the json proposalObject - this.$vuexSet('prop.prop.isDraft', false) - // save the changes - await this.autosaveDraft() - this.stopAutosave() + // Send splash screen + this.isLoading = true + // remove draft status from the json proposalObject + this.$vuexSet('prop.prop.isDraft', false) + // save the changes + await this.autosaveDraft() + this.stopAutosave() - const token = this.$apolloHelpers.getToken() - // create the PR etc - await this.submit(token) - // submit will commit success or error to the store, - // see this page's `watch`ers - } - catch (err) { - this.$vuexSet('prop.prop.isDraft', true) - await this.autosaveDraft() - this.isLoading = false - } + const token = this.$apolloHelpers.getToken() + // create the PR etc + await this.submit(token) + // submit will commit success or error to the store, + // see this page's `watch`ers }, stopAutosave () { clearInterval(this.saveInterval)