2024-11-05 18:33:41 +03:00
|
|
|
import { useState, useEffect } from "react";
|
|
|
|
|
import {
|
|
|
|
|
AlertDialog,
|
|
|
|
|
AlertDialogAction,
|
|
|
|
|
AlertDialogCancel,
|
|
|
|
|
AlertDialogContent,
|
2026-02-12 23:42:08 +03:00
|
|
|
AlertDialogDescription,
|
2024-11-05 18:33:41 +03:00
|
|
|
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";
|
|
|
|
|
|
2025-03-16 18:36:20 +03:00
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
|
|
2024-11-05 18:33:41 +03:00
|
|
|
type RestartDialogProps = {
|
|
|
|
|
isOpen: boolean;
|
|
|
|
|
onClose: () => void;
|
|
|
|
|
onRestart: () => void;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default function RestartDialog({
|
|
|
|
|
isOpen,
|
|
|
|
|
onClose,
|
|
|
|
|
onRestart,
|
|
|
|
|
}: RestartDialogProps) {
|
2025-03-16 18:36:20 +03:00
|
|
|
const { t } = useTranslation("components/dialog");
|
2024-11-05 18:33:41 +03:00
|
|
|
const [restartDialogOpen, setRestartDialogOpen] = useState(isOpen);
|
|
|
|
|
const [restartingSheetOpen, setRestartingSheetOpen] = useState(false);
|
|
|
|
|
const [countdown, setCountdown] = useState(60);
|
|
|
|
|
|
2026-02-12 23:42:08 +03:00
|
|
|
const clearBodyPointerEvents = () => {
|
|
|
|
|
if (typeof document !== "undefined") {
|
|
|
|
|
document.body.style.pointerEvents = "";
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-11-05 18:33:41 +03:00
|
|
|
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 (
|
|
|
|
|
<>
|
|
|
|
|
<AlertDialog
|
|
|
|
|
open={restartDialogOpen}
|
2026-02-12 23:42:08 +03:00
|
|
|
onOpenChange={(open) => {
|
|
|
|
|
if (!open) {
|
|
|
|
|
setRestartDialogOpen(false);
|
|
|
|
|
onClose();
|
|
|
|
|
clearBodyPointerEvents();
|
|
|
|
|
}
|
2024-11-05 18:33:41 +03:00
|
|
|
}}
|
|
|
|
|
>
|
2026-02-12 23:42:08 +03:00
|
|
|
<AlertDialogContent
|
|
|
|
|
onCloseAutoFocus={(event) => {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
clearBodyPointerEvents();
|
|
|
|
|
}}
|
|
|
|
|
>
|
2024-11-05 18:33:41 +03:00
|
|
|
<AlertDialogHeader>
|
2025-03-16 18:36:20 +03:00
|
|
|
<AlertDialogTitle>{t("restart.title")}</AlertDialogTitle>
|
2026-02-12 23:42:08 +03:00
|
|
|
<AlertDialogDescription className="sr-only">
|
|
|
|
|
{t("restart.description")}
|
|
|
|
|
</AlertDialogDescription>
|
2024-11-05 18:33:41 +03:00
|
|
|
</AlertDialogHeader>
|
|
|
|
|
<AlertDialogFooter>
|
2025-03-16 18:36:20 +03:00
|
|
|
<AlertDialogCancel>
|
|
|
|
|
{t("button.cancel", { ns: "common" })}
|
|
|
|
|
</AlertDialogCancel>
|
2024-11-05 18:33:41 +03:00
|
|
|
<AlertDialogAction onClick={handleRestart}>
|
2025-03-16 18:36:20 +03:00
|
|
|
{t("restart.button")}
|
2024-11-05 18:33:41 +03:00
|
|
|
</AlertDialogAction>
|
|
|
|
|
</AlertDialogFooter>
|
|
|
|
|
</AlertDialogContent>
|
|
|
|
|
</AlertDialog>
|
|
|
|
|
|
|
|
|
|
<Sheet
|
|
|
|
|
open={restartingSheetOpen}
|
|
|
|
|
onOpenChange={() => setRestartingSheetOpen(false)}
|
|
|
|
|
>
|
2025-11-07 16:53:27 +03:00
|
|
|
<SheetContent
|
|
|
|
|
side="top"
|
|
|
|
|
onInteractOutside={(e) => e.preventDefault()}
|
|
|
|
|
className="[&>button:first-of-type]:hidden"
|
|
|
|
|
>
|
2024-11-05 18:33:41 +03:00
|
|
|
<div className="flex flex-col items-center">
|
|
|
|
|
<ActivityIndicator />
|
|
|
|
|
<SheetHeader className="mt-5 text-center">
|
|
|
|
|
<SheetTitle className="text-center">
|
2025-03-16 18:36:20 +03:00
|
|
|
{t("restart.restarting.title")}
|
2024-11-05 18:33:41 +03:00
|
|
|
</SheetTitle>
|
|
|
|
|
<SheetDescription className="text-center">
|
2025-03-16 18:36:20 +03:00
|
|
|
<div>
|
|
|
|
|
{t("restart.restarting.content", {
|
|
|
|
|
countdown,
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
2024-11-05 18:33:41 +03:00
|
|
|
</SheetDescription>
|
|
|
|
|
</SheetHeader>
|
|
|
|
|
<Button
|
|
|
|
|
size="lg"
|
|
|
|
|
className="mt-5"
|
2025-03-16 18:36:20 +03:00
|
|
|
aria-label={t("restart.restarting.button")}
|
2024-11-05 18:33:41 +03:00
|
|
|
onClick={handleForceReload}
|
|
|
|
|
>
|
2025-03-16 18:36:20 +03:00
|
|
|
{t("restart.restarting.button")}
|
2024-11-05 18:33:41 +03:00
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</SheetContent>
|
|
|
|
|
</Sheet>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|