From 5143fb615e764ecdee44040b9fdb0407d3a1e804 Mon Sep 17 00:00:00 2001 From: Aleksandr Lushkin Date: Mon, 19 Aug 2024 11:06:15 +0200 Subject: [PATCH] Client: Fix getting accounts that don't belong current group when remove some user in this group --- .../dialogs/DeleteProfileEverDialog/index.js | 24 ++++++++++++++----- packages/client/src/store/GroupsStore.ts | 15 +++++++++++- packages/client/src/store/UsersStore.js | 9 +++++-- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/packages/client/src/components/dialogs/DeleteProfileEverDialog/index.js b/packages/client/src/components/dialogs/DeleteProfileEverDialog/index.js index 0c597931c3..a3b844ef1f 100644 --- a/packages/client/src/components/dialogs/DeleteProfileEverDialog/index.js +++ b/packages/client/src/components/dialogs/DeleteProfileEverDialog/index.js @@ -26,16 +26,18 @@ import React from "react"; import PropTypes from "prop-types"; +import { matchPath } from "react-router"; +import { withTranslation } from "react-i18next"; + import { Button } from "@docspace/shared/components/button"; import { toastr } from "@docspace/shared/components/toast"; import { ModalDialog } from "@docspace/shared/components/modal-dialog"; -import { withTranslation } from "react-i18next"; +import { mobileMore } from "@docspace/shared/utils"; import api from "@docspace/shared/api"; import ModalDialogContainer from "../ModalDialogContainer"; import { inject, observer } from "mobx-react"; import styled, { css } from "styled-components"; -import { mobileMore } from "@docspace/shared/utils"; import BodyComponent from "./sub-components/BodyComponent"; const { deleteUser } = api.people; @@ -108,6 +110,7 @@ const DeleteProfileEverDialogComponent = (props) => { removeUser, userIds, filter, + refreshInsideGroup, setSelected, deleteWithoutReassign, onlyOneUser, @@ -123,15 +126,22 @@ const DeleteProfileEverDialogComponent = (props) => { const areUsersOnly = usersToDelete.every((user) => user.isVisitor); + const isInsideGroup = matchPath( + "/accounts/groups/:groupId/filter", + location.pathname, + ); + const onDeleteUser = (id) => { setIsRequestRunning(true); deleteUser(id) + .then(() => { + return isInsideGroup + ? refreshInsideGroup() + : getUsersList(filter, true); + }) .then(() => { toastr.success(t("SuccessfullyDeleteUserInfoMessage")); - getUsersList(filter, true); - - return; }) .catch((error) => toastr.error(error)) .finally(() => { @@ -142,7 +152,7 @@ const DeleteProfileEverDialogComponent = (props) => { }; const onDeleteUsers = (ids) => { setIsRequestRunning(true); - removeUser(ids, filter) + removeUser(ids, filter, isInsideGroup) .then(() => { toastr.success(t("DeleteGroupUsersSuccessMessage")); }) @@ -239,6 +249,7 @@ DeleteProfileEverDialog.propTypes = { export default inject(({ peopleStore }, { users }) => { const { dialogStore, selectionStore, filterStore, usersStore } = peopleStore; + const { refreshInsideGroup } = peopleStore.groupsStore; const { getUsersList, needResetUserSelection } = peopleStore.usersStore; @@ -272,6 +283,7 @@ export default inject(({ peopleStore }, { users }) => { removeUser: usersStore.removeUser, needResetUserSelection, filter: filterStore.filter, + refreshInsideGroup, getUsersList, deleteWithoutReassign, onlyOneUser, diff --git a/packages/client/src/store/GroupsStore.ts b/packages/client/src/store/GroupsStore.ts index 28a14c28b2..9b8ccf915c 100644 --- a/packages/client/src/store/GroupsStore.ts +++ b/packages/client/src/store/GroupsStore.ts @@ -282,6 +282,7 @@ class GroupsStore { filter, updateFilter = false, withFilterLocalStorage = false, + updateCurrentGroup = false, ) => { this.setInsideGroupLoading(true); @@ -309,7 +310,7 @@ class GroupsStore { requests.push(api.people.getUserList(filterData)); - if (groupId !== this.currentGroup?.id) { + if (updateCurrentGroup || groupId !== this.currentGroup?.id) { requests.push(groupsApi.getGroupById(groupId)); } @@ -329,6 +330,18 @@ class GroupsStore { return Promise.resolve(filteredMembersRes.items); }; + refreshInsideGroup = async () => { + if (!this.currentGroup) return; + + await this.fetchGroup( + this.currentGroup.id, + this.insideGroupFilter, + true, + false, + true, + ); + }; + get hasMoreInsideGroupUsers() { return ( this.peopleStore.usersStore.users.length < this.insideGroupFilter.total diff --git a/packages/client/src/store/UsersStore.js b/packages/client/src/store/UsersStore.js index 6d5bf98f91..fec925f401 100644 --- a/packages/client/src/store/UsersStore.js +++ b/packages/client/src/store/UsersStore.js @@ -149,9 +149,14 @@ class UsersStore { return Promise.resolve(result); }; - removeUser = async (userId, filter) => { + removeUser = async (userId, filter, isInsideGroup) => { + const { refreshInsideGroup } = this.peopleStore.groupsStore; + await api.people.deleteUsers(userId); - await this.getUsersList(filter, true); + + isInsideGroup + ? await refreshInsideGroup() + : await this.getUsersList(filter, true); }; get needResetUserSelection() {