Completed merge and fixed errors

pull/18/head
Renato Di Giacomo 2022-08-08 19:59:47 -03:00
parent 992bdf8deb
commit 0f7e91c1bd
3 changed files with 127 additions and 195 deletions

View File

@ -67,7 +67,7 @@ export const initWbot = async (whatsapp: Whatsapp, backupSessionRestore: boolean
// usando instancia do chrome // usando instancia do chrome
const wbot: Session = new Client({ const wbot: Session = new Client({
session: sessionCfg, authStrategy: new LocalAuth({ clientId: 'bd_' + whatsapp.id }), session: sessionCfg, authStrategy: new LocalAuth({ clientId: 'bd_' + whatsapp.id }),
puppeteer: { args: ['--no-sandbox', '--disable-setuid-sandbox'], executablePath: process.env.CHROME_BIN || '/usr/bin/google-chrome-stable' }, puppeteer: { args: ['--no-sandbox', '--disable-setuid-sandbox'], executablePath: process.env.CHROME_BIN || undefined },
}); });

View File

@ -1,4 +1,4 @@
import React, { useContext, useReducer, useEffect } from "react"; import React, { useContext, useReducer, useEffect, useState } from "react";
import Paper from "@material-ui/core/Paper"; import Paper from "@material-ui/core/Paper";
import Container from "@material-ui/core/Container"; import Container from "@material-ui/core/Container";
@ -172,43 +172,33 @@ const reducer = (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;
} }
} }
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;
}
} }
} if (onlineUser.openClosedInQueue) {
state[index].openClosedInQueue = onlineUser.openClosedInQueue;
if(onlineUser.openClosedInQueue){
state[index].openClosedInQueue = onlineUser.openClosedInQueue
} }
if (onlineUser.openClosedOutQueue) { if (onlineUser.openClosedOutQueue) {
state[index].openClosedOutQueue = onlineUser.openClosedOutQueue; state[index].openClosedOutQueue = onlineUser.openClosedOutQueue;
} }
} }
return [...state]; return [...state];
} }
@ -219,25 +209,19 @@ const reducer = (state, action) => {
}; };
const Dashboard = () => { const Dashboard = () => {
const classes = useStyles() const classes = useStyles();
const [usersOnlineInfo, dispatch] = useReducer(reducer, []) const [usersOnlineInfo, dispatch] = useReducer(reducer, []);
const [ticketStatusChange, setStatus] = useState();
const [open, setOpen] = useState(0) const [open, setOpen] = useState(0);
const [closed, setClosed] = useState(0) const [closed, setClosed] = useState(0);
const [pending, setPending] = useState(0) const [pending, setPending] = useState(0);
const { user } = useContext(AuthContext); const { user } = useContext(AuthContext);
useEffect(() => { useEffect(() => {
dispatch({ type: "RESET" }); dispatch({ type: "RESET" });
}, []); }, []);
const handleLogouOnlineUser = async (userId) => { const handleLogouOnlineUser = async (userId) => {
try { try {
await api.get(`/users/logout/${userId}`); await api.get(`/users/logout/${userId}`);
@ -246,77 +230,59 @@ const Dashboard = () => {
} catch (err) { } catch (err) {
// toastError(err); // toastError(err);
} }
}; };
useEffect(() => { useEffect(() => {
//setLoading(true); //setLoading(true);
const delayDebounceFn = setTimeout(() => { const delayDebounceFn = setTimeout(() => {
// setLoading(true); // setLoading(true);
const fetchQueries = async () => { const fetchQueries = async () => {
try { try {
let date = new Date().toLocaleDateString("pt-BR").split("/");
let dateToday = `${date[2]}-${date[1]}-${date[0]}`;
let date = new Date().toLocaleDateString('pt-BR').split('/') const dataQuery = await api.get("/reports/user/services", {
let dateToday = `${date[2]}-${date[1]}-${date[0]}` params: { userId: null, startDate: dateToday, endDate: dateToday },
});
const dataQuery = await api.get("/reports/user/services", { params: { userId: null, startDate: dateToday, endDate: dateToday }, }); dispatch({ type: "RESET" });
dispatch({ type: "RESET" })
dispatch({ type: "LOAD_QUERY", payload: dataQuery.data }); dispatch({ type: "LOAD_QUERY", payload: dataQuery.data });
console.log('xxx REPORT 2 dataQuery : ', dataQuery.data) console.log("xxx REPORT 2 dataQuery : ", dataQuery.data);
//console.log() //console.log()
} catch (err) { } catch (err) {
console.log(err); console.log(err);
} }
}; };
fetchQueries(); fetchQueries();
}, 500); }, 500);
return () => clearTimeout(delayDebounceFn); return () => clearTimeout(delayDebounceFn);
}, []); }, []);
useEffect(() => { useEffect(() => {
const socket = openSocket(process.env.REACT_APP_BACKEND_URL); const socket = openSocket(process.env.REACT_APP_BACKEND_URL);
socket.on("ticketStatus", (data) => { socket.on("ticketStatus", (data) => {
// console.log('data: ',data) // console.log('data: ',data)
if(data.action === "update"){ if (data.action === "update") {
setStatus(data.ticketStatus.status) setStatus(data.ticketStatus.status);
} }
}); });
socket.on("onlineStatus", (data) => { socket.on("onlineStatus", (data) => {
if (data.action === "logout" || data.action === "update") {
if (data.action === "logout" || (data.action === "update")) {
// console.log('>>>>>>> data.userOnlineTime: ', data.userOnlineTime) // console.log('>>>>>>> data.userOnlineTime: ', data.userOnlineTime)
dispatch({ type: "UPDATE_STATUS_ONLINE", payload: data.userOnlineTime }); dispatch({ type: "UPDATE_STATUS_ONLINE", payload: data.userOnlineTime });
} else if (data.action === "delete") {
}
else if (data.action === "delete") {
dispatch({ type: "DELETE_USER_STATUS", payload: data.userOnlineTime }); dispatch({ type: "DELETE_USER_STATUS", payload: data.userOnlineTime });
} }
}); });
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 });
@ -326,45 +292,38 @@ const Dashboard = () => {
return () => { return () => {
socket.disconnect(); socket.disconnect();
}; };
}, []); }, []);
useEffect(() => { useEffect(() => {
const delayDebounceFn = setTimeout(() => { const delayDebounceFn = setTimeout(() => {
const fetchQueries = async () => { const fetchQueries = async () => {
try { try {
let date = new Date().toLocaleDateString("pt-BR").split("/");
let dateToday = `${date[2]}-${date[1]}-${date[0]}`;
let date = new Date().toLocaleDateString('pt-BR').split('/') const _open = await api.get("/tickets/count", {
let dateToday = `${date[2]}-${date[1]}-${date[0]}` params: { status: "open", date: dateToday },
});
const _open = await api.get("/tickets/count", { params: { status: 'open', date: dateToday } }); const _closed = await api.get("/tickets/count", {
const _closed = await api.get("/tickets/count", { params: { status: 'closed', date: dateToday } }); params: { status: "closed", date: dateToday },
const _pending = await api.get("/tickets/count", { params: { status: 'pending', date: dateToday } }); });
const _pending = await api.get("/tickets/count", {
setOpen(_open.data.count) params: { status: "pending", date: dateToday },
setClosed(_closed.data.count) });
setPending(_pending.data.count)
setOpen(_open.data.count);
setClosed(_closed.data.count);
setPending(_pending.data.count);
} catch (err) { } catch (err) {
console.log(err); console.log(err);
} }
}; };
fetchQueries(); fetchQueries();
}, 500); }, 500);
return () => clearTimeout(delayDebounceFn); return () => clearTimeout(delayDebounceFn);
}, [ticketStatusChange]); }, [ticketStatusChange]);
return ( return (
<Can <Can
role={user.profile} role={user.profile}
@ -404,7 +363,7 @@ const Dashboard = () => {
</Typography> </Typography>
<Grid item> <Grid item>
<Typography component="h1" variant="h4"> <Typography component="h1" variant="h4">
{GetTickets("open", "true", "false", "true")} {open}
</Typography> </Typography>
</Grid> </Grid>
</Paper> </Paper>
@ -420,7 +379,7 @@ const Dashboard = () => {
</Typography> </Typography>
<Grid item> <Grid item>
<Typography component="h1" variant="h4"> <Typography component="h1" variant="h4">
{GetTickets("pending", "true", "false", "true")} {pending}
</Typography> </Typography>
</Grid> </Grid>
</Paper> </Paper>
@ -436,7 +395,7 @@ const Dashboard = () => {
</Typography> </Typography>
<Grid item> <Grid item>
<Typography component="h1" variant="h4"> <Typography component="h1" variant="h4">
{GetTickets("closed", "true", "false", "true")} {closed}
</Typography> </Typography>
</Grid> </Grid>
</Paper> </Paper>
@ -549,6 +508,6 @@ const Dashboard = () => {
/**/ /**/
); );
} };
export default Dashboard export default Dashboard;

View File

@ -21,12 +21,8 @@ import { AuthProvider } from "../context/Auth/AuthContext";
import { WhatsAppsProvider } from "../context/WhatsApp/WhatsAppsContext"; import { WhatsAppsProvider } from "../context/WhatsApp/WhatsAppsContext";
import Route from "./Route"; import Route from "./Route";
//console.log('---AuthProvider: ',AuthProvider) //console.log('---AuthProvider: ',AuthProvider)
const Routes = () => { const Routes = () => {
return ( return (
<BrowserRouter> <BrowserRouter>
@ -37,41 +33,18 @@ const Routes = () => {
<WhatsAppsProvider> <WhatsAppsProvider>
<LoggedInLayout> <LoggedInLayout>
<Route exact path="/" component={Dashboard} isPrivate /> <Route exact path="/" component={Dashboard} isPrivate />
<Route <Route exact path="/tickets/:ticketId?" component={Tickets} isPrivate />
exact
path="/tickets/:ticketId?"
component={Tickets}
isPrivate
/>
<Route <Route exact path="/connections" component={Connections} isPrivate />
exact
path="/connections"
component={Connections}
isPrivate
/>
<Route
exact
path="/report"
component={Report}
isPrivate
/>
<Route exact path="/report" component={Report} isPrivate />
<Route exact path="/contacts" component={Contacts} isPrivate /> <Route exact path="/contacts" component={Contacts} isPrivate />
<Route exact path="/schedulesReminder" component={SchedulesReminder} isPrivate /> <Route exact path="/schedulesReminder" component={SchedulesReminder} isPrivate />
<Route exact path="/users" component={Users} isPrivate /> <Route exact path="/users" component={Users} isPrivate />
<Route <Route exact path="/quickAnswers" component={QuickAnswers} isPrivate />
exact
path="/quickAnswers"
component={QuickAnswers}
isPrivate
/>
<Route exact path="/Settings" component={Settings} isPrivate /> <Route exact path="/Settings" component={Settings} isPrivate />
<Route exact path="/Queues" component={Queues} isPrivate /> <Route exact path="/Queues" component={Queues} isPrivate />
</LoggedInLayout> </LoggedInLayout>