added method removeAllActiveSessionsById

This commit is contained in:
Elyor Djalilov 2024-06-08 16:58:09 +05:00
parent 97e050f5c7
commit 2b98f42a5b
4 changed files with 68 additions and 6 deletions

View File

@ -1,5 +1,6 @@
import { Text } from "@docspace/shared/components/text";
import { Button } from "@docspace/shared/components/button";
import { toastr } from "@docspace/shared/components/toast";
import styled from "styled-components";
import RowWrapper from "./sub-components";
@ -19,10 +20,25 @@ const Wrapper = styled.div`
`;
const AllSessionsBlock = (props) => {
const { t, sessionData } = props;
const {
t,
sessionData,
removeAllActiveSessionsById,
setSessionModalData,
fetchData,
} = props;
const onLogoutClick = () => {
console.log("Logout all sessions");
const isDisabled = sessionData.length > 0;
const onLogoutClick = async () => {
try {
await removeAllActiveSessionsById(sessionData[0]?.userId);
await fetchData();
setSessionModalData([]);
toastr.success("Successfully logout all sessions");
} catch (error) {
toastr.error(error);
}
};
return (
@ -36,6 +52,7 @@ const AllSessionsBlock = (props) => {
onClick={onLogoutClick}
scale={true}
isLoading={false}
isDisabled={!isDisabled}
/>
</Wrapper>

View File

@ -45,9 +45,31 @@ const StyledScrollbar = styled(Scrollbar)`
`;
const UserSessionsPanel = (props) => {
const { t, visible, setVisible } = props;
const {
t,
visible,
setVisible,
getUsersList,
getUserSessionsById,
setSessions,
setAllSessions,
} = props;
const scrollRef = useRef(null);
const fetchAndSetUserSessions = async () => {
try {
const users = await getUsersList();
const sessionsPromises = users.map((user) =>
getUserSessionsById(user.id),
);
const sessions = await Promise.all(sessionsPromises);
setSessions(sessions);
setAllSessions();
} catch (error) {
console.error(error);
}
};
const onClose = () => {
setVisible(false);
};
@ -74,34 +96,45 @@ const UserSessionsPanel = (props) => {
<StyledScrollbar ref={scrollRef}>
<UserInfoBlock {...props} />
<LastSessionBlock {...props} />
<AllSessionsBlock {...props} />
<AllSessionsBlock {...props} fetchData={fetchAndSetUserSessions} />
</StyledScrollbar>
</Aside>
</StyledSessionsPanel>
);
};
export default inject(({ setup, dialogsStore }) => {
export default inject(({ setup, dialogsStore, peopleStore }) => {
const { userSessionsPanelVisible, setUserSessionPanelVisible } = dialogsStore;
const { setSessions, setAllSessions } = peopleStore.selectionStore;
const { getUsersList } = peopleStore.usersStore;
const {
setLogoutAllDialogVisible,
setDisableDialogVisible,
userModalData,
sessionModalData,
setSessionModalData,
setDisplayName,
sessionStatus,
removeAllActiveSessionsById,
getUserSessionsById,
} = setup;
return {
userData: userModalData,
sessionData: sessionModalData,
setSessionModalData: setSessionModalData,
setLogoutAllDialogVisible,
setDisableDialogVisible,
visible: userSessionsPanelVisible,
setVisible: setUserSessionPanelVisible,
setDisplayName,
sessionStatus,
removeAllActiveSessionsById,
getUsersList,
getUserSessionsById,
setSessions,
setAllSessions,
};
})(
withTranslation(["Settings", "Profile", "Common"])(

View File

@ -561,6 +561,10 @@ class SettingsSetupStore {
return api.settings.getUserSessionsById(userId);
};
removeAllActiveSessionsById = (userId) => {
return api.settings.removeAllActiveSessionsById(userId);
};
removeAllSessions = () => {
return api.settings.removeAllActiveSessions();
};

View File

@ -904,6 +904,14 @@ export function getUserSessionsById(userId) {
});
}
export function removeAllActiveSessionsById(userId) {
return request({
method: "put",
url: `/security/activeconnections/logoutall/${userId}`,
data: { userId },
});
}
export function removeAllActiveSessions() {
return request({
method: "put",