2019-02-26 19:50:25 +00:00
|
|
|
import { fetchUsers, toggleUserActivation } from '@/api/users'
|
2019-02-23 21:40:26 +00:00
|
|
|
|
|
|
|
const user = {
|
|
|
|
state: {
|
2019-02-24 22:31:05 +00:00
|
|
|
fetchedUsers: [],
|
|
|
|
loading: true
|
2019-02-23 21:40:26 +00:00
|
|
|
},
|
|
|
|
mutations: {
|
|
|
|
SET_USERS: (state, users) => {
|
2019-02-26 19:50:25 +00:00
|
|
|
state.fetchedUsers = users.sort((a, b) => a.id.localeCompare(b.id))
|
2019-02-24 22:31:05 +00:00
|
|
|
},
|
|
|
|
SET_LOADING: (state, status) => {
|
|
|
|
state.loading = status
|
2019-02-26 19:50:25 +00:00
|
|
|
},
|
|
|
|
SWAP_USER: (state, user) => {
|
|
|
|
const usersWithoutSwapped = state.fetchedUsers.filter((u) => {
|
|
|
|
return u.id !== user.id
|
|
|
|
})
|
|
|
|
|
|
|
|
state.fetchedUsers = [...usersWithoutSwapped, user].sort((a, b) => a.id.localeCompare(b.id))
|
2019-02-27 22:13:20 +00:00
|
|
|
},
|
|
|
|
SET_COUNT: (state, count) => {
|
|
|
|
state.totalUsersCount = count
|
|
|
|
},
|
|
|
|
SET_PAGE_SIZE: (state, pageSize) => {
|
|
|
|
state.pageSize = pageSize
|
2019-02-23 21:40:26 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
actions: {
|
2019-02-27 22:13:20 +00:00
|
|
|
async FetchUsers({ commit }, page = 1) {
|
|
|
|
const response = await fetchUsers(page)
|
2019-02-23 21:40:26 +00:00
|
|
|
|
2019-02-27 22:13:20 +00:00
|
|
|
commit('SET_USERS', response.data.users)
|
|
|
|
commit('SET_COUNT', response.data.count)
|
|
|
|
commit('SET_PAGE_SIZE', response.data.page_size)
|
2019-02-24 22:31:05 +00:00
|
|
|
commit('SET_LOADING', false)
|
2019-02-26 19:50:25 +00:00
|
|
|
},
|
|
|
|
async ToggleUserActivation({ commit }, nickname) {
|
|
|
|
const response = await toggleUserActivation(nickname)
|
|
|
|
|
|
|
|
commit('SWAP_USER', response.data)
|
2019-02-23 21:40:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default user
|