projeto-hit/frontend/src/components/DashboardUser/TableUser.jsx

250 lines
10 KiB
React
Raw Normal View History

import React from "react";
import Select from "@mui/material/Select";
import TextField from "@mui/material/TextField";
import Typography from "@material-ui/core/Typography";
import Grid from "@material-ui/core/Grid";
import Table from "@material-ui/core/Table";
import TableBody from "@material-ui/core/TableBody";
import TableCell from "@material-ui/core/TableCell";
import TableContainer from "@material-ui/core/TableContainer";
import TableHead from "@material-ui/core/TableHead";
import TableRow from "@material-ui/core/TableRow";
import Paper from "@material-ui/core/Paper";
import Box from "@mui/material/Box";
import InputLabel from "@mui/material/InputLabel";
import MenuItem from "@mui/material/MenuItem";
import FormControl from "@mui/material/FormControl";
import Tooltip from "@mui/material/Tooltip";
import Zoom from "@mui/material/Zoom";
import CancelIcon from "@material-ui/icons/Cancel";
import CheckCircleIcon from "@material-ui/icons/CheckCircle";
import ErrorIcon from "@material-ui/icons/Error";
import RemoveCircleIcon from "@material-ui/icons/RemoveCircle";
import PowerSettingsNewIcon from "@material-ui/icons/PowerSettingsNew";
const TableUser = ({ classes, usersOnlineInfo, logout }) => {
const [search, setSearch] = React.useState("");
const [filterStatus, setFilterStatus] = React.useState(null);
const handleFilterChange = (event) => {
setFilterStatus(event.target.value);
};
const handlesearch = (event) => {
setSearch(event.target.value.toLowerCase());
};
return (
<Grid item xs={12}>
<Paper className={classes.cardPaperFix} sx={12} variant="outlined">
<Grid container sx={12} justifyContent="space-between" alignItems="baseline">
<Grid item sx={4}>
<Typography
component="h4"
variant="h6"
color="primary"
style={{ marginBottom: "16px" }}
>
Lista de Usuários
</Typography>
</Grid>
<Grid item sx={8} width="100%">
<Box sx={{ marginBottom: 2, display: "flex", gap: "12px" }}>
<TextField
id="outlined-basic"
label="Usuário"
variant="standard"
value={search}
onChange={handlesearch}
/>
<FormControl fullWidth variant="standard">
<InputLabel id="status">Status</InputLabel>
<Select
labelId="status"
id="status"
value={filterStatus}
label="Status"
onChange={handleFilterChange}
>
<MenuItem value={null}>Todos</MenuItem>
<MenuItem value={"online"}>Online</MenuItem>
<MenuItem value={"offline"}>Offline</MenuItem>
<MenuItem value={"not"}>Não entrou</MenuItem>
</Select>
</FormControl>
</Box>
</Grid>
</Grid>
<Grid container spacing={3} style={{ marginTop: "16px", marginBottom: "16px" }}>
<TableContainer component={Paper}>
<Table>
<TableHead>
<TableRow className={classes.tableRowHead}>
<TableCell>Nome</TableCell>
2022-08-08 21:06:48 +00:00
<TableCell>Em Atendimento/Finalizado(s)</TableCell>
2022-08-10 13:29:09 +00:00
<TableCell>abertos Por Fila</TableCell>
<TableCell>Fechados Por Fila</TableCell>
<TableCell>Tempo Online</TableCell>
<TableCell>Ações</TableCell>
</TableRow>
</TableHead>
2022-08-12 13:04:04 +00:00
{console.log(usersOnlineInfo)}
<TableBody style={{ overflowY: "scroll" }}>
2022-08-10 19:26:36 +00:00
{usersOnlineInfo &&
usersOnlineInfo
.filter((e) => {
if (filterStatus === null) return e;
if (filterStatus === "not") return !e.statusOnline;
return e.statusOnline && e.statusOnline.status === filterStatus;
})
.filter((e) => {
return e.name.toLowerCase().includes(search);
})
.sort((a) => {
if (a.statusOnline) {
if (a.statusOnline.status === "online") {
return -1;
}
return 0;
}
return 0;
})
.map((user, index) => (
<TableRow key={index} className={classes.tableRowBody}>
2022-08-08 21:06:48 +00:00
<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" }} />
)
) : (
2022-08-08 21:06:48 +00:00
<RemoveCircleIcon style={{ color: "black" }} />
)}
{user.name}
</Typography>
</TableCell>
2022-08-08 21:06:48 +00:00
<TableCell>
2022-08-10 19:26:36 +00:00
<div style={{ display: "flex", alignItems: "center", gap: "12px" }}>
<Typography className={classes.tableCounterOpen} title="Em Atendimento">
{user.sumOpen
? user.sumOpen.count !== ""
? user.sumOpen.count
: 0
: 0}
2022-08-08 21:06:48 +00:00
</Typography>
2022-08-10 19:26:36 +00:00
<Typography className={classes.tableCounterClosed} title="Finalzados">
{user.sumClosed
? user.sumClosed.count !== ""
? user.sumClosed.count
: 0
: 0}
2022-08-08 21:06:48 +00:00
</Typography>
</div>
</TableCell>
2022-08-08 21:06:48 +00:00
<TableCell>
2022-08-08 21:06:48 +00:00
<div
style={{
display: "flex",
flexWrap: "wrap",
alignItems: "center",
gap: "12px",
}}
>
2022-08-10 19:26:36 +00:00
{user.openClosedInQueue &&
user.openClosedInQueue.map((queue) => (
<Typography
key={queue.queueId}
className={classes.tableQueues}
title={queue.name}
style={{ backgroundColor: queue.color }}
>
2022-08-10 19:26:36 +00:00
{queue.countOpen ? queue.countOpen : "0"}
</Typography>
2022-08-10 19:26:36 +00:00
))}
<Typography
className={classes.tableQueues}
title="Sem Fila"
style={{ backgroundColor: "grey" }}
>
{user.openClosedOutQueue.countOpen === 0
? 0
: user.openClosedOutQueue.countOpen}
</Typography>
2022-08-08 21:06:48 +00:00
</div>
</TableCell>
<TableCell>
<div
style={{
display: "flex",
flexWrap: "wrap",
alignItems: "center",
gap: "12px",
}}
>
2022-08-10 19:26:36 +00:00
{user.openClosedInQueue &&
user.openClosedInQueue.map((queue) => (
<Typography
key={queue.queueId}
className={classes.tableQueues}
title={queue.name}
style={{ backgroundColor: queue.color }}
>
{queue.countClosed ? queue.countClosed : "0"}
</Typography>
))}
<Typography
className={classes.tableQueues}
title="Sem Fila"
style={{ backgroundColor: "grey" }}
>
2022-08-12 13:04:04 +00:00
{user.openClosedOutQueue.countClosed === 0
2022-08-10 19:26:36 +00:00
? 0
2022-08-12 13:04:04 +00:00
: user.openClosedOutQueue.countClosed}
2022-08-10 19:26:36 +00:00
</Typography>
2022-08-08 21:06:48 +00:00
</div>
</TableCell>
<TableCell>
{user.sumOnlineTime ? user.sumOnlineTime.sum : "Não entrou"}
</TableCell>
<TableCell>
{user.statusOnline && user.statusOnline.status === "online" ? (
<PowerSettingsNewIcon
style={{ color: "red", cursor: "pointer" }}
onClick={(e) => {
logout(user.id);
}}
/>
) : (
<PowerSettingsNewIcon
style={{ color: "grey", cursor: "not-allowed" }}
2022-08-10 19:26:36 +00:00
title="Agente Não Logado"
/>
)}
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
</Grid>
</Paper>
</Grid>
);
};
export default TableUser;