Pass userId for fetching user page only when necessary
This commit is contained in:
parent
6b94950e1e
commit
0e88c84463
4 changed files with 32 additions and 31 deletions
|
@ -79,14 +79,14 @@ const users = {
|
|||
}
|
||||
},
|
||||
actions: {
|
||||
async ActivateUsers({ dispatch, getters }, users) {
|
||||
async ActivateUsers({ dispatch, getters }, { users, _userId }) {
|
||||
const updatedUsers = users.map(user => {
|
||||
return { ...user, deactivated: false }
|
||||
})
|
||||
const nicknames = users.map(user => user.nickname)
|
||||
const callApiFn = async() => await activateUsers(nicknames, getters.authHost, getters.token)
|
||||
|
||||
dispatch('ApplyChanges', { updatedUsers, callApiFn, userId: users[0].id })
|
||||
dispatch('ApplyChanges', { updatedUsers, callApiFn, userId: _userId })
|
||||
},
|
||||
async ApplyChanges({ commit, dispatch, state }, { updatedUsers, callApiFn, userId }) {
|
||||
commit('SWAP_USERS', updatedUsers)
|
||||
|
@ -99,26 +99,28 @@ const users = {
|
|||
dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage })
|
||||
}
|
||||
|
||||
dispatch('FetchUserProfile', { userId, godmode: false })
|
||||
if (userId) {
|
||||
dispatch('FetchUserProfile', { userId, godmode: false })
|
||||
}
|
||||
dispatch('SuccessMessage')
|
||||
},
|
||||
async AddRight({ dispatch, getters }, { users, right }) {
|
||||
async AddRight({ dispatch, getters }, { users, right, _userId }) {
|
||||
const updatedUsers = users.map(user => {
|
||||
return user.local ? { ...user, roles: { ...user.roles, [right]: true }} : user
|
||||
})
|
||||
const nicknames = users.map(user => user.nickname)
|
||||
const callApiFn = async() => await addRight(nicknames, right, getters.authHost, getters.token)
|
||||
|
||||
dispatch('ApplyChanges', { updatedUsers, callApiFn, userId: users[0].id })
|
||||
dispatch('ApplyChanges', { updatedUsers, callApiFn, userId: _userId })
|
||||
},
|
||||
async AddTag({ dispatch, getters }, { users, tag }) {
|
||||
async AddTag({ dispatch, getters }, { users, tag, _userId }) {
|
||||
const updatedUsers = users.map(user => {
|
||||
return { ...user, tags: [...user.tags, tag] }
|
||||
})
|
||||
const nicknames = users.map(user => user.nickname)
|
||||
const callApiFn = async() => await tagUser(nicknames, [tag], getters.authHost, getters.token)
|
||||
|
||||
dispatch('ApplyChanges', { updatedUsers, callApiFn, userId: users[0].id })
|
||||
dispatch('ApplyChanges', { updatedUsers, callApiFn, userId: _userId })
|
||||
},
|
||||
async ClearFilters({ commit, dispatch, state }) {
|
||||
commit('CLEAR_USERS_FILTERS')
|
||||
|
@ -134,23 +136,23 @@ const users = {
|
|||
}
|
||||
dispatch('SuccessMessage')
|
||||
},
|
||||
async DeactivateUsers({ dispatch, getters }, users) {
|
||||
async DeactivateUsers({ dispatch, getters }, { users, _userId }) {
|
||||
const updatedUsers = users.map(user => {
|
||||
return { ...user, deactivated: true }
|
||||
})
|
||||
const nicknames = users.map(user => user.nickname)
|
||||
const callApiFn = async() => await deactivateUsers(nicknames, getters.authHost, getters.token)
|
||||
|
||||
dispatch('ApplyChanges', { updatedUsers, callApiFn, userId: users[0].id })
|
||||
dispatch('ApplyChanges', { updatedUsers, callApiFn, userId: _userId })
|
||||
},
|
||||
async ConfirmUsersEmail({ dispatch, getters }, users) {
|
||||
async ConfirmUsersEmail({ dispatch, getters }, { users, _userId }) {
|
||||
const updatedUsers = users.map(user => {
|
||||
return { ...user, confirmation_pending: false }
|
||||
})
|
||||
const nicknames = users.map(user => user.nickname)
|
||||
const callApiFn = async() => await confirmUserEmail(nicknames, getters.authHost, getters.token)
|
||||
|
||||
dispatch('ApplyChanges', { updatedUsers, callApiFn, userId: users[0].id })
|
||||
dispatch('ApplyChanges', { updatedUsers, callApiFn, userId: _userId })
|
||||
},
|
||||
async ResendConfirmationEmail({ dispatch, getters }, users) {
|
||||
const usersNicknames = users.map(user => user.nickname)
|
||||
|
@ -161,16 +163,16 @@ const users = {
|
|||
}
|
||||
dispatch('SuccessMessage')
|
||||
},
|
||||
async DeleteRight({ dispatch, getters }, { users, right }) {
|
||||
async DeleteRight({ dispatch, getters }, { users, right, _userId }) {
|
||||
const updatedUsers = users.map(user => {
|
||||
return user.local ? { ...user, roles: { ...user.roles, [right]: false }} : user
|
||||
})
|
||||
const nicknames = users.map(user => user.nickname)
|
||||
const callApiFn = async() => await deleteRight(nicknames, right, getters.authHost, getters.token)
|
||||
|
||||
dispatch('ApplyChanges', { updatedUsers, callApiFn, userId: users[0].id })
|
||||
dispatch('ApplyChanges', { updatedUsers, callApiFn, userId: _userId })
|
||||
},
|
||||
async DeleteUsers({ commit, dispatch, getters, state }, users) {
|
||||
async DeleteUsers({ commit, dispatch, getters, state }, { users, _userId }) {
|
||||
const usersNicknames = users.map(user => user.nickname)
|
||||
try {
|
||||
await deleteUsers(usersNicknames, getters.authHost, getters.token)
|
||||
|
@ -181,7 +183,7 @@ const users = {
|
|||
const updatedUsers = state.fetchedUsers.filter(user => !deletedUsersIds.includes(user.id))
|
||||
commit('SET_USERS', updatedUsers)
|
||||
|
||||
dispatch('FetchUserProfile', { userId: users[0].id, godmode: false })
|
||||
dispatch('FetchUserProfile', { userId: _userId, godmode: false })
|
||||
dispatch('SuccessMessage')
|
||||
},
|
||||
async FetchUsers({ commit, dispatch, getters, state }, { page }) {
|
||||
|
@ -198,14 +200,14 @@ const users = {
|
|||
RemovePasswordToken({ commit }) {
|
||||
commit('SET_PASSWORD_RESET_TOKEN', { link: '', token: '' })
|
||||
},
|
||||
async RemoveTag({ dispatch, getters }, { users, tag }) {
|
||||
async RemoveTag({ dispatch, getters }, { users, tag, _userId }) {
|
||||
const updatedUsers = users.map(user => {
|
||||
return { ...user, tags: user.tags.filter(userTag => userTag !== tag) }
|
||||
})
|
||||
const nicknames = users.map(user => user.nickname)
|
||||
const callApiFn = async() => await untagUser(nicknames, [tag], getters.authHost, getters.token)
|
||||
|
||||
dispatch('ApplyChanges', { updatedUsers, callApiFn, userId: users[0].id })
|
||||
dispatch('ApplyChanges', { updatedUsers, callApiFn, userId: _userId })
|
||||
},
|
||||
async RequirePasswordReset({ dispatch, getters }, users) {
|
||||
const nicknames = users.map(user => user.nickname)
|
||||
|
|
|
@ -91,7 +91,7 @@ export default {
|
|||
this.$store.dispatch('FetchStatusesPageByInstance')
|
||||
},
|
||||
clearSelection() {
|
||||
// TODO
|
||||
this.selectedUsers = []
|
||||
},
|
||||
handleStatusSelection(user) {
|
||||
if (this.selectedUsers.find(selectedUser => user.id === selectedUser.id) !== undefined) {
|
||||
|
|
|
@ -131,10 +131,10 @@ export default {
|
|||
this.$store.dispatch('ResendConfirmationEmail', [user])
|
||||
},
|
||||
handleDeletion(user) {
|
||||
this.$store.dispatch('DeleteUsers', [user])
|
||||
this.$store.dispatch('DeleteUsers', { users: [user], _userId: user.id })
|
||||
},
|
||||
handleEmailConfirmation(user) {
|
||||
this.$store.dispatch('ConfirmUsersEmail', [user])
|
||||
this.$store.dispatch('ConfirmUsersEmail', { users: [user], _userId: user.id })
|
||||
},
|
||||
requirePasswordReset(user) {
|
||||
const mailerEnabled = this.$store.state.user.nodeInfo.metadata.mailerEnabled
|
||||
|
@ -152,18 +152,18 @@ export default {
|
|||
},
|
||||
toggleActivation(user) {
|
||||
user.deactivated
|
||||
? this.$store.dispatch('ActivateUsers', [user])
|
||||
: this.$store.dispatch('DeactivateUsers', [user])
|
||||
? this.$store.dispatch('ActivateUsers', { users: [user], _userId: user.id })
|
||||
: this.$store.dispatch('DeactivateUsers', { users: [user], _userId: user.id })
|
||||
},
|
||||
toggleTag(user, tag) {
|
||||
user.tags.includes(tag)
|
||||
? this.$store.dispatch('RemoveTag', { users: [user], tag })
|
||||
: this.$store.dispatch('AddTag', { users: [user], tag })
|
||||
? this.$store.dispatch('RemoveTag', { users: [user], tag, _userId: user.id })
|
||||
: this.$store.dispatch('AddTag', { users: [user], tag, _userId: user.id })
|
||||
},
|
||||
toggleUserRight(user, right) {
|
||||
user.roles[right]
|
||||
? this.$store.dispatch('DeleteRight', { users: [user], right })
|
||||
: this.$store.dispatch('AddRight', { users: [user], right })
|
||||
? this.$store.dispatch('DeleteRight', { users: [user], right, _userId: user.id })
|
||||
: this.$store.dispatch('AddRight', { users: [user], right, _userId: user.id })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -180,19 +180,19 @@ export default {
|
|||
},
|
||||
activate: () => {
|
||||
const filtered = this.selectedUsers.filter(user => user.deactivated && this.$store.state.user.id !== user.id)
|
||||
const activateUsersFn = async(users) => await this.$store.dispatch('ActivateUsers', users)
|
||||
const activateUsersFn = async(users) => await this.$store.dispatch('ActivateUsers', { users })
|
||||
|
||||
applyAction(filtered, activateUsersFn)
|
||||
},
|
||||
deactivate: () => {
|
||||
const filtered = this.selectedUsers.filter(user => !user.deactivated && this.$store.state.user.id !== user.id)
|
||||
const deactivateUsersFn = async(users) => await this.$store.dispatch('DeactivateUsers', users)
|
||||
const deactivateUsersFn = async(users) => await this.$store.dispatch('DeactivateUsers', { users })
|
||||
|
||||
applyAction(filtered, deactivateUsersFn)
|
||||
},
|
||||
remove: () => {
|
||||
const filtered = this.selectedUsers.filter(user => this.$store.state.user.id !== user.id)
|
||||
const deleteAccountFn = async(users) => await this.$store.dispatch('DeleteUsers', users)
|
||||
const deleteAccountFn = async(users) => await this.$store.dispatch('DeleteUsers', { users })
|
||||
|
||||
applyAction(filtered, deleteAccountFn)
|
||||
},
|
||||
|
@ -202,7 +202,6 @@ export default {
|
|||
? user.local && !user.tags.includes(tag)
|
||||
: !user.tags.includes(tag))
|
||||
const addTagFn = async(users) => await this.$store.dispatch('AddTag', { users, tag })
|
||||
|
||||
applyAction(filtered, addTagFn)
|
||||
},
|
||||
removeTag: (tag) => async() => {
|
||||
|
@ -222,7 +221,7 @@ export default {
|
|||
},
|
||||
confirmAccounts: () => {
|
||||
const filtered = this.selectedUsers.filter(user => user.local && user.confirmation_pending)
|
||||
const confirmAccountFn = async(users) => await this.$store.dispatch('ConfirmUsersEmail', users)
|
||||
const confirmAccountFn = async(users) => await this.$store.dispatch('ConfirmUsersEmail', { users })
|
||||
|
||||
applyAction(filtered, confirmAccountFn)
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue