Update state structure and ToggleUsersFilter action

This commit is contained in:
Angelina Filippova 2019-03-25 00:59:00 +03:00
parent 093fd94b09
commit 7e3f385b4e

View file

@ -7,7 +7,12 @@ const users = {
searchQuery: '',
totalUsersCount: 0,
currentPage: 1,
showLocalUsersOnly: false
filters: {
showLocalUsersOnly: false,
showExternalUsersOnly: false,
showActiveUsersOnly: false,
showDeactivatedUsersOnly: false
}
},
mutations: {
SET_USERS: (state, users) => {
@ -37,13 +42,13 @@ const users = {
SET_SEARCH_QUERY: (state, query) => {
state.searchQuery = query
},
SET_LOCAL_USERS_FILTER: (state, value) => {
state.showLocalUsersOnly = value
SET_USERS_FILTER: (state, filters) => {
state.filters = filters
}
},
actions: {
async FetchUsers({ commit, state, getters }, { page }) {
const response = await fetchUsers(state.showLocalUsersOnly, getters.authHost, getters.token, page)
const response = await fetchUsers(state.filters.showLocalUsersOnly, getters.authHost, getters.token, page)
commit('SET_LOADING', true)
@ -62,14 +67,21 @@ const users = {
commit('SET_LOADING', true)
commit('SET_SEARCH_QUERY', query)
const response = await searchUsers(query, state.showLocalUsersOnly, getters.authHost, getters.token, page)
const response = await searchUsers(query, state.filters.showLocalUsersOnly, getters.authHost, getters.token, page)
loadUsers(commit, page, response.data)
}
},
async ToggleLocalUsersFilter({ commit, dispatch, state }, value) {
commit('SET_LOCAL_USERS_FILTER', value)
dispatch('SearchUsers', { query: state.searchQuery, page: 1 })
async ToggleUsersFilter({ commit, dispatch, state }, filters) {
const newFilters = Object.keys(state.filters).reduce((acc, filter) => {
if (filters.includes(filter)) {
return { ...acc, [filter]: true }
} else {
return { ...acc, [filter]: false }
}
}, {})
commit('SET_USERS_FILTER', newFilters)
// dispatch('SearchUsers', { query: state.searchQuery, page: 1 })
},
async ToggleRight({ commit, getters }, { user, right }) {
user.roles[right]