import { useState, useEffect } from "react"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog"; import { Sheet, SheetContent, SheetHeader, SheetTitle, SheetDescription, } from "@/components/ui/sheet"; import { Button } from "@/components/ui/button"; import ActivityIndicator from "@/components/indicators/activity-indicator"; import { baseUrl } from "@/api/baseUrl"; import { useTranslation } from "react-i18next"; type RestartDialogProps = { isOpen: boolean; onClose: () => void; onRestart: () => void; }; export default function RestartDialog({ isOpen, onClose, onRestart, }: RestartDialogProps) { const { t } = useTranslation("components/dialog"); const [restartDialogOpen, setRestartDialogOpen] = useState(isOpen); const [restartingSheetOpen, setRestartingSheetOpen] = useState(false); const [countdown, setCountdown] = useState(60); const clearBodyPointerEvents = () => { if (typeof document !== "undefined") { document.body.style.pointerEvents = ""; } }; useEffect(() => { setRestartDialogOpen(isOpen); }, [isOpen]); useEffect(() => { let countdownInterval: NodeJS.Timeout; if (restartingSheetOpen) { countdownInterval = setInterval(() => { setCountdown((prevCountdown) => prevCountdown - 1); }, 1000); } return () => { clearInterval(countdownInterval); }; }, [restartingSheetOpen]); useEffect(() => { if (countdown === 0) { window.location.href = baseUrl; } }, [countdown]); const handleRestart = () => { setRestartingSheetOpen(true); onRestart(); }; const handleForceReload = () => { window.location.href = baseUrl; }; return ( <> { if (!open) { setRestartDialogOpen(false); onClose(); clearBodyPointerEvents(); } }} > { event.preventDefault(); clearBodyPointerEvents(); }} > {t("restart.title")} {t("restart.description")} {t("button.cancel", { ns: "common" })} {t("restart.button")} setRestartingSheetOpen(false)} > e.preventDefault()} className="[&>button:first-of-type]:hidden" >
{t("restart.restarting.title")}
{t("restart.restarting.content", { countdown, })}
); }