diff --git a/packages/client/src/Shell.jsx b/packages/client/src/Shell.jsx index e2b4c810e5..30c4a1f8b8 100644 --- a/packages/client/src/Shell.jsx +++ b/packages/client/src/Shell.jsx @@ -91,9 +91,9 @@ const Shell = ({ items = [], page = "home", ...rest }) => { organizationName, setDataFromSocket, updateDataFromSocket, - sessisonLogout, + sessionLogout, setMultiConnections, - sessisonMultiLogout, + sessionMultiLogout, } = rest; const theme = useTheme(); @@ -176,7 +176,7 @@ const Shell = ({ items = [], page = "home", ...rest }) => { }); socketHelper.on("leave-in-portal", (data) => { - sessisonLogout(data); + sessionLogout(data); }); socketHelper.on("enter-session-in-portal", (data) => { @@ -184,16 +184,16 @@ const Shell = ({ items = [], page = "home", ...rest }) => { }); socketHelper.on("leave-session-in-portal", (data) => { - sessisonMultiLogout(data); + sessionMultiLogout(data); }); }, [ socketHelper, setDataFromSocket, updateDataFromSocket, - sessisonLogout, + sessionLogout, setMultiConnections, moveToLastSession, - sessisonMultiLogout, + sessionMultiLogout, ]); useEffect(() => { @@ -525,9 +525,9 @@ const ShellWrapper = inject( const { setDataFromSocket, updateDataFromSocket, - sessisonLogout, + sessionLogout, setMultiConnections, - sessisonMultiLogout, + sessionMultiLogout, } = peopleStore.selectionStore; const { @@ -620,9 +620,9 @@ const ShellWrapper = inject( organizationName, setDataFromSocket, updateDataFromSocket, - sessisonLogout, + sessionLogout, setMultiConnections, - sessisonMultiLogout, + sessionMultiLogout, }; }, )(observer(Shell)); diff --git a/packages/client/src/store/SelectionPeopleStore.js b/packages/client/src/store/SelectionPeopleStore.js index 428fa09219..9d8dd46eb7 100644 --- a/packages/client/src/store/SelectionPeopleStore.js +++ b/packages/client/src/store/SelectionPeopleStore.js @@ -544,7 +544,7 @@ class SelectionStore { }, []); }; - sessisonLogout = ({ userId, date }) => { + sessionLogout = ({ userId, date }) => { const newData = [...this.dataFromSocket]; const status = "offline"; @@ -585,13 +585,20 @@ class SelectionStore { setMultiConnections = ({ session, userId }) => { const index = this.findSessionIndexByUserId(userId); - this.dataFromSocket[index].sessions = [ - ...this.dataFromSocket[index].sessions, - session, - ]; + if (index === -1) return; + + const existingSessionIndex = this.dataFromSocket[index].sessions.findIndex( + (item) => item.id === session.id, + ); + + if (existingSessionIndex === -1) { + this.dataFromSocket[index].sessions.push(session); + } else { + this.dataFromSocket[index].sessions[existingSessionIndex] = session; + } }; - sessisonMultiLogout = ({ sessionId, userId, date }) => { + sessionMultiLogout = ({ sessionId, userId, date }) => { const index = this.findSessionIndexByUserId(userId); if (index === -1) return; @@ -602,11 +609,13 @@ class SelectionStore { if (sessionIndex === -1) return; - const [deletElement] = this.dataFromSocket[index].sessions.splice( + const [deletedElement] = this.dataFromSocket[index].sessions.splice( sessionIndex, 1, ); + if (!deletedElement) return; + const sessionsLength = this.dataFromSocket[index].sessions.length; const countActiveSession = this.dataFromSocket[index].sessions.filter( @@ -619,7 +628,7 @@ class SelectionStore { : 0; this.dataFromSocket[index].sessions.splice(addedIndex, 0, { - ...deletElement, + ...deletedElement, date, status: "offline", });