ConnectingState.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import { useParams } from 'common'
  2. import { ExternalLink, Loader, Monitor, Server } from 'lucide-react'
  3. import Link from 'next/link'
  4. import { useEffect, useRef } from 'react'
  5. import { Badge, Button } from 'ui'
  6. import ShimmerLine from '@/components/ui/ShimmerLine'
  7. import {
  8. useInvalidateProjectDetailsQuery,
  9. useSetProjectPostgrestStatus,
  10. type Project,
  11. } from '@/data/projects/project-detail-query'
  12. import { DOCS_URL } from '@/lib/constants'
  13. import pingPostgrest from '@/lib/pingPostgrest'
  14. export interface ConnectingStateProps {
  15. project: Project
  16. }
  17. const ConnectingState = ({ project }: ConnectingStateProps) => {
  18. const { ref } = useParams()
  19. const checkProjectConnectionIntervalRef = useRef<number>(null)
  20. const { setProjectPostgrestStatus } = useSetProjectPostgrestStatus()
  21. const { invalidateProjectDetailsQuery } = useInvalidateProjectDetailsQuery()
  22. useEffect(() => {
  23. if (!project.restUrl) return
  24. // Check project connection status every 4 seconds
  25. // pingPostgrest timeouts in 2s, wait for another 2s before checking again
  26. checkProjectConnectionIntervalRef.current = window.setInterval(testProjectConnection, 4000)
  27. return () => {
  28. if (checkProjectConnectionIntervalRef.current) {
  29. clearInterval(checkProjectConnectionIntervalRef.current)
  30. }
  31. }
  32. }, [project])
  33. const testProjectConnection = async () => {
  34. const result = await pingPostgrest(project.ref)
  35. if (result) {
  36. if (checkProjectConnectionIntervalRef.current) {
  37. clearInterval(checkProjectConnectionIntervalRef.current)
  38. }
  39. setProjectPostgrestStatus(project.ref, 'ONLINE')
  40. await invalidateProjectDetailsQuery(project.ref)
  41. }
  42. }
  43. return (
  44. <>
  45. <div className="mx-auto my-16 w-full max-w-7xl space-y-16">
  46. <div className="mx-6 space-y-16">
  47. <div className="flex flex-col space-y-4 lg:flex-row lg:items-center lg:space-y-0 lg:space-x-6">
  48. <h1 className="text-3xl">{project.name}</h1>
  49. <div>
  50. <Badge variant="success">
  51. <div className="flex items-center gap-2">
  52. <Loader className="animate-spin" size={12} />
  53. <span>Connecting to project</span>
  54. </div>
  55. </Badge>
  56. </div>
  57. </div>
  58. <div className="flex h-[500px] items-center justify-center rounded-sm border border-overlay bg-surface-100 p-8">
  59. <div className="w-[440px] space-y-4">
  60. <div className="mx-auto flex max-w-[300px] items-center justify-center">
  61. <div>
  62. <div className="flex items-center justify-center w-12 h-12 rounded-md border">
  63. <Monitor className="text-foreground-light" size={30} strokeWidth={1.5} />
  64. </div>
  65. </div>
  66. <ShimmerLine active />
  67. <div>
  68. <div className="flex items-center justify-center w-12 h-12 rounded-md border">
  69. <Server className="text-foreground-light" size={30} strokeWidth={1.5} />
  70. </div>
  71. </div>
  72. </div>
  73. <div className="space-y-1">
  74. <p className="text-center">Connecting to {project.name}</p>
  75. <p className="text-center text-sm text-foreground-light">
  76. If you are unable to connect after a few minutes, check your project's health to
  77. verify if it's running into any resource constraints.
  78. </p>
  79. </div>
  80. <div className="flex items-center justify-center space-x-2">
  81. <Button asChild type="default">
  82. <Link href={`/project/${ref}/settings/infrastructure`}>
  83. Check database health
  84. </Link>
  85. </Button>
  86. <Button asChild type="default" icon={<ExternalLink strokeWidth={1.5} />}>
  87. <Link
  88. href={`${DOCS_URL}/guides/troubleshooting?products=platform#unable-to-connect-to-your-briven-project`}
  89. className="translate-y-px"
  90. >
  91. Troubleshooting
  92. </Link>
  93. </Button>
  94. </div>
  95. </div>
  96. </div>
  97. </div>
  98. </div>
  99. </>
  100. )
  101. }
  102. export default ConnectingState