From 8e43bb289a4cf41f231567311614d4f1e14e42f0 Mon Sep 17 00:00:00 2001 From: Elyor Djalilov Date: Thu, 4 Jul 2024 14:16:28 +0500 Subject: [PATCH] fixed logoutall --- .../client/public/locales/en/Settings.json | 1 - .../client/public/locales/ru/Settings.json | 1 - .../dialogs/LogoutAllSessionDialog/index.js | 43 ++++++++++--------- .../categories/security/sessions/index.js | 27 +++++------- .../client/src/store/SelectionPeopleStore.js | 17 ++------ 5 files changed, 37 insertions(+), 52 deletions(-) diff --git a/packages/client/public/locales/en/Settings.json b/packages/client/public/locales/en/Settings.json index 74151e9ef0..ee57a04844 100644 --- a/packages/client/public/locales/en/Settings.json +++ b/packages/client/public/locales/en/Settings.json @@ -298,7 +298,6 @@ "UseDigits": "Use digits", "UsedStorage": "Used: {{size}}", "UseHttp": "Use Http", - "UserAlreadyLoggedOut": "The user {{displayName}} is already logged out", "UserAgreement": "I confirm and want to proceed", "UserLimitExceeded": "User limit exceeded. To proceed to the next step, please adjust the number of users or increase the {{productName}} user limit.", "UsersAreRegistered": "You selected users registered in your {{productName}}, with the roles already set. Please proceed to the next step or go back to select more users.", diff --git a/packages/client/public/locales/ru/Settings.json b/packages/client/public/locales/ru/Settings.json index d52748bc73..a6f6e5b790 100644 --- a/packages/client/public/locales/ru/Settings.json +++ b/packages/client/public/locales/ru/Settings.json @@ -295,7 +295,6 @@ "UseDigits": "Использовать цифры", "UsedStorage": "Используемое: {{size}}", "UseHttp": "Использовать Http", - "UserAlreadyLoggedOut": "Пользователь {{displayName}} уже вышел из системы.", "UserAgreement": "Я подтверждаю и хочу продолжить", "UserLimitExceeded": "Превышен лимит пользователя. Чтобы перейти к следующему шагу, измените количество пользователей или увеличьте лимит пользователей {{productName}}.", "UsersSectionDescription": "Раздел «Пользователи» включает пользователей, которых вы выбрали на предыдущем шаге. По умолчанию он всегда включен, и его нельзя отключить.", diff --git a/packages/client/src/components/dialogs/LogoutAllSessionDialog/index.js b/packages/client/src/components/dialogs/LogoutAllSessionDialog/index.js index 42110383c7..6cc496473f 100644 --- a/packages/client/src/components/dialogs/LogoutAllSessionDialog/index.js +++ b/packages/client/src/components/dialogs/LogoutAllSessionDialog/index.js @@ -25,46 +25,55 @@ // International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode import { useState } from "react"; -import { inject, observer } from "mobx-react"; import { ModalDialog } from "@docspace/shared/components/modal-dialog"; import { Checkbox } from "@docspace/shared/components/checkbox"; import { Button } from "@docspace/shared/components/button"; import { Text } from "@docspace/shared/components/text"; +import { toastr } from "@docspace/shared/components/toast"; import ModalDialogContainer from "../ModalDialogContainer"; const LogoutAllSessionDialog = ({ t, - exceptId, - userIds, - displayName, visible, isLoading, + userIds, + displayName, + selection, + bufferSelection, onClose, + onClosePanel, onRemoveAllSessions, onRemoveAllExceptThis, isSeveralSelection, onLogoutAllUsers, onLogoutAllSessions, onLogoutAllExceptThis, - setUserSessionPanelVisible, }) => { const [isChecked, setIsChecked] = useState(false); - const isProfile = location.pathname.includes("/profile"); + const selectionId = selection[0]?.connections[0]?.id; + const bufferSelectionId = bufferSelection?.connections[0]?.id; + + const exceptId = selectionId || bufferSelectionId; const onChangeCheckbox = () => { setIsChecked((prev) => !prev); }; const onClickLogout = () => { - if (!isChecked) { - isSeveralSelection - ? onLogoutAllUsers(t, userIds) - : onLogoutAllSessions(t).then(() => setUserSessionPanelVisible(false)); - onClose(); - } else { - onLogoutAllExceptThis(t, exceptId, displayName); + try { + if (!isChecked) { + isSeveralSelection + ? onLogoutAllUsers(t, userIds) + : onLogoutAllSessions(t, userIds, displayName); + onClosePanel(); + } else { + onLogoutAllExceptThis(t, exceptId, displayName); + } + } catch (error) { + toastr.error(error); + } finally { onClose(); } }; @@ -134,10 +143,4 @@ const LogoutAllSessionDialog = ({ ); }; -export default inject(({ peopleStore }) => { - const { isSeveralSelection } = peopleStore.selectionStore; - - return { - isSeveralSelection, - }; -})(observer(LogoutAllSessionDialog)); +export default LogoutAllSessionDialog; diff --git a/packages/client/src/pages/PortalSettings/categories/security/sessions/index.js b/packages/client/src/pages/PortalSettings/categories/security/sessions/index.js index 1cf3e6937e..a57583bf57 100644 --- a/packages/client/src/pages/PortalSettings/categories/security/sessions/index.js +++ b/packages/client/src/pages/PortalSettings/categories/security/sessions/index.js @@ -100,6 +100,7 @@ const Sessions = ({ getLoginHistoryReport, isLoadingDownloadReport, setUserSessionPanelVisible, + isSeveralSelection, isSessionsLoaded, }) => { const { t } = useTranslation([ @@ -122,24 +123,12 @@ const Sessions = ({ currentDeviceType, }); - const getIdFromConnections = (connections) => connections[0]?.id; - - const idFromSelection = - selection.length > 0 - ? getIdFromConnections(selection[0].connections) - : undefined; - - const idFromBufferSelection = bufferSelection - ? getIdFromConnections(bufferSelection.connections) - : undefined; - - const exceptId = idFromSelection || idFromBufferSelection; - const userIdsFromSelection = selection.map((user) => user.id); + const selectionUserId = selection.map((user) => user.id); const userIds = bufferSelection?.id !== undefined - ? [bufferSelection.id, ...userIdsFromSelection] - : [...userIdsFromSelection]; + ? [bufferSelection.id, ...selectionUserId] + : [...selectionUserId]; if (!isSessionsLoaded) return ; @@ -191,14 +180,16 @@ const Sessions = ({ t={t} visible={logoutAllDialogVisible} isLoading={isLoading} - exceptId={exceptId} userIds={userIds} displayName={displayName} + selection={selection} + bufferSelection={bufferSelection} + isSeveralSelection={isSeveralSelection} onClose={() => setLogoutAllDialogVisible(false)} + onClosePanel={() => setUserSessionPanelVisible(false)} onLogoutAllUsers={onClickLogoutAllUsers} onLogoutAllSessions={onClickLogoutAllSessions} onLogoutAllExceptThis={onClickLogoutAllExceptThis} - setUserSessionPanelVisible={setUserSessionPanelVisible} /> )} @@ -218,6 +209,7 @@ export default inject(({ settingsStore, setup, peopleStore, dialogsStore }) => { selection, bufferSelection, isLoading, + isSeveralSelection, onClickLogoutAllUsers, onClickLogoutAllSessions, onClickLogoutAllExceptThis, @@ -263,6 +255,7 @@ export default inject(({ settingsStore, setup, peopleStore, dialogsStore }) => { getLoginHistoryReport, isLoadingDownloadReport, setUserSessionPanelVisible, + isSeveralSelection, isSessionsLoaded: allSessions.length > 0, }; })(observer(Sessions)); diff --git a/packages/client/src/store/SelectionPeopleStore.js b/packages/client/src/store/SelectionPeopleStore.js index 0e23da4cc6..4a030cbe1e 100644 --- a/packages/client/src/store/SelectionPeopleStore.js +++ b/packages/client/src/store/SelectionPeopleStore.js @@ -649,7 +649,7 @@ class SelectionStore { const filteredSessions = sessions.filter( (item) => item.connections.length !== 0 && - item.sessions.some((session) => session.hasOwnProperty("id")), + item.sessions?.some((session) => session.hasOwnProperty("id")), ); return filteredSessions; @@ -672,18 +672,9 @@ class SelectionStore { } }; - onClickLogoutAllSessions = async (t) => { + onClickLogoutAllSessions = async (t, userId, displayName) => { const { removeAllActiveSessionsById } = this.settingsSetupStore; - const bufferSelection = this.bufferSelection?.id; - const selection = this.selection[0]?.id; - const userId = selection || bufferSelection; - - if (!userId) - return toastr.error( - t("Settings:UserAlreadyLoggedOut", { displayName: this.displayName }), - ); - try { this.setIsLoading(true); await removeAllActiveSessionsById(userId); @@ -693,12 +684,12 @@ class SelectionStore { sessions: [], }; this.setItems(newData); - const index = this.findSessionIndexByUserId(this.items.id); + const index = this.findSessionIndexByUserId(userId); this.dataFromSocket[index] = newData; toastr.success( t("Settings:LoggedOutByUser", { - displayName: this.displayName, + displayName: displayName, }), ); } catch (error) {