diff --git a/backend/src/controllers/TicketController.ts b/backend/src/controllers/TicketController.ts index bf63ec2..cc7f7e8 100644 --- a/backend/src/controllers/TicketController.ts +++ b/backend/src/controllers/TicketController.ts @@ -95,7 +95,7 @@ export const index = async (req: Request, res: Response): Promise => { if (queueIdsStringified) { queueIds = JSON.parse(queueIdsStringified); - } + } const { tickets, count, hasMore } = await ListTicketsService({ searchParam, @@ -109,7 +109,7 @@ export const index = async (req: Request, res: Response): Promise => { unlimited, searchParamContent }); - + return res.status(200).json({ tickets, count, hasMore }); }; @@ -127,9 +127,9 @@ export const remoteTicketCreation = async ( return res .status(400) .json({ error: `Property '${prop}' is undefined.` }); - - if(validateOnlyNumber.includes(prop)){ - if(!(/^\d+$/.test(req.body[prop]))){ + + if (validateOnlyNumber.includes(prop)) { + if (!/^\d+$/.test(req.body[prop])) { return res .status(400) .json({ error: `The property '${prop}' must be a number` }); @@ -237,11 +237,9 @@ export const remoteTicketCreation = async ( console.log( `REMOTE TICKET CREATION FROM ENDPOINT | STATUS: 500 | MSG: Whatsapp number ${contact_from} disconnected or it doesn't exist in omnihit` ); - return res - .status(500) - .json({ - msg: `Whatsapp number ${contact_from} disconnected or it doesn't exist in omnihit` - }); + return res.status(500).json({ + msg: `Whatsapp number ${contact_from} disconnected or it doesn't exist in omnihit` + }); }; export const store = async (req: Request, res: Response): Promise => { diff --git a/backend/src/routes/ticketRoutes.ts b/backend/src/routes/ticketRoutes.ts index 2c17f9e..80fa9d3 100644 --- a/backend/src/routes/ticketRoutes.ts +++ b/backend/src/routes/ticketRoutes.ts @@ -5,7 +5,6 @@ import * as TicketController from "../controllers/TicketController"; const ticketRoutes = express.Router(); - // ticketRoutes.get("/tickets/cache", isAuth, TicketController.ticketsCache); ticketRoutes.get("/tickets/count", isAuth, TicketController.count); diff --git a/backend/src/services/TicketServices/ListTicketsService.ts b/backend/src/services/TicketServices/ListTicketsService.ts index ac2e2fb..1ea2cc6 100644 --- a/backend/src/services/TicketServices/ListTicketsService.ts +++ b/backend/src/services/TicketServices/ListTicketsService.ts @@ -59,13 +59,8 @@ const ListTicketsService = async ({ let whereCondition: Filterable["where"] = { [Op.or]: [{ userId }, { status: "pending" }], queueId: { [Op.or]: [queueIds, null] } }; - console.log('PAGE NUMBER TICKET: ', pageNumber) - - //TEST DEL - // const url = await getWbot(46) - // console.log('---------> URL: ', url) - // - + console.log('PAGE NUMBER TICKET: ', pageNumber) + if (pageNumber.trim().length == 0) { pageNumber = '1' } @@ -136,15 +131,14 @@ const ListTicketsService = async ({ whereCondition = { ...whereCondition, status }; - if (unlimited === 'true' && status !== 'pending') { - + if (unlimited === "current" && status !== "pending") { whereCondition = { ...whereCondition, createdAt: { - [Op.gte]: dateToday.fullDate + ' 00:00:00.000000', - [Op.lte]: dateToday.fullDate + ' 23:59:59.999999' + [Op.gte]: dateToday.fullDate + " 00:00:00.000000", + [Op.lte]: dateToday.fullDate + " 23:59:59.999999" } - } + }; } } @@ -196,8 +190,8 @@ const ListTicketsService = async ({ if ( userProfile.dataValues.profile != "admin" && - userProfile.dataValues.profile != "master" - // userProfile.dataValues.profile != "supervisor" + userProfile.dataValues.profile != "master" && + userProfile.dataValues.profile != "supervisor" ) { whereCondition = { ...whereCondition, userId }; } @@ -224,9 +218,10 @@ const ListTicketsService = async ({ }; } - const limit = unlimited === 'true' ? 100000 : 40; - const offset = limit * (+pageNumber - 1); + const limit = unlimited === "current" || unlimited === "all" ? 100000 : 40; + const offset = limit * (+pageNumber - 1); + console.log("kkkkkkkkk limit: ", limit); const { count, rows: tickets } = await Ticket.findAndCountAll({ where: whereCondition, diff --git a/frontend/src/components/TicketsList/index.js b/frontend/src/components/TicketsList/index.js index 6e5bf4b..203e371 100644 --- a/frontend/src/components/TicketsList/index.js +++ b/frontend/src/components/TicketsList/index.js @@ -1,20 +1,20 @@ -import React, { useState, useEffect, useReducer, useContext } from "react"; +import React, { useState, useEffect, useReducer, useContext } from "react" -import openSocket from "socket.io-client"; +import openSocket from "socket.io-client" -import { makeStyles } from "@material-ui/core/styles"; -import List from "@material-ui/core/List"; -import Paper from "@material-ui/core/Paper"; +import { makeStyles } from "@material-ui/core/styles" +import List from "@material-ui/core/List" +import Paper from "@material-ui/core/Paper" -import TicketListItem from "../TicketListItem"; -import TicketsListSkeleton from "../TicketsListSkeleton"; +import TicketListItem from "../TicketListItem" +import TicketsListSkeleton from "../TicketsListSkeleton" -import useTickets from "../../hooks/useTickets"; -import { i18n } from "../../translate/i18n"; -import { AuthContext } from "../../context/Auth/AuthContext"; +import useTickets from "../../hooks/useTickets" +import { i18n } from "../../translate/i18n" +import { AuthContext } from "../../context/Auth/AuthContext" -import { SearchTicketContext } from "../../context/SearchTicket/SearchTicket"; +import { SearchTicketContext } from "../../context/SearchTicket/SearchTicket" const useStyles = makeStyles(theme => ({ ticketsListWrapper: { @@ -73,64 +73,64 @@ const useStyles = makeStyles(theme => ({ alignItems: "center", justifyContent: "center", }, -})); +})) const reducer = (state, action) => { if (action.type === "LOAD_TICKETS") { - const newTickets = action.payload; + const newTickets = action.payload newTickets.forEach(ticket => { - const ticketIndex = state.findIndex(t => +t.id === +ticket.id); + const ticketIndex = state.findIndex(t => +t.id === +ticket.id) if (ticketIndex !== -1) { - state[ticketIndex] = ticket; + state[ticketIndex] = ticket if (+ticket.unreadMessages > 0) { - state.unshift(state.splice(ticketIndex, 1)[0]); + state.unshift(state.splice(ticketIndex, 1)[0]) } } else { - state.push(ticket); + state.push(ticket) } - }); + }) - return [...state]; + return [...state] } if (action.type === "RESET_UNREAD") { - const ticketId = action.payload; + const ticketId = action.payload - const ticketIndex = state.findIndex(t => +t.id === +ticketId); + const ticketIndex = state.findIndex(t => +t.id === +ticketId) if (ticketIndex !== -1) { - state[ticketIndex].unreadMessages = 0; + state[ticketIndex].unreadMessages = 0 } - return [...state]; + return [...state] } if (action.type === "UPDATE_TICKET") { - const ticket = action.payload; + const ticket = action.payload - const ticketIndex = state.findIndex(t => +t.id === +ticket.id); + const ticketIndex = state.findIndex(t => +t.id === +ticket.id) if (ticketIndex !== -1) { - state[ticketIndex] = ticket; + state[ticketIndex] = ticket } else { - state.unshift(ticket); + state.unshift(ticket) } - return [...state]; + return [...state] } if (action.type === "UPDATE_TICKET_UNREAD_MESSAGES") { const message = action.payload.message - const ticket = action.payload.ticket; + const ticket = action.payload.ticket - const ticketIndex = state.findIndex(t => +t.id === +ticket.id); + const ticketIndex = state.findIndex(t => +t.id === +ticket.id) if (ticketIndex !== -1) { @@ -142,69 +142,70 @@ const reducer = (state, action) => { ticket.unreadMessages += 1 } - state[ticketIndex] = ticket; - state.unshift(state.splice(ticketIndex, 1)[0]); + state[ticketIndex] = ticket + state.unshift(state.splice(ticketIndex, 1)[0]) } else { - state.unshift(ticket); + state.unshift(ticket) } - return [...state]; + return [...state] } if (action.type === "UPDATE_TICKET_CONTACT") { - const contact = action.payload; - const ticketIndex = state.findIndex(t => +t.contactId === +contact.id); + const contact = action.payload + const ticketIndex = state.findIndex(t => +t.contactId === +contact.id) if (ticketIndex !== -1) { - state[ticketIndex].contact = contact; + state[ticketIndex].contact = contact } - return [...state]; + return [...state] } if (action.type === "DELETE_TICKET") { - const ticketId = action.payload; - const ticketIndex = state.findIndex(t => +t.id === +ticketId); + const ticketId = action.payload + const ticketIndex = state.findIndex(t => +t.id === +ticketId) if (ticketIndex !== -1) { - state.splice(ticketIndex, 1); + state.splice(ticketIndex, 1) } - return [...state]; + return [...state] } if (action.type === "RESET") { - return []; + return [] } -}; +} const TicketsList = (props) => { - const { status, searchParam, searchParamContent, showAll, selectedQueueIds, updateCount, style, tab } = props; - const classes = useStyles(); - const [pageNumber, setPageNumber] = useState(1); - const [ticketsList, dispatch] = useReducer(reducer, []); - const { user } = useContext(AuthContext); + const { status, searchParam, searchParamContent, showAll, selectedQueueIds, updateCount, style, tab } = props + const classes = useStyles() + const [pageNumber, setPageNumber] = useState(1) + const [ticketsList, dispatch] = useReducer(reducer, []) + const { user } = useContext(AuthContext) const { searchTicket } = useContext(SearchTicketContext) useEffect(() => { - dispatch({ type: "RESET" }); - setPageNumber(1); + dispatch({ type: "RESET" }) + setPageNumber(1) - }, [status, searchParam, searchParamContent, showAll, selectedQueueIds, searchTicket]); + }, [status, searchParam, searchParamContent, showAll, selectedQueueIds, searchTicket]) const { tickets, hasMore, loading } = useTickets({ pageNumber, searchParam, searchParamContent, status, - showAll, + showAll, queueIds: JSON.stringify(selectedQueueIds), - tab - }); + tab, + unlimited:"all" + }) useEffect(() => { - if (!status && !searchParam) return; + if (!status && !searchParam) return // if (searchParam) { // @@ -217,31 +218,31 @@ const TicketsList = (props) => { dispatch({ type: "RESET" }) } - dispatch({ type: "LOAD_TICKETS", payload: tickets, }); + dispatch({ type: "LOAD_TICKETS", payload: tickets, }) - }, [tickets, status, searchParam, pageNumber]); + }, [tickets, status, searchParam, pageNumber]) useEffect(() => { // if (tab=='search')return - const socket = openSocket(process.env.REACT_APP_BACKEND_URL); + const socket = openSocket(process.env.REACT_APP_BACKEND_URL) const shouldUpdateTicket = ticket => (!ticket.userId || ticket.userId === user?.id || showAll) && - (!ticket.queueId || selectedQueueIds.indexOf(ticket.queueId) > -1); + (!ticket.queueId || selectedQueueIds.indexOf(ticket.queueId) > -1) const notBelongsToUserQueues = ticket => - ticket.queueId && selectedQueueIds.indexOf(ticket.queueId) === -1; + ticket.queueId && selectedQueueIds.indexOf(ticket.queueId) === -1 socket.on("connect", () => { if (status) { - socket.emit("joinTickets", status); + socket.emit("joinTickets", status) } else { - socket.emit("joinNotification"); + socket.emit("joinNotification") } - }); + }) @@ -254,7 +255,7 @@ const TicketsList = (props) => { dispatch({ type: "RESET_UNREAD", payload: data.ticketId, - }); + }) } if (data.action === "update" && shouldUpdateTicket(data.ticket)) { @@ -264,17 +265,17 @@ const TicketsList = (props) => { dispatch({ type: "UPDATE_TICKET", payload: data.ticket, - }); + }) } if (data.action === "update" && notBelongsToUserQueues(data.ticket)) { - dispatch({ type: "DELETE_TICKET", payload: data.ticket.id }); + dispatch({ type: "DELETE_TICKET", payload: data.ticket.id }) } if (data.action === "delete") { - dispatch({ type: "DELETE_TICKET", payload: data.ticketId }); + dispatch({ type: "DELETE_TICKET", payload: data.ticketId }) } - }); + }) socket.on("appMessage", data => { @@ -287,51 +288,49 @@ const TicketsList = (props) => { type: "UPDATE_TICKET_UNREAD_MESSAGES", // payload: data.ticket, payload: data, - }); + }) } - }); + }) socket.on("contact", data => { if (data.action === "update") { dispatch({ type: "UPDATE_TICKET_CONTACT", payload: data.contact, - }); + }) } - }); + }) return () => { - socket.disconnect(); - }; - }, [status, showAll, user, selectedQueueIds, tab]); + socket.disconnect() + } + }, [status, showAll, user, selectedQueueIds, tab]) useEffect(() => { - - if (typeof updateCount === "function") { - updateCount(ticketsList.length); + updateCount(ticketsList.length) } // eslint-disable-next-line react-hooks/exhaustive-deps - }, [ticketsList]); + }, [ticketsList]) const loadMore = () => { - setPageNumber(prevState => prevState + 1); - }; + setPageNumber(prevState => prevState + 1) + } const handleScroll = e => { - if (!hasMore || loading) return; + if (!hasMore || loading) return - const { scrollTop, scrollHeight, clientHeight } = e.currentTarget; + const { scrollTop, scrollHeight, clientHeight } = e.currentTarget if (scrollHeight - (scrollTop + 100) < clientHeight) { - loadMore(); + loadMore() } - }; + } return ( @@ -363,7 +362,7 @@ const TicketsList = (props) => { - ); -}; + ) +} -export default TicketsList; +export default TicketsList diff --git a/frontend/src/components/VcardPreview/index.js b/frontend/src/components/VcardPreview/index.js index 0b2e48a..f2a63be 100644 --- a/frontend/src/components/VcardPreview/index.js +++ b/frontend/src/components/VcardPreview/index.js @@ -31,10 +31,7 @@ const VcardPreview = ({ contact, numbers }) => { number: numbers !== undefined && numbers.replace(/\D/g, ""), email: "" } - - console.log('contactObj: ', contactObj) - // return - + const { data } = await api.post("/contact", contactObj); setContact(data) diff --git a/frontend/src/pages/Dashboard/Chart.js b/frontend/src/pages/Dashboard/Chart.js index e79e964..5d0de34 100644 --- a/frontend/src/pages/Dashboard/Chart.js +++ b/frontend/src/pages/Dashboard/Chart.js @@ -20,7 +20,7 @@ const Chart = (props) => { const theme = useTheme(); const date = useRef(new Date().toISOString()); - let { tickets } = useTickets({ date: date.current, unlimited: "true" }); + let { tickets } = useTickets({ date: date.current, unlimited: "current" }); const [chartData, setChartData] = useState([ { time: "08:00", amount: 0 },