From 679c4433d1daec926b20a2be6a87c43b126db421 Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Fri, 25 Oct 2019 00:00:23 +0200 Subject: [PATCH] Move try/catch and success message from multiple users menu view to action --- src/store/modules/users.js | 29 +++++++++++++------ .../users/components/MultipleUsersMenu.vue | 11 +------ 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/store/modules/users.js b/src/store/modules/users.js index 5513d7ca..5d7fb257 100644 --- a/src/store/modules/users.js +++ b/src/store/modules/users.js @@ -87,6 +87,7 @@ const users = { } finally { dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage }) } + dispatch('SuccessMessage') }, async AddRight({ commit, dispatch, getters, state }, { users, right }) { const updatedUsers = users.map(user => { @@ -102,6 +103,7 @@ const users = { } finally { dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage }) } + dispatch('SuccessMessage') }, async AddTag({ commit, dispatch, getters, state }, { users, tag }) { const updatedUsers = users.map(user => { @@ -117,6 +119,7 @@ const users = { } finally { dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage }) } + dispatch('SuccessMessage') }, async ClearFilters({ commit, dispatch, state }) { commit('CLEAR_USERS_FILTERS') @@ -130,11 +133,7 @@ const users = { } finally { dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage }) } - Message({ - message: i18n.t('users.accountCreated'), - type: 'success', - duration: 5 * 1000 - }) + dispatch('SuccessMessage') }, async DeactivateUsers({ commit, dispatch, getters, state }, users) { const updatedUsers = users.map(user => { @@ -150,6 +149,7 @@ const users = { } finally { dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage }) } + dispatch('SuccessMessage') }, async DeleteRight({ commit, dispatch, getters, state }, { users, right }) { const updatedUsers = users.map(user => { @@ -165,8 +165,9 @@ const users = { } finally { dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage }) } + dispatch('SuccessMessage') }, - async DeleteUsers({ commit, getters, state }, users) { + async DeleteUsers({ commit, dispatch, getters, state }, users) { const usersNicknames = users.map(user => user.nickname) try { await deleteUsers(usersNicknames, getters.authHost, getters.token) @@ -176,9 +177,7 @@ const users = { const deletedUsersIds = users.map(deletedUser => deletedUser.id) const updatedUsers = state.fetchedUsers.filter(user => !deletedUsersIds.includes(user.id)) commit('SET_USERS', updatedUsers) - }, - async RequirePasswordReset({ getters }, user) { - await requirePasswordReset(user.nickname, getters.authHost, getters.token) + dispatch('SuccessMessage') }, async FetchUsers({ commit, dispatch, getters, state }, { page }) { commit('SET_LOADING', true) @@ -208,6 +207,11 @@ const users = { } finally { dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage }) } + dispatch('SuccessMessage') + }, + async RequirePasswordReset({ dispatch, getters }, user) { + await requirePasswordReset(user.nickname, getters.authHost, getters.token) + dispatch('SuccessMessage') }, async SearchUsers({ commit, dispatch, state, getters }, { query, page }) { if (query.length === 0) { @@ -223,6 +227,13 @@ const users = { loadUsers(commit, page, response.data) } }, + SuccessMessage() { + return Message({ + message: i18n.t('users.completed'), + type: 'success', + duration: 5 * 1000 + }) + }, async ToggleUsersFilter({ commit, dispatch, state }, filters) { const defaultFilters = { local: false, diff --git a/src/views/users/components/MultipleUsersMenu.vue b/src/views/users/components/MultipleUsersMenu.vue index 53f778b8..1122f237 100644 --- a/src/views/users/components/MultipleUsersMenu.vue +++ b/src/views/users/components/MultipleUsersMenu.vue @@ -151,16 +151,7 @@ export default { methods: { mappers() { const applyAction = async(users, dispatchAction) => { - try { - await dispatchAction(users) - } catch (err) { - console.log(err) - return - } - this.$message({ - type: 'success', - message: this.$t('users.completed') - }) + await dispatchAction(users) this.$emit('apply-action') } return {