Skip to content

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

Update to support when PITR addons are not available for self serve just yet

Joshen Limb0acf0dbd1c2
diff --git a/studio/components/interfaces/Billing/AddOns/AddOns.utils.ts b/studio/components/interfaces/Billing/AddOns/AddOns.utils.ts
index 4feb43e98dc..d3d559d3abf 100644
--- a/studio/components/interfaces/Billing/AddOns/AddOns.utils.ts
+++ b/studio/components/interfaces/Billing/AddOns/AddOns.utils.ts
@@ -82,11 +82,12 @@ export const formatPITROptions = (addons: DatabaseAddon[]) => {
],
}
- return [noPITROption]
- .concat(
- pitrOrder.map((id: string) => {
- return addons.find((option) => option.metadata.supabase_prod_id === id)
- }) as DatabaseAddon[]
- )
- .filter((option) => option !== undefined)
+ const pitrOptions = pitrOrder
+ .map((id: string) => {
+ return addons.find((option) => option.metadata.supabase_prod_id === id)
+ })
+ .filter((option) => option !== undefined) as DatabaseAddon[]
+
+ if (pitrOptions.length === 0) return []
+ else return [noPITROption].concat(pitrOptions)
}
diff --git a/studio/components/interfaces/Billing/Billing.utils.ts b/studio/components/interfaces/Billing/Billing.utils.ts
index 4ca7e8689b3..2c839e9459a 100644
--- a/studio/components/interfaces/Billing/Billing.utils.ts
+++ b/studio/components/interfaces/Billing/Billing.utils.ts
@@ -13,9 +13,9 @@ export const getProductPrice = (product: any) => {
export const validateSubscriptionUpdatePayload = (
selectedComputeSize: DatabaseAddon,
- selectedPITRDuration: DatabaseAddon
+ selectedPITRDuration?: DatabaseAddon
) => {
- if (selectedPITRDuration.id !== undefined && selectedComputeSize.id === undefined) {
+ 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
@@ -24,7 +24,7 @@ export const validateSubscriptionUpdatePayload = (
export const formSubscriptionUpdatePayload = (
selectedTier: any,
selectedComputeSize: DatabaseAddon,
- selectedPITRDuration: DatabaseAddon,
+ selectedPITRDuration: DatabaseAddon | undefined,
selectedPaymentMethod: string,
region: string
) => {
@@ -32,7 +32,7 @@ export const formSubscriptionUpdatePayload = (
const addons =
region === 'af-south-1'
? []
- : [selectedComputeSize.prices[0].id, selectedPITRDuration.prices[0].id].filter(
+ : [selectedComputeSize.prices[0].id, selectedPITRDuration?.prices?.[0].id].filter(
(x) => x !== undefined
)
const proration_date = Math.floor(Date.now() / 1000)
diff --git a/studio/components/interfaces/Billing/EnterpriseUpdate.tsx b/studio/components/interfaces/Billing/EnterpriseUpdate.tsx
index 6033a2b7c1e..360c2f96987 100644
--- a/studio/components/interfaces/Billing/EnterpriseUpdate.tsx
+++ b/studio/components/interfaces/Billing/EnterpriseUpdate.tsx
@@ -176,13 +176,17 @@ const EnterpriseUpdate: FC<Props> = ({
</div>
{projectRegion !== 'af-south-1' && (
<>
- <Divider light />
- <PITRDurationSelection
- pitrDurationOptions={pitrDurationOptions || []}
- currentPitrDuration={currentPITRDuration}
- selectedPitrDuration={selectedPITRDuration}
- onSelectOption={setSelectedPITRDuration}
- />
+ {pitrDurationOptions.length > 0 && (
+ <>
+ <Divider light />
+ <PITRDurationSelection
+ pitrDurationOptions={pitrDurationOptions}
+ currentPitrDuration={currentPITRDuration}
+ selectedPitrDuration={selectedPITRDuration}
+ onSelectOption={setSelectedPITRDuration}
+ />
+ </>
+ )}
<Divider light />
<ComputeSizeSelection
computeSizes={computeSizes || []}
diff --git a/studio/components/interfaces/Billing/PaymentSummaryPanel/PaymentSummaryPanel.tsx b/studio/components/interfaces/Billing/PaymentSummaryPanel/PaymentSummaryPanel.tsx
index c48366685dd..208b162a0a1 100644
--- a/studio/components/interfaces/Billing/PaymentSummaryPanel/PaymentSummaryPanel.tsx
+++ b/studio/components/interfaces/Billing/PaymentSummaryPanel/PaymentSummaryPanel.tsx
@@ -21,15 +21,17 @@ import InformationBox from 'components/ui/InformationBox'
import { DatabaseAddon } from '../AddOns/AddOns.types'
import { getPITRDays } from './PaymentSummaryPanel.utils'
+// [Joshen] PITR stuff can be undefined for now until we officially launch PITR self serve
+
interface Props {
isRefreshingPreview: boolean
subscriptionPreview?: SubscriptionPreview
currentPlan: any
currentComputeSize: DatabaseAddon
- currentPITRDuration: DatabaseAddon
+ currentPITRDuration: DatabaseAddon | undefined
selectedPlan?: any
selectedComputeSize: DatabaseAddon
- selectedPITRDuration: DatabaseAddon
+ selectedPITRDuration: DatabaseAddon | undefined
isSpendCapEnabled: boolean
paymentMethods?: any
selectedPaymentMethod: any
@@ -76,8 +78,9 @@ const PaymentSummaryPanel: FC<Props> = ({
const [showConfirmModal, setShowConfirmModal] = useState(false)
- const currentPITRDays = getPITRDays(currentPITRDuration)
- const selectedPITRDays = getPITRDays(selectedPITRDuration)
+ const currentPITRDays = currentPITRDuration !== undefined ? getPITRDays(currentPITRDuration) : 0
+ const selectedPITRDays =
+ selectedPITRDuration !== undefined ? getPITRDays(selectedPITRDuration) : 0
const isEnterprise = currentPlan.supabase_prod_id === PRICING_TIER_PRODUCT_IDS.ENTERPRISE
const isChangingPlan =
@@ -87,7 +90,7 @@ const PaymentSummaryPanel: FC<Props> = ({
(currentPlan.prod_id !== STRIPE_PRODUCT_IDS.PAYG && !isSpendCapEnabled) ||
(currentPlan.prod_id === STRIPE_PRODUCT_IDS.PAYG && isSpendCapEnabled)
const isChangingComputeSize = currentComputeSize.id !== selectedComputeSize.id
- const isChangingPITRDuration = currentPITRDuration.id !== selectedPITRDuration.id
+ const isChangingPITRDuration = currentPITRDuration?.id !== selectedPITRDuration?.id
// If it's enterprise we only only changing of add-ons
const hasChangesToPlan = isEnterprise
@@ -166,14 +169,14 @@ const PaymentSummaryPanel: FC<Props> = ({
</p>
</div>
)}
- {currentPITRDuration.id !== undefined && (
+ {currentPITRDuration?.id !== undefined && (
<div className="flex items-center justify-between">
<p
className={`${
isChangingPITRDuration ? 'text-scale-1100 line-through' : ''
} text-sm`}
>
- {currentPITRDuration.name}
+ {currentPITRDuration?.name}
</p>
<p
className={`${
@@ -186,7 +189,7 @@ const PaymentSummaryPanel: FC<Props> = ({
)}
{isChangingPITRDuration && (
<div className="flex items-center justify-between">
- <p className="text-sm">{selectedPITRDuration.name}</p>
+ <p className="text-sm">{selectedPITRDuration?.name}</p>
<p className="text-sm">
${(getProductPrice(selectedPITRDuration).unit_amount / 100).toFixed(2)}
</p>
@@ -201,9 +204,9 @@ const PaymentSummaryPanel: FC<Props> = ({
defaultVisibility
icon={<IconAlertCircle strokeWidth={2} />}
title={
- currentPITRDuration.id === undefined
+ currentPITRDuration?.id === undefined
? 'Enabling PITR'
- : selectedPITRDuration.id === undefined
+ : selectedPITRDuration?.id === undefined
? 'Disabling PITR'
: 'Updating PITR duration'
}
diff --git a/studio/components/interfaces/Billing/ProUpgrade.tsx b/studio/components/interfaces/Billing/ProUpgrade.tsx
index 01228f9b264..42c8884cbb2 100644
--- a/studio/components/interfaces/Billing/ProUpgrade.tsx
+++ b/studio/components/interfaces/Billing/ProUpgrade.tsx
@@ -219,15 +219,19 @@ const ProUpgrade: FC<Props> = ({
</div>
{projectRegion !== 'af-south-1' && (
<>
- <Divider light />
- <PITRDurationSelection
- pitrDurationOptions={pitrDurationOptions || []}
- currentPitrDuration={
- isManagingProSubscription ? currentPITRDuration : undefined
- }
- selectedPitrDuration={selectedPITRDuration}
- onSelectOption={setSelectedPITRDuration}
- />
+ {pitrDurationOptions.length > 0 && (
+ <>
+ <Divider light />
+ <PITRDurationSelection
+ pitrDurationOptions={pitrDurationOptions}
+ currentPitrDuration={
+ isManagingProSubscription ? currentPITRDuration : undefined
+ }
+ selectedPitrDuration={selectedPITRDuration}
+ onSelectOption={setSelectedPITRDuration}
+ />
+ </>
+ )}
<Divider light />
<ComputeSizeSelection
computeSizes={computeSizes || []}