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,7 +114,10 @@ const TableUser = ({ classes, usersOnlineInfo, logout }) => {
})
.map((user, index) => (
<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.status === "online" ? (
<CheckCircleIcon style={{ color: "green" }} />
@ -124,17 +129,53 @@ const TableUser = ({ classes, usersOnlineInfo, logout }) => {
) : (
<RemoveCircleIcon style={{ color: "black" }} />
)}
{user.name}
</Typography>
</TableCell>
<TableCell>{user.name}</TableCell>
<TableCell>
<div style={{ display: "flex", alignItems: "center", gap: "12px" }}>
<Typography className={classes.tableCounterOpen}>
{user.sumOpen ? user.sumOpen.count : "0"}
</Typography>
</TableCell>
<TableCell>
<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,11 +105,8 @@ 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}`);
@ -121,110 +118,88 @@ const reducer = (state, action) => {
return [...state];
}
if (action.type === 'LOAD_QUERY') {
const queries = action.payload
const newQueries = []
if (action.type === "LOAD_QUERY") {
const queries = action.payload;
const newQueries = [];
queries.forEach((query) => {
const queryIndex = state.findIndex((q) => q.id === query.id)
const queryIndex = state.findIndex((q) => q.id === query.id);
if (queryIndex !== -1) {
state[queryIndex] = query
}
else {
newQueries.push(query)
state[queryIndex] = query;
} else {
newQueries.push(query);
}
});
})
return [...state, ...newQueries]
return [...state, ...newQueries];
}
if (action.type === "UPDATE_STATUS_ONLINE") {
let onlineUser = action.payload;
let index = -1;
let onlineUser = action.payload
let index = -1
let onlySumOpenClosed = false
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)))
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 (!onlySumOpenClosed) {
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 ("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] }
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
state[index].sumOpen["count"] = onlineUser.sumOpen.count;
} else if (!("sumOpen" in state[index])) {
// console.log(' >>>>>>>>>>>>>>>>>> sumOpen 1')
state[index].sumOpen = onlineUser.sumOpen
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
state[index].sumClosed["count"] = onlineUser.sumClosed.count;
} else if (!("sumClosed" in state[index])) {
// console.log(' >>>>>>>>>>>>>>>>>> sumOpen 1')
state[index].sumClosed = onlineUser.sumClosed
state[index].sumClosed = onlineUser.sumClosed;
}
}
if (onlineUser.openClosedInQueue) {
state[index].openClosedInQueue = onlineUser.openClosedInQueue
state[index].openClosedInQueue = onlineUser.openClosedInQueue;
}
if (onlineUser.openClosedOutQueue) {
state[index].openClosedOutQueue = onlineUser.openClosedOutQueue
state[index].openClosedOutQueue = onlineUser.openClosedOutQueue;
}
// if(onlineUser.closedTicketByUserIn){
// state[index].closedTicketByUserIn = onlineUser.closedTicketByUserIn
// }
@ -237,19 +212,14 @@ const reducer = (state, action) => {
// if(onlineUser.openTicketByUserOut){
// state[index].openTicketByUserOut = onlineUser.openTicketByUserOut
// }
}
return [...state]
return [...state];
}
if (action.type === "RESET") {
return [];
}
}
};
const Dashboard = () => {
const classes = useStyles();