mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-20 12:49:32 +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";
|
import api from "../../services/api";
|
||||||
|
|
||||||
const useTickets = ({
|
const useTickets = ({
|
||||||
searchParam,
|
searchParam,
|
||||||
pageNumber,
|
pageNumber,
|
||||||
status,
|
status,
|
||||||
date,
|
date,
|
||||||
showAll,
|
showAll,
|
||||||
queueIds,
|
queueIds,
|
||||||
withUnreadMessages,
|
withUnreadMessages,
|
||||||
}) => {
|
}) => {
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [hasMore, setHasMore] = useState(false);
|
const [hasMore, setHasMore] = useState(false);
|
||||||
const [tickets, setTickets] = useState([]);
|
const [tickets, setTickets] = useState([]);
|
||||||
|
const [count, setCount] = useState(0);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const delayDebounceFn = setTimeout(() => {
|
const delayDebounceFn = setTimeout(() => {
|
||||||
const fetchTickets = async () => {
|
const fetchTickets = async() => {
|
||||||
try {
|
try {
|
||||||
const { data } = await api.get("/tickets", {
|
const { data } = await api.get("/tickets", {
|
||||||
params: {
|
params: {
|
||||||
searchParam,
|
searchParam,
|
||||||
pageNumber,
|
pageNumber,
|
||||||
status,
|
status,
|
||||||
date,
|
date,
|
||||||
showAll,
|
showAll,
|
||||||
queueIds,
|
queueIds,
|
||||||
withUnreadMessages,
|
withUnreadMessages,
|
||||||
},
|
},
|
||||||
});
|
})
|
||||||
setTickets(data.tickets);
|
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,
|
|
||||||
]);
|
|
||||||
|
|
||||||
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 GetTickets = (status, showAll, withUnreadMessages) => {
|
||||||
|
|
||||||
const { tickets } = useTickets({
|
const { count } = useTickets({
|
||||||
status: status,
|
status: status,
|
||||||
showAll: showAll,
|
showAll: showAll,
|
||||||
withUnreadMessages: withUnreadMessages,
|
withUnreadMessages: withUnreadMessages,
|
||||||
queueIds: JSON.stringify(userQueueIds)
|
queueIds: JSON.stringify(userQueueIds)
|
||||||
});
|
});
|
||||||
return tickets.length;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user