refactor(healthpage): replace API health check logic with useApiHealth hook in DashboardLayoutContent

This commit is contained in:
sharath 2025-07-15 13:27:22 +00:00
parent 5bf935b46d
commit 89fa1afc6e
No known key found for this signature in database
1 changed files with 6 additions and 24 deletions

View File

@ -9,7 +9,7 @@ import { useAccounts } from '@/hooks/use-accounts';
import { useAuth } from '@/components/AuthProvider'; import { useAuth } from '@/components/AuthProvider';
import { useRouter } from 'next/navigation'; import { useRouter } from 'next/navigation';
import { Loader2 } from 'lucide-react'; import { Loader2 } from 'lucide-react';
import { checkApiHealth } from '@/lib/api'; import { useApiHealth } from '@/hooks/react-query';
import { MaintenancePage } from '@/components/maintenance/maintenance-page'; import { MaintenancePage } from '@/components/maintenance/maintenance-page';
import { DeleteOperationProvider } from '@/contexts/DeleteOperationContext'; import { DeleteOperationProvider } from '@/contexts/DeleteOperationContext';
import { StatusOverlay } from '@/components/ui/status-overlay'; import { StatusOverlay } from '@/components/ui/status-overlay';
@ -28,37 +28,19 @@ export default function DashboardLayoutContent({
}: DashboardLayoutContentProps) { }: DashboardLayoutContentProps) {
// const [showPricingAlert, setShowPricingAlert] = useState(false) // const [showPricingAlert, setShowPricingAlert] = useState(false)
const [showMaintenanceAlert, setShowMaintenanceAlert] = useState(false); const [showMaintenanceAlert, setShowMaintenanceAlert] = useState(false);
const [isApiHealthy, setIsApiHealthy] = useState(true);
const [isCheckingHealth, setIsCheckingHealth] = useState(true);
const { data: accounts } = useAccounts(); const { data: accounts } = useAccounts();
const personalAccount = accounts?.find((account) => account.personal_account); const personalAccount = accounts?.find((account) => account.personal_account);
const { user, isLoading } = useAuth(); const { user, isLoading } = useAuth();
const router = useRouter(); const router = useRouter();
const { data: healthData, isLoading: isCheckingHealth, error: healthError } = useApiHealth();
useEffect(() => { useEffect(() => {
// setShowPricingAlert(false) // setShowPricingAlert(false)
setShowMaintenanceAlert(false); setShowMaintenanceAlert(false);
}, []); }, []);
// Check API health // API health is now managed by useApiHealth hook
useEffect(() => { const isApiHealthy = healthData?.status === 'ok' && !healthError;
const checkHealth = async () => {
try {
const health = await checkApiHealth();
setIsApiHealthy(health.status === 'ok');
} catch (error) {
console.error('API health check failed:', error);
setIsApiHealthy(false);
} finally {
setIsCheckingHealth(false);
}
};
checkHealth();
// Check health every 30 seconds
const interval = setInterval(checkHealth, 30000);
return () => clearInterval(interval);
}, []);
// Check authentication status // Check authentication status
useEffect(() => { useEffect(() => {
@ -107,8 +89,8 @@ export default function DashboardLayoutContent({
return null; return null;
} }
// Show maintenance page if API is not healthy // Show maintenance page if API is not healthy (but not during initial loading)
if (!isApiHealthy) { if (!isCheckingHealth && !isApiHealthy) {
return <MaintenancePage />; return <MaintenancePage />;
} }