fix some erros

pull/17/head
Renato Di Giacomo 2022-08-08 18:06:48 -03:00
parent 16bfcdce1e
commit 6cec68516f
2 changed files with 160 additions and 149 deletions

View File

@ -34,6 +34,8 @@ const TableUser = ({ classes, usersOnlineInfo, logout }) => {
setSearch(event.target.value.toLowerCase());
};
console.log(usersOnlineInfo);
return (
<Grid item xs={12}>
<Paper className={classes.cardPaperFix} sx={12} variant="outlined">
@ -81,10 +83,10 @@ const TableUser = ({ classes, usersOnlineInfo, logout }) => {
<Table>
<TableHead>
<TableRow className={classes.tableRowHead}>
<TableCell>Status</TableCell>
<TableCell>Nome</TableCell>
<TableCell>Em Atendimento</TableCell>
<TableCell>Finalizado(s)</TableCell>
<TableCell>Em Atendimento/Finalizado(s)</TableCell>
<TableCell>Por Fila abertos</TableCell>
<TableCell>Por Fila Fechados</TableCell>
<TableCell>Tempo Online</TableCell>
<TableCell>Ações</TableCell>
</TableRow>
@ -112,29 +114,68 @@ const TableUser = ({ classes, usersOnlineInfo, logout }) => {
})
.map((user, index) => (
<TableRow key={index} className={classes.tableRowBody}>
<TableCell title={user.statusOnline && user.statusOnline.status}>
{user.statusOnline ? (
user.statusOnline.status === "online" ? (
<CheckCircleIcon style={{ color: "green" }} />
) : user.statusOnline.status === "offline" ? (
<CancelIcon style={{ color: "red" }} />
<TableCell>
<Typography
style={{ display: "flex", verticalAlign: "center", gap: "6px" }}
>
{user.statusOnline ? (
user.statusOnline.status === "online" ? (
<CheckCircleIcon style={{ color: "green" }} />
) : user.statusOnline.status === "offline" ? (
<CancelIcon style={{ color: "red" }} />
) : (
<ErrorIcon style={{ color: "gold" }} />
)
) : (
<ErrorIcon style={{ color: "gold" }} />
)
) : (
<RemoveCircleIcon style={{ color: "black" }} />
)}
</TableCell>
<TableCell>{user.name}</TableCell>
<TableCell>
<Typography className={classes.tableCounterOpen}>
{user.sumOpen ? user.sumOpen.count : "0"}
<RemoveCircleIcon style={{ color: "black" }} />
)}
{user.name}
</Typography>
</TableCell>
<TableCell>
<Typography className={classes.tableCounterClosed}>
{user.sumClosed ? user.sumClosed.count : "0"}
</Typography>
<div style={{ display: "flex", alignItems: "center", gap: "12px" }}>
<Typography className={classes.tableCounterOpen}>
{user.sumOpen ? user.sumOpen.count : "0"}
</Typography>
<Typography className={classes.tableCounterClosed}>
{user.sumClosed ? user.sumClosed.count : "0"}
</Typography>
</div>
</TableCell>
<TableCell>
<div
style={{
display: "flex",
flexWrap: "wrap",
alignItems: "center",
gap: "12px",
}}
>
<Typography title="Cobrança">0</Typography>
<Typography>0</Typography>
<Typography>0</Typography>
<Typography>0</Typography>
<Typography>0</Typography>
</div>
</TableCell>
<TableCell>
<div
style={{
display: "flex",
flexWrap: "wrap",
alignItems: "center",
gap: "12px",
}}
>
<Typography title="Cobrança">0</Typography>
<Typography>0</Typography>
<Typography>0</Typography>
<Typography>0</Typography>
<Typography>0</Typography>
</div>
</TableCell>
<TableCell>
{user.sumOnlineTime ? user.sumOnlineTime.sum : "Não entrou"}

View File

@ -1,4 +1,4 @@
import React, { useContext, useReducer, useEffect, useState } from "react";
import React, { useContext, useReducer, useEffect } from "react";
import Paper from "@material-ui/core/Paper";
import Container from "@material-ui/core/Container";
@ -105,151 +105,121 @@ const useStyles = makeStyles((theme) => ({
},
}));
const reducer = (state, action) => {
if (action.type === "DELETE_USER_STATUS") {
const userId = action.payload;
if (action.type === "DELETE_USER_STATUS") {
const userIndex = state.findIndex((u) => `${u.id}` === `${userId}`);
const userId = action.payload;
if (userIndex !== -1) {
state.splice(userIndex, 1);
}
const userIndex = state.findIndex((u) => `${u.id}` === `${userId}`);
return [...state];
}
if (userIndex !== -1) {
state.splice(userIndex, 1);
}
if (action.type === "LOAD_QUERY") {
const queries = action.payload;
const newQueries = [];
return [...state];
}
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 === 'LOAD_QUERY') {
if (action.type === "UPDATE_STATUS_ONLINE") {
let onlineUser = action.payload;
let index = -1;
const queries = action.payload
const newQueries = []
let onlySumOpenClosed = false;
queries.forEach((query) => {
if (onlineUser.sumOpen || onlineUser.sumClosed) {
index = state.findIndex(
(e) =>
(onlineUser.sumOpen && e.id === onlineUser.sumOpen.userId) ||
(onlineUser.sumClosed && e.id === onlineUser.sumClosed.userId)
);
const queryIndex = state.findIndex((q) => q.id === query.id)
onlySumOpenClosed = true;
} else {
index = state.findIndex((e) => `${e.id}` === `${onlineUser.userId}`);
}
if (queryIndex !== -1) {
state[queryIndex] = query
}
else {
newQueries.push(query)
}
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],
};
}
}
return [...state, ...newQueries]
}
if (onlineUser.sumOpen) {
if ("sumOpen" in state[index]) {
// console.log(' >>>>>>>>>>>>>>>>>> sumOpen 1 | state[index].sumOpen["count"]: ', state[index].sumOpen['count'], ' | onlineUser.sumOpen.count: ', onlineUser.sumOpen.count)
state[index].sumOpen["count"] = onlineUser.sumOpen.count;
} else if (!("sumOpen" in state[index])) {
// console.log(' >>>>>>>>>>>>>>>>>> sumOpen 1')
state[index].sumOpen = onlineUser.sumOpen;
}
}
if (action.type === "UPDATE_STATUS_ONLINE") {
if (onlineUser.sumClosed) {
if ("sumClosed" in state[index]) {
// console.log(' >>>>>>>>>>>>>>>>>> sumClosed 1 | state[index].sumClosed["count"]: ', state[index].sumClosed['count'], ' | onlineUser.sumClosed.count: ', onlineUser.sumClosed.count)
state[index].sumClosed["count"] = onlineUser.sumClosed.count;
} else if (!("sumClosed" in state[index])) {
// console.log(' >>>>>>>>>>>>>>>>>> sumOpen 1')
state[index].sumClosed = onlineUser.sumClosed;
}
}
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]) {
// console.log(' >>>>>>>>>>>>>>>>>> sumOpen 1 | state[index].sumOpen["count"]: ', state[index].sumOpen['count'], ' | onlineUser.sumOpen.count: ', onlineUser.sumOpen.count)
state[index].sumOpen['count'] = onlineUser.sumOpen.count
} else if (!("sumOpen" in state[index])) {
// console.log(' >>>>>>>>>>>>>>>>>> sumOpen 1')
state[index].sumOpen = onlineUser.sumOpen
}
}
if (onlineUser.sumClosed) {
if ("sumClosed" in state[index]) {
// console.log(' >>>>>>>>>>>>>>>>>> sumClosed 1 | state[index].sumClosed["count"]: ', state[index].sumClosed['count'], ' | onlineUser.sumClosed.count: ', onlineUser.sumClosed.count)
state[index].sumClosed['count'] = onlineUser.sumClosed.count
} else if (!("sumClosed" in state[index])) {
// console.log(' >>>>>>>>>>>>>>>>>> sumOpen 1')
state[index].sumClosed = onlineUser.sumClosed
}
}
if(onlineUser.openClosedInQueue){
state[index].openClosedInQueue = onlineUser.openClosedInQueue
}
if(onlineUser.openClosedOutQueue){
state[index].openClosedOutQueue = onlineUser.openClosedOutQueue
}
// if(onlineUser.closedTicketByUserIn){
// state[index].closedTicketByUserIn = onlineUser.closedTicketByUserIn
// }
// if(onlineUser.closedTicketByUserOut){
// state[index].closedTicketByUserOut = onlineUser.closedTicketByUserOut
// }
// if(onlineUser.openTicketByUserIn){
// state[index].openTicketByUserIn = onlineUser.openTicketByUserIn
// }
// if(onlineUser.openTicketByUserOut){
// state[index].openTicketByUserOut = onlineUser.openTicketByUserOut
// }
}
return [...state]
}
if (action.type === "RESET") {
return [];
}
}
if (onlineUser.openClosedInQueue) {
state[index].openClosedInQueue = onlineUser.openClosedInQueue;
}
if (onlineUser.openClosedOutQueue) {
state[index].openClosedOutQueue = onlineUser.openClosedOutQueue;
}
// if(onlineUser.closedTicketByUserIn){
// state[index].closedTicketByUserIn = onlineUser.closedTicketByUserIn
// }
// if(onlineUser.closedTicketByUserOut){
// state[index].closedTicketByUserOut = onlineUser.closedTicketByUserOut
// }
// if(onlineUser.openTicketByUserIn){
// state[index].openTicketByUserIn = onlineUser.openTicketByUserIn
// }
// if(onlineUser.openTicketByUserOut){
// state[index].openTicketByUserOut = onlineUser.openTicketByUserOut
// }
}
return [...state];
}
if (action.type === "RESET") {
return [];
}
};
const Dashboard = () => {
const classes = useStyles();