diff --git a/frontend/src/pages/Dashboard/index.js b/frontend/src/pages/Dashboard/index.js index 866be85..b69fa9f 100644 --- a/frontend/src/pages/Dashboard/index.js +++ b/frontend/src/pages/Dashboard/index.js @@ -22,10 +22,6 @@ import openSocket from "socket.io-client"; import api from "../../services/api"; -import openSocket from "socket.io-client"; - -import api from "../../services/api"; - import { Can } from "../../components/Can"; import CardUser from "../../components/DashboardUser/CardUser"; import TableUser from "../../components/DashboardUser/TableUser"; @@ -109,98 +105,6 @@ const useStyles = makeStyles((theme) => ({ }, })); -const reducer = (state, action) => { - if (action.type === "DELETE_USER_STATUS") { - const userId = action.payload; - - const userIndex = state.findIndex((u) => `${u.id}` === `${userId}`); - - if (userIndex !== -1) { - state.splice(userIndex, 1); - } - - return [...state]; - } - - if (action.type === "LOAD_QUERY") { - const queries = action.payload; - const newQueries = []; - - queries.forEach((query) => { - const queryIndex = state.findIndex((q) => q.id === query.id); - - if (queryIndex !== -1) { - state[queryIndex] = query; - } else { - newQueries.push(query); - } - }); - - return [...state, ...newQueries]; - } - - if (action.type === "UPDATE_STATUS_ONLINE") { - let onlineUser = action.payload; - let index = -1; - - let onlySumOpenClosed = false; - - if (onlineUser.sumOpen || onlineUser.sumClosed) { - index = state.findIndex( - (e) => - (onlineUser.sumOpen && e.id === onlineUser.sumOpen.userId) || - (onlineUser.sumClosed && e.id === onlineUser.sumClosed.userId) - ); - - onlySumOpenClosed = true; - } else { - index = state.findIndex((e) => `${e.id}` === `${onlineUser.userId}`); - } - - if (index !== -1) { - if (!onlySumOpenClosed) { - if (!("statusOnline" in state[index])) { - state[index].statusOnline = onlineUser; - } else if ("statusOnline" in state[index]) { - state[index].statusOnline["status"] = onlineUser.status; - } - } - - if ("onlineTime" in onlineUser) { - if ("sumOnlineTime" in state[index]) { - state[index].sumOnlineTime["sum"] = onlineUser.onlineTime.split(" ")[1]; - } else if (!("sumOnlineTime" in state[index])) { - state[index].sumOnlineTime = { - userId: onlineUser.userId, - sum: onlineUser.onlineTime.split(" ")[1], - }; - } - } - - if (onlineUser.sumOpen) { - if ("sumOpen" in state[index]) { - state[index].sumOpen["count"] = onlineUser.sumOpen.count; - } else if (!("sumOpen" in state[index])) { - state[index].sumOpen = onlineUser.sumOpen; - } - } - - if (onlineUser.sumClosed) { - if ("sumClosed" in state[index]) { - state[index].sumClosed["count"] = onlineUser.sumClosed.count; - } else if (!("sumClosed" in state[index])) { - state[index].sumClosed = onlineUser.sumClosed; - } - } - } - return [...state]; - } - - if (action.type === "RESET") { - return []; - } -}; - const reducer = (state, action) => {