import { useParams } from 'common'
import Link from 'next/link'
import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
import { useResourceWarningsQuery } from 'data/usage/resource-warnings-query'
import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'
import { useState } from 'react'
import {
AlertDescription_Shadcn_,
AlertTitle_Shadcn_,
Alert_Shadcn_,
Button,
IconAlertTriangle,
IconExternalLink,
} from 'ui'
import ConfirmDisableReadOnlyModeModal from './DatabaseSettings/ConfirmDisableReadOnlyModal'
export const DatabaseReadOnlyAlert = () => {
const { ref: projectRef } = useParams()
const organization = useSelectedOrganization()
const [showConfirmationModal, setShowConfirmationModal] = useState(false)
const { data: resourceWarnings } = useResourceWarningsQuery()
const { data: subscription } = useOrgSubscriptionQuery({ orgSlug: organization?.slug })
const isReadOnlyMode =
(resourceWarnings ?? [])?.find((warning) => warning.project === projectRef)
?.is_readonly_mode_enabled ?? false
return (
<>
{isReadOnlyMode && (
Project is in read-only mode and database is no longer accepting write requests
You have reached 95% of your project's disk space, and read-only mode has been enabled
to preserve your database's stability and prevent your project from exceeding its
current billing plan. To resolve this, you may:
-
Temporarily disable read-only mode to free up space and reduce your database size
{subscription?.plan.id === 'free' ? (
-
Upgrade to the Pro Plan
{' '}
to increase your database size limit to 8GB.
) : subscription?.plan.id === 'pro' && subscription?.usage_billing_enabled ? (
-
Disable your Spend Cap
{' '}
to allow your project to auto-scale and expand beyond the 8GB database size limit
) : null}
}>
Learn more
)}
setShowConfirmationModal(false)}
/>
>
)
}