'use client'; import React, { useEffect, useState } from 'react'; import { AlertCircle, RefreshCw } from 'lucide-react'; import { config } from '../lib/config'; export default function CMSConnectivityNotice() { const [, setStatus] = useState<'checking' | 'ok' | 'error'>('checking'); const [errorMsg, setErrorMsg] = useState(''); const [isVisible, setIsVisible] = useState(false); useEffect(() => { // Only show if we've detected an issue AND we are in a context where we want to see it const checkCMS = async () => { const isDebug = new URLSearchParams(window.location.search).has('cms_debug'); const isLocal = config.isDevelopment; const isTesting = config.isTesting; // Only proceed with check if it's developer context (Local or Testing) // Staging and Production should NEVER see this unless forced with ?cms_debug if (!isLocal && !isTesting && !isDebug) return; try { const response = await fetch('/api/health/cms'); const data = await response.json(); if (data.status !== 'ok') { setStatus('error'); setErrorMsg(data.message); setIsVisible(true); } else { setStatus('ok'); setIsVisible(false); } } catch { // If it's a connection error, only show if we are really debugging if (isDebug || isLocal) { setStatus('error'); setErrorMsg('Could not connect to CMS health endpoint'); setIsVisible(true); } } }; checkCMS(); }, []); if (!isVisible) return null; return (
{errorMsg === 'relation "products" does not exist' ? 'The database schema is missing. Please sync your local data to this environment.' : errorMsg || 'The application cannot connect to the Directus CMS.'}