2024-04-29 13:00:51 +00:00
|
|
|
import React, { useContext, useReducer, useEffect, useState, useCallback } from "react"
|
2022-01-06 01:26:15 +00:00
|
|
|
|
2024-01-29 11:48:20 +00:00
|
|
|
import { addHours, addMinutes, addSeconds, intervalToDuration } from "date-fns"
|
2022-12-27 14:25:50 +00:00
|
|
|
|
2024-01-29 11:48:20 +00:00
|
|
|
import Paper from "@material-ui/core/Paper"
|
|
|
|
import Container from "@material-ui/core/Container"
|
|
|
|
import Grid from "@material-ui/core/Grid"
|
|
|
|
import { makeStyles } from "@material-ui/core/styles"
|
|
|
|
import Typography from "@material-ui/core/Typography"
|
|
|
|
import Tooltip from "@mui/material/Tooltip"
|
|
|
|
import Zoom from "@mui/material/Zoom"
|
|
|
|
import IconButton from "@mui/material/IconButton"
|
|
|
|
import Info from "@material-ui/icons/Info"
|
2024-04-29 13:00:51 +00:00
|
|
|
import SelectField from "../../components/Report/SelectField"
|
2022-01-06 01:26:15 +00:00
|
|
|
|
2024-01-29 11:48:20 +00:00
|
|
|
import { AuthContext } from "../../context/Auth/AuthContext"
|
2024-07-25 16:05:39 +00:00
|
|
|
import { i18n } from "../../translate/i18n";
|
2024-01-29 11:48:20 +00:00
|
|
|
import Chart from "./Chart"
|
2024-03-27 20:52:20 +00:00
|
|
|
import PieChart from "./PieChart"
|
2024-01-29 11:48:20 +00:00
|
|
|
import openSocket from "socket.io-client"
|
|
|
|
import api from "../../services/api"
|
2022-08-08 16:47:28 +00:00
|
|
|
|
2024-01-29 11:48:20 +00:00
|
|
|
import { Can } from "../../components/Can"
|
|
|
|
import TableUser from "../../components/DashboardUser/TableUser"
|
2022-08-02 21:07:19 +00:00
|
|
|
|
2022-08-01 19:33:24 +00:00
|
|
|
const useStyles = makeStyles((theme) => ({
|
|
|
|
container: {
|
|
|
|
paddingTop: theme.spacing(4),
|
|
|
|
paddingBottom: theme.spacing(4),
|
|
|
|
},
|
|
|
|
fixedHeightPaper: {
|
|
|
|
padding: theme.spacing(2),
|
|
|
|
display: "flex",
|
|
|
|
overflow: "auto",
|
|
|
|
flexDirection: "column",
|
2024-03-27 20:52:20 +00:00
|
|
|
height: 280,
|
2022-08-01 19:33:24 +00:00
|
|
|
},
|
|
|
|
customFixedHeightPaper: {
|
|
|
|
padding: theme.spacing(2),
|
|
|
|
display: "flex",
|
|
|
|
overflow: "auto",
|
|
|
|
flexDirection: "column",
|
|
|
|
height: 120,
|
|
|
|
},
|
|
|
|
customFixedHeightPaperLg: {
|
|
|
|
padding: theme.spacing(2),
|
|
|
|
display: "flex",
|
|
|
|
overflow: "auto",
|
|
|
|
flexDirection: "column",
|
|
|
|
height: "100%",
|
|
|
|
},
|
2022-08-03 14:10:08 +00:00
|
|
|
containerPaperFix: {
|
2022-08-03 17:11:40 +00:00
|
|
|
width: "100%",
|
2022-08-03 14:10:08 +00:00
|
|
|
textTransform: "capitalize",
|
|
|
|
padding: theme.spacing(2),
|
|
|
|
paddingBottom: theme.spacing(4),
|
|
|
|
height: "auto",
|
|
|
|
overflowY: "hidden",
|
|
|
|
},
|
2022-08-01 19:33:24 +00:00
|
|
|
cardPaperFix: {
|
|
|
|
textTransform: "capitalize",
|
2022-08-04 19:23:21 +00:00
|
|
|
paddingLeft: theme.spacing(4),
|
|
|
|
paddingRight: theme.spacing(4),
|
|
|
|
height: window.innerWidth <= 992 ? "500px" : "auto",
|
|
|
|
overflowY: "hidden",
|
2022-08-01 19:33:24 +00:00
|
|
|
},
|
|
|
|
cardStyleFix: {
|
|
|
|
display: "flex",
|
|
|
|
flexDirection: "row",
|
|
|
|
justifyContent: "left",
|
|
|
|
alignItems: "center",
|
|
|
|
gap: "32px",
|
|
|
|
},
|
|
|
|
logginBtn: {
|
|
|
|
position: "absolute",
|
|
|
|
bottom: "21px",
|
|
|
|
right: "21px",
|
|
|
|
fontSize: "12px",
|
|
|
|
},
|
2022-08-04 19:23:21 +00:00
|
|
|
tableRowHead: {
|
|
|
|
backgroundColor: "lightgrey",
|
|
|
|
},
|
|
|
|
tableRowBody: {
|
|
|
|
textAlign: "center",
|
|
|
|
" &:nth-child(even)": {
|
|
|
|
backgroundColor: "#f7f7f7",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
tableCounterOpen: {
|
|
|
|
color: "white",
|
|
|
|
backgroundColor: "green",
|
|
|
|
width: "25px",
|
|
|
|
textAlign: "center",
|
|
|
|
borderRadius: "5px",
|
|
|
|
},
|
|
|
|
tableCounterClosed: {
|
|
|
|
color: "white",
|
|
|
|
backgroundColor: "red",
|
|
|
|
width: "25px",
|
|
|
|
textAlign: "center",
|
|
|
|
borderRadius: "5px",
|
|
|
|
},
|
2022-08-09 19:45:44 +00:00
|
|
|
tableQueues: {
|
|
|
|
color: "white",
|
|
|
|
width: "25px",
|
|
|
|
textAlign: "center",
|
|
|
|
borderRadius: "5px",
|
|
|
|
},
|
2024-01-29 11:48:20 +00:00
|
|
|
}))
|
2022-08-08 16:47:28 +00:00
|
|
|
|
2022-12-27 14:25:50 +00:00
|
|
|
var _fifo
|
|
|
|
|
2024-03-27 20:52:20 +00:00
|
|
|
const sumOnlineTimeNow = (oldOnlineTimeSum) => {
|
2022-12-27 14:25:50 +00:00
|
|
|
|
|
|
|
let onlineTime = new Date()
|
|
|
|
|
2024-01-29 11:48:20 +00:00
|
|
|
if (!oldOnlineTimeSum.onlineTime) {
|
2022-12-27 21:19:24 +00:00
|
|
|
|
|
|
|
oldOnlineTimeSum.onlineTime = `${oldOnlineTimeSum.updatedAt.split(' ')[0]} 00:00:00`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-12-27 14:25:50 +00:00
|
|
|
onlineTime.setUTCHours(new Date(oldOnlineTimeSum.onlineTime).getHours())
|
|
|
|
onlineTime.setUTCMinutes(new Date(oldOnlineTimeSum.onlineTime).getMinutes())
|
|
|
|
onlineTime.setUTCSeconds(new Date(oldOnlineTimeSum.onlineTime).getSeconds())
|
|
|
|
|
|
|
|
|
|
|
|
let newtTime = intervalToDuration({ start: new Date(oldOnlineTimeSum.updatedAt), end: new Date() })
|
|
|
|
|
|
|
|
|
|
|
|
if (newtTime.hours && +newtTime.hours > 0) {
|
|
|
|
onlineTime = addHours(onlineTime, newtTime.hours)
|
|
|
|
}
|
|
|
|
if (newtTime.minutes && +newtTime.minutes > 0) {
|
|
|
|
onlineTime = addMinutes(onlineTime, newtTime.minutes)
|
|
|
|
}
|
|
|
|
if (newtTime.seconds && +newtTime.seconds > 0) {
|
|
|
|
onlineTime = addSeconds(onlineTime, newtTime.seconds)
|
|
|
|
}
|
|
|
|
|
2024-01-29 11:48:20 +00:00
|
|
|
const isoDate = new Date(onlineTime)
|
2022-12-27 21:19:24 +00:00
|
|
|
|
2024-03-27 20:52:20 +00:00
|
|
|
const newOnlinetime = isoDate.toJSON().slice(0, 19).replace('T', ' ')
|
2022-12-27 14:25:50 +00:00
|
|
|
|
|
|
|
return newOnlinetime
|
|
|
|
}
|
|
|
|
|
2022-08-08 16:47:28 +00:00
|
|
|
const reducer = (state, action) => {
|
2022-08-08 21:06:48 +00:00
|
|
|
if (action.type === "DELETE_USER_STATUS") {
|
2024-01-29 11:48:20 +00:00
|
|
|
const userId = action.payload
|
2022-08-08 16:47:28 +00:00
|
|
|
|
2024-01-29 11:48:20 +00:00
|
|
|
const userIndex = state.findIndex((u) => `${u.id}` === `${userId}`)
|
2022-08-08 16:47:28 +00:00
|
|
|
|
2022-08-08 21:06:48 +00:00
|
|
|
if (userIndex !== -1) {
|
2024-01-29 11:48:20 +00:00
|
|
|
state.splice(userIndex, 1)
|
2022-08-08 21:06:48 +00:00
|
|
|
}
|
2022-08-08 16:47:28 +00:00
|
|
|
|
2024-01-29 11:48:20 +00:00
|
|
|
return [...state]
|
2022-08-08 21:06:48 +00:00
|
|
|
}
|
2022-08-08 16:47:28 +00:00
|
|
|
|
2022-08-08 21:06:48 +00:00
|
|
|
if (action.type === "LOAD_QUERY") {
|
2024-01-29 11:48:20 +00:00
|
|
|
const queries = action.payload
|
|
|
|
const newQueries = []
|
2022-08-08 16:47:28 +00:00
|
|
|
|
2022-08-08 21:06:48 +00:00
|
|
|
queries.forEach((query) => {
|
2024-01-29 11:48:20 +00:00
|
|
|
const queryIndex = state.findIndex((q) => q.id === query.id)
|
2022-08-08 16:47:28 +00:00
|
|
|
|
2022-08-08 21:06:48 +00:00
|
|
|
if (queryIndex !== -1) {
|
2024-01-29 11:48:20 +00:00
|
|
|
state[queryIndex] = query
|
2022-08-08 21:06:48 +00:00
|
|
|
} else {
|
2024-01-29 11:48:20 +00:00
|
|
|
newQueries.push(query)
|
2022-08-08 21:06:48 +00:00
|
|
|
}
|
2024-01-29 11:48:20 +00:00
|
|
|
})
|
2022-08-08 16:47:28 +00:00
|
|
|
|
2024-01-29 11:48:20 +00:00
|
|
|
return [...state, ...newQueries]
|
2022-08-08 21:06:48 +00:00
|
|
|
}
|
2022-08-08 16:47:28 +00:00
|
|
|
|
2022-08-08 21:06:48 +00:00
|
|
|
if (action.type === "UPDATE_STATUS_ONLINE") {
|
2024-01-29 11:48:20 +00:00
|
|
|
let onlineUser = action.payload
|
|
|
|
let index = -1
|
2022-08-08 21:06:48 +00:00
|
|
|
|
2022-12-27 14:25:50 +00:00
|
|
|
// console.log('UPDATE_STATUS_ONLINE: ', onlineUser)
|
|
|
|
|
2024-01-29 11:48:20 +00:00
|
|
|
let onlySumOpenClosed = false
|
2022-08-08 21:06:48 +00:00
|
|
|
|
|
|
|
if (onlineUser.sumOpen || onlineUser.sumClosed) {
|
|
|
|
index = state.findIndex(
|
|
|
|
(e) =>
|
|
|
|
(onlineUser.sumOpen && e.id === onlineUser.sumOpen.userId) ||
|
|
|
|
(onlineUser.sumClosed && e.id === onlineUser.sumClosed.userId)
|
2024-01-29 11:48:20 +00:00
|
|
|
)
|
2022-08-08 21:06:48 +00:00
|
|
|
|
2024-01-29 11:48:20 +00:00
|
|
|
onlySumOpenClosed = true
|
2022-08-08 21:06:48 +00:00
|
|
|
} else {
|
2024-01-29 11:48:20 +00:00
|
|
|
index = state.findIndex((e) => `${e.id}` === `${onlineUser.userId}`)
|
2022-08-08 21:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (index !== -1) {
|
|
|
|
if (!onlySumOpenClosed) {
|
|
|
|
if (!("statusOnline" in state[index])) {
|
2024-01-29 11:48:20 +00:00
|
|
|
state[index].statusOnline = onlineUser
|
2022-08-08 21:06:48 +00:00
|
|
|
} else if ("statusOnline" in state[index]) {
|
2022-12-27 14:25:50 +00:00
|
|
|
|
2024-01-29 11:48:20 +00:00
|
|
|
state[index].statusOnline["status"] = onlineUser.status
|
2022-12-27 14:25:50 +00:00
|
|
|
|
2022-08-08 21:06:48 +00:00
|
|
|
}
|
|
|
|
}
|
2022-12-27 21:19:24 +00:00
|
|
|
|
2022-08-08 21:06:48 +00:00
|
|
|
|
|
|
|
if ("onlineTime" in onlineUser) {
|
2022-12-27 14:25:50 +00:00
|
|
|
|
2024-03-27 20:52:20 +00:00
|
|
|
if ("sumOnlineTime" in state[index]) {
|
2022-12-27 14:25:50 +00:00
|
|
|
|
2024-03-27 20:52:20 +00:00
|
|
|
state[index].sumOnlineTime.sum = onlineUser.onlineTime.split(" ")[1]
|
2022-12-27 14:25:50 +00:00
|
|
|
|
2022-12-27 21:19:24 +00:00
|
|
|
} else if (!("sumOnlineTime" in state[index])) {
|
2022-12-27 14:25:50 +00:00
|
|
|
|
2022-08-08 21:06:48 +00:00
|
|
|
state[index].sumOnlineTime = {
|
|
|
|
userId: onlineUser.userId,
|
|
|
|
sum: onlineUser.onlineTime.split(" ")[1],
|
2024-01-29 11:48:20 +00:00
|
|
|
}
|
2022-12-27 14:25:50 +00:00
|
|
|
|
2022-08-08 21:06:48 +00:00
|
|
|
}
|
|
|
|
}
|
2022-08-08 16:47:28 +00:00
|
|
|
|
2022-08-08 22:59:47 +00:00
|
|
|
if (onlineUser.sumOpen) {
|
|
|
|
if ("sumOpen" in state[index]) {
|
2024-01-29 11:48:20 +00:00
|
|
|
state[index].sumOpen["count"] = onlineUser.sumOpen.count
|
2022-08-08 22:59:47 +00:00
|
|
|
} else if (!("sumOpen" in state[index])) {
|
2024-01-29 11:48:20 +00:00
|
|
|
state[index].sumOpen = onlineUser.sumOpen
|
2022-08-08 22:59:47 +00:00
|
|
|
}
|
|
|
|
}
|
2022-08-08 16:47:28 +00:00
|
|
|
|
2022-08-08 22:59:47 +00:00
|
|
|
if (onlineUser.sumClosed) {
|
|
|
|
if ("sumClosed" in state[index]) {
|
2024-01-29 11:48:20 +00:00
|
|
|
state[index].sumClosed["count"] = onlineUser.sumClosed.count
|
2022-08-08 22:59:47 +00:00
|
|
|
} else if (!("sumClosed" in state[index])) {
|
2024-01-29 11:48:20 +00:00
|
|
|
state[index].sumClosed = onlineUser.sumClosed
|
2022-08-08 22:59:47 +00:00
|
|
|
}
|
|
|
|
}
|
2022-08-08 16:47:28 +00:00
|
|
|
|
2022-08-08 22:59:47 +00:00
|
|
|
if (onlineUser.openClosedInQueue) {
|
2024-01-29 11:48:20 +00:00
|
|
|
state[index].openClosedInQueue = onlineUser.openClosedInQueue
|
2022-08-08 22:59:47 +00:00
|
|
|
}
|
2022-08-08 21:06:48 +00:00
|
|
|
if (onlineUser.openClosedOutQueue) {
|
2024-01-29 11:48:20 +00:00
|
|
|
state[index].openClosedOutQueue = onlineUser.openClosedOutQueue
|
2022-08-08 21:06:48 +00:00
|
|
|
}
|
|
|
|
}
|
2024-01-29 11:48:20 +00:00
|
|
|
return [...state]
|
2022-08-08 21:06:48 +00:00
|
|
|
}
|
2022-08-08 16:47:28 +00:00
|
|
|
|
2022-08-08 21:06:48 +00:00
|
|
|
if (action.type === "RESET") {
|
2024-01-29 11:48:20 +00:00
|
|
|
return []
|
2022-08-08 21:06:48 +00:00
|
|
|
}
|
2024-01-29 11:48:20 +00:00
|
|
|
}
|
2022-08-08 16:47:28 +00:00
|
|
|
|
2022-01-06 01:26:15 +00:00
|
|
|
const Dashboard = () => {
|
2024-04-29 13:00:51 +00:00
|
|
|
const { user } = useContext(AuthContext)
|
2024-01-29 11:48:20 +00:00
|
|
|
const classes = useStyles()
|
|
|
|
const [usersOnlineInfo, dispatch] = useReducer(reducer, [])
|
|
|
|
const [ticketStatusChange, setStatus] = useState()
|
|
|
|
const [ticketsStatus, setTicktsStatus] = useState({ open: 0, openAll: 0, pending: 0, closed: 0 })
|
2024-03-28 17:12:30 +00:00
|
|
|
const [ticketStatusChatEnd, setTicketStatusChatEnd] = useState([])
|
2024-04-29 13:00:51 +00:00
|
|
|
|
2024-04-30 19:20:48 +00:00
|
|
|
const userQueueIds = user.queues?.map((q) => q.id);
|
2024-04-29 13:00:51 +00:00
|
|
|
const [selectedQueue, setSelectedQueue] = useState(userQueueIds || []);
|
2022-08-08 22:59:47 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
2024-01-29 11:48:20 +00:00
|
|
|
dispatch({ type: "RESET" })
|
|
|
|
}, [])
|
2022-08-08 22:59:47 +00:00
|
|
|
|
|
|
|
const handleLogouOnlineUser = async (userId) => {
|
|
|
|
try {
|
2024-01-29 11:48:20 +00:00
|
|
|
await api.get(`/users/logout/${userId}`)
|
2022-08-08 22:59:47 +00:00
|
|
|
//toast.success(("Desloged!"));
|
|
|
|
//handleDeleteRows(scheduleId)
|
|
|
|
} catch (err) {
|
|
|
|
// toastError(err);
|
|
|
|
}
|
2024-01-29 11:48:20 +00:00
|
|
|
}
|
2022-08-08 16:47:28 +00:00
|
|
|
|
2022-08-08 22:59:47 +00:00
|
|
|
useEffect(() => {
|
|
|
|
//setLoading(true);
|
2022-08-08 16:47:28 +00:00
|
|
|
|
2022-08-08 22:59:47 +00:00
|
|
|
const delayDebounceFn = setTimeout(() => {
|
|
|
|
// setLoading(true);
|
|
|
|
const fetchQueries = async () => {
|
|
|
|
try {
|
2024-01-29 11:48:20 +00:00
|
|
|
let date = new Date().toLocaleDateString("pt-BR").split("/")
|
|
|
|
let dateToday = `${date[2]}-${date[1]}-${date[0]}`
|
2024-03-27 20:52:20 +00:00
|
|
|
|
2022-12-27 14:25:50 +00:00
|
|
|
const { data } = await api.get("/reports/user/services", {
|
2024-04-29 13:00:51 +00:00
|
|
|
params: { userId: null, startDate: dateToday, endDate: dateToday, userQueues: selectedQueue },
|
2024-03-28 17:12:30 +00:00
|
|
|
})
|
2022-12-27 14:25:50 +00:00
|
|
|
|
2024-01-29 11:48:20 +00:00
|
|
|
dispatch({ type: "RESET" })
|
|
|
|
dispatch({ type: "LOAD_QUERY", payload: data.usersProfile })
|
2024-03-28 17:12:30 +00:00
|
|
|
|
2024-04-01 12:09:59 +00:00
|
|
|
const { data: ticketStatusChatEndData } = await api.get("/reports/count/statusChatEnd", {
|
2024-04-29 13:00:51 +00:00
|
|
|
params: { startDate: dateToday, endDate: dateToday, userQueues: selectedQueue },
|
2024-04-01 12:09:59 +00:00
|
|
|
})
|
2024-03-28 17:12:30 +00:00
|
|
|
|
|
|
|
setTicketStatusChatEnd(ticketStatusChatEndData.reportStatusChatEnd)
|
|
|
|
|
2022-08-08 22:59:47 +00:00
|
|
|
} catch (err) {
|
2022-12-27 14:25:50 +00:00
|
|
|
|
2022-08-08 22:59:47 +00:00
|
|
|
}
|
2024-01-29 11:48:20 +00:00
|
|
|
}
|
2022-08-08 16:47:28 +00:00
|
|
|
|
2024-01-29 11:48:20 +00:00
|
|
|
fetchQueries()
|
|
|
|
}, 500)
|
|
|
|
return () => clearTimeout(delayDebounceFn)
|
2024-04-29 13:00:51 +00:00
|
|
|
}, [selectedQueue])
|
2022-08-08 16:47:28 +00:00
|
|
|
|
2022-12-27 14:25:50 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
|
|
|
2022-12-27 21:19:24 +00:00
|
|
|
if (!usersOnlineInfo || usersOnlineInfo.length === 0) return
|
2022-12-27 14:25:50 +00:00
|
|
|
|
|
|
|
if (_fifo) {
|
2024-01-29 11:48:20 +00:00
|
|
|
clearInterval(_fifo)
|
2022-12-27 14:25:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_fifo = setInterval(() => {
|
|
|
|
|
2022-12-27 21:19:24 +00:00
|
|
|
for (let i = 0; i < usersOnlineInfo.length; i++) {
|
|
|
|
|
2024-01-29 11:48:20 +00:00
|
|
|
if (usersOnlineInfo[i].statusOnline && usersOnlineInfo[i].statusOnline.status === 'online') {
|
2022-12-27 14:25:50 +00:00
|
|
|
|
2024-01-29 11:48:20 +00:00
|
|
|
let onlineTimeCurrent = sumOnlineTimeNow({ onlineTime: usersOnlineInfo[i].statusOnline.onlineTime, updatedAt: usersOnlineInfo[i].statusOnline.updatedAt })
|
2024-03-27 20:52:20 +00:00
|
|
|
|
2024-01-29 11:48:20 +00:00
|
|
|
dispatch({ type: "UPDATE_STATUS_ONLINE", payload: { userId: usersOnlineInfo[i].id, status: usersOnlineInfo[i].statusOnline.status, onlineTime: onlineTimeCurrent } })
|
2022-12-27 14:25:50 +00:00
|
|
|
|
|
|
|
}
|
2022-12-27 21:19:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// usersOnlineInfo.map((e) => {
|
|
|
|
|
|
|
|
// if (e.statusOnline && e.statusOnline.status === 'online') {
|
|
|
|
|
|
|
|
// let onlineTimeCurrent = sumOnlineTimeNow({onlineTime: e.statusOnline.onlineTime, updatedAt: e.statusOnline.updatedAt})
|
|
|
|
|
|
|
|
// dispatch({ type: "UPDATE_STATUS_ONLINE", payload: { userId: e.id, status: e.statusOnline.status, onlineTime: onlineTimeCurrent } });
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// })
|
2022-12-27 14:25:50 +00:00
|
|
|
|
|
|
|
|
2024-01-29 11:48:20 +00:00
|
|
|
}, 3000)
|
2022-12-27 14:25:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
}, [usersOnlineInfo])
|
|
|
|
|
|
|
|
|
2022-08-08 22:59:47 +00:00
|
|
|
useEffect(() => {
|
2024-01-29 11:48:20 +00:00
|
|
|
const socket = openSocket(process.env.REACT_APP_BACKEND_URL)
|
2022-08-08 18:28:47 +00:00
|
|
|
|
2022-08-10 12:14:05 +00:00
|
|
|
socket.on("ticketStatus", (data) => {
|
2022-08-10 19:26:36 +00:00
|
|
|
if (data.action === "update") {
|
2024-01-29 11:48:20 +00:00
|
|
|
setStatus("")
|
|
|
|
setStatus(data.ticketStatus.status)
|
2022-08-08 22:59:47 +00:00
|
|
|
}
|
2024-01-29 11:48:20 +00:00
|
|
|
})
|
2022-08-08 16:47:28 +00:00
|
|
|
|
2022-08-08 22:59:47 +00:00
|
|
|
socket.on("onlineStatus", (data) => {
|
2024-03-27 20:52:20 +00:00
|
|
|
if (data.action === "logout" || data.action === "update") {
|
2024-01-29 11:48:20 +00:00
|
|
|
|
|
|
|
dispatch({ type: "UPDATE_STATUS_ONLINE", payload: data.userOnlineTime })
|
2022-08-08 22:59:47 +00:00
|
|
|
} else if (data.action === "delete") {
|
2024-01-29 11:48:20 +00:00
|
|
|
dispatch({ type: "DELETE_USER_STATUS", payload: data.userOnlineTime })
|
2022-08-08 22:59:47 +00:00
|
|
|
}
|
2024-01-29 11:48:20 +00:00
|
|
|
})
|
2022-08-08 16:47:28 +00:00
|
|
|
|
2022-08-08 22:59:47 +00:00
|
|
|
socket.on("user", (data) => {
|
|
|
|
if (data.action === "delete") {
|
2024-01-29 11:48:20 +00:00
|
|
|
dispatch({ type: "DELETE_USER", payload: +data.userId })
|
2022-08-08 22:59:47 +00:00
|
|
|
}
|
2024-01-29 11:48:20 +00:00
|
|
|
})
|
2022-08-08 16:47:28 +00:00
|
|
|
|
2022-08-08 22:59:47 +00:00
|
|
|
return () => {
|
2024-01-29 11:48:20 +00:00
|
|
|
socket.disconnect()
|
|
|
|
}
|
|
|
|
}, [])
|
2024-04-29 13:00:51 +00:00
|
|
|
|
|
|
|
const handleSelectedQueue = useCallback((queueSelected) => {
|
|
|
|
if(queueSelected !== 'All'){
|
|
|
|
const queueIndex = user?.queues?.findIndex((q) => q.id === parseInt(queueSelected));
|
|
|
|
const queueIds = []
|
|
|
|
queueIds.push(user?.queues[queueIndex]?.id);
|
|
|
|
setSelectedQueue(queueIds);
|
|
|
|
}else{
|
|
|
|
const queueIds = user?.queues?.map((queue) => queue.id);
|
|
|
|
setSelectedQueue(queueIds);
|
|
|
|
}
|
|
|
|
},[user, setSelectedQueue])
|
2022-08-08 22:59:47 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
2022-12-27 14:25:50 +00:00
|
|
|
if (ticketStatusChange === "") return
|
2022-08-08 22:59:47 +00:00
|
|
|
const delayDebounceFn = setTimeout(() => {
|
|
|
|
const fetchQueries = async () => {
|
|
|
|
try {
|
2024-01-29 11:48:20 +00:00
|
|
|
let date = new Date().toLocaleDateString("pt-BR").split("/")
|
|
|
|
let dateToday = `${date[2]}-${date[1]}-${date[0]}`
|
2022-08-08 22:59:47 +00:00
|
|
|
|
|
|
|
const _open = await api.get("/tickets/count", {
|
2024-04-29 13:00:51 +00:00
|
|
|
params: { status: "open", date: dateToday, queueIds: selectedQueue },
|
2024-01-29 11:48:20 +00:00
|
|
|
})
|
2022-08-08 22:59:47 +00:00
|
|
|
const _closed = await api.get("/tickets/count", {
|
2024-04-29 13:00:51 +00:00
|
|
|
params: { status: "closed", date: dateToday, queueIds: selectedQueue },
|
2024-01-29 11:48:20 +00:00
|
|
|
})
|
2022-08-08 22:59:47 +00:00
|
|
|
const _pending = await api.get("/tickets/count", {
|
2024-04-29 13:00:51 +00:00
|
|
|
params: { status: "pending", queueIds: selectedQueue },
|
2024-01-29 11:48:20 +00:00
|
|
|
})
|
2022-08-15 13:03:45 +00:00
|
|
|
|
|
|
|
const _openAll = await api.get("/tickets/count", {
|
2024-04-29 13:00:51 +00:00
|
|
|
params: { status: "open", queueIds: selectedQueue },
|
2024-01-29 11:48:20 +00:00
|
|
|
})
|
2022-08-16 19:33:40 +00:00
|
|
|
setTicktsStatus({
|
|
|
|
open: _open.data.count,
|
|
|
|
openAll: _openAll.data.count,
|
|
|
|
closed: _closed.data.count,
|
|
|
|
pending: _pending.data.count,
|
2024-01-29 11:48:20 +00:00
|
|
|
})
|
2022-08-16 19:33:40 +00:00
|
|
|
// setOpen(_open.data.count);
|
|
|
|
// setClosed(_closed.data.count);
|
|
|
|
// setPending(_pending.data.count);
|
2022-08-08 22:59:47 +00:00
|
|
|
} catch (err) {
|
2024-01-29 11:48:20 +00:00
|
|
|
console.log(err)
|
2022-08-08 22:59:47 +00:00
|
|
|
}
|
2024-01-29 11:48:20 +00:00
|
|
|
}
|
2022-08-08 16:47:28 +00:00
|
|
|
|
2024-01-29 11:48:20 +00:00
|
|
|
fetchQueries()
|
|
|
|
}, 500)
|
|
|
|
return () => clearTimeout(delayDebounceFn)
|
2024-04-29 13:00:51 +00:00
|
|
|
}, [ticketStatusChange, selectedQueue])
|
2022-08-08 16:47:28 +00:00
|
|
|
|
2022-08-01 19:33:24 +00:00
|
|
|
return (
|
|
|
|
<Can
|
|
|
|
role={user.profile}
|
|
|
|
perform="dashboard-view:show"
|
|
|
|
yes={() => (
|
2022-08-03 14:10:08 +00:00
|
|
|
<Container maxWidth="lg" className={classes.container}>
|
|
|
|
<Grid container spacing={3}>
|
|
|
|
<Paper className={classes.containerPaperFix} sx={12}>
|
|
|
|
<Grid item sx={4}>
|
|
|
|
<Typography
|
|
|
|
component="h1"
|
|
|
|
variant="h4"
|
|
|
|
color="primary"
|
|
|
|
style={{ marginBottom: "16px" }}
|
|
|
|
>
|
|
|
|
tickets
|
|
|
|
<Tooltip
|
2022-08-10 12:14:05 +00:00
|
|
|
title={`Os dados informados abaixo é baseado na data: ${new Date().toLocaleDateString(
|
|
|
|
"pt-BR",
|
|
|
|
{ timeZone: "UTC" }
|
|
|
|
)}`}
|
2022-08-03 14:10:08 +00:00
|
|
|
color="primary"
|
|
|
|
TransitionComponent={Zoom}
|
|
|
|
>
|
|
|
|
<IconButton>
|
|
|
|
<Info />
|
|
|
|
</IconButton>
|
|
|
|
</Tooltip>
|
|
|
|
</Typography>
|
2022-08-01 19:33:24 +00:00
|
|
|
</Grid>
|
2024-04-29 13:00:51 +00:00
|
|
|
<Grid style={{ display: 'flex', flexDirection: 'column', padding: '10px 0', alignItems: 'start' }}>
|
|
|
|
<SelectField
|
|
|
|
func={handleSelectedQueue}
|
|
|
|
textBoxFieldSelected={'All'}
|
|
|
|
emptyField={false}
|
2024-07-25 16:05:39 +00:00
|
|
|
header={i18n.t('dashboard.titles.selectQueues')}
|
2024-04-29 13:00:51 +00:00
|
|
|
currencies={user.queues.map((obj) => {
|
|
|
|
return { 'value': obj.id, 'label': obj.name }
|
|
|
|
})} />
|
|
|
|
</Grid>
|
2022-08-03 14:10:08 +00:00
|
|
|
<Grid container spacing={3}>
|
|
|
|
<Grid item xs={12} sm={6} md={6} lg={4}>
|
|
|
|
<Paper
|
|
|
|
className={classes.customFixedHeightPaper}
|
|
|
|
style={{ overflow: "hidden" }}
|
|
|
|
variant="outlined"
|
|
|
|
>
|
|
|
|
<Typography component="h3" variant="h6" color="primary" paragraph>
|
2024-07-25 16:05:39 +00:00
|
|
|
{i18n.t('dashboard.titles.waiting')}
|
2022-08-01 19:33:24 +00:00
|
|
|
</Typography>
|
2022-08-03 14:10:08 +00:00
|
|
|
<Grid item>
|
|
|
|
<Typography component="h1" variant="h4">
|
2022-08-16 19:33:40 +00:00
|
|
|
{ticketsStatus.pending}
|
2022-08-03 14:10:08 +00:00
|
|
|
</Typography>
|
|
|
|
</Grid>
|
|
|
|
</Paper>
|
|
|
|
</Grid>
|
|
|
|
<Grid item xs={12} sm={6} md={6} lg={4}>
|
|
|
|
<Paper
|
|
|
|
className={classes.customFixedHeightPaper}
|
|
|
|
style={{ overflow: "hidden" }}
|
|
|
|
variant="outlined"
|
|
|
|
>
|
2022-12-27 14:25:50 +00:00
|
|
|
<Typography component="h3" variant="h6" color="primary" style={{ marginBottom: "0" }} paragraph>
|
2024-07-25 16:05:39 +00:00
|
|
|
{i18n.t('dashboard.titles.inService')}
|
2022-08-01 19:33:24 +00:00
|
|
|
</Typography>
|
2022-12-27 14:25:50 +00:00
|
|
|
<Typography paragraph style={{ fontSize: "12px", margin: "0px" }}>Hoje/Todo Periodo</Typography>
|
2022-08-16 19:33:40 +00:00
|
|
|
|
2022-08-03 14:10:08 +00:00
|
|
|
<Grid item>
|
|
|
|
<Typography component="h1" variant="h4">
|
2022-08-16 19:33:40 +00:00
|
|
|
{ticketsStatus.open}/{ticketsStatus.openAll}
|
2022-08-03 14:10:08 +00:00
|
|
|
</Typography>
|
|
|
|
</Grid>
|
|
|
|
</Paper>
|
|
|
|
</Grid>
|
2022-08-16 19:33:40 +00:00
|
|
|
|
2022-08-03 14:10:08 +00:00
|
|
|
<Grid item xs={12} sm={6} md={6} lg={4}>
|
|
|
|
<Paper
|
|
|
|
className={classes.customFixedHeightPaper}
|
|
|
|
style={{ overflow: "hidden" }}
|
|
|
|
variant="outlined"
|
|
|
|
>
|
|
|
|
<Typography component="h3" variant="h6" color="primary" paragraph>
|
2022-08-16 19:33:40 +00:00
|
|
|
Fechados
|
2022-08-02 21:07:19 +00:00
|
|
|
</Typography>
|
2022-08-03 14:10:08 +00:00
|
|
|
<Grid item>
|
|
|
|
<Typography component="h1" variant="h4">
|
2022-08-16 19:33:40 +00:00
|
|
|
{ticketsStatus.closed}
|
2022-08-03 14:10:08 +00:00
|
|
|
</Typography>
|
|
|
|
</Grid>
|
|
|
|
</Paper>
|
|
|
|
</Grid>
|
2024-03-27 20:52:20 +00:00
|
|
|
<Grid item container spacing={3}>
|
|
|
|
<Grid item xs={12} sm={12} md={6} lg={6}>
|
|
|
|
<Paper className={classes.fixedHeightPaper} variant="outlined">
|
2024-04-29 13:00:51 +00:00
|
|
|
<Chart allTickets={usersOnlineInfo} selectedQueue = {selectedQueue}/>
|
2024-03-27 20:52:20 +00:00
|
|
|
</Paper>
|
|
|
|
</Grid>
|
|
|
|
<Grid item xs={12} sm={12} md={6} lg={6}>
|
|
|
|
<Paper className={classes.fixedHeightPaper} variant="outlined">
|
2024-03-28 17:12:30 +00:00
|
|
|
<PieChart data={ticketStatusChatEnd} />
|
2024-03-27 20:52:20 +00:00
|
|
|
</Paper>
|
|
|
|
</Grid>
|
2022-08-03 14:10:08 +00:00
|
|
|
</Grid>
|
2022-08-02 21:07:19 +00:00
|
|
|
</Grid>
|
2022-08-03 14:10:08 +00:00
|
|
|
</Paper>
|
2022-08-03 17:11:40 +00:00
|
|
|
<Paper className={classes.containerPaperFix} style={{ marginTop: "21px" }} sx={12}>
|
2022-08-03 14:10:08 +00:00
|
|
|
<Grid item sx={4}>
|
|
|
|
<Typography
|
|
|
|
component="h1"
|
|
|
|
variant="h4"
|
|
|
|
color="primary"
|
|
|
|
style={{ marginBottom: "16px" }}
|
|
|
|
>
|
2024-07-25 16:05:39 +00:00
|
|
|
{i18n.t('dashboard.titles.users')}
|
2022-08-03 14:10:08 +00:00
|
|
|
<Tooltip
|
2022-08-10 12:14:05 +00:00
|
|
|
title={`Os dados informados abaixo é baseado na data: ${new Date().toLocaleDateString(
|
|
|
|
"pt-BR",
|
|
|
|
{ timeZone: "UTC" }
|
|
|
|
)}`}
|
2022-08-03 14:10:08 +00:00
|
|
|
color="primary"
|
|
|
|
TransitionComponent={Zoom}
|
|
|
|
>
|
|
|
|
<IconButton>
|
|
|
|
<Info />
|
|
|
|
</IconButton>
|
|
|
|
</Tooltip>
|
|
|
|
</Typography>
|
2022-08-02 21:07:19 +00:00
|
|
|
</Grid>
|
2022-08-03 14:10:08 +00:00
|
|
|
<Grid container spacing={3}>
|
|
|
|
<Grid item xs={12} sm={6} md={6} lg={4}>
|
|
|
|
<Paper
|
|
|
|
className={classes.customFixedHeightPaper}
|
|
|
|
style={{ overflow: "hidden" }}
|
|
|
|
variant="outlined"
|
|
|
|
>
|
|
|
|
<Typography component="h3" variant="h6" color="primary" paragraph>
|
|
|
|
Total de Agentes
|
2022-08-02 21:07:19 +00:00
|
|
|
</Typography>
|
2022-08-03 14:10:08 +00:00
|
|
|
<Grid item>
|
|
|
|
<Typography component="h1" variant="h4">
|
|
|
|
{usersOnlineInfo.length}
|
|
|
|
</Typography>
|
|
|
|
</Grid>
|
|
|
|
</Paper>
|
|
|
|
</Grid>
|
|
|
|
<Grid item xs={12} sm={6} md={6} lg={4}>
|
|
|
|
<Paper
|
|
|
|
className={classes.customFixedHeightPaper}
|
|
|
|
style={{ overflow: "hidden" }}
|
|
|
|
variant="outlined"
|
2022-08-01 19:33:24 +00:00
|
|
|
>
|
2022-08-03 14:10:08 +00:00
|
|
|
<Typography component="h3" variant="h6" color="primary" paragraph>
|
|
|
|
Online
|
|
|
|
</Typography>
|
|
|
|
<Grid item>
|
|
|
|
<Typography component="h1" variant="h4">
|
|
|
|
{
|
|
|
|
usersOnlineInfo.filter(
|
|
|
|
(status) =>
|
|
|
|
status.statusOnline && status.statusOnline.status === "online"
|
|
|
|
).length
|
|
|
|
}
|
|
|
|
</Typography>
|
|
|
|
</Grid>
|
|
|
|
</Paper>
|
2022-08-01 19:33:24 +00:00
|
|
|
</Grid>
|
2022-08-03 14:10:08 +00:00
|
|
|
<Grid item xs={12} sm={6} md={6} lg={4}>
|
|
|
|
<Paper
|
|
|
|
className={classes.customFixedHeightPaper}
|
|
|
|
style={{ overflow: "hidden" }}
|
|
|
|
variant="outlined"
|
|
|
|
>
|
|
|
|
<Typography component="h3" variant="h6" color="primary" paragraph>
|
|
|
|
Offline
|
|
|
|
</Typography>
|
|
|
|
<Grid item>
|
|
|
|
<Typography component="h1" variant="h4">
|
|
|
|
{
|
|
|
|
usersOnlineInfo.filter(
|
|
|
|
(status) =>
|
|
|
|
!status.statusOnline || status.statusOnline.status === "offline"
|
|
|
|
).length
|
|
|
|
}
|
|
|
|
</Typography>
|
|
|
|
</Grid>
|
|
|
|
</Paper>
|
2022-08-01 19:33:24 +00:00
|
|
|
</Grid>
|
2022-08-09 19:45:44 +00:00
|
|
|
|
2022-12-27 21:19:24 +00:00
|
|
|
{usersOnlineInfo &&
|
|
|
|
<TableUser
|
|
|
|
classes={classes}
|
|
|
|
usersOnlineInfo={usersOnlineInfo}
|
|
|
|
logout={handleLogouOnlineUser}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-01 19:33:24 +00:00
|
|
|
</Grid>
|
|
|
|
</Paper>
|
2022-08-03 14:10:08 +00:00
|
|
|
</Grid>
|
|
|
|
</Container>
|
2022-08-01 19:33:24 +00:00
|
|
|
)}
|
|
|
|
/>
|
2024-01-29 11:48:20 +00:00
|
|
|
)
|
|
|
|
}
|
2022-01-06 01:26:15 +00:00
|
|
|
|
2024-01-29 11:48:20 +00:00
|
|
|
export default Dashboard
|