mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-17 19:37:02 +00:00
Corrigido problema na contagem de chamados e adicionado possibilidade de fechar chamados automaticamente após um periodo de tempo
This commit is contained in:
@@ -1 +1,2 @@
|
||||
REACT_APP_BACKEND_URL = http://localhost:8080/
|
||||
REACT_APP_BACKEND_URL = http://localhost:8080/
|
||||
REACT_APP_HORAS_FECHAR_CHAMADOS_AUTO =
|
||||
@@ -4,56 +4,84 @@ import toastError from "../../errors/toastError";
|
||||
import api from "../../services/api";
|
||||
|
||||
const useTickets = ({
|
||||
searchParam,
|
||||
pageNumber,
|
||||
status,
|
||||
date,
|
||||
showAll,
|
||||
queueIds,
|
||||
withUnreadMessages,
|
||||
searchParam,
|
||||
pageNumber,
|
||||
status,
|
||||
date,
|
||||
showAll,
|
||||
queueIds,
|
||||
withUnreadMessages,
|
||||
}) => {
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [hasMore, setHasMore] = useState(false);
|
||||
const [tickets, setTickets] = useState([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [hasMore, setHasMore] = useState(false);
|
||||
const [tickets, setTickets] = useState([]);
|
||||
const [count, setCount] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
setLoading(true);
|
||||
const delayDebounceFn = setTimeout(() => {
|
||||
const fetchTickets = async () => {
|
||||
try {
|
||||
const { data } = await api.get("/tickets", {
|
||||
params: {
|
||||
searchParam,
|
||||
pageNumber,
|
||||
status,
|
||||
date,
|
||||
showAll,
|
||||
queueIds,
|
||||
withUnreadMessages,
|
||||
},
|
||||
});
|
||||
setTickets(data.tickets);
|
||||
setHasMore(data.hasMore);
|
||||
setLoading(false);
|
||||
} catch (err) {
|
||||
setLoading(false);
|
||||
toastError(err);
|
||||
}
|
||||
};
|
||||
fetchTickets();
|
||||
}, 500);
|
||||
return () => clearTimeout(delayDebounceFn);
|
||||
}, [
|
||||
searchParam,
|
||||
pageNumber,
|
||||
status,
|
||||
date,
|
||||
showAll,
|
||||
queueIds,
|
||||
withUnreadMessages,
|
||||
]);
|
||||
useEffect(() => {
|
||||
setLoading(true);
|
||||
const delayDebounceFn = setTimeout(() => {
|
||||
const fetchTickets = async() => {
|
||||
try {
|
||||
const { data } = await api.get("/tickets", {
|
||||
params: {
|
||||
searchParam,
|
||||
pageNumber,
|
||||
status,
|
||||
date,
|
||||
showAll,
|
||||
queueIds,
|
||||
withUnreadMessages,
|
||||
},
|
||||
})
|
||||
setTickets(data.tickets)
|
||||
|
||||
return { tickets, loading, hasMore };
|
||||
let horasFecharAutomaticamente = process.env.REACT_APP_HOURS_CLOSE_TICKETS_AUTO
|
||||
|
||||
if (status === "open" && horasFecharAutomaticamente && horasFecharAutomaticamente !== "" &&
|
||||
horasFecharAutomaticamente !== "0" && Number(horasFecharAutomaticamente) > 0) {
|
||||
|
||||
let dataLimite = new Date()
|
||||
dataLimite.setHours(dataLimite.getHours() - Number(horasFecharAutomaticamente))
|
||||
|
||||
data.tickets.forEach(ticket => {
|
||||
if (ticket.status !== "closed") {
|
||||
let dataUltimaInteracaoChamado = new Date(ticket.updatedAt)
|
||||
if (dataUltimaInteracaoChamado < dataLimite)
|
||||
closeTicket(ticket)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
setHasMore(data.hasMore)
|
||||
setCount(data.count)
|
||||
setLoading(false)
|
||||
} catch (err) {
|
||||
setLoading(false)
|
||||
toastError(err)
|
||||
}
|
||||
}
|
||||
|
||||
const closeTicket = async(ticket) => {
|
||||
await api.put(`/tickets/${ticket.id}`, {
|
||||
status: "closed",
|
||||
userId: ticket.userId || null,
|
||||
})
|
||||
}
|
||||
|
||||
fetchTickets()
|
||||
}, 500)
|
||||
return () => clearTimeout(delayDebounceFn)
|
||||
}, [
|
||||
searchParam,
|
||||
pageNumber,
|
||||
status,
|
||||
date,
|
||||
showAll,
|
||||
queueIds,
|
||||
withUnreadMessages,
|
||||
])
|
||||
|
||||
return { tickets, loading, hasMore, count };
|
||||
};
|
||||
|
||||
export default useTickets;
|
||||
export default useTickets;
|
||||
@@ -54,13 +54,13 @@ const Dashboard = () => {
|
||||
|
||||
const GetTickets = (status, showAll, withUnreadMessages) => {
|
||||
|
||||
const { tickets } = useTickets({
|
||||
const { count } = useTickets({
|
||||
status: status,
|
||||
showAll: showAll,
|
||||
withUnreadMessages: withUnreadMessages,
|
||||
queueIds: JSON.stringify(userQueueIds)
|
||||
});
|
||||
return tickets.length;
|
||||
return count;
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -114,4 +114,4 @@ const Dashboard = () => {
|
||||
)
|
||||
}
|
||||
|
||||
export default Dashboard
|
||||
export default Dashboard
|
||||
Reference in New Issue
Block a user