import React, { useState } from "react"; import { Box, Typography, Button, Stack } from "@mui/material"; import { useTheme } from "@emotion/react"; import { useNavigate } from "react-router-dom"; import { networkService } from "@/Utils/NetworkService.js"; import Alert from "@/Components/v1/Alert/index.jsx"; import { createToast } from "@/Utils/toastUtils.jsx"; import { useTranslation } from "react-i18next"; import Background from "@/assets/Images/background-grid.svg?react"; import Logo from "@/assets/icons/checkmate-icon.svg?react"; import ThemeSwitch from "@/Components/v1/ThemeSwitch/index.jsx"; import LanguageSelector from "@/Components/LanguageSelector.jsx"; const ServerUnreachable = () => { const theme = useTheme(); const navigate = useNavigate(); const { t } = useTranslation(); // State for tracking connection check status const [isCheckingConnection, setIsCheckingConnection] = useState(false); const handleRetry = React.useCallback(async () => { setIsCheckingConnection(true); try { // Try to connect to the backend with a simple API call // We'll use any lightweight endpoint that doesn't require authentication await networkService.axiosInstance.get("/health", { timeout: 5000 }); // If successful, show toast and navigate to login page createToast({ body: t("errorPages.serverUnreachable.toasts.reconnected"), }); navigate("/login"); } catch (error) { // If still unreachable, stay on this page and show toast createToast({ body: t("errorPages.serverUnreachable.toasts.stillUnreachable"), }); } finally { setIsCheckingConnection(false); } }, [navigate, t]); return ( {/* Header with logo */} {t("common.appName")} .MuiStack-root": { border: 1, borderRadius: theme.spacing(5), borderColor: theme.palette.primary.lowContrast, backgroundColor: theme.palette.primary.main, padding: { xs: theme.spacing(12), sm: theme.spacing(20), }, }, }} > {t("errorPages.serverUnreachable.description")} ); }; export default ServerUnreachable;