link-stack/apps/link/app/(main)/overview/[overview]/_components/ZammadOverview.tsx

44 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-06-26 10:07:12 +00:00
"use client";
2023-10-16 09:20:40 +02:00
import { FC, useEffect, useState } from "react";
import { redirect } from "next/navigation";
import { getOverviewTicketsAction } from "app/_actions/overviews";
2023-06-26 10:07:12 +00:00
import { TicketList } from "./TicketList";
type ZammadOverviewProps = {
name: string;
};
2022-12-02 17:45:14 +01:00
export const ZammadOverview: FC<ZammadOverviewProps> = ({ name }) => {
2023-10-16 09:20:40 +02:00
const [tickets, setTickets] = useState([]);
2024-12-13 16:37:20 +01:00
if (typeof window !== "undefined") {
useEffect(() => {
const hash = window?.location?.hash;
if (hash) {
const ticketID = hash.replace("#ticket/zoom/", "");
if (ticketID && !isNaN(parseInt(ticketID, 10))) {
redirect(`/tickets/${ticketID}`);
}
}
2024-12-13 16:37:20 +01:00
}, [window?.location?.hash]);
}
useEffect(() => {
const fetchTickets = async () => {
const { tickets } = await getOverviewTicketsAction(name);
setTickets(tickets);
};
2023-06-07 08:02:29 +00:00
fetchTickets();
2023-10-16 09:20:40 +02:00
2024-08-07 15:25:53 +02:00
const interval = setInterval(fetchTickets, 10000);
2023-10-16 09:20:40 +02:00
return () => clearInterval(interval);
2023-10-16 09:20:40 +02:00
}, [name]);
return <TicketList title={name} tickets={tickets} />;
2023-06-07 08:02:29 +00:00
};