Merge branch 'dual_session_test' into dialogflow

pull/20/head
adriano 2022-12-27 18:25:34 -03:00
commit 2d02a69b19
4 changed files with 82 additions and 22 deletions

View File

@ -96,6 +96,7 @@ const TableUser = ({ classes, usersOnlineInfo, logout }) => {
</TableRow> </TableRow>
</TableHead> </TableHead>
<TableBody style={{ overflowY: "scroll" }}> <TableBody style={{ overflowY: "scroll" }}>
{usersOnlineInfo && {usersOnlineInfo &&
usersOnlineInfo usersOnlineInfo

View File

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

View File

@ -118,6 +118,8 @@ const Connections = () => {
const [disabled, setDisabled] = useState(true); const [disabled, setDisabled] = useState(true);
const [buttons, setClicks] = useState([])
const confirmationModalInitialState = { const confirmationModalInitialState = {
action: "", action: "",
@ -139,10 +141,24 @@ const Connections = () => {
}; };
const handleRestartWhatsAppSession = async whatsAppId => {
const handleRestartWhatsAppSession = async whatsapp => {
try { try {
await api.post(`/restartwhatsappsession/${whatsAppId}`); whatsapp.disabled = true
setClicks([...buttons, whatsapp.id])
function enable_button(whatsappId) {
setClicks(buttons => buttons.filter(id => { return +id !== +whatsappId }),);
}
setTimeout(enable_button, 25000, whatsapp.id)
await api.post(`/restartwhatsappsession/${whatsapp.id}`);
} catch (err) { } catch (err) {
toastError(err); toastError(err);
@ -150,6 +166,24 @@ const Connections = () => {
}; };
useEffect(() => {
// whatsApps.map((e) => {
// if (buttons.includes(e.id)) {
// e.disabled = true
// }
// })
for (let i = 0; i < whatsApps.length; i++) {
if (buttons.includes(whatsApps[i].id)) {
whatsApps[i].disabled = true
}
}
}, [whatsApps, buttons])
const handleRequestNewQrCode = async whatsAppId => { const handleRequestNewQrCode = async whatsAppId => {
try { try {
await api.put(`/whatsappsession/${whatsAppId}`); await api.put(`/whatsappsession/${whatsAppId}`);
@ -354,6 +388,8 @@ const Connections = () => {
setDisabled(false) setDisabled(false)
setClicks(buttons => buttons.map((e) => { return { id: e.id, disabled: false } }))
} catch (err) { } catch (err) {
console.log(err); console.log(err);
} }
@ -579,7 +615,7 @@ const Connections = () => {
size="small" size="small"
variant="contained" variant="contained"
color="primary" color="primary"
onClick={() => handleRestartWhatsAppSession(whatsApp.id)} onClick={() => handleRestartWhatsAppSession(whatsApp)}
> >
Restore Restore

View File

@ -1,6 +1,6 @@
import React, { useContext, useReducer, useEffect, useState } from "react"; import React, { useContext, useReducer, useEffect, useState } from "react";
import { addHours, addMinutes, addSeconds, intervalToDuration, add } from "date-fns"; import { addHours, addMinutes, addSeconds, intervalToDuration } from "date-fns";
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";
@ -112,6 +112,12 @@ const sumOnlineTimeNow = (oldOnlineTimeSum) => {
let onlineTime = new Date() let onlineTime = new Date()
if (!oldOnlineTimeSum.onlineTime) {
oldOnlineTimeSum.onlineTime = `${oldOnlineTimeSum.updatedAt.split(' ')[0]} 00:00:00`
}
onlineTime.setUTCHours(new Date(oldOnlineTimeSum.onlineTime).getHours()) onlineTime.setUTCHours(new Date(oldOnlineTimeSum.onlineTime).getHours())
onlineTime.setUTCMinutes(new Date(oldOnlineTimeSum.onlineTime).getMinutes()) onlineTime.setUTCMinutes(new Date(oldOnlineTimeSum.onlineTime).getMinutes())
onlineTime.setUTCSeconds(new Date(oldOnlineTimeSum.onlineTime).getSeconds()) onlineTime.setUTCSeconds(new Date(oldOnlineTimeSum.onlineTime).getSeconds())
@ -131,6 +137,7 @@ const sumOnlineTimeNow = (oldOnlineTimeSum) => {
} }
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', ' ');
return newOnlinetime return newOnlinetime
@ -300,7 +307,7 @@ const Dashboard = () => {
useEffect(() => { useEffect(() => {
if (!usersOnlineInfo || usersOnlineInfo.length == 0) return if (!usersOnlineInfo || usersOnlineInfo.length === 0) return
if (_fifo) { if (_fifo) {
clearInterval(_fifo); clearInterval(_fifo);
@ -308,17 +315,29 @@ const Dashboard = () => {
_fifo = setInterval(() => { _fifo = setInterval(() => {
usersOnlineInfo.map((e) => { for (let i = 0; i < usersOnlineInfo.length; i++) {
if (e.statusOnline && e.statusOnline.status === 'online') { if (usersOnlineInfo[i].statusOnline && usersOnlineInfo[i].statusOnline.status === 'online') {
let onlineTimeCurrent = sumOnlineTimeNow({onlineTime: e.statusOnline.onlineTime, updatedAt: e.statusOnline.updatedAt}) let onlineTimeCurrent = sumOnlineTimeNow({ onlineTime: usersOnlineInfo[i].statusOnline.onlineTime, updatedAt: usersOnlineInfo[i].statusOnline.updatedAt })
dispatch({ type: "UPDATE_STATUS_ONLINE", payload: { userId: e.id, status: e.statusOnline.status, onlineTime: onlineTimeCurrent } }); dispatch({ type: "UPDATE_STATUS_ONLINE", payload: { userId: usersOnlineInfo[i].id, status: usersOnlineInfo[i].statusOnline.status, onlineTime: onlineTimeCurrent } });
} }
}
})
// 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 } });
// }
// })
}, 3000); }, 3000);
@ -568,11 +587,15 @@ const Dashboard = () => {
</Paper> </Paper>
</Grid> </Grid>
{usersOnlineInfo &&
<TableUser <TableUser
classes={classes} classes={classes}
usersOnlineInfo={usersOnlineInfo} usersOnlineInfo={usersOnlineInfo}
logout={handleLogouOnlineUser} logout={handleLogouOnlineUser}
/> />
}
</Grid> </Grid>
</Paper> </Paper>
</Grid> </Grid>