Project.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import Link from 'next/link'
  2. import { Button, Card, CardContent } from 'ui'
  3. import {
  4. PageSection,
  5. PageSectionContent,
  6. PageSectionDescription,
  7. PageSectionMeta,
  8. PageSectionSummary,
  9. PageSectionTitle,
  10. } from 'ui-patterns/PageSection'
  11. import PauseProjectButton from './Infrastructure/PauseProjectButton'
  12. import RestartServerButton from './Infrastructure/RestartServerButton'
  13. import { ResumeProjectButton } from '@/components/interfaces/Project/ResumeProjectButton'
  14. import { useProjectPauseStatusQuery } from '@/data/projects/project-pause-status-query'
  15. import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
  16. import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
  17. import { PROJECT_STATUS } from '@/lib/constants'
  18. export const Project = () => {
  19. const { data: project } = useSelectedProjectQuery()
  20. const isPaused = project?.status === PROJECT_STATUS.INACTIVE
  21. const { projectSettingsRestartProject } = useIsFeatureEnabled([
  22. 'project_settings:restart_project',
  23. ])
  24. const {
  25. data: pauseStatus,
  26. isError: isPauseStatusError,
  27. isSuccess: isPauseStatusSuccess,
  28. } = useProjectPauseStatusQuery({ ref: project?.ref }, { enabled: isPaused })
  29. const shouldShowDashboardLink =
  30. isPaused && (isPauseStatusError || (isPauseStatusSuccess && !pauseStatus.can_restore))
  31. const primaryActionLabel = isPaused
  32. ? shouldShowDashboardLink
  33. ? 'View project dashboard'
  34. : 'Resume project'
  35. : projectSettingsRestartProject
  36. ? 'Restart project'
  37. : 'Restart database'
  38. const primaryActionDescription = isPaused
  39. ? isPauseStatusSuccess && !pauseStatus.can_restore
  40. ? 'This project can no longer be resumed here. Open the dashboard to download backups and view recovery options.'
  41. : isPauseStatusError
  42. ? 'Open the dashboard to manage this paused project.'
  43. : 'Bring your paused project back online.'
  44. : 'Your project will not be available for a few minutes.'
  45. return (
  46. <>
  47. <PageSection id="restart-project">
  48. <PageSectionMeta>
  49. <PageSectionSummary>
  50. <PageSectionTitle>Project availability</PageSectionTitle>
  51. <PageSectionDescription>
  52. {isPaused
  53. ? 'Resume your paused project or review recovery options'
  54. : 'Restart or pause your project when performing maintenance'}
  55. </PageSectionDescription>
  56. </PageSectionSummary>
  57. </PageSectionMeta>
  58. <PageSectionContent>
  59. <Card>
  60. <CardContent>
  61. <div className="flex flex-col @lg:flex-row @lg:justify-between @lg:items-center gap-4">
  62. <div>
  63. <p className="text-sm">{primaryActionLabel}</p>
  64. <div className="max-w-[420px]">
  65. <p className="text-sm text-foreground-light">{primaryActionDescription}</p>
  66. </div>
  67. </div>
  68. {isPaused ? (
  69. shouldShowDashboardLink ? (
  70. <Button asChild type="default">
  71. <Link href={`/project/${project?.ref}`}>View project dashboard</Link>
  72. </Button>
  73. ) : (
  74. <ResumeProjectButton />
  75. )
  76. ) : (
  77. <RestartServerButton />
  78. )}
  79. </div>
  80. </CardContent>
  81. {!isPaused && (
  82. <CardContent>
  83. <div
  84. className="flex w-full flex-col @lg:flex-row @lg:justify-between @lg:items-center gap-4"
  85. id="pause-project"
  86. >
  87. <div>
  88. <p className="text-sm">Pause project</p>
  89. <div className="max-w-[420px]">
  90. <p className="text-sm text-foreground-light">
  91. Your project will not be accessible while it is paused.
  92. </p>
  93. </div>
  94. </div>
  95. <PauseProjectButton />
  96. </div>
  97. </CardContent>
  98. )}
  99. </Card>
  100. </PageSectionContent>
  101. </PageSection>
  102. </>
  103. )
  104. }