import { useTranslation } from 'react-i18next'; import { useLocation, useNavigate } from 'react-router-dom'; import { AlertCircle, Home, Loader2, RefreshCw } from 'lucide-react'; import { useState } from 'react'; import { Button } from '@/components/ui/button'; import { initializeSystemInfo, systemInfo } from '@/app/infra/http'; const RETURN_TO_STORAGE_KEY = 'langbot_backend_unavailable_return_to'; type BackendUnavailableLocationState = { from?: string; }; export default function BackendUnavailablePage() { const { t } = useTranslation(); const navigate = useNavigate(); const location = useLocation(); const [checking, setChecking] = useState(false); const [retryError, setRetryError] = useState(null); async function handleRetry() { setChecking(true); setRetryError(null); try { await initializeSystemInfo({ throwOnError: true }); const state = location.state as BackendUnavailableLocationState | null; const storedReturnTo = sessionStorage.getItem(RETURN_TO_STORAGE_KEY); const returnTo = state?.from || storedReturnTo || '/home'; sessionStorage.removeItem(RETURN_TO_STORAGE_KEY); if (systemInfo.wizard_status === 'none') { navigate('/wizard', { replace: true }); return; } navigate(returnTo === '/backend-unavailable' ? '/home' : returnTo, { replace: true, }); } catch (error) { setRetryError( error instanceof Error ? error.message : t('errorPage.retryFailed'), ); } finally { setChecking(false); } } return (

{t('errorPage.backendUnavailableStatus')}

{t('common.loginLoadError')}

{t('common.loginLoadErrorDesc')}

{retryError ? (

{t('errorPage.retryFailed')}

) : null}
); }