diff --git a/components/publicwishlist.vue b/components/publicwishlist.vue index 8597a94..2bd5043 100644 --- a/components/publicwishlist.vue +++ b/components/publicwishlist.vue @@ -39,17 +39,17 @@ export default { return wish.owner_id === id; }); }, - claimWish(id) { - let response = this.$swal({ + async claimWish(id) { + let response = await this.$swal({ title: 'Wunsch reservieren?', html: 'Du kannst Wünsche NICHT wieder freigeben!
Bitte sei dir sicher bevor du reservierst!', type: 'warning', showCancelButton: true, cancelButtonText: "Abbrechen", confirmButtonText: 'Reservieren', - }).value; + }); - if(!response) { + if (!response.value) { return; } diff --git a/store/wishes.js b/store/wishes.js index 453d0bb..b7cb406 100644 --- a/store/wishes.js +++ b/store/wishes.js @@ -41,13 +41,23 @@ export const actions = { deleteWish({ commit, state }, wishid) { return this.$axios.$delete(BASE_API_URL + '/wishes/' + wishid, getAxiosConfig(localStorage.getItem("token"))).then(() => { commit('setPersonal', state.personal.filter(w => w.id !== wishid)) + }).catch((err) => { + this._vm.$swal({ + text: err.response.data.toString(), + type: 'error', + showConfirmButton: false, + timerProgressBar: true, + timer: 3000, + toast: true, + position: 'bottom-center', + iconColor: 'white' + }) }) }, claimWish({ commit, state }, wishid) { return this.$axios.$post(BASE_API_URL + '/wishes/' + wishid + '/claim', {}, getAxiosConfig(localStorage.getItem("token"))).then(async () => { commit('setPublic', state.public.filter(w => w.id !== wishid)) - await this.dispatch('wishes/fetchPublic') - await this.dispatch('wishes/fetchClaimed') + await this.dispatch('fetchClaimed', state) }) }, }