Move try/catch and success message from multiple users menu view to action
This commit is contained in:
parent
453cde8435
commit
679c4433d1
2 changed files with 21 additions and 19 deletions
|
@ -87,6 +87,7 @@ const users = {
|
||||||
} finally {
|
} finally {
|
||||||
dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage })
|
dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage })
|
||||||
}
|
}
|
||||||
|
dispatch('SuccessMessage')
|
||||||
},
|
},
|
||||||
async AddRight({ commit, dispatch, getters, state }, { users, right }) {
|
async AddRight({ commit, dispatch, getters, state }, { users, right }) {
|
||||||
const updatedUsers = users.map(user => {
|
const updatedUsers = users.map(user => {
|
||||||
|
@ -102,6 +103,7 @@ const users = {
|
||||||
} finally {
|
} finally {
|
||||||
dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage })
|
dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage })
|
||||||
}
|
}
|
||||||
|
dispatch('SuccessMessage')
|
||||||
},
|
},
|
||||||
async AddTag({ commit, dispatch, getters, state }, { users, tag }) {
|
async AddTag({ commit, dispatch, getters, state }, { users, tag }) {
|
||||||
const updatedUsers = users.map(user => {
|
const updatedUsers = users.map(user => {
|
||||||
|
@ -117,6 +119,7 @@ const users = {
|
||||||
} finally {
|
} finally {
|
||||||
dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage })
|
dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage })
|
||||||
}
|
}
|
||||||
|
dispatch('SuccessMessage')
|
||||||
},
|
},
|
||||||
async ClearFilters({ commit, dispatch, state }) {
|
async ClearFilters({ commit, dispatch, state }) {
|
||||||
commit('CLEAR_USERS_FILTERS')
|
commit('CLEAR_USERS_FILTERS')
|
||||||
|
@ -130,11 +133,7 @@ const users = {
|
||||||
} finally {
|
} finally {
|
||||||
dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage })
|
dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage })
|
||||||
}
|
}
|
||||||
Message({
|
dispatch('SuccessMessage')
|
||||||
message: i18n.t('users.accountCreated'),
|
|
||||||
type: 'success',
|
|
||||||
duration: 5 * 1000
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
async DeactivateUsers({ commit, dispatch, getters, state }, users) {
|
async DeactivateUsers({ commit, dispatch, getters, state }, users) {
|
||||||
const updatedUsers = users.map(user => {
|
const updatedUsers = users.map(user => {
|
||||||
|
@ -150,6 +149,7 @@ const users = {
|
||||||
} finally {
|
} finally {
|
||||||
dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage })
|
dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage })
|
||||||
}
|
}
|
||||||
|
dispatch('SuccessMessage')
|
||||||
},
|
},
|
||||||
async DeleteRight({ commit, dispatch, getters, state }, { users, right }) {
|
async DeleteRight({ commit, dispatch, getters, state }, { users, right }) {
|
||||||
const updatedUsers = users.map(user => {
|
const updatedUsers = users.map(user => {
|
||||||
|
@ -165,8 +165,9 @@ const users = {
|
||||||
} finally {
|
} finally {
|
||||||
dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage })
|
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)
|
const usersNicknames = users.map(user => user.nickname)
|
||||||
try {
|
try {
|
||||||
await deleteUsers(usersNicknames, getters.authHost, getters.token)
|
await deleteUsers(usersNicknames, getters.authHost, getters.token)
|
||||||
|
@ -176,9 +177,7 @@ const users = {
|
||||||
const deletedUsersIds = users.map(deletedUser => deletedUser.id)
|
const deletedUsersIds = users.map(deletedUser => deletedUser.id)
|
||||||
const updatedUsers = state.fetchedUsers.filter(user => !deletedUsersIds.includes(user.id))
|
const updatedUsers = state.fetchedUsers.filter(user => !deletedUsersIds.includes(user.id))
|
||||||
commit('SET_USERS', updatedUsers)
|
commit('SET_USERS', updatedUsers)
|
||||||
},
|
dispatch('SuccessMessage')
|
||||||
async RequirePasswordReset({ getters }, user) {
|
|
||||||
await requirePasswordReset(user.nickname, getters.authHost, getters.token)
|
|
||||||
},
|
},
|
||||||
async FetchUsers({ commit, dispatch, getters, state }, { page }) {
|
async FetchUsers({ commit, dispatch, getters, state }, { page }) {
|
||||||
commit('SET_LOADING', true)
|
commit('SET_LOADING', true)
|
||||||
|
@ -208,6 +207,11 @@ const users = {
|
||||||
} finally {
|
} finally {
|
||||||
dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage })
|
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 }) {
|
async SearchUsers({ commit, dispatch, state, getters }, { query, page }) {
|
||||||
if (query.length === 0) {
|
if (query.length === 0) {
|
||||||
|
@ -223,6 +227,13 @@ const users = {
|
||||||
loadUsers(commit, page, response.data)
|
loadUsers(commit, page, response.data)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
SuccessMessage() {
|
||||||
|
return Message({
|
||||||
|
message: i18n.t('users.completed'),
|
||||||
|
type: 'success',
|
||||||
|
duration: 5 * 1000
|
||||||
|
})
|
||||||
|
},
|
||||||
async ToggleUsersFilter({ commit, dispatch, state }, filters) {
|
async ToggleUsersFilter({ commit, dispatch, state }, filters) {
|
||||||
const defaultFilters = {
|
const defaultFilters = {
|
||||||
local: false,
|
local: false,
|
||||||
|
|
|
@ -151,16 +151,7 @@ export default {
|
||||||
methods: {
|
methods: {
|
||||||
mappers() {
|
mappers() {
|
||||||
const applyAction = async(users, dispatchAction) => {
|
const applyAction = async(users, dispatchAction) => {
|
||||||
try {
|
await dispatchAction(users)
|
||||||
await dispatchAction(users)
|
|
||||||
} catch (err) {
|
|
||||||
console.log(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
this.$message({
|
|
||||||
type: 'success',
|
|
||||||
message: this.$t('users.completed')
|
|
||||||
})
|
|
||||||
this.$emit('apply-action')
|
this.$emit('apply-action')
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in a new issue