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-23 21:40:26 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
actions: {
|
|
|
|
async FetchUsers({ commit }) {
|
|
|
|
const response = await fetchUsers()
|
|
|
|
|
|
|
|
commit('SET_USERS', response.data)
|
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
|