import React, { useState } from "react"; import { Box, Typography, Button, Stack } from "@mui/material"; import { useTheme } from "@emotion/react"; import { useNavigate } from "react-router"; import { networkService } from "../Utils/NetworkService"; import Alert from "../Components/Alert"; import { createToast } from "../Utils/toastUtils"; 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/ThemeSwitch"; import LanguageSelector from "../Components/LanguageSelector"; 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("backendReconnected", "Connection to server restored"), }); navigate("/login"); } catch (error) { // If still unreachable, stay on this page and show toast createToast({ body: t("backendStillUnreachable", "Server is still unreachable"), }); } finally { setIsCheckingConnection(false); } }, [navigate, t]); return ( {/* Header with logo */} Checkmate .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("backendUnreachableMessage", "The Checkmate server is not responding. Please check your deployment configuration or try again later.")} ); }; export default ServerUnreachable;