import { useParams } from 'common' import { ExternalLink, Loader, Monitor, Server } from 'lucide-react' import Link from 'next/link' import { useEffect, useRef } from 'react' import { Badge, Button } from 'ui' import ShimmerLine from '@/components/ui/ShimmerLine' import { useInvalidateProjectDetailsQuery, useSetProjectPostgrestStatus, type Project, } from '@/data/projects/project-detail-query' import { DOCS_URL } from '@/lib/constants' import pingPostgrest from '@/lib/pingPostgrest' export interface ConnectingStateProps { project: Project } const ConnectingState = ({ project }: ConnectingStateProps) => { const { ref } = useParams() const checkProjectConnectionIntervalRef = useRef(null) const { setProjectPostgrestStatus } = useSetProjectPostgrestStatus() const { invalidateProjectDetailsQuery } = useInvalidateProjectDetailsQuery() 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 () => { if (checkProjectConnectionIntervalRef.current) { clearInterval(checkProjectConnectionIntervalRef.current) } } }, [project]) const testProjectConnection = async () => { const result = await pingPostgrest(project.ref) if (result) { if (checkProjectConnectionIntervalRef.current) { clearInterval(checkProjectConnectionIntervalRef.current) } setProjectPostgrestStatus(project.ref, 'ONLINE') await invalidateProjectDetailsQuery(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