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 ("sumOpen" in state[index]) {
// 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;
} else if (!("sumOpen" in state[index])) {
// console.log(' >>>>>>>>>>>>>>>>>> sumOpen 1')
state[index].sumOpen = onlineUser.sumOpen;
}
}
if (onlineUser.sumOpen) { if (onlineUser.sumClosed) {
if ("sumClosed" in state[index]) {
// 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;
} else if (!("sumClosed" in state[index])) {
// console.log(' >>>>>>>>>>>>>>>>>> sumOpen 1')
state[index].sumClosed = onlineUser.sumClosed;
}
}
if ("sumOpen" in state[index]) { if (onlineUser.openClosedInQueue) {
// console.log(' >>>>>>>>>>>>>>>>>> sumOpen 1 | state[index].sumOpen["count"]: ', state[index].sumOpen['count'], ' | onlineUser.sumOpen.count: ', onlineUser.sumOpen.count) state[index].openClosedInQueue = onlineUser.openClosedInQueue;
state[index].sumOpen['count'] = onlineUser.sumOpen.count }
} else if (!("sumOpen" in state[index])) {
// console.log(' >>>>>>>>>>>>>>>>>> sumOpen 1')
state[index].sumOpen = onlineUser.sumOpen
}
}
if (onlineUser.sumClosed) {
if ("sumClosed" in state[index]) {
// 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
} else if (!("sumClosed" in state[index])) {
// console.log(' >>>>>>>>>>>>>>>>>> sumOpen 1')
state[index].sumClosed = onlineUser.sumClosed
}
}
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,151 +209,120 @@ 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 [closed, setClosed] = useState(0);
const [pending, setPending] = useState(0);
const [open, setOpen] = useState(0) const { user } = useContext(AuthContext);
const [closed, setClosed] = useState(0)
const [pending, setPending] = useState(0)
const { user } = useContext(AuthContext); useEffect(() => {
dispatch({ type: "RESET" });
}, []);
const handleLogouOnlineUser = async (userId) => {
try {
await api.get(`/users/logout/${userId}`);
//toast.success(("Desloged!"));
//handleDeleteRows(scheduleId)
} catch (err) {
// toastError(err);
}
};
useEffect(() => { useEffect(() => {
//setLoading(true);
dispatch({ type: "RESET" }); const delayDebounceFn = setTimeout(() => {
// setLoading(true);
const fetchQueries = async () => {
try {
let date = new Date().toLocaleDateString("pt-BR").split("/");
let dateToday = `${date[2]}-${date[1]}-${date[0]}`;
}, []); const dataQuery = await api.get("/reports/user/services", {
params: { userId: null, startDate: dateToday, endDate: dateToday },
});
dispatch({ type: "RESET" });
dispatch({ type: "LOAD_QUERY", payload: dataQuery.data });
console.log("xxx REPORT 2 dataQuery : ", dataQuery.data);
//console.log()
} catch (err) {
console.log(err);
}
};
fetchQueries();
}, 500);
return () => clearTimeout(delayDebounceFn);
}, []);
const handleLogouOnlineUser = async (userId) => { useEffect(() => {
try { const socket = openSocket(process.env.REACT_APP_BACKEND_URL);
await api.get(`/users/logout/${userId}`);
//toast.success(("Desloged!"));
//handleDeleteRows(scheduleId)
} catch (err) {
// toastError(err);
}
socket.on("ticketStatus", (data) => {
// console.log('data: ',data)
}; if (data.action === "update") {
setStatus(data.ticketStatus.status);
}
});
socket.on("onlineStatus", (data) => {
if (data.action === "logout" || data.action === "update") {
// console.log('>>>>>>> data.userOnlineTime: ', data.userOnlineTime)
useEffect(() => { dispatch({ type: "UPDATE_STATUS_ONLINE", payload: data.userOnlineTime });
} else if (data.action === "delete") {
dispatch({ type: "DELETE_USER_STATUS", payload: data.userOnlineTime });
}
});
//setLoading(true); socket.on("user", (data) => {
if (data.action === "delete") {
// console.log(' entrou no delete user: ', data)
dispatch({ type: "DELETE_USER", payload: +data.userId });
}
});
const delayDebounceFn = setTimeout(() => { return () => {
socket.disconnect();
};
}, []);
// setLoading(true); useEffect(() => {
const fetchQueries = async () => { const delayDebounceFn = setTimeout(() => {
try { const fetchQueries = async () => {
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 dataQuery = await api.get("/reports/user/services", { params: { userId: null, startDate: dateToday, endDate: dateToday }, }); const _closed = await api.get("/tickets/count", {
dispatch({ type: "RESET" }) params: { status: "closed", date: dateToday },
dispatch({ type: "LOAD_QUERY", payload: dataQuery.data }); });
const _pending = await api.get("/tickets/count", {
console.log('xxx REPORT 2 dataQuery : ', dataQuery.data) params: { status: "pending", date: dateToday },
});
//console.log()
} catch (err) {
console.log(err);
}
};
fetchQueries();
}, 500);
return () => clearTimeout(delayDebounceFn);
}, []);
useEffect(() => {
const socket = openSocket(process.env.REACT_APP_BACKEND_URL);
socket.on("ticketStatus", (data) => {
// console.log('data: ',data)
if(data.action === "update"){
setStatus(data.ticketStatus.status)
}
});
socket.on("onlineStatus", (data) => {
if (data.action === "logout" || (data.action === "update")) {
// console.log('>>>>>>> data.userOnlineTime: ', data.userOnlineTime)
dispatch({ type: "UPDATE_STATUS_ONLINE", payload: data.userOnlineTime });
}
else if (data.action === "delete") {
dispatch({ type: "DELETE_USER_STATUS", payload: data.userOnlineTime });
}
});
socket.on("user", (data) => {
if (data.action === "delete") {
// console.log(' entrou no delete user: ', data)
dispatch({ type: "DELETE_USER", payload: +data.userId });
}
});
return () => {
socket.disconnect();
};
}, []);
useEffect(() => {
const delayDebounceFn = setTimeout(() => {
const fetchQueries = async () => {
try {
let date = new Date().toLocaleDateString('pt-BR').split('/')
let dateToday = `${date[2]}-${date[1]}-${date[0]}`
const _open = await api.get("/tickets/count", { params: { status: 'open', date: dateToday } });
const _closed = await api.get("/tickets/count", { params: { status: 'closed', date: dateToday } });
const _pending = await api.get("/tickets/count", { params: { status: 'pending', date: dateToday } });
setOpen(_open.data.count)
setClosed(_closed.data.count)
setPending(_pending.data.count)
} catch (err) {
console.log(err);
}
};
fetchQueries();
}, 500);
return () => clearTimeout(delayDebounceFn);
}, [ticketStatusChange]);
setOpen(_open.data.count);
setClosed(_closed.data.count);
setPending(_pending.data.count);
} catch (err) {
console.log(err);
}
};
fetchQueries();
}, 500);
return () => clearTimeout(delayDebounceFn);
}, [ticketStatusChange]);
return ( return (
<Can <Can
@ -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>