Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Add validation and indication that enabling of PITR requires a minimum of small ad on

Joshen Lim28e8f6aff5d5
diff --git a/studio/components/interfaces/Billing/AddOns/AddOns.types.ts b/studio/components/interfaces/Billing/AddOns/AddOns.types.ts
index bbad348d383..1611bbdf517 100644
--- a/studio/components/interfaces/Billing/AddOns/AddOns.types.ts
+++ b/studio/components/interfaces/Billing/AddOns/AddOns.types.ts
@@ -1,5 +1,5 @@
export interface DatabaseAddon {
- id: string
+ id?: string
name: string
description?: string | null
prices: AddonPrice[]
diff --git a/studio/components/interfaces/Billing/AddOns/AddOns.utils.ts b/studio/components/interfaces/Billing/AddOns/AddOns.utils.ts
index 61c3910b879..4ba28364bf9 100644
--- a/studio/components/interfaces/Billing/AddOns/AddOns.utils.ts
+++ b/studio/components/interfaces/Billing/AddOns/AddOns.utils.ts
@@ -14,7 +14,7 @@ export const formatComputeSizes = (addons: DatabaseAddon[]) => {
]
const microOption: DatabaseAddon = {
- id: 'micro-add-on',
+ id: undefined,
name: 'Micro Add-on',
metadata: {
default_price_id: undefined,
@@ -47,15 +47,10 @@ export const formatComputeSizes = (addons: DatabaseAddon[]) => {
}
export const formatPITROptions = (addons: DatabaseAddon[]) => {
- const pitrOrder = [
- 'addon_pitr_0days',
- 'addon_pitr_7days',
- 'addon_pitr_14days',
- 'addon_pitr_28days',
- ]
+ const pitrOrder = ['addon_pitr_7days', 'addon_pitr_14days', 'addon_pitr_28days']
const noPITROption: DatabaseAddon = {
- id: 'pitr-disabled',
+ id: undefined,
name: 'Disable PITR',
metadata: {
default_price_id: undefined,
diff --git a/studio/components/interfaces/Billing/AddOns/ComputeSizeSelection.tsx b/studio/components/interfaces/Billing/AddOns/ComputeSizeSelection.tsx
index 2657b931c68..23b452b0e7a 100644
--- a/studio/components/interfaces/Billing/AddOns/ComputeSizeSelection.tsx
+++ b/studio/components/interfaces/Billing/AddOns/ComputeSizeSelection.tsx
@@ -43,7 +43,7 @@ const ComputeSizeSelection: FC<Props> = ({
return (
<Radio
hidden
- key={option.id}
+ key={option.id || 'micro-add-on'}
align="vertical"
// @ts-ignore
label={
diff --git a/studio/components/interfaces/Billing/AddOns/PITRDurationSelection.tsx b/studio/components/interfaces/Billing/AddOns/PITRDurationSelection.tsx
index 89dc082ca09..6bb2efcaa12 100644
--- a/studio/components/interfaces/Billing/AddOns/PITRDurationSelection.tsx
+++ b/studio/components/interfaces/Billing/AddOns/PITRDurationSelection.tsx
@@ -1,10 +1,11 @@
import { FC } from 'react'
-import { Badge, Radio } from 'ui'
+import { Badge, IconAlertCircle, Radio } from 'ui'
import { useFlag } from 'hooks'
import { DatabaseAddon } from './AddOns.types'
import { getProductPrice } from '../Billing.utils'
import DisabledWarningDueToIncident from 'components/ui/DisabledWarningDueToIncident'
+import InformationBox from 'components/ui/InformationBox'
interface Props {
pitrDurationOptions: DatabaseAddon[]
@@ -31,6 +32,13 @@ const PITRDurationSelection: FC<Props> = ({
<p className="text-sm text-scale-1100">
Restore your database from a specific point in time
</p>
+ <div className="mt-2">
+ <InformationBox
+ icon={<IconAlertCircle strokeWidth={2} />}
+ title="Your project is required to minimally be on a Small Add-on to enable PITR"
+ description="This is to ensure that your project has enough resources to execute PITR successfully"
+ />
+ </div>
</div>
{addonUpdateDisabled ? (
<DisabledWarningDueToIncident title="Updating database add-ons is currently disabled" />
@@ -41,7 +49,7 @@ const PITRDurationSelection: FC<Props> = ({
return (
<Radio
hidden
- key={option.id}
+ key={option.id || 'pitr-disabled'}
align="vertical"
// @ts-ignore
label={
diff --git a/studio/components/interfaces/Billing/Billing.utils.ts b/studio/components/interfaces/Billing/Billing.utils.ts
index 885e4885c24..4ca7e8689b3 100644
--- a/studio/components/interfaces/Billing/Billing.utils.ts
+++ b/studio/components/interfaces/Billing/Billing.utils.ts
@@ -11,6 +11,16 @@ export const getProductPrice = (product: any) => {
return price
}
+export const validateSubscriptionUpdatePayload = (
+ selectedComputeSize: DatabaseAddon,
+ selectedPITRDuration: DatabaseAddon
+) => {
+ if (selectedPITRDuration.id !== undefined && selectedComputeSize.id === undefined) {
+ return 'To enable PITR for your project, your project must minimally be on a Small Add-on.'
+ }
+ return undefined
+}
+
export const formSubscriptionUpdatePayload = (
selectedTier: any,
selectedComputeSize: DatabaseAddon,
diff --git a/studio/components/interfaces/Billing/EnterpriseUpdate.tsx b/studio/components/interfaces/Billing/EnterpriseUpdate.tsx
index f609ef422c7..31e8c7c3271 100644
--- a/studio/components/interfaces/Billing/EnterpriseUpdate.tsx
+++ b/studio/components/interfaces/Billing/EnterpriseUpdate.tsx
@@ -19,7 +19,11 @@ import {
UpdateSuccess,
} from './'
import { PaymentMethod, SubscriptionPreview } from './Billing.types'
-import { formSubscriptionUpdatePayload, getCurrentAddons } from './Billing.utils'
+import {
+ validateSubscriptionUpdatePayload,
+ formSubscriptionUpdatePayload,
+ getCurrentAddons,
+} from './Billing.utils'
interface Props {
products: { tiers: any[]; addons: DatabaseAddon[] }
@@ -97,6 +101,15 @@ const EnterpriseUpdate: FC<Props> = ({
// Last todo to support enterprise billing on dashboard + E2E test
const onConfirmPayment = async () => {
+ const error = validateSubscriptionUpdatePayload(selectedComputeSize, selectedPITRDuration)
+ if (error) {
+ return ui.setNotification({
+ duration: 4000,
+ category: 'error',
+ message: error,
+ })
+ }
+
const payload = {
...formSubscriptionUpdatePayload(
null,
diff --git a/studio/components/interfaces/Billing/PaymentSummaryPanel/PaymentSummaryPanel.tsx b/studio/components/interfaces/Billing/PaymentSummaryPanel/PaymentSummaryPanel.tsx
index d410ea33301..c0fe582964b 100644
--- a/studio/components/interfaces/Billing/PaymentSummaryPanel/PaymentSummaryPanel.tsx
+++ b/studio/components/interfaces/Billing/PaymentSummaryPanel/PaymentSummaryPanel.tsx
@@ -149,7 +149,7 @@ const PaymentSummaryPanel: FC<Props> = ({
</p>
</div>
)}
- {currentPITRDuration.id !== 'pitr-disabled' && (
+ {currentPITRDuration.id !== undefined && (
<div className="flex items-center justify-between">
<p
className={`${
diff --git a/studio/components/interfaces/Billing/ProUpgrade.tsx b/studio/components/interfaces/Billing/ProUpgrade.tsx
index aad76c8d6f0..c5e160ab00d 100644
--- a/studio/components/interfaces/Billing/ProUpgrade.tsx
+++ b/studio/components/interfaces/Billing/ProUpgrade.tsx
@@ -19,7 +19,11 @@ import {
import { STRIPE_PRODUCT_IDS } from 'lib/constants'
import UpdateSuccess from './UpdateSuccess'
import { PaymentMethod, SubscriptionPreview } from './Billing.types'
-import { formSubscriptionUpdatePayload, getCurrentAddons } from './Billing.utils'
+import {
+ validateSubscriptionUpdatePayload,
+ formSubscriptionUpdatePayload,
+ getCurrentAddons,
+} from './Billing.utils'
import { DatabaseAddon } from './AddOns/AddOns.types'
import { formatComputeSizes, formatPITROptions } from './AddOns/AddOns.utils'
import BackButton from 'components/ui/BackButton'
@@ -116,6 +120,15 @@ const ProUpgrade: FC<Props> = ({
}
const onConfirmPayment = async () => {
+ const error = validateSubscriptionUpdatePayload(selectedComputeSize, selectedPITRDuration)
+ if (error) {
+ return ui.setNotification({
+ duration: 4000,
+ category: 'error',
+ message: error,
+ })
+ }
+
const payload = formSubscriptionUpdatePayload(
selectedTier,
selectedComputeSize,
@@ -167,8 +180,8 @@ const ProUpgrade: FC<Props> = ({
enterTo="transform opacity-100 translate-x-0"
className="flex w-full items-start justify-between"
>
- <div className="2xl:min-w-5xl mx-auto mt-10">
- <div className="relative space-y-4 px-5">
+ <div className="2xl:min-w-5xl mx-auto mt-10 px-36">
+ <div className="relative space-y-4">
<BackButton onClick={() => onSelectBack()} />
<div className="space-y-8">
<h4 className="text-lg text-scale-900">Change your project's subscription</h4>