2022-05-16 02:48:06 +00:00
|
|
|
import React, { useState, useEffect, useReducer, useContext, useRef } from "react";
|
|
|
|
import MainContainer from "../../components/MainContainer";
|
|
|
|
import api from "../../services/api";
|
|
|
|
import SelectField from "../../components/Report/SelectField";
|
2022-02-11 12:54:22 +00:00
|
|
|
//import { data } from '../../components/Report/MTable/data';
|
2022-05-16 02:48:06 +00:00
|
|
|
import DatePicker1 from '../../components/Report/DatePicker'
|
|
|
|
import DatePicker2 from '../../components/Report/DatePicker'
|
|
|
|
import MTable from "../../components/Report/MTable";
|
2022-01-24 11:44:42 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import Box from '@mui/material/Box';
|
2022-01-27 00:33:16 +00:00
|
|
|
import { AuthContext } from "../../context/Auth/AuthContext";
|
|
|
|
import { Can } from "../../components/Can";
|
2022-01-24 11:44:42 +00:00
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
import { Button } from "@material-ui/core";
|
2022-04-18 14:12:49 +00:00
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
import ReportModal from "../../components/ReportModal";
|
|
|
|
import MaterialTable from 'material-table';
|
2022-05-16 03:33:09 +00:00
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
import LogoutIcon from '@material-ui/icons/CancelOutlined';
|
2022-04-18 14:12:49 +00:00
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
|
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
import { CSVLink } from "react-csv";
|
2022-04-18 14:12:49 +00:00
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
// import CircularProgress from '@mui/material/CircularProgress';
|
2022-04-18 14:12:49 +00:00
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
import openSocket from "socket.io-client";
|
2022-05-16 02:48:06 +00:00
|
|
|
|
|
|
|
const report = [{ 'value': '1', 'label': 'Atendimento por atendentes' }, { 'value': '2', 'label': 'Usuários online/offline' }]
|
2022-04-18 14:12:49 +00:00
|
|
|
|
|
|
|
let columns = [
|
|
|
|
{
|
2022-05-16 02:48:06 +00:00
|
|
|
key: 'ticket.whatsapp.name',
|
|
|
|
label: 'Loja',
|
|
|
|
|
2022-04-18 14:12:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2022-05-16 02:48:06 +00:00
|
|
|
key: 'id',
|
|
|
|
label: 'id Mensagem',
|
2022-04-18 14:12:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2022-05-16 02:48:06 +00:00
|
|
|
key: 'ticket.id',
|
|
|
|
label: 'id Conversa',
|
2022-04-18 14:12:49 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2022-05-16 02:48:06 +00:00
|
|
|
key: 'ticket.contact.name',
|
|
|
|
label: 'Cliente',
|
|
|
|
},
|
|
|
|
|
2022-04-18 14:12:49 +00:00
|
|
|
{
|
2022-05-16 02:48:06 +00:00
|
|
|
key: 'ticket.user.name',
|
|
|
|
label: 'Atendente',
|
|
|
|
},
|
2022-04-18 14:12:49 +00:00
|
|
|
{
|
2022-05-16 02:48:06 +00:00
|
|
|
key: 'body',
|
|
|
|
label: 'Mensagem',
|
2022-04-18 14:12:49 +00:00
|
|
|
},
|
|
|
|
{
|
2022-05-16 02:48:06 +00:00
|
|
|
key: 'fromMe',
|
|
|
|
label: 'Sentido',
|
2022-04-18 14:12:49 +00:00
|
|
|
},
|
|
|
|
{
|
2022-05-16 02:48:06 +00:00
|
|
|
key: 'createdAt',
|
|
|
|
label: 'Criada',
|
2022-04-18 14:12:49 +00:00
|
|
|
},
|
|
|
|
{
|
2022-05-16 02:48:06 +00:00
|
|
|
key: 'ticket.contact.number',
|
|
|
|
label: 'Telefone cliente',
|
2022-04-18 14:12:49 +00:00
|
|
|
},
|
|
|
|
{
|
2022-05-16 02:48:06 +00:00
|
|
|
key: 'ticket.queue.name',
|
|
|
|
label: 'Fila',
|
2022-04-18 14:12:49 +00:00
|
|
|
},
|
2022-05-16 02:48:06 +00:00
|
|
|
{
|
|
|
|
key: 'ticket.status',
|
|
|
|
label: 'Status',
|
2022-05-19 21:29:38 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'ticket.statusChatEnd',
|
2022-07-28 17:55:23 +00:00
|
|
|
label: 'Status de encerramento',
|
2022-05-19 21:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
]
|
2022-04-18 14:12:49 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
2022-01-25 14:24:05 +00:00
|
|
|
|
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const reducerQ = (state, action) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (action.type === "DELETE_USER_STATUS") {
|
|
|
|
|
|
|
|
const userId = action.payload;
|
|
|
|
|
2022-05-16 03:33:09 +00:00
|
|
|
//console.log('Entrou no delete user status userId: ', userId)
|
2022-05-16 02:48:06 +00:00
|
|
|
|
|
|
|
const userIndex = state.findIndex((u) => `${u.id}` === `${userId}`);
|
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
// console.log('>>>>>>>>>>>>>>>>>>>>> userIndex: ', userIndex)
|
2022-05-16 02:48:06 +00:00
|
|
|
|
|
|
|
if (userIndex !== -1) {
|
|
|
|
state.splice(userIndex, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return [...state];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (action.type === 'LOAD_QUERY') {
|
|
|
|
|
|
|
|
const queries = action.payload
|
2022-01-25 14:24:05 +00:00
|
|
|
const newQueries = []
|
|
|
|
|
|
|
|
queries.forEach((query) => {
|
2022-05-16 02:48:06 +00:00
|
|
|
|
2022-01-25 14:24:05 +00:00
|
|
|
const queryIndex = state.findIndex((q) => q.id === query.id)
|
2022-05-16 02:48:06 +00:00
|
|
|
|
|
|
|
if (queryIndex !== -1) {
|
2022-01-25 14:24:05 +00:00
|
|
|
state[queryIndex] = query
|
|
|
|
}
|
2022-05-16 02:48:06 +00:00
|
|
|
else {
|
2022-01-25 14:24:05 +00:00
|
|
|
newQueries.push(query)
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
return [...state, ...newQueries]
|
|
|
|
}
|
2022-05-16 02:48:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (action.type === "UPDATE_STATUS_ONLINE") {
|
|
|
|
|
|
|
|
let onlineUser = action.payload
|
|
|
|
let index = -1
|
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
// console.log('sssssssssstate: ', state, ' | ONLINE USERS: onlineUser.userId ', onlineUser.userId)
|
2022-05-16 02:48:06 +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)))
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
index = state.findIndex((e) => `${e.id}` === `${onlineUser.userId}`)
|
|
|
|
}
|
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
//console.log(' *********************** index: ', index)
|
2022-05-16 02:48:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (index !== -1) {
|
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
// console.log('ENTROU NO INDEX')
|
2022-05-16 02:48:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
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]) {
|
2022-07-28 17:55:23 +00:00
|
|
|
// console.log(' >>>>>>>>>>>>>>>>>> sumOpen 1 | state[index].sumOpen["count"]: ', state[index].sumOpen['count'], ' | onlineUser.sumOpen.count: ', onlineUser.sumOpen.count)
|
2022-05-16 02:48:06 +00:00
|
|
|
state[index].sumOpen['count'] = onlineUser.sumOpen.count
|
|
|
|
} else if (!("sumOpen" in state[index])) {
|
2022-07-28 17:55:23 +00:00
|
|
|
// console.log(' >>>>>>>>>>>>>>>>>> sumOpen 1')
|
2022-05-16 02:48:06 +00:00
|
|
|
state[index].sumOpen = onlineUser.sumOpen
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (onlineUser.sumClosed) {
|
|
|
|
|
|
|
|
if ("sumClosed" in state[index]) {
|
2022-07-28 17:55:23 +00:00
|
|
|
// console.log(' >>>>>>>>>>>>>>>>>> sumClosed 1 | state[index].sumClosed["count"]: ', state[index].sumClosed['count'], ' | onlineUser.sumClosed.count: ', onlineUser.sumClosed.count)
|
2022-05-16 02:48:06 +00:00
|
|
|
state[index].sumClosed['count'] = onlineUser.sumClosed.count
|
|
|
|
} else if (!("sumClosed" in state[index])) {
|
2022-07-28 17:55:23 +00:00
|
|
|
// console.log(' >>>>>>>>>>>>>>>>>> sumOpen 1')
|
2022-05-16 02:48:06 +00:00
|
|
|
state[index].sumClosed = onlineUser.sumClosed
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
return [...state]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-01-25 14:24:05 +00:00
|
|
|
if (action.type === "RESET") {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-01-24 11:44:42 +00:00
|
|
|
const reducer = (state, action) => {
|
2022-05-16 02:48:06 +00:00
|
|
|
|
2022-01-24 11:44:42 +00:00
|
|
|
if (action.type === "LOAD_USERS") {
|
|
|
|
const users = action.payload;
|
|
|
|
const newUsers = [];
|
|
|
|
|
|
|
|
users.forEach((user) => {
|
|
|
|
const userIndex = state.findIndex((u) => u.id === user.id);
|
|
|
|
if (userIndex !== -1) {
|
|
|
|
state[userIndex] = user;
|
|
|
|
} else {
|
|
|
|
newUsers.push(user);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return [...state, ...newUsers];
|
2022-05-16 02:48:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === "DELETE_USER") {
|
|
|
|
const userId = action.payload;
|
|
|
|
|
|
|
|
const userIndex = state.findIndex((u) => u.id === userId);
|
|
|
|
if (userIndex !== -1) {
|
|
|
|
state.splice(userIndex, 1);
|
|
|
|
}
|
|
|
|
return [...state];
|
|
|
|
}
|
2022-01-24 11:44:42 +00:00
|
|
|
|
|
|
|
if (action.type === "RESET") {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
|
2022-01-24 11:44:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
function Item(props) {
|
|
|
|
const { sx, ...other } = props;
|
|
|
|
return (
|
|
|
|
<Box
|
|
|
|
sx={{
|
|
|
|
bgcolor: (theme) => (theme.palette.mode === 'dark' ? '#101010' : '#fff'),
|
|
|
|
color: (theme) => (theme.palette.mode === 'dark' ? 'grey.300' : 'grey.800'),
|
|
|
|
border: '1px solid',
|
|
|
|
borderColor: (theme) =>
|
|
|
|
theme.palette.mode === 'dark' ? 'grey.800' : 'grey.300',
|
|
|
|
p: 1,
|
|
|
|
m: 1,
|
|
|
|
borderRadius: 2,
|
|
|
|
fontSize: '0.875rem',
|
|
|
|
fontWeight: '700',
|
|
|
|
...sx,
|
|
|
|
}}
|
|
|
|
{...other}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Item.propTypes = {
|
|
|
|
sx: PropTypes.oneOfType([
|
|
|
|
PropTypes.arrayOf(
|
|
|
|
PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool]),
|
|
|
|
),
|
|
|
|
PropTypes.func,
|
|
|
|
PropTypes.object,
|
|
|
|
]),
|
2022-05-16 02:48:06 +00:00
|
|
|
};
|
|
|
|
|
2022-01-24 11:44:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
let columnsData = [
|
2022-05-16 02:48:06 +00:00
|
|
|
{ title: 'Unidade', field: 'whatsapp.name' },
|
|
|
|
{ title: 'Atendente', field: 'user.name' },
|
|
|
|
{ title: 'Contato', field: 'contact.number' },
|
|
|
|
{ title: 'Nome', field: 'contact.name' },
|
|
|
|
{ title: 'Assunto', field: 'queue.name' },
|
2022-05-19 21:29:38 +00:00
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
{ title: 'Status', field: 'status' },
|
2022-07-28 17:55:23 +00:00
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
{ title: 'Criado', field: 'createdAt' },
|
2022-05-19 21:29:38 +00:00
|
|
|
//{title: 'Atualizado', field: 'updatedAt'},
|
2022-07-28 17:55:23 +00:00
|
|
|
{ title: 'Status de encerramento', field: 'statusChatEnd' }];
|
2022-05-16 02:48:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
const Report = () => {
|
|
|
|
|
|
|
|
const csvLink = useRef()
|
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
const { user: userA } = useContext(AuthContext);
|
2022-01-24 11:44:42 +00:00
|
|
|
|
|
|
|
//--------
|
2022-02-11 12:54:22 +00:00
|
|
|
const [searchParam] = useState("");
|
2022-07-28 17:55:23 +00:00
|
|
|
|
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
const [hasMore, setHasMore] = useState(false);
|
|
|
|
const [pageNumberTickets, setTicketsPageNumber] = useState(1);
|
|
|
|
const [totalCountTickets, setTotalCountTickets] = useState(0);
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
const [pageNumber, setPageNumber] = useState(1);
|
|
|
|
const [users, dispatch] = useReducer(reducer, []);
|
2022-02-11 12:54:22 +00:00
|
|
|
//const [columns, setColums] = useState([])
|
2022-05-16 02:48:06 +00:00
|
|
|
const [startDate, setDatePicker1] = useState(new Date())
|
|
|
|
const [endDate, setDatePicker2] = useState(new Date())
|
|
|
|
const [userId, setUser] = useState(null)
|
2022-01-25 14:24:05 +00:00
|
|
|
const [query, dispatchQ] = useReducer(reducerQ, [])
|
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
const [dataCSV, setDataCSV] = useState([])
|
2022-04-18 14:12:49 +00:00
|
|
|
const [isMount, setIsMount] = useState(true);
|
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
const [reportOption, setReport] = useState('1')
|
|
|
|
const [reporList,] = useState(report)
|
|
|
|
const [profile, setProfile] = useState('')
|
|
|
|
const [dataRows, setData] = useState([]);
|
2022-07-28 17:55:23 +00:00
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2022-01-24 11:44:42 +00:00
|
|
|
useEffect(() => {
|
2022-05-16 02:48:06 +00:00
|
|
|
dispatch({ type: "RESET" });
|
2022-01-25 14:24:05 +00:00
|
|
|
dispatchQ({ type: "RESET" })
|
2022-07-28 17:55:23 +00:00
|
|
|
setTicketsPageNumber(1)
|
2022-01-24 11:44:42 +00:00
|
|
|
setPageNumber(1);
|
2022-05-16 02:48:06 +00:00
|
|
|
}, [searchParam, profile]);
|
|
|
|
|
|
|
|
|
2022-01-24 11:44:42 +00:00
|
|
|
|
|
|
|
useEffect(() => {
|
2022-02-11 12:54:22 +00:00
|
|
|
//setLoading(true);
|
2022-01-25 21:54:46 +00:00
|
|
|
|
2022-01-24 11:44:42 +00:00
|
|
|
const delayDebounceFn = setTimeout(() => {
|
2022-01-25 14:24:05 +00:00
|
|
|
|
2022-01-24 11:44:42 +00:00
|
|
|
const fetchUsers = async () => {
|
|
|
|
try {
|
2022-05-16 02:48:06 +00:00
|
|
|
|
2022-05-16 03:33:09 +00:00
|
|
|
//console.log('profile: ', profile)
|
2022-05-16 02:48:06 +00:00
|
|
|
|
2022-01-24 11:44:42 +00:00
|
|
|
const { data } = await api.get("/users/", {
|
2022-05-16 02:48:06 +00:00
|
|
|
params: { searchParam, pageNumber, profile },
|
|
|
|
});
|
|
|
|
|
2022-01-24 11:44:42 +00:00
|
|
|
dispatch({ type: "LOAD_USERS", payload: data.users });
|
2022-02-11 12:54:22 +00:00
|
|
|
//setHasMore(data.hasMore);
|
2022-05-16 02:48:06 +00:00
|
|
|
//setLoading(false);
|
|
|
|
|
|
|
|
|
2022-01-24 11:44:42 +00:00
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
|
|
|
}
|
|
|
|
};
|
2022-01-25 14:24:05 +00:00
|
|
|
|
2022-01-24 11:44:42 +00:00
|
|
|
fetchUsers();
|
2022-01-25 14:24:05 +00:00
|
|
|
|
2022-01-24 11:44:42 +00:00
|
|
|
}, 500);
|
|
|
|
return () => clearTimeout(delayDebounceFn);
|
2022-05-16 02:48:06 +00:00
|
|
|
}, [searchParam, pageNumber, reportOption, profile]);
|
|
|
|
|
2022-01-24 11:44:42 +00:00
|
|
|
|
|
|
|
|
2022-01-25 14:24:05 +00:00
|
|
|
useEffect(() => {
|
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
//setLoading(true);
|
2022-01-25 14:24:05 +00:00
|
|
|
|
|
|
|
const delayDebounceFn = setTimeout(() => {
|
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
setLoading(true);
|
2022-01-25 14:24:05 +00:00
|
|
|
const fetchQueries = async () => {
|
|
|
|
try {
|
2022-01-25 21:54:46 +00:00
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
if (reportOption === '1') {
|
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
const { data } = await api.get("/reports/", { params: { userId, startDate, endDate, pageNumber: pageNumberTickets }, });
|
2022-05-16 02:48:06 +00:00
|
|
|
|
2022-07-28 21:21:14 +00:00
|
|
|
// console.log('dataQuery: ', data)
|
|
|
|
// console.log('pageNumberTickets: ', pageNumberTickets)
|
2022-01-25 14:24:05 +00:00
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
// dispatchQ({ type: "RESET" })
|
|
|
|
dispatchQ({ type: "LOAD_QUERY", payload: data.tickets });
|
|
|
|
|
|
|
|
setHasMore(data.hasMore);
|
|
|
|
setTotalCountTickets(data.count)
|
|
|
|
setLoading(false);
|
2022-01-25 14:24:05 +00:00
|
|
|
|
2022-04-18 14:12:49 +00:00
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
}
|
|
|
|
else if (reportOption === '2') {
|
|
|
|
|
|
|
|
const dataQuery = await api.get("/reports/user/services", { params: { userId, startDate, endDate }, });
|
|
|
|
dispatchQ({ type: "RESET" })
|
|
|
|
dispatchQ({ type: "LOAD_QUERY", payload: dataQuery.data });
|
|
|
|
|
|
|
|
//setLoading(false);
|
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
// console.log('REPORT 2 dataQuery : ', dataQuery.data)
|
2022-05-16 02:48:06 +00:00
|
|
|
|
2022-05-16 03:33:09 +00:00
|
|
|
//console.log()
|
2022-05-16 02:48:06 +00:00
|
|
|
|
|
|
|
}
|
2022-04-17 21:02:15 +00:00
|
|
|
|
2022-01-25 14:24:05 +00:00
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
fetchQueries();
|
2022-01-24 11:44:42 +00:00
|
|
|
|
2022-01-25 14:24:05 +00:00
|
|
|
}, 500);
|
|
|
|
return () => clearTimeout(delayDebounceFn);
|
2022-01-24 11:44:42 +00:00
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
}, [userId, startDate, endDate, reportOption, pageNumberTickets, totalCountTickets]);
|
2022-05-16 02:48:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Get from child 1
|
|
|
|
const datePicker1Value = (data) => {
|
2022-01-24 11:44:42 +00:00
|
|
|
|
|
|
|
setDatePicker1(data)
|
2022-05-16 02:48:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get from child 2
|
|
|
|
const datePicker2Value = (data) => {
|
2022-01-24 11:44:42 +00:00
|
|
|
|
|
|
|
setDatePicker2(data)
|
2022-05-16 02:48:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get from child 3
|
|
|
|
const textFieldSelectUser = (data) => {
|
2022-01-24 11:44:42 +00:00
|
|
|
|
|
|
|
setUser(data)
|
2022-05-16 02:48:06 +00:00
|
|
|
}
|
2022-04-18 14:12:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
// Get from report option
|
|
|
|
const reportValue = (data) => {
|
2022-04-18 14:12:49 +00:00
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
setReport(data)
|
2022-04-18 14:12:49 +00:00
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
// console.log(' data: ', data)
|
2022-05-16 02:48:06 +00:00
|
|
|
}
|
2022-04-18 14:12:49 +00:00
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
useEffect(() => {
|
2022-04-18 14:12:49 +00:00
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
if (reportOption === '1') {
|
|
|
|
setProfile('')
|
|
|
|
}
|
|
|
|
else if (reportOption === '2') {
|
|
|
|
setProfile('user')
|
|
|
|
}
|
2022-04-18 14:12:49 +00:00
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
}, [reportOption])
|
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
const handleCSVMessages = () => {
|
2022-05-16 02:48:06 +00:00
|
|
|
|
|
|
|
const fetchQueries = async () => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const dataQuery = await api.get("/reports/messages", { params: { userId, startDate, endDate }, });
|
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
console.log('dataQuery messages: ', dataQuery.data)
|
2022-05-16 02:48:06 +00:00
|
|
|
|
|
|
|
if (dataQuery.data.length > 0) {
|
|
|
|
|
|
|
|
let dataCSVFormat = dataQuery.data;
|
|
|
|
|
|
|
|
for (var i = 0; i < dataCSVFormat.length; i++) {
|
|
|
|
if (dataCSVFormat[i].fromMe) {
|
|
|
|
dataCSVFormat[i].fromMe = 'Atendente'
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dataCSVFormat[i].fromMe = 'Cliente'
|
|
|
|
}
|
2022-07-28 17:55:23 +00:00
|
|
|
}
|
2022-05-16 02:48:06 +00:00
|
|
|
|
|
|
|
setDataCSV(dataCSVFormat)
|
2022-07-28 17:55:23 +00:00
|
|
|
setIsMount(false);
|
|
|
|
}
|
2022-05-16 02:48:06 +00:00
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
|
|
|
}
|
|
|
|
};
|
2022-04-18 14:12:49 +00:00
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
fetchQueries();
|
2022-04-18 14:12:49 +00:00
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
|
|
if (isMount) {
|
|
|
|
return;
|
2022-04-18 14:12:49 +00:00
|
|
|
}
|
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
csvLink.current.link.click()
|
2022-04-18 14:12:49 +00:00
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
}, [dataCSV, isMount, csvLink]);
|
2022-04-18 14:12:49 +00:00
|
|
|
|
|
|
|
|
2022-04-18 18:21:28 +00:00
|
|
|
|
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
useEffect(() => {
|
2022-04-18 14:12:49 +00:00
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
if (reportOption === '2') {
|
|
|
|
|
|
|
|
const socket = openSocket(process.env.REACT_APP_BACKEND_URL);
|
|
|
|
|
|
|
|
socket.on("onlineStatus", (data) => {
|
|
|
|
|
|
|
|
// setLoading(true);
|
|
|
|
|
|
|
|
|
|
|
|
let date = new Date().toLocaleDateString('pt-BR').split('/')
|
|
|
|
let dateToday = `${date[2]}-${date[1]}-${date[0]}`
|
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
// console.log('date: ', new Date(startDate).toLocaleDateString('pt-BR'))
|
|
|
|
// console.log('date2: ', startDate)
|
2022-05-16 02:48:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (data.action === "logout" || (data.action === "update" &&
|
|
|
|
((`${startDate}` === `${endDate}`) && (`${endDate}` === `${dateToday}`) && (`${startDate}` === `${dateToday}`)))) {
|
|
|
|
|
2022-05-16 03:33:09 +00:00
|
|
|
//console.log('UPDATE FROM ONLINE/OFFLINE LOGED USERS: ', data.userOnlineTime, ' | data.action : ', data.action)
|
2022-05-16 02:48:06 +00:00
|
|
|
|
|
|
|
dispatchQ({ type: "UPDATE_STATUS_ONLINE", payload: data.userOnlineTime });
|
|
|
|
|
|
|
|
}
|
|
|
|
else if (data.action === "delete") {
|
|
|
|
dispatchQ({ type: "DELETE_USER_STATUS", payload: data.userOnlineTime });
|
|
|
|
}
|
|
|
|
|
|
|
|
// setLoading(false);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.on("user", (data) => {
|
|
|
|
|
|
|
|
if (data.action === "delete") {
|
2022-07-28 17:55:23 +00:00
|
|
|
// console.log(' entrou no delete user: ', data)
|
2022-05-16 02:48:06 +00:00
|
|
|
dispatch({ type: "DELETE_USER", payload: +data.userId });
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
socket.disconnect();
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2022-07-28 17:55:23 +00:00
|
|
|
else if (reportOption === "1") {
|
|
|
|
dispatchQ({ type: "RESET" })
|
|
|
|
setTicketsPageNumber(1)
|
|
|
|
}
|
2022-05-16 02:48:06 +00:00
|
|
|
|
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
}, [reportOption, startDate, endDate, userId]);
|
2022-05-16 02:48:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
// const handleDeleteRows = (id) => {
|
|
|
|
|
|
|
|
// let _data = [...dataRows];
|
|
|
|
|
|
|
|
// _data.forEach(rd => {
|
|
|
|
// _data = _data.filter(t => t.id !== id);
|
|
|
|
// });
|
|
|
|
// setData(_data);
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
|
|
//if (!loading) {
|
2022-04-18 14:12:49 +00:00
|
|
|
|
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
// setData(query.map(({ scheduleReminder, ...others }) => (
|
|
|
|
// { ...others, 'scheduleReminder': `${others.statusChatEndId}` === '3' ? 'Agendamento' : 'Lembrete' }
|
|
|
|
// )))
|
|
|
|
// }
|
2022-01-25 14:24:05 +00:00
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
setData(query.map((column) => { return { ...column } }))
|
|
|
|
|
|
|
|
}, [query])
|
|
|
|
|
|
|
|
const handleLogouOnlineUser = async (userId) => {
|
|
|
|
try {
|
|
|
|
await api.get(`/users/logout/${userId}`);
|
|
|
|
//toast.success(("Desloged!"));
|
|
|
|
//handleDeleteRows(scheduleId)
|
|
|
|
} catch (err) {
|
|
|
|
// toastError(err);
|
|
|
|
}
|
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const loadMore = () => {
|
|
|
|
setTicketsPageNumber((prevState) => prevState + 1);
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleScroll = (e) => {
|
|
|
|
|
|
|
|
if (!hasMore || loading) return;
|
|
|
|
|
|
|
|
const { scrollTop, scrollHeight, clientHeight } = e.currentTarget;
|
|
|
|
|
|
|
|
// console.log('scrollTop: ', scrollTop,
|
|
|
|
// ' | scrollHeight: ', scrollHeight,
|
|
|
|
// ' | clientHeight: ', clientHeight,
|
|
|
|
// ' | scrollHeight - (scrollTop + 1): ', scrollHeight - (scrollTop + 1))
|
|
|
|
|
|
|
|
if (scrollHeight - (scrollTop + 1) < clientHeight) {
|
|
|
|
|
|
|
|
loadMore();
|
|
|
|
|
|
|
|
// e.currentTarget.scrollTo(0, 200);
|
|
|
|
}
|
2022-05-16 02:48:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
2022-01-25 14:24:05 +00:00
|
|
|
|
2022-01-27 00:33:16 +00:00
|
|
|
<Can
|
2022-05-16 02:48:06 +00:00
|
|
|
role={userA.profile}
|
|
|
|
perform="ticket-report:show"
|
|
|
|
yes={() => (
|
|
|
|
|
|
|
|
<MainContainer>
|
|
|
|
<Box sx={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)' }}>
|
|
|
|
|
|
|
|
<Item><SelectField func={textFieldSelectUser} emptyField={true} header={'Usuário'} currencies={users.map((obj) => {
|
|
|
|
return { 'value': obj.id, 'label': obj.name }
|
|
|
|
})} /></Item>
|
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
<Item><DatePicker1 func={datePicker1Value} minDate={false} startEmpty={false} title={'Data inicio'} /></Item>
|
2022-05-16 02:48:06 +00:00
|
|
|
<Item><DatePicker2 func={datePicker2Value} minDate={false} startEmpty={false} title={'Data fim'} /></Item>
|
|
|
|
|
2022-05-16 03:33:09 +00:00
|
|
|
<Item sx={{ display: 'grid', gridColumn: '4 / 5', }}>
|
2022-04-18 14:12:49 +00:00
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
<ReportModal currencies={reporList} func={reportValue} reportOption={reportOption} />
|
|
|
|
|
2022-05-16 03:33:09 +00:00
|
|
|
<div style={{ margin: '2px' }}></div>
|
|
|
|
|
|
|
|
{reportOption === '1' &&
|
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
<div>
|
|
|
|
<Button style={{display: "none"}}
|
2022-07-20 15:34:12 +00:00
|
|
|
variant="contained"
|
2022-05-16 03:33:09 +00:00
|
|
|
color="primary"
|
2022-07-28 17:55:23 +00:00
|
|
|
onClick={(e) => {
|
|
|
|
handleCSVMessages()
|
|
|
|
}}
|
2022-05-16 03:33:09 +00:00
|
|
|
>
|
|
|
|
{"CSV ALL"}
|
2022-07-28 17:55:23 +00:00
|
|
|
</Button>
|
2022-05-16 03:33:09 +00:00
|
|
|
|
|
|
|
<div>
|
|
|
|
<CSVLink
|
|
|
|
data={dataCSV}
|
|
|
|
headers={columns}
|
|
|
|
filename={'Relatorio_detalhado_atendimento_atendentes.csv'}
|
|
|
|
target={'_blank'}
|
|
|
|
ref={csvLink} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
</Item>
|
2022-05-16 03:33:09 +00:00
|
|
|
|
2022-01-24 11:44:42 +00:00
|
|
|
</Box>
|
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
<Box sx={{
|
|
|
|
display: 'grid',
|
|
|
|
}}>
|
|
|
|
|
|
|
|
<Item sx={{ gridColumn: '1', gridRow: 'span 1' }}>
|
|
|
|
|
|
|
|
{reportOption === '1' &&
|
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
// <div onScroll={handleScroll} style={{ height: 400, overflowY: "scroll" }}>
|
|
|
|
// </div>
|
|
|
|
|
|
|
|
<>
|
|
|
|
|
|
|
|
<MTable data={query}
|
|
|
|
columns={columnsData}
|
|
|
|
hasChild={true}
|
|
|
|
removeClickRow={false}
|
|
|
|
|
|
|
|
handleScroll={handleScroll}
|
|
|
|
|
|
|
|
table_title={'Atendimento por atendentes'} />
|
|
|
|
|
|
|
|
</>
|
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
}
|
|
|
|
{reportOption === '2' &&
|
|
|
|
|
|
|
|
<MaterialTable
|
|
|
|
|
|
|
|
localization={{
|
|
|
|
|
|
|
|
header: {
|
|
|
|
actions: 'Deslogar'
|
|
|
|
},
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
title="Usuários online/offline"
|
|
|
|
columns={
|
|
|
|
[
|
|
|
|
|
|
|
|
// { title: 'Foto', field: 'ticket.contact.profilePicUrl', render: rowData => <img src={rowData['ticket.contact.profilePicUrl']} alt="imagem de perfil do whatsapp" style={{ width: 40, borderRadius: '50%' }} /> },
|
2022-07-28 17:55:23 +00:00
|
|
|
{ title: 'Nome', field: 'name', cellStyle: { whiteSpace: 'nowrap' }, },
|
2022-05-16 02:48:06 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
title: 'Status', field: 'statusOnline.status',
|
|
|
|
|
|
|
|
cellStyle: (e, rowData) => {
|
|
|
|
|
|
|
|
if (rowData['statusOnline'] && rowData['statusOnline'].status) {
|
2022-05-16 03:33:09 +00:00
|
|
|
|
2022-05-16 02:48:06 +00:00
|
|
|
if (rowData['statusOnline'].status === 'offline') {
|
|
|
|
|
|
|
|
return { color: "red" };
|
|
|
|
}
|
|
|
|
else if (rowData['statusOnline'].status === 'online') {
|
|
|
|
return { color: "green" };
|
|
|
|
}
|
|
|
|
else if (rowData['statusOnline'].status === 'logout...') {
|
|
|
|
return { color: "orange" };
|
|
|
|
}
|
|
|
|
else if (rowData['statusOnline'].status === 'waiting...') {
|
|
|
|
return { color: "orange" };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{ title: 'Tempo online', field: 'sumOnlineTime.sum' },
|
|
|
|
{ title: 'Data inicio', field: 'startDate' },
|
|
|
|
{ title: 'Data fim', field: 'endDate' },
|
|
|
|
{ title: 'Em atendimento', field: 'sumOpen.count' },
|
|
|
|
{ title: 'Finalizado', field: 'sumClosed.count' },
|
|
|
|
|
|
|
|
]
|
|
|
|
}
|
|
|
|
data={dataRows}
|
|
|
|
// icons={tableIcons}
|
|
|
|
|
|
|
|
actions={[
|
|
|
|
(rowData) => {
|
|
|
|
|
|
|
|
if (rowData.statusOnline &&
|
|
|
|
rowData.statusOnline['status'] &&
|
|
|
|
rowData.statusOnline['status'] === 'online') {
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
icon: LogoutIcon,
|
|
|
|
tooltip: 'deslogar',
|
|
|
|
disable: false,
|
|
|
|
onClick: (event, rowData) => {
|
|
|
|
|
2022-07-28 17:55:23 +00:00
|
|
|
// console.log(' ROW DATA INFO: ', rowData, ' | rowData: ', rowData.id)
|
2022-05-16 02:48:06 +00:00
|
|
|
handleLogouOnlineUser(rowData.id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]}
|
|
|
|
|
|
|
|
|
|
|
|
options={
|
|
|
|
{
|
|
|
|
search: true,
|
|
|
|
selection: false,
|
|
|
|
paging: false,
|
|
|
|
padding: 'dense',
|
|
|
|
sorting: true,
|
|
|
|
//loadingType: 'linear',
|
|
|
|
searchFieldStyle: {
|
|
|
|
width: 300,
|
|
|
|
},
|
|
|
|
|
|
|
|
pageSize: 20,
|
|
|
|
headerStyle: {
|
|
|
|
position: "sticky",
|
|
|
|
top: "0"
|
|
|
|
},
|
|
|
|
maxBodyHeight: "400px",
|
|
|
|
|
|
|
|
rowStyle: {
|
|
|
|
fontSize: 14,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// cellStyle: (rowData) => {
|
|
|
|
// return {
|
|
|
|
// fontSize: 12,
|
|
|
|
// color: "#fff",
|
|
|
|
|
|
|
|
// };
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
</Item>
|
|
|
|
|
|
|
|
</Box>
|
2022-01-24 11:44:42 +00:00
|
|
|
</MainContainer>
|
2022-05-16 02:48:06 +00:00
|
|
|
|
|
|
|
)}
|
|
|
|
/>
|
2022-01-24 11:44:42 +00:00
|
|
|
)
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Report;
|