From b8d6bbcf29b5ac0435044d404fb7cf1d5fca0220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Mon, 22 Aug 2022 15:53:48 +0200 Subject: [PATCH] Finalize axios replacement in MyE&P SPA --- .../Private/Assets/js/myep/Address.vue | 6 ++++- .../Private/Assets/js/myep/Login.vue | 22 ++++++++++--------- .../Private/Assets/js/myep/api/index.js | 10 ++++++++- .../Private/Assets/js/myep/store/index.js | 14 +++++------- 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/Address.vue b/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/Address.vue index f210fb0a..f903dc6c 100644 --- a/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/Address.vue +++ b/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/Address.vue @@ -83,6 +83,10 @@ this.picker.setDate(new Date(this.userData.dateOfBirth), true); this.$emit('loaded') }) + .catch(() => { + this.logout() + this.$router.push({name: 'login'}) + }) }, mounted () { Vue.nextTick(() => { @@ -97,7 +101,7 @@ }) }, methods: { - ...mapMutations(['alert']), + ...mapMutations(['logout', 'alert']), ...mapActions(['loadAddress', 'saveAddress']), save () { this.formErrors = {} diff --git a/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/Login.vue b/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/Login.vue index 3f4a00e8..190613bc 100644 --- a/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/Login.vue +++ b/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/Login.vue @@ -66,7 +66,7 @@ }, methods: { ...mapMutations(['alert']), - ...mapActions(['loadCountries']), + ...mapActions(['login', 'resetPassword', 'loadCountries']), toggleMode () { this.mode = this.mode === 'login' ? 'reset' : 'login'; this.password = '' @@ -74,12 +74,12 @@ submit () { this.message = ''; if (this.mode === 'login') { - this.login() + this.performLogin() } else { - this.resetPassword() + this.performPasswordReset() } }, - login () { + performLogin () { this.formErrors = {}; if (!this.email || !this.password) { this.alert({ @@ -88,18 +88,21 @@ }); return } - this.$store.dispatch('login', { + this.login({ email: this.email, password: this.password }).then(() => { this.loadCountries() .then(() => { - this.$router.replace({ name: 'address' }) + this.$router.push({ name: 'address' }) }) }).catch(error => { + }).finally(() => { + this.email = '' + this.password = '' }) }, - resetPassword () { + performPasswordReset () { this.formErrors = {}; if (!this.email) { this.alert({ @@ -108,9 +111,8 @@ }); return; } - this.$store.dispatch('resetPassword', - this.email - ).then(response => { + this.resetPassword(this.email) + .then(response => { this.email = ''; if (response.data.success) { this.alert({ diff --git a/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/api/index.js b/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/api/index.js index 55e53ea1..1771ad2a 100644 --- a/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/api/index.js +++ b/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/api/index.js @@ -15,4 +15,12 @@ function checkStatus(response) { } } -export { checkStatus, defaultOptions } +function handleError() { + commit('alert', { + message: 'Es ist ein Fehler aufgetreten :(', + success: false, + }) + throw error +} + +export { checkStatus, handleError, defaultOptions } diff --git a/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/store/index.js b/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/store/index.js index 0e54dde2..e16204bd 100644 --- a/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/store/index.js +++ b/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/myep/store/index.js @@ -1,6 +1,6 @@ import Vue from 'vue' import Vuex from 'vuex' -import { checkStatus, defaultOptions } from '../api' +import { checkStatus, handleError, defaultOptions } from '../api' const configElement = document.getElementById('appconfig') const config = JSON.parse(configElement.innerHTML) @@ -101,7 +101,7 @@ export default new Vuex.Store({ .then(data => { commit('setCountries', data) }) - .catch(() => {}) + .catch(handleError) .finally(() => { commit('endLoading') }) @@ -166,6 +166,7 @@ export default new Vuex.Store({ .then(checkStatus) .then(response => response.json()) .then(response => response) + .catch(handleError) .finally(() => { commit('endLoading') }) @@ -183,6 +184,7 @@ export default new Vuex.Store({ .then(checkStatus) .then(response => response.json()) .then(data => data) + .catch(handleError) .finally(() => { commit('endLoading') }) @@ -203,12 +205,7 @@ export default new Vuex.Store({ commit('setWatchlist', data.watchlist) } }) - .catch(() => { - commit('alert', { - message: 'Es ist ein Fehler aufgetreten :(', - success: false, - }) - }) + .catch(handleError) .finally(() => { commit('endLoading') }) @@ -231,6 +228,7 @@ export default new Vuex.Store({ success: true, }) }) + .catch(handleError) .finally(() => { commit('endLoading') })