Correção para que usuários que não estejam em nenhuma fila possam enviar mensagem a apartir da primeira conexão que esteja com status connected. Correção dos hooks do reack e implementação do unlimited para o dashboard exibir mais que 40 tickets
							parent
							
								
									59485325cd
								
							
						
					
					
						commit
						33fc280801
					
				|  | @ -24,6 +24,7 @@ type IndexQuery = { | ||||||
|   showAll: string; |   showAll: string; | ||||||
|   withUnreadMessages: string; |   withUnreadMessages: string; | ||||||
|   queueIds: string; |   queueIds: string; | ||||||
|  |   unlimited?: string; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| interface TicketData { | interface TicketData { | ||||||
|  | @ -44,9 +45,12 @@ export const index = async (req: Request, res: Response): Promise<Response> => { | ||||||
|     searchParam, |     searchParam, | ||||||
|     showAll, |     showAll, | ||||||
|     queueIds: queueIdsStringified, |     queueIds: queueIdsStringified, | ||||||
|     withUnreadMessages |     withUnreadMessages, | ||||||
|  |     unlimited | ||||||
|   } = req.query as IndexQuery; |   } = req.query as IndexQuery; | ||||||
| 
 | 
 | ||||||
|  |   | ||||||
|  | 
 | ||||||
|   const userId = req.user.id;  |   const userId = req.user.id;  | ||||||
| 
 | 
 | ||||||
|   let queueIds: number[] = []; |   let queueIds: number[] = []; | ||||||
|  | @ -63,7 +67,8 @@ export const index = async (req: Request, res: Response): Promise<Response> => { | ||||||
|     showAll, |     showAll, | ||||||
|     userId, |     userId, | ||||||
|     queueIds, |     queueIds, | ||||||
|     withUnreadMessages |     withUnreadMessages, | ||||||
|  |     unlimited | ||||||
|   }); |   }); | ||||||
|   |   | ||||||
|   return res.status(200).json({ tickets, count, hasMore }); |   return res.status(200).json({ tickets, count, hasMore }); | ||||||
|  | @ -171,6 +176,8 @@ export const update = async ( req: Request, res: Response ): Promise<Response> = | ||||||
| 
 | 
 | ||||||
|     const ticketData: TicketData = req.body; |     const ticketData: TicketData = req.body; | ||||||
| 
 | 
 | ||||||
|  |     //ticketData:  { status: 'open', userId: 4 } , ticketId
 | ||||||
|  | 
 | ||||||
|     const { ticket } = await UpdateTicketService({ |     const { ticket } = await UpdateTicketService({ | ||||||
|       ticketData, |       ticketData, | ||||||
|       ticketId |       ticketId | ||||||
|  |  | ||||||
|  | @ -26,6 +26,10 @@ const GetDefaultWhatsApp = async (userId?: string | number ): Promise<Whatsapp> | ||||||
|      |      | ||||||
|           console.log('+++++++++++++++ queueId: ',queue?.queueId, '   |  userId: ', userId) |           console.log('+++++++++++++++ queueId: ',queue?.queueId, '   |  userId: ', userId) | ||||||
|          |          | ||||||
|  |         if(queue?.queueId){ | ||||||
|  | 
 | ||||||
|  |             console.log('Usuário está adicionado à fila!') | ||||||
|  | 
 | ||||||
|             const whatsapp = await WhatsappQueue.findOne(  |             const whatsapp = await WhatsappQueue.findOne(  | ||||||
|               { |               { | ||||||
|                 where: { queueId: `${queue?.queueId }`}, |                 where: { queueId: `${queue?.queueId }`}, | ||||||
|  | @ -38,9 +42,18 @@ const GetDefaultWhatsApp = async (userId?: string | number ): Promise<Whatsapp> | ||||||
|             defaultWhatsapp = await Whatsapp.findOne({ |             defaultWhatsapp = await Whatsapp.findOne({ | ||||||
|               where: { id: `${whatsapp?.whatsappId}` } |               where: { id: `${whatsapp?.whatsappId}` } | ||||||
|             });   |             });   | ||||||
| 
 |  | ||||||
|         } |         } | ||||||
|         else{ |         else{ | ||||||
|  | 
 | ||||||
|  |           console.log('Usuário não está adicionando a nenhuma fila e vai enviar a mensagem  a partir da primeira conexao disponível!') | ||||||
|  |           defaultWhatsapp = await Whatsapp.findOne({ | ||||||
|  |             where: { status:  'CONNECTED' } | ||||||
|  |           }); | ||||||
|  | 
 | ||||||
|  |         }  | ||||||
|  |       } | ||||||
|  |       else{ | ||||||
|  |         | ||||||
|         defaultWhatsapp = await Whatsapp.findOne({ |         defaultWhatsapp = await Whatsapp.findOne({ | ||||||
|           where: { status:  'CONNECTED' } |           where: { status:  'CONNECTED' } | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
|  | @ -16,6 +16,7 @@ interface Request { | ||||||
|   userId: string; |   userId: string; | ||||||
|   withUnreadMessages?: string; |   withUnreadMessages?: string; | ||||||
|   queueIds: number[]; |   queueIds: number[]; | ||||||
|  |   unlimited?: string; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| interface Response { | interface Response { | ||||||
|  | @ -32,7 +33,8 @@ const ListTicketsService = async ({ | ||||||
|   date, |   date, | ||||||
|   showAll, |   showAll, | ||||||
|   userId, |   userId, | ||||||
|   withUnreadMessages |   withUnreadMessages, | ||||||
|  |   unlimited='false' | ||||||
| }: Request): Promise<Response> => { | }: Request): Promise<Response> => { | ||||||
|   let whereCondition: Filterable["where"] = { |   let whereCondition: Filterable["where"] = { | ||||||
|     [Op.or]: [{ userId }, { status: "pending" }], |     [Op.or]: [{ userId }, { status: "pending" }], | ||||||
|  | @ -126,7 +128,7 @@ const ListTicketsService = async ({ | ||||||
|     }; |     }; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   const limit = 40; |   const limit = unlimited === 'true' ? 100000 : 40; | ||||||
|   const offset = limit * (+pageNumber - 1); |   const offset = limit * (+pageNumber - 1); | ||||||
| 
 | 
 | ||||||
|   const { count, rows: tickets } = await Ticket.findAndCountAll({ |   const { count, rows: tickets } = await Ticket.findAndCountAll({ | ||||||
|  |  | ||||||
|  | @ -107,6 +107,9 @@ const TransferTicketModal = ({ modalOpen, onClose, ticketid }) => { | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 
 | 
 | ||||||
|  | 			// test del PARA APARECER NA FILA DE OUTRO ATENDENTE E O MESMO CLICAR EM ACEITAR AO INVES DE ENVIAR PARA ATENDENDO
 | ||||||
|  | 			data.status = 'pending' | ||||||
|  | 
 | ||||||
| 			await api.put(`/tickets/${ticketid}`, data); | 			await api.put(`/tickets/${ticketid}`, data); | ||||||
| 
 | 
 | ||||||
| 			setLoading(false); | 			setLoading(false); | ||||||
|  |  | ||||||
|  | @ -11,6 +11,7 @@ const useTickets = ({ | ||||||
| 	showAll, | 	showAll, | ||||||
| 	queueIds, | 	queueIds, | ||||||
| 	withUnreadMessages, | 	withUnreadMessages, | ||||||
|  | 	unlimited | ||||||
| }) => { | }) => { | ||||||
| 	const [loading, setLoading] = useState(true); | 	const [loading, setLoading] = useState(true); | ||||||
| 	const [hasMore, setHasMore] = useState(false); | 	const [hasMore, setHasMore] = useState(false); | ||||||
|  | @ -30,6 +31,7 @@ const useTickets = ({ | ||||||
| 							showAll, | 							showAll, | ||||||
| 							queueIds, | 							queueIds, | ||||||
| 							withUnreadMessages, | 							withUnreadMessages, | ||||||
|  | 							unlimited | ||||||
| 						}, | 						}, | ||||||
| 					}); | 					}); | ||||||
| 					setTickets(data.tickets); | 					setTickets(data.tickets); | ||||||
|  | @ -51,6 +53,8 @@ const useTickets = ({ | ||||||
| 		showAll, | 		showAll, | ||||||
| 		queueIds, | 		queueIds, | ||||||
| 		withUnreadMessages, | 		withUnreadMessages, | ||||||
|  | 		 | ||||||
|  | 		unlimited | ||||||
| 	]); | 	]); | ||||||
| 
 | 
 | ||||||
| 	return { tickets, loading, hasMore }; | 	return { tickets, loading, hasMore }; | ||||||
|  |  | ||||||
|  | @ -54,13 +54,14 @@ const Dashboard = () => { | ||||||
| 		userQueueIds = user.queues.map(q => q.id); | 		userQueueIds = user.queues.map(q => q.id); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	const GetTickets = (status, showAll, withUnreadMessages) => { | 	const GetTickets = (status, showAll, withUnreadMessages, unlimited) => { | ||||||
| 
 | 
 | ||||||
| 		const { tickets } = useTickets({ | 		const { tickets } = useTickets({ | ||||||
| 			status: status, | 			status: status, | ||||||
| 			showAll: showAll, | 			showAll: showAll, | ||||||
| 			withUnreadMessages: withUnreadMessages, | 			withUnreadMessages: withUnreadMessages, | ||||||
| 			queueIds: JSON.stringify(userQueueIds) | 			queueIds: JSON.stringify(userQueueIds), | ||||||
|  | 			unlimited: unlimited | ||||||
| 		}); | 		}); | ||||||
| 		return tickets.length; | 		return tickets.length; | ||||||
| 	} | 	} | ||||||
|  | @ -81,7 +82,7 @@ const Dashboard = () => { | ||||||
| 									</Typography> | 									</Typography> | ||||||
| 									<Grid item> | 									<Grid item> | ||||||
| 										<Typography component="h1" variant="h4"> | 										<Typography component="h1" variant="h4"> | ||||||
| 											{GetTickets("open", "true", "false")} | 											{GetTickets("open", "true", "false", "true")} | ||||||
| 										</Typography> | 										</Typography> | ||||||
| 									</Grid> | 									</Grid> | ||||||
| 								</Paper> | 								</Paper> | ||||||
|  | @ -93,7 +94,7 @@ const Dashboard = () => { | ||||||
| 									</Typography> | 									</Typography> | ||||||
| 									<Grid item> | 									<Grid item> | ||||||
| 										<Typography component="h1" variant="h4"> | 										<Typography component="h1" variant="h4"> | ||||||
| 											{GetTickets("pending", "true", "false")} | 											{GetTickets("pending", "true", "false", "true")} | ||||||
| 										</Typography> | 										</Typography> | ||||||
| 									</Grid> | 									</Grid> | ||||||
| 								</Paper> | 								</Paper> | ||||||
|  | @ -105,7 +106,7 @@ const Dashboard = () => { | ||||||
| 									</Typography> | 									</Typography> | ||||||
| 									<Grid item> | 									<Grid item> | ||||||
| 										<Typography component="h1" variant="h4"> | 										<Typography component="h1" variant="h4"> | ||||||
| 											{GetTickets("closed", "true", "false")} | 											{GetTickets("closed", "true", "false", "true")} | ||||||
| 										</Typography> | 										</Typography> | ||||||
| 									</Grid> | 									</Grid> | ||||||
| 								</Paper> | 								</Paper> | ||||||
|  |  | ||||||
|  | @ -290,7 +290,7 @@ const Report = () => { | ||||||
| 
 | 
 | ||||||
|           //setLoading(false);
 |           //setLoading(false);
 | ||||||
| 
 | 
 | ||||||
|         //  console.log('dataQuery: ', dataQuery.data)
 |           console.log('dataQuery: ', dataQuery.data) | ||||||
| 
 | 
 | ||||||
|           console.log()  |           console.log()  | ||||||
| 
 | 
 | ||||||
|  | @ -359,6 +359,7 @@ const handleCSVMessages = () =>{ | ||||||
|       //  console.log('dataCSVFormat: ', dataCSVFormat)
 |       //  console.log('dataCSVFormat: ', dataCSVFormat)
 | ||||||
|          |          | ||||||
|            setDataCSV(dataCSVFormat) |            setDataCSV(dataCSVFormat) | ||||||
|  |            setIsMount(false); | ||||||
|         // setDataCSV(dataQuery.data)
 |         // setDataCSV(dataQuery.data)
 | ||||||
|       }  |       }  | ||||||
| 
 | 
 | ||||||
|  | @ -374,16 +375,18 @@ const handleCSVMessages = () =>{ | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |   | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| useEffect(() => { | useEffect(() => { | ||||||
| 
 | 
 | ||||||
|   if(isMount){  |   if(isMount){  | ||||||
|     setIsMount(false); |  | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|    |    | ||||||
|   csvLink.current.link.click() |   csvLink.current.link.click() | ||||||
| 
 | 
 | ||||||
| }, [dataCSV]); | }, [dataCSV, isMount, csvLink]); | ||||||
| 
 | 
 | ||||||
|    |    | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue