Skip to content

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

Prevent changing of PITR for subscription if already has PITR addon but with 0

Joshen Lim851f5ca4f9ca
diff --git a/studio/components/interfaces/Billing/AddOns/AddOns.types.ts b/studio/components/interfaces/Billing/AddOns/AddOns.types.ts
index 1611bbdf517..d9e2c99a09d 100644
--- a/studio/components/interfaces/Billing/AddOns/AddOns.types.ts
+++ b/studio/components/interfaces/Billing/AddOns/AddOns.types.ts
@@ -8,6 +8,8 @@ export interface DatabaseAddon {
default_price_id?: string
supabase_prod_id: string
}
+ // UI specific, do not allow changes if add on has a $0 price to it
+ isLocked?: boolean
}
export interface AddonPrice {
diff --git a/studio/components/interfaces/Billing/AddOns/PITRDurationSelection.tsx b/studio/components/interfaces/Billing/AddOns/PITRDurationSelection.tsx
index ec5ed6bf2a6..40cffc8fda7 100644
--- a/studio/components/interfaces/Billing/AddOns/PITRDurationSelection.tsx
+++ b/studio/components/interfaces/Billing/AddOns/PITRDurationSelection.tsx
@@ -41,7 +41,7 @@ const PITRDurationSelection: FC<Props> = ({
<p className="text-sm text-scale-1100">
Restore your database from a specific point in time
</p>
- {canUsePITR && (
+ {canUsePITR && !currentPitrDuration?.isLocked && (
<div className="mt-2">
<InformationBox
icon={<IconAlertCircle strokeWidth={2} />}
@@ -72,6 +72,29 @@ const PITRDurationSelection: FC<Props> = ({
}
icon={<IconAlertCircle strokeWidth={2} />}
/>
+ ) : currentPitrDuration?.isLocked ? (
+ <div
+ className={[
+ 'flex items-center justify-between block w-full rounded px-4 py-3',
+ 'border border-scale-600 bg-scale-100 dark:border-scale-500 dark:bg-scale-400',
+ ].join(' ')}
+ >
+ <div className="space-y-3">
+ <h5 className="text-sm text-scale-1200">
+ Your project currently has {currentPitrDuration.name}
+ </h5>
+ <p className="text-sm text-scale-1100">
+ If you would like to change your PITR duration, do reach out to us
+ </p>
+ </div>
+ <div className="">
+ <Link href={`/support/new?ref=${ref}&category=sales&subject=Change%20PITR%20duration`}>
+ <a>
+ <Button>Contact us</Button>
+ </a>
+ </Link>
+ </div>
+ </div>
) : (
<Radio.Group type="cards" className="billing-compute-radio">
{pitrDurationOptions.map((option: any) => {
diff --git a/studio/components/interfaces/Billing/AddOns/SupportPlan.tsx b/studio/components/interfaces/Billing/AddOns/SupportPlan.tsx
index 48f66b7fc97..56f22afce68 100644
--- a/studio/components/interfaces/Billing/AddOns/SupportPlan.tsx
+++ b/studio/components/interfaces/Billing/AddOns/SupportPlan.tsx
@@ -17,30 +17,28 @@ const SupportPlan: FC<Props> = ({ currentOption }) => {
</div>
<p className="text-sm text-scale-1100">Designated support with guaranteed response times</p>
</div>
- {currentOption !== undefined && (
- <div
- className={[
- 'flex items-center justify-between block w-full rounded px-4 py-3',
- 'border border-scale-600 bg-scale-100 dark:border-scale-500 dark:bg-scale-400',
- ].join(' ')}
- >
- <div className="space-y-3">
- <h5 className="text-sm text-scale-1200">
- Your project is currently on {currentOption.name}
- </h5>
- <p className="text-sm text-scale-1100">
- If you would like to change your support plan, do reach out to us
- </p>
- </div>
- <div className="">
- <Link href={`/support/new?ref=${ref}&category=sales&subject=Change%20support%20plan`}>
- <a>
- <Button>Contact us</Button>
- </a>
- </Link>
- </div>
+ <div
+ className={[
+ 'flex items-center justify-between block w-full rounded px-4 py-3',
+ 'border border-scale-600 bg-scale-100 dark:border-scale-500 dark:bg-scale-400',
+ ].join(' ')}
+ >
+ <div className="space-y-3">
+ <h5 className="text-sm text-scale-1200">
+ Your project is currently on {currentOption.name}
+ </h5>
+ <p className="text-sm text-scale-1100">
+ If you would like to change your support plan, do reach out to us
+ </p>
</div>
- )}
+ <div className="">
+ <Link href={`/support/new?ref=${ref}&category=sales&subject=Change%20support%20plan`}>
+ <a>
+ <Button>Contact us</Button>
+ </a>
+ </Link>
+ </div>
+ </div>
</div>
)
}
diff --git a/studio/components/interfaces/Billing/Billing.utils.ts b/studio/components/interfaces/Billing/Billing.utils.ts
index c8cc3762084..cef7e645d4c 100644
--- a/studio/components/interfaces/Billing/Billing.utils.ts
+++ b/studio/components/interfaces/Billing/Billing.utils.ts
@@ -1,3 +1,4 @@
+import { add } from 'lodash'
import { DatabaseAddon } from './AddOns/AddOns.types'
import {
formatComputeSizes,
@@ -58,6 +59,26 @@ export const formSubscriptionUpdatePayload = (
}
}
+const findAddon = (
+ subscription: StripeSubscription,
+ addons: DatabaseAddon[],
+ key: string,
+ defaultKey: string
+): DatabaseAddon => {
+ const product = addons.find((option) => {
+ const subscriptionAddon = subscription.addons.find((addon) =>
+ addon.supabase_prod_id.includes(key)
+ )
+ return option.id === subscriptionAddon?.prod_id
+ })
+ if (product === undefined) {
+ return addons.find((addon) => addon.metadata.supabase_prod_id === defaultKey) as DatabaseAddon
+ } else {
+ const subscriptionAddon = subscription.addons.find((addon) => addon.prod_id === product.id)
+ return { ...product, isLocked: subscriptionAddon?.unit_amount === 0 }
+ }
+}
+
export const getCurrentAddons = (
currentSubscription: StripeSubscription,
addons: DatabaseAddon[]
@@ -71,42 +92,26 @@ export const getCurrentAddons = (
const pitrDurationOptions = formatPITROptions(addons)
const customDomainOptions = formatCustomDomainOptions(addons)
- console.log({ currentSubscription })
-
- const computeSize =
- computeSizes.find((option: any) => {
- const subscriptionComputeSize = currentSubscription?.addons.find((addon) =>
- addon.supabase_prod_id.includes('_instance_')
- )
- return option.id === subscriptionComputeSize?.prod_id
- }) ||
- (computeSizes.find(
- (option: any) => option.metadata.supabase_prod_id === 'addon_instance_micro'
- ) as DatabaseAddon)
-
- const pitrDuration =
- pitrDurationOptions.find((option: any) => {
- const subscriptionPitrDuration = currentSubscription?.addons.find((addon) =>
- addon.supabase_prod_id.includes('_pitr_')
- )
- return option.id === subscriptionPitrDuration?.prod_id
- }) ||
- (pitrDurationOptions.find(
- (option: any) => option.metadata.supabase_prod_id === 'addon_pitr_0days'
- ) as DatabaseAddon)
-
- const customDomains =
- customDomainOptions.find((option: any) => {
- const subscriptionCustomDomain = currentSubscription?.addons.find((addon) =>
- addon.supabase_prod_id.includes('_custom_domains')
- )
- return option.id === subscriptionCustomDomain?.prod_id
- }) ||
- (customDomainOptions.find(
- (option: any) => option.metadata.supabase_prod_id === 'addon_custom_domains_disabled'
- ) as DatabaseAddon)
+ const computeSize = findAddon(
+ currentSubscription,
+ computeSizes,
+ '_instance_',
+ 'addon_instance_micro'
+ )
+ const pitrDuration = findAddon(
+ currentSubscription,
+ pitrDurationOptions,
+ '_pitr_',
+ 'addon_pitr_0days'
+ )
+ const customDomains = findAddon(
+ currentSubscription,
+ customDomainOptions,
+ '_custom_domains',
+ 'addon_custom_domains_disabled'
+ )
- const supportPlan = addons.find((option: any) => {
+ const supportPlan = addons.find((option) => {
const subscriptionSupportPlan = currentSubscription?.addons.find((addon) =>
addon.supabase_prod_id.includes('_support_')
)
diff --git a/studio/components/interfaces/Billing/ProUpgrade.tsx b/studio/components/interfaces/Billing/ProUpgrade.tsx
index 5ff559adc1a..ccc8cda5a2b 100644
--- a/studio/components/interfaces/Billing/ProUpgrade.tsx
+++ b/studio/components/interfaces/Billing/ProUpgrade.tsx
@@ -28,6 +28,7 @@ import {
formatPITROptions,
} from './AddOns/AddOns.utils'
import BackButton from 'components/ui/BackButton'
+import SupportPlan from './AddOns/SupportPlan'
// Do not allow compute size changes for af-south-1
@@ -242,6 +243,12 @@ const ProUpgrade: FC<Props> = ({
</div>
{projectRegion !== 'af-south-1' && (
<>
+ {currentAddons.supportPlan !== undefined && (
+ <>
+ <Divider light />
+ <SupportPlan currentOption={currentAddons.supportPlan} />
+ </>
+ )}
{isCustomDomainsEnabled && customDomainOptions.length > 0 && (
<>
<Divider light />