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()); setSearch(event.target.value.toLowerCase());
}; };
console.log(usersOnlineInfo);
return ( return (
<Grid item xs={12}> <Grid item xs={12}>
<Paper className={classes.cardPaperFix} sx={12} variant="outlined"> <Paper className={classes.cardPaperFix} sx={12} variant="outlined">
@ -81,10 +83,10 @@ const TableUser = ({ classes, usersOnlineInfo, logout }) => {
<Table> <Table>
<TableHead> <TableHead>
<TableRow className={classes.tableRowHead}> <TableRow className={classes.tableRowHead}>
<TableCell>Status</TableCell>
<TableCell>Nome</TableCell> <TableCell>Nome</TableCell>
<TableCell>Em Atendimento</TableCell> <TableCell>Em Atendimento/Finalizado(s)</TableCell>
<TableCell>Finalizado(s)</TableCell> <TableCell>Por Fila abertos</TableCell>
<TableCell>Por Fila Fechados</TableCell>
<TableCell>Tempo Online</TableCell> <TableCell>Tempo Online</TableCell>
<TableCell>Ações</TableCell> <TableCell>Ações</TableCell>
</TableRow> </TableRow>
@ -112,7 +114,10 @@ const TableUser = ({ classes, usersOnlineInfo, logout }) => {
}) })
.map((user, index) => ( .map((user, index) => (
<TableRow key={index} className={classes.tableRowBody}> <TableRow key={index} className={classes.tableRowBody}>
<TableCell title={user.statusOnline && user.statusOnline.status}> <TableCell>
<Typography
style={{ display: "flex", verticalAlign: "center", gap: "6px" }}
>
{user.statusOnline ? ( {user.statusOnline ? (
user.statusOnline.status === "online" ? ( user.statusOnline.status === "online" ? (
<CheckCircleIcon style={{ color: "green" }} /> <CheckCircleIcon style={{ color: "green" }} />
@ -124,17 +129,53 @@ const TableUser = ({ classes, usersOnlineInfo, logout }) => {
) : ( ) : (
<RemoveCircleIcon style={{ color: "black" }} /> <RemoveCircleIcon style={{ color: "black" }} />
)} )}
{user.name}
</Typography>
</TableCell> </TableCell>
<TableCell>{user.name}</TableCell>
<TableCell> <TableCell>
<div style={{ display: "flex", alignItems: "center", gap: "12px" }}>
<Typography className={classes.tableCounterOpen}> <Typography className={classes.tableCounterOpen}>
{user.sumOpen ? user.sumOpen.count : "0"} {user.sumOpen ? user.sumOpen.count : "0"}
</Typography> </Typography>
</TableCell>
<TableCell>
<Typography className={classes.tableCounterClosed}> <Typography className={classes.tableCounterClosed}>
{user.sumClosed ? user.sumClosed.count : "0"} {user.sumClosed ? user.sumClosed.count : "0"}
</Typography> </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>
<TableCell> <TableCell>
{user.sumOnlineTime ? user.sumOnlineTime.sum : "Não entrou"} {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 Paper from "@material-ui/core/Paper";
import Container from "@material-ui/core/Container"; import Container from "@material-ui/core/Container";
@ -105,11 +105,8 @@ const useStyles = makeStyles((theme) => ({
}, },
})); }));
const reducer = (state, action) => { const reducer = (state, action) => {
if (action.type === "DELETE_USER_STATUS") { if (action.type === "DELETE_USER_STATUS") {
const userId = action.payload; const userId = action.payload;
const userIndex = state.findIndex((u) => `${u.id}` === `${userId}`); const userIndex = state.findIndex((u) => `${u.id}` === `${userId}`);
@ -121,109 +118,87 @@ const reducer = (state, action) => {
return [...state]; return [...state];
} }
if (action.type === "LOAD_QUERY") {
const queries = action.payload;
if (action.type === 'LOAD_QUERY') { const newQueries = [];
const queries = action.payload
const newQueries = []
queries.forEach((query) => { queries.forEach((query) => {
const queryIndex = state.findIndex((q) => q.id === query.id);
const queryIndex = state.findIndex((q) => q.id === query.id)
if (queryIndex !== -1) { if (queryIndex !== -1) {
state[queryIndex] = query state[queryIndex] = query;
} } else {
else { newQueries.push(query);
newQueries.push(query)
} }
});
}) return [...state, ...newQueries];
return [...state, ...newQueries]
} }
if (action.type === "UPDATE_STATUS_ONLINE") { if (action.type === "UPDATE_STATUS_ONLINE") {
let onlineUser = action.payload;
let index = -1;
let onlineUser = action.payload let onlySumOpenClosed = false;
let index = -1
let onlySumOpenClosed = false
if (onlineUser.sumOpen || onlineUser.sumClosed) { if (onlineUser.sumOpen || onlineUser.sumClosed) {
index = state.findIndex((e) => ((onlineUser.sumOpen && e.id === onlineUser.sumOpen.userId) || (onlineUser.sumClosed && e.id === onlineUser.sumClosed.userId))) index = state.findIndex(
(e) =>
(onlineUser.sumOpen && e.id === onlineUser.sumOpen.userId) ||
(onlineUser.sumClosed && e.id === onlineUser.sumClosed.userId)
);
onlySumOpenClosed = true onlySumOpenClosed = true;
} else {
index = state.findIndex((e) => `${e.id}` === `${onlineUser.userId}`);
} }
else {
index = state.findIndex((e) => `${e.id}` === `${onlineUser.userId}`)
}
if (index !== -1) { if (index !== -1) {
if (!onlySumOpenClosed) { if (!onlySumOpenClosed) {
if (!("statusOnline" in state[index])) { if (!("statusOnline" in state[index])) {
state[index].statusOnline = onlineUser;
state[index].statusOnline = onlineUser } else if ("statusOnline" in state[index]) {
state[index].statusOnline["status"] = onlineUser.status;
} }
else if ("statusOnline" in state[index]) {
state[index].statusOnline['status'] = onlineUser.status
} }
}
if ("onlineTime" in onlineUser) { if ("onlineTime" in onlineUser) {
if ("sumOnlineTime" in state[index]) { if ("sumOnlineTime" in state[index]) {
state[index].sumOnlineTime['sum'] = (onlineUser.onlineTime).split(" ")[1] state[index].sumOnlineTime["sum"] = onlineUser.onlineTime.split(" ")[1];
} } else if (!("sumOnlineTime" in state[index])) {
else if (!("sumOnlineTime" in state[index])) { state[index].sumOnlineTime = {
state[index].sumOnlineTime = { userId: onlineUser.userId, sum: (onlineUser.onlineTime).split(" ")[1] } userId: onlineUser.userId,
sum: onlineUser.onlineTime.split(" ")[1],
};
} }
} }
if (onlineUser.sumOpen) { if (onlineUser.sumOpen) {
if ("sumOpen" in state[index]) { if ("sumOpen" in state[index]) {
// console.log(' >>>>>>>>>>>>>>>>>> sumOpen 1 | state[index].sumOpen["count"]: ', state[index].sumOpen['count'], ' | onlineUser.sumOpen.count: ', onlineUser.sumOpen.count) // 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 state[index].sumOpen["count"] = onlineUser.sumOpen.count;
} else if (!("sumOpen" in state[index])) { } else if (!("sumOpen" in state[index])) {
// console.log(' >>>>>>>>>>>>>>>>>> sumOpen 1') // console.log(' >>>>>>>>>>>>>>>>>> sumOpen 1')
state[index].sumOpen = onlineUser.sumOpen state[index].sumOpen = onlineUser.sumOpen;
} }
} }
if (onlineUser.sumClosed) { if (onlineUser.sumClosed) {
if ("sumClosed" in state[index]) { if ("sumClosed" in state[index]) {
// console.log(' >>>>>>>>>>>>>>>>>> sumClosed 1 | state[index].sumClosed["count"]: ', state[index].sumClosed['count'], ' | onlineUser.sumClosed.count: ', onlineUser.sumClosed.count) // 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 state[index].sumClosed["count"] = onlineUser.sumClosed.count;
} else if (!("sumClosed" in state[index])) { } else if (!("sumClosed" in state[index])) {
// console.log(' >>>>>>>>>>>>>>>>>> sumOpen 1') // console.log(' >>>>>>>>>>>>>>>>>> sumOpen 1')
state[index].sumClosed = onlineUser.sumClosed state[index].sumClosed = onlineUser.sumClosed;
}
} }
if (onlineUser.openClosedInQueue) {
state[index].openClosedInQueue = onlineUser.openClosedInQueue;
} }
if (onlineUser.openClosedOutQueue) {
state[index].openClosedOutQueue = onlineUser.openClosedOutQueue;
if(onlineUser.openClosedInQueue){
state[index].openClosedInQueue = onlineUser.openClosedInQueue
} }
if(onlineUser.openClosedOutQueue){
state[index].openClosedOutQueue = onlineUser.openClosedOutQueue
}
// if(onlineUser.closedTicketByUserIn){ // if(onlineUser.closedTicketByUserIn){
// state[index].closedTicketByUserIn = onlineUser.closedTicketByUserIn // state[index].closedTicketByUserIn = onlineUser.closedTicketByUserIn
@ -237,19 +212,14 @@ const reducer = (state, action) => {
// if(onlineUser.openTicketByUserOut){ // if(onlineUser.openTicketByUserOut){
// state[index].openTicketByUserOut = onlineUser.openTicketByUserOut // state[index].openTicketByUserOut = onlineUser.openTicketByUserOut
// } // }
} }
return [...state] return [...state];
} }
if (action.type === "RESET") { if (action.type === "RESET") {
return []; return [];
} }
};
}
const Dashboard = () => { const Dashboard = () => {
const classes = useStyles(); const classes = useStyles();