From 5c34b7911ed10d54917d07e250d01c749a17adbe Mon Sep 17 00:00:00 2001 From: adriano Date: Tue, 9 Aug 2022 15:44:28 -0300 Subject: [PATCH] =?UTF-8?q?Corre=C3=A7=C3=A3o=20da=20atualiza=C3=A7=C3=A3o?= =?UTF-8?q?=20do=20pending?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TicketServices/CreateTicketService.ts | 2 +- .../TicketServices/UpdateTicketService.ts | 12 ++-- frontend/src/pages/Dashboard/index.js | 61 +++++++++---------- 3 files changed, 35 insertions(+), 40 deletions(-) diff --git a/backend/src/services/TicketServices/CreateTicketService.ts b/backend/src/services/TicketServices/CreateTicketService.ts index ff0f53f..50eb44d 100644 --- a/backend/src/services/TicketServices/CreateTicketService.ts +++ b/backend/src/services/TicketServices/CreateTicketService.ts @@ -50,7 +50,7 @@ const CreateTicketService = async ({ const dateToday = splitDateTime(new Date(format(new Date(), 'yyyy-MM-dd HH:mm:ss', { locale: ptBR }))) - //openByUser : [ { id: 13, status: 'online' } ] + //openByUser : [ { id: 13, status: 'online' } ] TicketEmiterSumOpenClosedByUser(userId.toString(), dateToday.fullDate, dateToday.fullDate) diff --git a/backend/src/services/TicketServices/UpdateTicketService.ts b/backend/src/services/TicketServices/UpdateTicketService.ts index a874e87..1b790c8 100644 --- a/backend/src/services/TicketServices/UpdateTicketService.ts +++ b/backend/src/services/TicketServices/UpdateTicketService.ts @@ -51,14 +51,14 @@ const UpdateTicketService = async ({ await ticket.reload(); - const io = getIO(); + let io = getIO(); if (ticket.status !== oldStatus || ticket.user?.id !== oldUserId) { io.to(oldStatus).emit("ticket", { action: "delete", ticketId: ticket.id }); - } + } io.to(ticket.status) @@ -68,12 +68,12 @@ const UpdateTicketService = async ({ action: "update", ticket }); - - io.emit("ticketStatus", { + + io.emit("ticketStatus", { action: "update", - ticketStatus: {ticketId: ticket.id, status: ticket.status} - }); + ticketStatus: { ticketId: ticket.id, status: ticket.status } + }); return { ticket, oldStatus, oldUserId }; diff --git a/frontend/src/pages/Dashboard/index.js b/frontend/src/pages/Dashboard/index.js index 29d59e7..fb4f131 100644 --- a/frontend/src/pages/Dashboard/index.js +++ b/frontend/src/pages/Dashboard/index.js @@ -160,30 +160,19 @@ const reducer = (state, action) => { } } - - - if(onlineUser.openClosedInQueue){ - state[index].openClosedInQueue = onlineUser.openClosedInQueue + + + if (onlineUser.openClosedInQueue) { + state[index].openClosedInQueue = onlineUser.openClosedInQueue } - if(onlineUser.openClosedOutQueue){ - state[index].openClosedOutQueue = onlineUser.openClosedOutQueue + if (onlineUser.openClosedOutQueue) { + state[index].openClosedOutQueue = onlineUser.openClosedOutQueue } - // if(onlineUser.closedTicketByUserIn){ - // state[index].closedTicketByUserIn = onlineUser.closedTicketByUserIn - // } - // if(onlineUser.closedTicketByUserOut){ - // state[index].closedTicketByUserOut = onlineUser.closedTicketByUserOut - // } - // if(onlineUser.openTicketByUserIn){ - // state[index].openTicketByUserIn = onlineUser.openTicketByUserIn - // } - // if(onlineUser.openTicketByUserOut){ - // state[index].openTicketByUserOut = onlineUser.openTicketByUserOut - // } + } return [...state] @@ -291,19 +280,23 @@ const Dashboard = () => { socket.on("ticketStatus", (data) => { - // console.log('data: ',data) - - if(data.action === "update"){ + console.log('data: ', data) + + if (data.action === "update") { + + setStatus('') + + console.log('data.ticketStatus.status: ', data.ticketStatus.status) setStatus(data.ticketStatus.status) } }); socket.on("onlineStatus", (data) => { - if (data.action === "logout" || (data.action === "update")) { + if (data.action === "logout" || (data.action === "update")) { // console.log('>>>>>>> data.userOnlineTime: ', data.userOnlineTime) - + dispatch({ type: "UPDATE_STATUS_ONLINE", payload: data.userOnlineTime }); @@ -320,7 +313,7 @@ const Dashboard = () => { // console.log(' entrou no delete user: ', data) dispatch({ type: "DELETE_USER", payload: +data.userId }); } - }); + }); return () => { socket.disconnect(); @@ -332,8 +325,9 @@ const Dashboard = () => { useEffect(() => { - const delayDebounceFn = setTimeout(() => { - + if (ticketStatusChange === '') return + + const delayDebounceFn = setTimeout(() => { const fetchQueries = async () => { try { @@ -358,7 +352,8 @@ const Dashboard = () => { fetchQueries(); }, 500); - return () => clearTimeout(delayDebounceFn); + return () => clearTimeout(delayDebounceFn); + }, [ticketStatusChange]); @@ -510,7 +505,7 @@ const Dashboard = () => { userInfo.openClosedInQueue.map((info, index) => ( <> - {info.name}: OPEN {info.countOpen} | CLOSED {info.countClosed} + {info.name}: OPEN {info.countOpen} | CLOSED {info.countClosed} )) @@ -524,14 +519,14 @@ const Dashboard = () => {
Em atendimento(open/closed) sem fila, conversas iniciadas por atendentes:
{userInfo.openClosedOutQueue && - - - SEM FILA: OPEN {userInfo.openClosedOutQueue.countOpen} | CLOSED {userInfo.openClosedOutQueue.countClosed} - + + + SEM FILA: OPEN {userInfo.openClosedOutQueue.countOpen} | CLOSED {userInfo.openClosedOutQueue.countClosed} + } - + {userInfo.statusOnline && userInfo.statusOnline.status === "online" &&