feat: Update to display total number of pending and waiting tickets

feat-scaling-ticket-remote-creation
adriano 2024-02-26 16:58:39 -03:00
parent 237fa8124e
commit c9905eefb7
6 changed files with 109 additions and 121 deletions

View File

@ -128,8 +128,8 @@ export const remoteTicketCreation = async (
.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,9 +237,7 @@ 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({
return res.status(500).json({
msg: `Whatsapp number ${contact_from} disconnected or it doesn't exist in omnihit`
});
};

View File

@ -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);

View File

@ -61,11 +61,6 @@ const ListTicketsService = async ({
console.log('PAGE NUMBER TICKET: ', pageNumber)
//TEST DEL
// const url = await getWbot(46)
// console.log('---------> URL: ', url)
//
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 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,

View File

@ -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,55 +142,55 @@ 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,
@ -199,12 +199,13 @@ const TicketsList = (props) => {
status,
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 (
<Paper className={classes.ticketsListWrapper} style={style}>
@ -363,7 +362,7 @@ const TicketsList = (props) => {
</List>
</Paper>
</Paper>
);
};
)
}
export default TicketsList;
export default TicketsList

View File

@ -32,9 +32,6 @@ const VcardPreview = ({ contact, numbers }) => {
email: ""
}
console.log('contactObj: ', contactObj)
// return
const { data } = await api.post("/contact", contactObj);
setContact(data)

View File

@ -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 },