import { useEffect, useState } from 'react'; import { Box, Stack, Text } from '@jtl-software/platform-ui-react'; import { TriangleAlert } from 'lucide-react'; import { apiUrl } from './constants'; type HealthResponse = { status: 'ok' | 'misconfigured'; missing: string[]; }; const POLL_INTERVAL_MS = 5000; const ConfigWarningBanner: React.FC = () => { const [missing, setMissing] = useState(null); useEffect(() => { let cancelled = false; const check = async (): Promise => { try { const res = await fetch(`${apiUrl}/health`); if (!res.ok) return; const data = (await res.json()) as HealthResponse; if (cancelled) return; setMissing(data.status === 'misconfigured' ? data.missing : null); } catch { // Backend not reachable yet (still starting). Try again on the next tick. } }; void check(); const id = window.setInterval(check, POLL_INTERVAL_MS); return () => { cancelled = true; window.clearInterval(id); }; }, []); if (!missing || missing.length === 0) return null; return ( Backend is missing credentials: {missing.join(', ')} Every JTL API call will fail until you add these to{' '} packages/backend/.env (Node) or{' '} appsettings.Local.json (.NET). Get the values from the{' '} Partner Portal {' '} under your app's Client credentials, then restart the backend. ); }; export default ConfigWarningBanner;