DatabaseReadOnlyAlert.tsx 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { useParams } from 'common'
  2. import { AlertTriangle, ExternalLink } from 'lucide-react'
  3. import Link from 'next/link'
  4. import { useState } from 'react'
  5. import { Alert, AlertDescription, AlertTitle, Button } from 'ui'
  6. import ConfirmDisableReadOnlyModeModal from './DatabaseSettings/ConfirmDisableReadOnlyModal'
  7. import { useResourceWarningsQuery } from '@/data/usage/resource-warnings-query'
  8. import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
  9. import { DOCS_URL } from '@/lib/constants'
  10. export const DatabaseReadOnlyAlert = () => {
  11. const { ref: projectRef } = useParams()
  12. const { data: organization } = useSelectedOrganizationQuery()
  13. const [showConfirmationModal, setShowConfirmationModal] = useState(false)
  14. const { data: resourceWarnings } = useResourceWarningsQuery({ ref: projectRef })
  15. // [Joshen Cleanup] JFYI this can be cleaned up once BE changes are live which will only return the warnings based on the provided ref
  16. // No longer need to filter by ref on the client side
  17. const isReadOnlyMode =
  18. (resourceWarnings ?? [])?.find((warning) => warning.project === projectRef)
  19. ?.is_readonly_mode_enabled ?? false
  20. return (
  21. <>
  22. {isReadOnlyMode && (
  23. <Alert variant="destructive">
  24. <AlertTriangle />
  25. <AlertTitle>
  26. Project is in read-only mode and database is no longer accepting write requests
  27. </AlertTitle>
  28. <AlertDescription>
  29. You have reached 95% of your project's disk space, and read-only mode has been enabled
  30. to preserve your database's stability and prevent your project from exceeding its
  31. current billing plan. To resolve this, you may:
  32. <ul className="list-disc pl-6 mt-1">
  33. <li>
  34. Temporarily disable read-only mode to free up space and reduce your database size
  35. </li>
  36. {organization?.plan.id === 'free' ? (
  37. <li>
  38. <Link
  39. href={`/org/${organization?.slug}/billing?panel=subscriptionPlan&source=databaseReadOnlyAlertUpgradePlan`}
  40. >
  41. <a className="text underline">Upgrade to the Pro Plan</a>
  42. </Link>{' '}
  43. to increase your database size limit to 8GB.
  44. </li>
  45. ) : organization?.plan.id === 'pro' && organization?.usage_billing_enabled ? (
  46. <li>
  47. <Link
  48. href={`/org/${organization?.slug}/billing?panel=subscriptionPlan&source=databaseReadOnlyAlertSpendCap`}
  49. >
  50. <a className="text-foreground underline">Disable your Spend Cap</a>
  51. </Link>{' '}
  52. to allow your project to auto-scale and expand beyond the 8GB database size limit
  53. </li>
  54. ) : null}
  55. </ul>
  56. </AlertDescription>
  57. <div className="mt-4 flex items-center space-x-2">
  58. <Button type="default" onClick={() => setShowConfirmationModal(true)}>
  59. Disable read-only mode
  60. </Button>
  61. <Button asChild type="default" icon={<ExternalLink />}>
  62. <a
  63. href={`${DOCS_URL}/guides/platform/database-size#disabling-read-only-mode`}
  64. target="_blank"
  65. rel="noreferrer"
  66. >
  67. Learn more
  68. </a>
  69. </Button>
  70. </div>
  71. </Alert>
  72. )}
  73. <ConfirmDisableReadOnlyModeModal
  74. visible={showConfirmationModal}
  75. onClose={() => setShowConfirmationModal(false)}
  76. />
  77. </>
  78. )
  79. }