import { useQueryClient } from '@tanstack/react-query' import { useParams } from 'common' import Link from 'next/link' import { useEffect, useRef } from 'react' import { Badge, Button } from 'ui' import ShimmerLine from 'components/ui/ShimmerLine' import { invalidateProjectDetailsQuery, type Project } from 'data/projects/project-detail-query' import { setProjectPostgrestStatus } from 'data/projects/projects-query' import pingPostgrest from 'lib/pingPostgrest' import { Loader, Monitor, Server, ExternalLink } from 'lucide-react' export interface ConnectingStateProps { project: Project } const ConnectingState = ({ project }: ConnectingStateProps) => { const { ref } = useParams() const queryClient = useQueryClient() const checkProjectConnectionIntervalRef = useRef() useEffect(() => { if (!project.restUrl) return // Check project connection status every 4 seconds // pingPostgrest timeouts in 2s, wait for another 2s before checking again checkProjectConnectionIntervalRef.current = window.setInterval(testProjectConnection, 4000) return () => { clearInterval(checkProjectConnectionIntervalRef.current) } }, [project]) const testProjectConnection = async () => { const result = await pingPostgrest(project.ref) if (result) { clearInterval(checkProjectConnectionIntervalRef.current) setProjectPostgrestStatus(queryClient, project.ref, 'ONLINE') await invalidateProjectDetailsQuery(queryClient, project.ref) } } return ( <>

{project.name}

Connecting to project

Connecting to {project.name}

If you are unable to connect after a few minutes, check your project's health to verify if it's running into any resource constraints.

) } export default ConnectingState