refactor: mais 7 conexoes movidas para conexao ws global
parent
4d3cab5333
commit
5981f9dd5e
|
@ -3,8 +3,8 @@ import React, { useState, useEffect, useRef, useContext } from "react"
|
||||||
import * as Yup from "yup"
|
import * as Yup from "yup"
|
||||||
import { Formik, Form, Field } from "formik"
|
import { Formik, Form, Field } from "formik"
|
||||||
import { toast } from "react-toastify"
|
import { toast } from "react-toastify"
|
||||||
import openSocket from 'socket.io-client'
|
//import openSocket from 'socket.io-client'
|
||||||
|
import { socket } from "../../services/socket"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
makeStyles,
|
makeStyles,
|
||||||
|
@ -87,9 +87,9 @@ const PositionModal = ({
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const socket = openSocket(process.env.REACT_APP_BACKEND_URL)
|
//const socket = openSocket(process.env.REACT_APP_BACKEND_URL)
|
||||||
|
|
||||||
socket.on('settings', (data) => {
|
const onSettingsPosition = (data) => {
|
||||||
if (data.action === 'update') {
|
if (data.action === 'update') {
|
||||||
setSettings((prevState) => {
|
setSettings((prevState) => {
|
||||||
const aux = [...prevState]
|
const aux = [...prevState]
|
||||||
|
@ -98,10 +98,12 @@ const PositionModal = ({
|
||||||
return aux
|
return aux
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
|
socket.on('settings', onSettingsPosition)
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
socket.disconnect()
|
socket.off("settings", onSettingsPosition)
|
||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import React, { useEffect, useState, useContext } from "react";
|
import React, { useEffect, useState, useContext } from "react";
|
||||||
import QRCode from "qrcode.react";
|
import QRCode from "qrcode.react";
|
||||||
import openSocket from "socket.io-client";
|
//import openSocket from "socket.io-client";
|
||||||
|
import { socket } from "../../services/socket";
|
||||||
|
|
||||||
import toastError from "../../errors/toastError";
|
import toastError from "../../errors/toastError";
|
||||||
|
|
||||||
import { Dialog, DialogContent, Paper, Typography } from "@material-ui/core";
|
import { Dialog, DialogContent, Paper, Typography } from "@material-ui/core";
|
||||||
|
@ -31,9 +33,9 @@ const QrcodeModal = ({ open, onClose, whatsAppId }) => {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!whatsAppId) return;
|
if (!whatsAppId) return;
|
||||||
const socket = openSocket(process.env.REACT_APP_BACKEND_URL);
|
//const socket = openSocket(process.env.REACT_APP_BACKEND_URL);
|
||||||
|
|
||||||
socket.on("whatsappSession", data => {
|
const onWhatsAppSessionQrCode = data => {
|
||||||
if (data.action === "update" && data.session.id === whatsAppId) {
|
if (data.action === "update" && data.session.id === whatsAppId) {
|
||||||
setQrCode(data.session.qrcode);
|
setQrCode(data.session.qrcode);
|
||||||
}
|
}
|
||||||
|
@ -44,19 +46,21 @@ const QrcodeModal = ({ open, onClose, whatsAppId }) => {
|
||||||
|
|
||||||
if (data.action === "error") {
|
if (data.action === "error") {
|
||||||
|
|
||||||
console.log('user.profile: ', user.profile)
|
console.log('user.profile: ', user.profile)
|
||||||
|
|
||||||
if(user.profile === 'master'){
|
if (user.profile === 'master') {
|
||||||
|
|
||||||
alert(data.msg)
|
alert(data.msg)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
socket.on("whatsappSession", onWhatsAppSessionQrCode);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
socket.disconnect();
|
socket.off("whatsappSession", onWhatsAppSessionQrCode);
|
||||||
};
|
};
|
||||||
}, [whatsAppId, onClose, user.profile]);
|
}, [whatsAppId, onClose, user.profile]);
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,8 @@ import { IconButton, InputAdornment } from "@material-ui/core"
|
||||||
import { Colorize } from "@material-ui/icons"
|
import { Colorize } from "@material-ui/icons"
|
||||||
|
|
||||||
import { AuthContext } from '../../context/Auth/AuthContext'
|
import { AuthContext } from '../../context/Auth/AuthContext'
|
||||||
import openSocket from 'socket.io-client'
|
//import openSocket from 'socket.io-client'
|
||||||
|
import { socket } from "../../services/socket"
|
||||||
|
|
||||||
|
|
||||||
const useStyles = makeStyles(theme => ({
|
const useStyles = makeStyles(theme => ({
|
||||||
|
@ -92,9 +92,9 @@ const QueueModal = ({ open, onClose, queueId }) => {
|
||||||
}, [setting])
|
}, [setting])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const socket = openSocket(process.env.REACT_APP_BACKEND_URL)
|
//const socket = openSocket(process.env.REACT_APP_BACKEND_URL)
|
||||||
|
|
||||||
socket.on('settings', (data) => {
|
const onSettingsQueueModal = (data) => {
|
||||||
if (data.action === 'update') {
|
if (data.action === 'update') {
|
||||||
setSettings((prevState) => {
|
setSettings((prevState) => {
|
||||||
const aux = [...prevState]
|
const aux = [...prevState]
|
||||||
|
@ -103,10 +103,12 @@ const QueueModal = ({ open, onClose, queueId }) => {
|
||||||
return aux
|
return aux
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
|
socket.on('settings', onSettingsQueueModal)
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
socket.disconnect()
|
socket.off("settings", onSettingsQueueModal)
|
||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,8 @@ import React, { useState, useEffect, useRef, useContext } from "react"
|
||||||
import * as Yup from "yup"
|
import * as Yup from "yup"
|
||||||
import { Formik, Form, Field } from "formik"
|
import { Formik, Form, Field } from "formik"
|
||||||
import { toast } from "react-toastify"
|
import { toast } from "react-toastify"
|
||||||
import openSocket from 'socket.io-client'
|
//import openSocket from 'socket.io-client'
|
||||||
|
import { socket } from "../../services/socket"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
makeStyles,
|
makeStyles,
|
||||||
|
@ -101,9 +101,9 @@ const QuickAnswersModal = ({
|
||||||
}, [open,])
|
}, [open,])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const socket = openSocket(process.env.REACT_APP_BACKEND_URL)
|
//const socket = openSocket(process.env.REACT_APP_BACKEND_URL)
|
||||||
|
|
||||||
socket.on('settings', (data) => {
|
const onSettingsQuickAnswersModal = (data) => {
|
||||||
if (data.action === 'update') {
|
if (data.action === 'update') {
|
||||||
setSettings((prevState) => {
|
setSettings((prevState) => {
|
||||||
const aux = [...prevState]
|
const aux = [...prevState]
|
||||||
|
@ -112,10 +112,12 @@ const QuickAnswersModal = ({
|
||||||
return aux
|
return aux
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
|
socket.on('settings', onSettingsQuickAnswersModal)
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
socket.disconnect()
|
socket.off("settings", onSettingsQuickAnswersModal)
|
||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import React, { useState, useContext, useMemo, useEffect } from "react"
|
import React, { useState, useContext, useMemo, useEffect } from "react"
|
||||||
import { useHistory } from "react-router-dom"
|
import { useHistory } from "react-router-dom"
|
||||||
import openSocket from "socket.io-client"
|
//import openSocket from "socket.io-client"
|
||||||
|
import { socket } from "../../services/socket"
|
||||||
|
|
||||||
import Button from "@material-ui/core/Button"
|
import Button from "@material-ui/core/Button"
|
||||||
import Dialog from "@material-ui/core/Dialog"
|
import Dialog from "@material-ui/core/Dialog"
|
||||||
|
@ -110,9 +111,9 @@ const TransferTicketModal = ({ modalOpen, onClose, ticketid }) => {
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const socket = openSocket(process.env.REACT_APP_BACKEND_URL)
|
//const socket = openSocket(process.env.REACT_APP_BACKEND_URL)
|
||||||
|
|
||||||
socket.on('settings', (data) => {
|
const onSettingsTransferTicketModal = (data) => {
|
||||||
console.log('settings updated ----------------------------xxxxxxxxxxxx')
|
console.log('settings updated ----------------------------xxxxxxxxxxxx')
|
||||||
|
|
||||||
if (data.action === 'update') {
|
if (data.action === 'update') {
|
||||||
|
@ -123,10 +124,12 @@ const TransferTicketModal = ({ modalOpen, onClose, ticketid }) => {
|
||||||
return aux
|
return aux
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
|
socket.on('settings', onSettingsTransferTicketModal)
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
socket.disconnect()
|
socket.off("settings", onSettingsTransferTicketModal)
|
||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
@ -228,7 +231,7 @@ const TransferTicketModal = ({ modalOpen, onClose, ticketid }) => {
|
||||||
{i18n.t("transferTicketModal.title")}
|
{i18n.t("transferTicketModal.title")}
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
<DialogContent dividers >
|
<DialogContent dividers >
|
||||||
<FormControl variant="outlined" className={classes.maxWidth} style={{marginBottom: '8px'}}>
|
<FormControl variant="outlined" className={classes.maxWidth} style={{ marginBottom: '8px' }}>
|
||||||
{/* <InputLabel>{i18n.t("transferTicketModal.fieldQueueLabel")}</InputLabel> */}
|
{/* <InputLabel>{i18n.t("transferTicketModal.fieldQueueLabel")}</InputLabel> */}
|
||||||
|
|
||||||
<InputLabel>{'Usuário'}</InputLabel>
|
<InputLabel>{'Usuário'}</InputLabel>
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import React, { useState, useCallback, useEffect, useReducer, useContext } from 'react'
|
import React, { useState, useCallback, useEffect, useReducer, useContext } from 'react'
|
||||||
import { toast } from 'react-toastify'
|
import { toast } from 'react-toastify'
|
||||||
|
|
||||||
import openSocket from 'socket.io-client'
|
//import openSocket from 'socket.io-client'
|
||||||
|
import { socket } from '../../services/socket'
|
||||||
|
|
||||||
import { makeStyles } from '@material-ui/core/styles'
|
import { makeStyles } from '@material-ui/core/styles'
|
||||||
import { green } from '@material-ui/core/colors'
|
import { green } from '@material-ui/core/colors'
|
||||||
|
@ -296,10 +297,9 @@ const Campaign = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const socket = openSocket(process.env.REACT_APP_BACKEND_URL)
|
//const socket = openSocket(process.env.REACT_APP_BACKEND_URL)
|
||||||
|
|
||||||
|
const onContactsBulkCampaing = (data) => {
|
||||||
socket.on("contactsBulkInsertOnQueueStatus", (data) => {
|
|
||||||
if (data.action === 'update') {
|
if (data.action === 'update') {
|
||||||
|
|
||||||
if (String(data.insertOnQueue.adminId) === String(user.id)) {
|
if (String(data.insertOnQueue.adminId) === String(user.id)) {
|
||||||
|
@ -312,19 +312,24 @@ const Campaign = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
socket.on('campaign', (data) => {
|
socket.on("contactsBulkInsertOnQueueStatus", onContactsBulkCampaing)
|
||||||
|
|
||||||
|
const onCampaignCampaign = (data) => {
|
||||||
|
|
||||||
if (data.action === 'update') {
|
if (data.action === 'update') {
|
||||||
dispatch({ type: "UPDATE_CAMPAIGNS", payload: data.campaign })
|
dispatch({ type: "UPDATE_CAMPAIGNS", payload: data.campaign })
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
|
socket.on('campaign', onCampaignCampaign)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
socket.disconnect()
|
socket.off("campaign", onCampaignCampaign)
|
||||||
|
socket.off("contactsBulkInsertOnQueueStatus", onContactsBulkCampaing)
|
||||||
}
|
}
|
||||||
}, [user.id])
|
}, [user.id])
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,8 @@ import React, { useState, useCallback, useEffect, useContext } from 'react'
|
||||||
import { toast } from 'react-toastify'
|
import { toast } from 'react-toastify'
|
||||||
import { format, parseISO } from 'date-fns'
|
import { format, parseISO } from 'date-fns'
|
||||||
|
|
||||||
import openSocket from 'socket.io-client'
|
//import openSocket from 'socket.io-client'
|
||||||
|
import { socket } from '../../services/socket'
|
||||||
|
|
||||||
import { makeStyles } from '@material-ui/core/styles'
|
import { makeStyles } from '@material-ui/core/styles'
|
||||||
import { green, red, yellow, grey } from '@material-ui/core/colors'
|
import { green, red, yellow, grey } from '@material-ui/core/colors'
|
||||||
|
@ -451,15 +452,17 @@ const Connections = () => {
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const socket = openSocket(process.env.REACT_APP_BACKEND_URL)
|
//const socket = openSocket(process.env.REACT_APP_BACKEND_URL)
|
||||||
|
|
||||||
socket.on('diskSpaceMonit', (data) => {
|
const onDiskSpaceMonitConnections = (data) => {
|
||||||
if (data.action === 'update') {
|
if (data.action === 'update') {
|
||||||
setDiskSpaceInfo(data.diskSpace)
|
setDiskSpaceInfo(data.diskSpace)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
socket.on('settings', (data) => {
|
socket.on('diskSpaceMonit', onDiskSpaceMonitConnections)
|
||||||
|
|
||||||
|
const onSettingsConnections = (data) => {
|
||||||
if (data.action === 'update') {
|
if (data.action === 'update') {
|
||||||
setSettings((prevState) => {
|
setSettings((prevState) => {
|
||||||
const aux = [...prevState]
|
const aux = [...prevState]
|
||||||
|
@ -468,10 +471,13 @@ const Connections = () => {
|
||||||
return aux
|
return aux
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
|
socket.on('settings', onSettingsConnections)
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
socket.disconnect()
|
socket.off("settings", onSettingsConnections)
|
||||||
|
socket.off("diskSpaceMonit", onDiskSpaceMonitConnections)
|
||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue