Pass userId for fetching user page only when necessary

This commit is contained in:
Angelina Filippova 2020-02-04 22:47:49 +03:00
parent 6b94950e1e
commit 0e88c84463
4 changed files with 32 additions and 31 deletions

View file

@ -79,14 +79,14 @@ const users = {
} }
}, },
actions: { actions: {
async ActivateUsers({ dispatch, getters }, users) { async ActivateUsers({ dispatch, getters }, { users, _userId }) {
const updatedUsers = users.map(user => { const updatedUsers = users.map(user => {
return { ...user, deactivated: false } return { ...user, deactivated: false }
}) })
const nicknames = users.map(user => user.nickname) const nicknames = users.map(user => user.nickname)
const callApiFn = async() => await activateUsers(nicknames, getters.authHost, getters.token) 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 }) { async ApplyChanges({ commit, dispatch, state }, { updatedUsers, callApiFn, userId }) {
commit('SWAP_USERS', updatedUsers) commit('SWAP_USERS', updatedUsers)
@ -99,26 +99,28 @@ const users = {
dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage }) dispatch('SearchUsers', { query: state.searchQuery, page: state.currentPage })
} }
if (userId) {
dispatch('FetchUserProfile', { userId, godmode: false }) dispatch('FetchUserProfile', { userId, godmode: false })
}
dispatch('SuccessMessage') dispatch('SuccessMessage')
}, },
async AddRight({ dispatch, getters }, { users, right }) { async AddRight({ dispatch, getters }, { users, right, _userId }) {
const updatedUsers = users.map(user => { const updatedUsers = users.map(user => {
return user.local ? { ...user, roles: { ...user.roles, [right]: true }} : user return user.local ? { ...user, roles: { ...user.roles, [right]: true }} : user
}) })
const nicknames = users.map(user => user.nickname) const nicknames = users.map(user => user.nickname)
const callApiFn = async() => await addRight(nicknames, right, getters.authHost, getters.token) 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 => { const updatedUsers = users.map(user => {
return { ...user, tags: [...user.tags, tag] } return { ...user, tags: [...user.tags, tag] }
}) })
const nicknames = users.map(user => user.nickname) const nicknames = users.map(user => user.nickname)
const callApiFn = async() => await tagUser(nicknames, [tag], getters.authHost, getters.token) 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 }) { async ClearFilters({ commit, dispatch, state }) {
commit('CLEAR_USERS_FILTERS') commit('CLEAR_USERS_FILTERS')
@ -134,23 +136,23 @@ const users = {
} }
dispatch('SuccessMessage') dispatch('SuccessMessage')
}, },
async DeactivateUsers({ dispatch, getters }, users) { async DeactivateUsers({ dispatch, getters }, { users, _userId }) {
const updatedUsers = users.map(user => { const updatedUsers = users.map(user => {
return { ...user, deactivated: true } return { ...user, deactivated: true }
}) })
const nicknames = users.map(user => user.nickname) const nicknames = users.map(user => user.nickname)
const callApiFn = async() => await deactivateUsers(nicknames, getters.authHost, getters.token) 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 => { const updatedUsers = users.map(user => {
return { ...user, confirmation_pending: false } return { ...user, confirmation_pending: false }
}) })
const nicknames = users.map(user => user.nickname) const nicknames = users.map(user => user.nickname)
const callApiFn = async() => await confirmUserEmail(nicknames, getters.authHost, getters.token) 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) { async ResendConfirmationEmail({ dispatch, getters }, users) {
const usersNicknames = users.map(user => user.nickname) const usersNicknames = users.map(user => user.nickname)
@ -161,16 +163,16 @@ const users = {
} }
dispatch('SuccessMessage') dispatch('SuccessMessage')
}, },
async DeleteRight({ dispatch, getters }, { users, right }) { async DeleteRight({ dispatch, getters }, { users, right, _userId }) {
const updatedUsers = users.map(user => { const updatedUsers = users.map(user => {
return user.local ? { ...user, roles: { ...user.roles, [right]: false }} : user return user.local ? { ...user, roles: { ...user.roles, [right]: false }} : user
}) })
const nicknames = users.map(user => user.nickname) const nicknames = users.map(user => user.nickname)
const callApiFn = async() => await deleteRight(nicknames, right, getters.authHost, getters.token) 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) const usersNicknames = users.map(user => user.nickname)
try { try {
await deleteUsers(usersNicknames, getters.authHost, getters.token) await deleteUsers(usersNicknames, getters.authHost, getters.token)
@ -181,7 +183,7 @@ const users = {
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('FetchUserProfile', { userId: users[0].id, godmode: false }) dispatch('FetchUserProfile', { userId: _userId, godmode: false })
dispatch('SuccessMessage') dispatch('SuccessMessage')
}, },
async FetchUsers({ commit, dispatch, getters, state }, { page }) { async FetchUsers({ commit, dispatch, getters, state }, { page }) {
@ -198,14 +200,14 @@ const users = {
RemovePasswordToken({ commit }) { RemovePasswordToken({ commit }) {
commit('SET_PASSWORD_RESET_TOKEN', { link: '', token: '' }) 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 => { const updatedUsers = users.map(user => {
return { ...user, tags: user.tags.filter(userTag => userTag !== tag) } return { ...user, tags: user.tags.filter(userTag => userTag !== tag) }
}) })
const nicknames = users.map(user => user.nickname) const nicknames = users.map(user => user.nickname)
const callApiFn = async() => await untagUser(nicknames, [tag], getters.authHost, getters.token) 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) { async RequirePasswordReset({ dispatch, getters }, users) {
const nicknames = users.map(user => user.nickname) const nicknames = users.map(user => user.nickname)

View file

@ -91,7 +91,7 @@ export default {
this.$store.dispatch('FetchStatusesPageByInstance') this.$store.dispatch('FetchStatusesPageByInstance')
}, },
clearSelection() { clearSelection() {
// TODO this.selectedUsers = []
}, },
handleStatusSelection(user) { handleStatusSelection(user) {
if (this.selectedUsers.find(selectedUser => user.id === selectedUser.id) !== undefined) { if (this.selectedUsers.find(selectedUser => user.id === selectedUser.id) !== undefined) {

View file

@ -131,10 +131,10 @@ export default {
this.$store.dispatch('ResendConfirmationEmail', [user]) this.$store.dispatch('ResendConfirmationEmail', [user])
}, },
handleDeletion(user) { handleDeletion(user) {
this.$store.dispatch('DeleteUsers', [user]) this.$store.dispatch('DeleteUsers', { users: [user], _userId: user.id })
}, },
handleEmailConfirmation(user) { handleEmailConfirmation(user) {
this.$store.dispatch('ConfirmUsersEmail', [user]) this.$store.dispatch('ConfirmUsersEmail', { users: [user], _userId: user.id })
}, },
requirePasswordReset(user) { requirePasswordReset(user) {
const mailerEnabled = this.$store.state.user.nodeInfo.metadata.mailerEnabled const mailerEnabled = this.$store.state.user.nodeInfo.metadata.mailerEnabled
@ -152,18 +152,18 @@ export default {
}, },
toggleActivation(user) { toggleActivation(user) {
user.deactivated user.deactivated
? this.$store.dispatch('ActivateUsers', [user]) ? this.$store.dispatch('ActivateUsers', { users: [user], _userId: user.id })
: this.$store.dispatch('DeactivateUsers', [user]) : this.$store.dispatch('DeactivateUsers', { users: [user], _userId: user.id })
}, },
toggleTag(user, tag) { toggleTag(user, tag) {
user.tags.includes(tag) user.tags.includes(tag)
? this.$store.dispatch('RemoveTag', { users: [user], tag }) ? this.$store.dispatch('RemoveTag', { users: [user], tag, _userId: user.id })
: this.$store.dispatch('AddTag', { users: [user], tag }) : this.$store.dispatch('AddTag', { users: [user], tag, _userId: user.id })
}, },
toggleUserRight(user, right) { toggleUserRight(user, right) {
user.roles[right] user.roles[right]
? this.$store.dispatch('DeleteRight', { users: [user], right }) ? this.$store.dispatch('DeleteRight', { users: [user], right, _userId: user.id })
: this.$store.dispatch('AddRight', { users: [user], right }) : this.$store.dispatch('AddRight', { users: [user], right, _userId: user.id })
} }
} }
} }

View file

@ -180,19 +180,19 @@ export default {
}, },
activate: () => { activate: () => {
const filtered = this.selectedUsers.filter(user => user.deactivated && this.$store.state.user.id !== user.id) 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) applyAction(filtered, activateUsersFn)
}, },
deactivate: () => { deactivate: () => {
const filtered = this.selectedUsers.filter(user => !user.deactivated && this.$store.state.user.id !== user.id) 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) applyAction(filtered, deactivateUsersFn)
}, },
remove: () => { remove: () => {
const filtered = this.selectedUsers.filter(user => this.$store.state.user.id !== user.id) 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) applyAction(filtered, deleteAccountFn)
}, },
@ -202,7 +202,6 @@ export default {
? user.local && !user.tags.includes(tag) ? user.local && !user.tags.includes(tag)
: !user.tags.includes(tag)) : !user.tags.includes(tag))
const addTagFn = async(users) => await this.$store.dispatch('AddTag', { users, tag }) const addTagFn = async(users) => await this.$store.dispatch('AddTag', { users, tag })
applyAction(filtered, addTagFn) applyAction(filtered, addTagFn)
}, },
removeTag: (tag) => async() => { removeTag: (tag) => async() => {
@ -222,7 +221,7 @@ export default {
}, },
confirmAccounts: () => { confirmAccounts: () => {
const filtered = this.selectedUsers.filter(user => user.local && user.confirmation_pending) 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) applyAction(filtered, confirmAccountFn)
}, },