Recurso online/offline finalizado

pull/1/head
adriano 2022-05-16 00:33:09 -03:00
parent d74e3a7a97
commit c7fa85c509
6 changed files with 68 additions and 58 deletions

View File

@ -24,7 +24,7 @@ import { addHours, addMinutes, addSeconds, intervalToDuration, add } from "date-
const isoDate = new Date(onlineTime); const isoDate = new Date(onlineTime);
const newOnlinetime = isoDate.toJSON().slice(0, 19).replace('T', ' '); const newOnlinetime = isoDate.toJSON().slice(0, 19).replace('T', ' ');
console.log('sum new online time: ', newOnlinetime) //console.log('sum new online time: ', newOnlinetime)
return newOnlinetime return newOnlinetime
} }

View File

@ -101,7 +101,7 @@ const monitor = async () => {
} }
} else { } else {
console.log(' * TEST OBJ', test.ob) // console.log(' * TEST OBJ', test.ob)
test.ob.listOnline.forEach(async (el: any) => { test.ob.listOnline.forEach(async (el: any) => {
@ -139,12 +139,12 @@ const monitor = async () => {
}); });
console.log('----------- 1 lstOnline: ', lstOnline) // console.log('----------- 1 lstOnline: ', lstOnline)
let difference = lstOnline.filter((x: any) => !test.ob.listOnline.map((e: any) => e.id).includes(x.id)); let difference = lstOnline.filter((x: any) => !test.ob.listOnline.map((e: any) => e.id).includes(x.id));
console.log(' * diference: ', difference) // console.log(' * diference: ', difference)
difference.forEach(async (e: any) => { difference.forEach(async (e: any) => {
@ -154,12 +154,12 @@ const monitor = async () => {
lstOnline.splice(index, 1) lstOnline.splice(index, 1)
console.log('----------- 2 lstOnline: ', lstOnline) // console.log('----------- 2 lstOnline: ', lstOnline)
const userOnline = await createOrUpdateOnlineUserService({ userId: e.id, status: 'offline' }) const userOnline = await createOrUpdateOnlineUserService({ userId: e.id, status: 'offline' })
if (userOnline) { if (userOnline) {
console.log(' * UPDATED USER TO OFFLINE: ', userOnline.userId) // console.log(' * UPDATED USER TO OFFLINE: ', userOnline.userId)
} }
@ -202,7 +202,7 @@ const monitor = async () => {
}); });
console.log('***************** TIME INTERVAL: ', timeInterval) // console.log('***************** TIME INTERVAL: ', timeInterval)
}; };

View File

@ -156,7 +156,7 @@ export const initIO = (httpServer: Server): SocketIO => {
}) })
console.log(' difference2: ', difference) // console.log(' difference2: ', difference)
} }
obj.listOnline = lstOnline obj.listOnline = lstOnline

View File

@ -122,7 +122,7 @@ const NotificationsPopOver = () => {
return () => { return () => {
socket.disconnect(); socket.disconnect();
}; };
}, []); }, [user.id, handleLogout]);

View File

@ -1,4 +1,4 @@
import React, { useState, useEffect, useReducer, useContext, useRef } from "react"; import React, { useState, useEffect } from "react";
import Box from '@mui/material/Box'; import Box from '@mui/material/Box';
import Button from '@mui/material/Button'; import Button from '@mui/material/Button';
import Dialog from '@mui/material/Dialog'; import Dialog from '@mui/material/Dialog';
@ -7,17 +7,17 @@ import DialogContent from '@mui/material/DialogContent';
import DialogContentText from '@mui/material/DialogContentText'; import DialogContentText from '@mui/material/DialogContentText';
import DialogTitle from '@mui/material/DialogTitle'; import DialogTitle from '@mui/material/DialogTitle';
import FormControl from '@mui/material/FormControl'; import FormControl from '@mui/material/FormControl';
import FormControlLabel from '@mui/material/FormControlLabel';
import InputLabel from '@mui/material/InputLabel'; import InputLabel from '@mui/material/InputLabel';
import MenuItem from '@mui/material/MenuItem'; import MenuItem from '@mui/material/MenuItem';
import Select from '@mui/material/Select'; import Select from '@mui/material/Select';
import Switch from '@mui/material/Switch';
export default function MaxWidthDialog(props) { export default function MaxWidthDialog(props) {
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const [fullWidth, setFullWidth] = useState(true); const [fullWidth, ] = useState(true);
const [currency, setCurrency] = useState(props.reportOption); const [currency, setCurrency] = useState(props.reportOption);
@ -43,9 +43,7 @@ useEffect(()=>{
console.log('event.target.value: ', event.target.value) console.log('event.target.value: ', event.target.value)
}; };
const handleFullWidthChange = (event) => {
setFullWidth(event.target.checked);
};
return ( return (
<React.Fragment> <React.Fragment>

View File

@ -15,14 +15,13 @@ import { Button } from "@material-ui/core";
import ReportModal from "../../components/ReportModal"; import ReportModal from "../../components/ReportModal";
import MaterialTable from 'material-table'; import MaterialTable from 'material-table';
import Delete from '@material-ui/icons/Delete';
import Edit from '@material-ui/icons/Edit';
import LogoutIcon from '@material-ui/icons/CancelOutlined'; import LogoutIcon from '@material-ui/icons/CancelOutlined';
import { CSVLink } from "react-csv"; import { CSVLink } from "react-csv";
import openSocket from "socket.io-client"; import openSocket from "socket.io-client";
const report = [{ 'value': '1', 'label': 'Atendimento por atendentes' }, { 'value': '2', 'label': 'Usuários online/offline' }] const report = [{ 'value': '1', 'label': 'Atendimento por atendentes' }, { 'value': '2', 'label': 'Usuários online/offline' }]
@ -95,11 +94,11 @@ const reducerQ = (state, action) => {
const userId = action.payload; const userId = action.payload;
console.log('Entrou no delete user status userId: ', userId) //console.log('Entrou no delete user status userId: ', userId)
const userIndex = state.findIndex((u) => `${u.id}` === `${userId}`); const userIndex = state.findIndex((u) => `${u.id}` === `${userId}`);
console.log('>>>>>>>>>>>>>>>>>>>>> userIndex: ', userIndex) // console.log('>>>>>>>>>>>>>>>>>>>>> userIndex: ', userIndex)
if (userIndex !== -1) { if (userIndex !== -1) {
state.splice(userIndex, 1); state.splice(userIndex, 1);
@ -138,7 +137,7 @@ const reducerQ = (state, action) => {
let onlineUser = action.payload let onlineUser = action.payload
let index = -1 let index = -1
console.log('sssssssssstate: ', state, ' | ONLINE USERS: onlineUser.userId ', onlineUser.userId) // console.log('sssssssssstate: ', state, ' | ONLINE USERS: onlineUser.userId ', onlineUser.userId)
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)))
@ -147,13 +146,13 @@ const reducerQ = (state, action) => {
index = state.findIndex((e) => `${e.id}` === `${onlineUser.userId}`) index = state.findIndex((e) => `${e.id}` === `${onlineUser.userId}`)
} }
console.log(' *********************** index: ', index) //console.log(' *********************** index: ', index)
if (index !== -1) { if (index !== -1) {
console.log('ENTROU NO INDEX') // console.log('ENTROU NO INDEX')
if (!("statusOnline" in state[index])) { if (!("statusOnline" in state[index])) {
@ -178,10 +177,10 @@ const reducerQ = (state, action) => {
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
} }
@ -190,10 +189,10 @@ const reducerQ = (state, action) => {
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
} }
@ -324,7 +323,7 @@ const Report = () => {
const [reporList,] = useState(report) const [reporList,] = useState(report)
const [profile, setProfile] = useState('') const [profile, setProfile] = useState('')
const [dataRows, setData] = useState([]); const [dataRows, setData] = useState([]);
const [selectedUserId, setSelectedUserId] = useState(null);
@ -345,7 +344,7 @@ const Report = () => {
const fetchUsers = async () => { const fetchUsers = async () => {
try { try {
console.log('profile: ', profile) //console.log('profile: ', profile)
const { data } = await api.get("/users/", { const { data } = await api.get("/users/", {
params: { searchParam, pageNumber, profile }, params: { searchParam, pageNumber, profile },
@ -386,9 +385,9 @@ const Report = () => {
//setLoading(false); //setLoading(false);
console.log('dataQuery: ', dataQuery.data) // console.log('dataQuery: ', dataQuery.data)
console.log() // console.log()
} }
else if (reportOption === '2') { else if (reportOption === '2') {
@ -399,9 +398,9 @@ const Report = () => {
//setLoading(false); //setLoading(false);
console.log('REPORT 2 dataQuery : ', dataQuery.data) // console.log('REPORT 2 dataQuery : ', dataQuery.data)
console.log() //console.log()
} }
@ -444,7 +443,7 @@ const Report = () => {
setReport(data) setReport(data)
console.log(' data: ', data) // console.log(' data: ', data)
} }
useEffect(() => { useEffect(() => {
@ -543,14 +542,14 @@ const Report = () => {
let date = new Date().toLocaleDateString('pt-BR').split('/') let date = new Date().toLocaleDateString('pt-BR').split('/')
let dateToday = `${date[2]}-${date[1]}-${date[0]}` let dateToday = `${date[2]}-${date[1]}-${date[0]}`
console.log('date: ', new Date(startDate).toLocaleDateString('pt-BR')) // console.log('date: ', new Date(startDate).toLocaleDateString('pt-BR'))
console.log('date2: ', startDate) // console.log('date2: ', startDate)
if (data.action === "logout" || (data.action === "update" && if (data.action === "logout" || (data.action === "update" &&
((`${startDate}` === `${endDate}`) && (`${endDate}` === `${dateToday}`) && (`${startDate}` === `${dateToday}`)))) { ((`${startDate}` === `${endDate}`) && (`${endDate}` === `${dateToday}`) && (`${startDate}` === `${dateToday}`)))) {
console.log('UPDATE FROM ONLINE/OFFLINE LOGED USERS: ', data.userOnlineTime, ' | data.action : ', data.action) //console.log('UPDATE FROM ONLINE/OFFLINE LOGED USERS: ', data.userOnlineTime, ' | data.action : ', data.action)
dispatchQ({ type: "UPDATE_STATUS_ONLINE", payload: data.userOnlineTime }); dispatchQ({ type: "UPDATE_STATUS_ONLINE", payload: data.userOnlineTime });
@ -566,7 +565,7 @@ const Report = () => {
socket.on("user", (data) => { socket.on("user", (data) => {
if (data.action === "delete") { if (data.action === "delete") {
console.log(' entrou no delete user: ', data) // console.log(' entrou no delete user: ', data)
dispatch({ type: "DELETE_USER", payload: +data.userId }); dispatch({ type: "DELETE_USER", payload: +data.userId });
} }
}); });
@ -616,7 +615,7 @@ const Report = () => {
// toastError(err); // toastError(err);
} }
setSelectedUserId(null);
}; };
@ -637,29 +636,42 @@ const Report = () => {
<Item><DatePicker1 func={datePicker1Value} minDate={false} startEmpty={false} title={'Data inicio'} /></Item> <Item><DatePicker1 func={datePicker1Value} minDate={false} startEmpty={false} title={'Data inicio'} /></Item>
<Item><DatePicker2 func={datePicker2Value} minDate={false} startEmpty={false} title={'Data fim'} /></Item> <Item><DatePicker2 func={datePicker2Value} minDate={false} startEmpty={false} title={'Data fim'} /></Item>
<Item sx={{ gridColumn: '4 / 5' }}> <Item sx={{ display: 'grid', gridColumn: '4 / 5', }}>
<ReportModal currencies={reporList} func={reportValue} reportOption={reportOption} /> <ReportModal currencies={reporList} func={reportValue} reportOption={reportOption} />
{/* <Button <div style={{ margin: '2px' }}></div>
variant="contained"
color="primary" {reportOption === '1' &&
onClick={(e) => handleCSVMessages()}
> <div>
{"CSV ALL"} <Button
</Button> variant="contained"
color="primary"
onClick={(e) => handleCSVMessages()}
>
{"CSV ALL"}
</Button>
<div>
<CSVLink
data={dataCSV}
headers={columns}
filename={'Relatorio_detalhado_atendimento_atendentes.csv'}
target={'_blank'}
ref={csvLink} />
</div>
</div>
}
<div>
<CSVLink
data={dataCSV}
headers={columns}
filename={'Relatorio_detalhado_atendimento_atendentes.csv'}
target={'_blank'}
ref={csvLink} />
</div> */}
</Item> </Item>
</Box> </Box>
<Box sx={{ <Box sx={{
@ -701,7 +713,7 @@ const Report = () => {
cellStyle: (e, rowData) => { cellStyle: (e, rowData) => {
if (rowData['statusOnline'] && rowData['statusOnline'].status) { if (rowData['statusOnline'] && rowData['statusOnline'].status) {
if (rowData['statusOnline'].status === 'offline') { if (rowData['statusOnline'].status === 'offline') {
return { color: "red" }; return { color: "red" };
@ -747,7 +759,7 @@ const Report = () => {
disable: false, disable: false,
onClick: (event, rowData) => { onClick: (event, rowData) => {
console.log(' ROW DATA INFO: ', rowData, ' | rowData: ', rowData.id) // console.log(' ROW DATA INFO: ', rowData, ' | rowData: ', rowData.id)
handleLogouOnlineUser(rowData.id) handleLogouOnlineUser(rowData.id)
} }
} }