Skip to content

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

Set up FE logic for PITR self serve

Joshen Limb5744b3d8720
diff --git a/studio/components/interfaces/Billing/AddOns/AddOns.types.ts b/studio/components/interfaces/Billing/AddOns/AddOns.types.ts
new file mode 100644
index 00000000000..bbad348d383
--- /dev/null
+++ b/studio/components/interfaces/Billing/AddOns/AddOns.types.ts
@@ -0,0 +1,24 @@
+export interface DatabaseAddon {
+ id: string
+ name: string
+ description?: string | null
+ prices: AddonPrice[]
+ metadata: {
+ features: string
+ default_price_id?: string
+ supabase_prod_id: string
+ }
+}
+
+export interface AddonPrice {
+ id?: string
+ currency: string
+ unit_amount: number
+ recurring: {
+ aggregate_usage: number | null
+ interval: 'month' | 'year'
+ interval_count: number
+ trial_period_days: number | null
+ usage_type: string
+ }
+}
diff --git a/studio/components/interfaces/Billing/AddOns/AddOns.utils.ts b/studio/components/interfaces/Billing/AddOns/AddOns.utils.ts
index fb55d21b3b3..61c3910b879 100644
--- a/studio/components/interfaces/Billing/AddOns/AddOns.utils.ts
+++ b/studio/components/interfaces/Billing/AddOns/AddOns.utils.ts
@@ -1,11 +1,20 @@
-export const formatComputeSizes = (computeSizes: any[]) => {
- // Just need to order the options - ideally if the API can filter this that'll be great
- // but for now just let FE order to get things moving quickly
+import { DatabaseAddon } from './AddOns.types'
- // FE will also inject the micro option as this will not be saved in our stripe dashboard
+export const formatComputeSizes = (addons: DatabaseAddon[]) => {
+ const addonsOrder = [
+ 'addon_instance_small',
+ 'addon_instance_medium',
+ 'addon_instance_large',
+ 'addon_instance_xlarge',
+ 'addon_instance_xxlarge',
+ 'addon_instance_4xlarge',
+ 'addon_instance_8xlarge',
+ 'addon_instance_12xlarge',
+ 'addon_instance_16xlarge',
+ ]
- const microOption = {
- id: '',
+ const microOption: DatabaseAddon = {
+ id: 'micro-add-on',
name: 'Micro Add-on',
metadata: {
default_price_id: undefined,
@@ -28,23 +37,52 @@ export const formatComputeSizes = (computeSizes: any[]) => {
],
}
- const addonsOrder = [
- 'addon_instance_small',
- 'addon_instance_medium',
- 'addon_instance_large',
- 'addon_instance_xlarge',
- 'addon_instance_xxlarge',
- 'addon_instance_4xlarge',
- 'addon_instance_8xlarge',
- 'addon_instance_12xlarge',
- 'addon_instance_16xlarge',
- ]
-
return [microOption]
.concat(
addonsOrder.map((id: string) => {
- return computeSizes.find((option: any) => option.metadata.supabase_prod_id === id)
- })
+ return addons.find((option) => option.metadata.supabase_prod_id === id)
+ }) as DatabaseAddon[]
+ )
+ .filter((option) => option !== undefined)
+}
+
+export const formatPITROptions = (addons: DatabaseAddon[]) => {
+ const pitrOrder = [
+ 'addon_pitr_0days',
+ 'addon_pitr_7days',
+ 'addon_pitr_14days',
+ 'addon_pitr_28days',
+ ]
+
+ const noPITROption: DatabaseAddon = {
+ id: 'pitr-disabled',
+ name: 'Disable PITR',
+ metadata: {
+ default_price_id: undefined,
+ supabase_prod_id: 'addon_pitr_0days',
+ features: '',
+ },
+ prices: [
+ {
+ id: undefined,
+ currency: 'usd',
+ recurring: {
+ interval: 'month',
+ usage_type: 'licensed',
+ interval_count: 1,
+ aggregate_usage: null,
+ trial_period_days: null,
+ },
+ unit_amount: 0,
+ },
+ ],
+ }
+
+ return [noPITROption]
+ .concat(
+ pitrOrder.map((id: string) => {
+ return addons.find((option) => option.metadata.supabase_prod_id === id)
+ }) as DatabaseAddon[]
)
.filter((option) => option !== undefined)
}
diff --git a/studio/components/interfaces/Billing/AddOns/PITRDurationSelection.tsx b/studio/components/interfaces/Billing/AddOns/PITRDurationSelection.tsx
new file mode 100644
index 00000000000..89dc082ca09
--- /dev/null
+++ b/studio/components/interfaces/Billing/AddOns/PITRDurationSelection.tsx
@@ -0,0 +1,74 @@
+import { FC } from 'react'
+import { Badge, Radio } from 'ui'
+
+import { useFlag } from 'hooks'
+import { DatabaseAddon } from './AddOns.types'
+import { getProductPrice } from '../Billing.utils'
+import DisabledWarningDueToIncident from 'components/ui/DisabledWarningDueToIncident'
+
+interface Props {
+ pitrDurationOptions: DatabaseAddon[]
+ currentPitrDuration?: DatabaseAddon
+ selectedPitrDuration?: DatabaseAddon
+ onSelectOption: (option: any) => void
+}
+
+const PITRDurationSelection: FC<Props> = ({
+ pitrDurationOptions,
+ currentPitrDuration,
+ selectedPitrDuration,
+ onSelectOption,
+}) => {
+ const addonUpdateDisabled = useFlag('disableProjectCreationAndUpdate')
+
+ return (
+ <div className="space-y-4">
+ <div>
+ <div className="flex items-center space-x-2">
+ <h4 className="text-lg">Point in time recovery</h4>
+ <Badge color="green">Optional</Badge>
+ </div>
+ <p className="text-sm text-scale-1100">
+ Restore your database from a specific point in time
+ </p>
+ </div>
+ {addonUpdateDisabled ? (
+ <DisabledWarningDueToIncident title="Updating database add-ons is currently disabled" />
+ ) : (
+ <Radio.Group type="cards" className="billing-compute-radio">
+ {pitrDurationOptions.map((option: any) => {
+ const defaultPrice = getProductPrice(option)
+ return (
+ <Radio
+ hidden
+ key={option.id}
+ align="vertical"
+ // @ts-ignore
+ label={
+ <div className="flex items-center space-x-4">
+ <p>{option.name}</p>
+ {currentPitrDuration?.id === option.id && (
+ <Badge color="brand">Current selection</Badge>
+ )}
+ </div>
+ }
+ // @ts-ignore
+ description={
+ <div>
+ <p>{option.metadata.features}</p>
+ </div>
+ }
+ value={option.id}
+ optionalLabel={<div>${defaultPrice.unit_amount / 100} / month</div>}
+ checked={selectedPitrDuration?.id === option.id}
+ onChange={() => onSelectOption(option)}
+ />
+ )
+ })}
+ </Radio.Group>
+ )}
+ </div>
+ )
+}
+
+export default PITRDurationSelection
diff --git a/studio/components/interfaces/Billing/Billing.types.ts b/studio/components/interfaces/Billing/Billing.types.ts
index be3ebd37e9b..8066b18b1df 100644
--- a/studio/components/interfaces/Billing/Billing.types.ts
+++ b/studio/components/interfaces/Billing/Billing.types.ts
@@ -24,3 +24,28 @@ export interface SubscriptionPreview {
has_changes: boolean
cost_breakdown: any[]
}
+
+export interface PaymentMethod {
+ id: string
+ billing_details: object
+ card: {
+ brand: string
+ checks: object
+ country: string
+ exp_month: number
+ exp_year: number
+ fingerprint: string
+ funding: string
+ generated_from: any
+ last4: string
+ networks: object
+ three_d_secure_usage: object
+ wallet: any
+ }
+ created: number
+ customer: string
+ livemode: boolean
+ metadata: object
+ object: string
+ type: string
+}
diff --git a/studio/components/interfaces/Billing/Billing.utils.ts b/studio/components/interfaces/Billing/Billing.utils.ts
index 44dca5e310c..885e4885c24 100644
--- a/studio/components/interfaces/Billing/Billing.utils.ts
+++ b/studio/components/interfaces/Billing/Billing.utils.ts
@@ -1,3 +1,7 @@
+import { DatabaseAddon } from './AddOns/AddOns.types'
+import { formatComputeSizes, formatPITROptions } from './AddOns/AddOns.utils'
+import { StripeSubscription } from './Subscription/Subscription.types'
+
export const getProductPrice = (product: any) => {
const defaultPriceId = product.metadata?.default_price_id
const price =
@@ -9,13 +13,18 @@ export const getProductPrice = (product: any) => {
export const formSubscriptionUpdatePayload = (
selectedTier: any,
- selectedComputeSize: any,
+ selectedComputeSize: DatabaseAddon,
+ selectedPITRDuration: DatabaseAddon,
selectedPaymentMethod: string,
region: string
) => {
const defaultPrice = selectedTier ? getProductPrice(selectedTier) : undefined
const addons =
- region === 'af-south-1' || !selectedComputeSize.id ? [] : [selectedComputeSize.prices[0].id]
+ region === 'af-south-1'
+ ? []
+ : [selectedComputeSize.prices[0].id, selectedPITRDuration.prices[0].id].filter(
+ (x) => x !== undefined
+ )
const proration_date = Math.floor(Date.now() / 1000)
return {
...(defaultPrice && { tier: defaultPrice.id }),
@@ -24,3 +33,35 @@ export const formSubscriptionUpdatePayload = (
payment_method: selectedPaymentMethod,
}
}
+
+export const getCurrentAddons = (
+ currentSubscription: StripeSubscription,
+ addons: DatabaseAddon[]
+) => {
+ const computeSizes = formatComputeSizes(addons)
+ const pitrDurationOptions = formatPITROptions(addons)
+
+ const currentComputeSize =
+ 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 currentPITRDuration =
+ pitrDurationOptions.find((option: any) => {
+ const subscriptionComputeSize = currentSubscription?.addons.find((addon) =>
+ addon.supabase_prod_id.includes('_pitr_')
+ )
+ return option.id === subscriptionComputeSize?.prod_id
+ }) ||
+ (pitrDurationOptions.find(
+ (option: any) => option.metadata.supabase_prod_id === 'addon_pitr_0days'
+ ) as DatabaseAddon)
+
+ return { currentComputeSize, currentPITRDuration }
+}
diff --git a/studio/components/interfaces/Billing/EnterpriseUpdate.tsx b/studio/components/interfaces/Billing/EnterpriseUpdate.tsx
index 639c374842a..f609ef422c7 100644
--- a/studio/components/interfaces/Billing/EnterpriseUpdate.tsx
+++ b/studio/components/interfaces/Billing/EnterpriseUpdate.tsx
@@ -8,20 +8,22 @@ import { post, patch } from 'lib/common/fetch'
import { API_URL, PROJECT_STATUS } from 'lib/constants'
import Divider from 'components/ui/Divider'
-import { formatComputeSizes } from './AddOns/AddOns.utils'
+import { DatabaseAddon } from './AddOns/AddOns.types'
+import { formatComputeSizes, formatPITROptions } from './AddOns/AddOns.utils'
import {
AddNewPaymentMethodModal,
ComputeSizeSelection,
+ PITRDurationSelection,
StripeSubscription,
PaymentSummaryPanel,
UpdateSuccess,
} from './'
-import { SubscriptionPreview } from './Billing.types'
-import { formSubscriptionUpdatePayload } from './Billing.utils'
+import { PaymentMethod, SubscriptionPreview } from './Billing.types'
+import { formSubscriptionUpdatePayload, getCurrentAddons } from './Billing.utils'
interface Props {
- products: { tiers: any[]; addons: any[] }
- paymentMethods?: any[]
+ products: { tiers: any[]; addons: DatabaseAddon[] }
+ paymentMethods?: PaymentMethod[]
currentSubscription: StripeSubscription
isLoadingPaymentMethods: boolean
}
@@ -41,12 +43,13 @@ const EnterpriseUpdate: FC<Props> = ({
const { addons } = products
const computeSizes = formatComputeSizes(addons)
- const currentComputeSize =
- computeSizes.find((option: any) => option.id === currentSubscription?.addons[0]?.prod_id) ||
- computeSizes.find((option: any) => option.metadata.supabase_prod_id === 'addon_instance_micro')
+ const pitrDurationOptions = formatPITROptions(addons)
+ const { currentComputeSize, currentPITRDuration } = getCurrentAddons(currentSubscription, addons)
- const [selectedPaymentMethod, setSelectedPaymentMethod] = useState<any>()
- const [selectedComputeSize, setSelectedComputeSize] = useState<any>(currentComputeSize)
+ const [selectedPaymentMethodId, setSelectedPaymentMethodId] = useState<any>()
+ const [selectedComputeSize, setSelectedComputeSize] = useState<DatabaseAddon>(currentComputeSize)
+ const [selectedPITRDuration, setSelectedPITRDuration] =
+ useState<DatabaseAddon>(currentPITRDuration)
const [subscriptionPreview, setSubscriptionPreview] = useState<SubscriptionPreview>()
const [isRefreshingPreview, setIsRefreshingPreview] = useState(false)
@@ -58,11 +61,11 @@ const EnterpriseUpdate: FC<Props> = ({
useEffect(() => {
getSubscriptionPreview()
- }, [selectedComputeSize])
+ }, [selectedComputeSize, selectedPITRDuration])
useEffect(() => {
if (!isLoadingPaymentMethods && paymentMethods && paymentMethods.length > 0) {
- setSelectedPaymentMethod(paymentMethods[0].id)
+ setSelectedPaymentMethodId(paymentMethods[0].id)
}
}, [isLoadingPaymentMethods, paymentMethods])
@@ -73,7 +76,8 @@ const EnterpriseUpdate: FC<Props> = ({
...formSubscriptionUpdatePayload(
null,
selectedComputeSize,
- selectedPaymentMethod,
+ selectedPITRDuration,
+ selectedPaymentMethodId,
projectRegion
),
tier: currentSubscription.tier.price_id,
@@ -97,7 +101,8 @@ const EnterpriseUpdate: FC<Props> = ({
...formSubscriptionUpdatePayload(
null,
selectedComputeSize,
- selectedPaymentMethod,
+ selectedPITRDuration,
+ selectedPaymentMethodId,
projectRegion
),
tier: currentSubscription.tier.price_id,
@@ -163,7 +168,7 @@ const EnterpriseUpdate: FC<Props> = ({
'flex max-w-[600px] items-center justify-between gap-16 rounded border px-6 py-4 drop-shadow-sm',
].join(' ')}
>
- <p>
+ <p className="text-sm">
If you'd like to change your subscription away from enterprise, please reach out
to <span className="text-brand-900">[email protected]</span> with your
request.
@@ -171,6 +176,13 @@ const EnterpriseUpdate: FC<Props> = ({
</div>
{projectRegion !== 'af-south-1' && (
<>
+ <Divider light />
+ <PITRDurationSelection
+ pitrDurationOptions={pitrDurationOptions || []}
+ currentPitrDuration={currentPITRDuration}
+ selectedPitrDuration={selectedPITRDuration}
+ onSelectOption={setSelectedPITRDuration}
+ />
<Divider light />
<ComputeSizeSelection
computeSizes={computeSizes || []}
@@ -190,13 +202,17 @@ const EnterpriseUpdate: FC<Props> = ({
isSubmitting={isSubmitting}
isRefreshingPreview={isRefreshingPreview}
subscriptionPreview={subscriptionPreview}
+ // Current subscription configuration based on DB
currentPlan={currentSubscription.tier}
currentComputeSize={currentComputeSize}
+ currentPITRDuration={currentPITRDuration}
+ // Selected subscription configuration based on UI
selectedComputeSize={selectedComputeSize}
+ selectedPITRDuration={selectedPITRDuration}
paymentMethods={paymentMethods}
isLoadingPaymentMethods={isLoadingPaymentMethods}
- selectedPaymentMethod={selectedPaymentMethod}
- onSelectPaymentMethod={setSelectedPaymentMethod}
+ selectedPaymentMethod={selectedPaymentMethodId}
+ onSelectPaymentMethod={setSelectedPaymentMethodId}
onSelectAddNewPaymentMethod={() => {
setShowAddPaymentMethodModal(true)
}}
diff --git a/studio/components/interfaces/Billing/PaymentSummaryPanel/PaymentSummaryPanel.tsx b/studio/components/interfaces/Billing/PaymentSummaryPanel/PaymentSummaryPanel.tsx
index c7b2587ae34..d410ea33301 100644
--- a/studio/components/interfaces/Billing/PaymentSummaryPanel/PaymentSummaryPanel.tsx
+++ b/studio/components/interfaces/Billing/PaymentSummaryPanel/PaymentSummaryPanel.tsx
@@ -18,14 +18,17 @@ import { SubscriptionPreview } from '../Billing.types'
import { getProductPrice } from '../Billing.utils'
import PaymentTotal from './PaymentTotal'
import InformationBox from 'components/ui/InformationBox'
+import { DatabaseAddon } from '../AddOns/AddOns.types'
interface Props {
isRefreshingPreview: boolean
subscriptionPreview?: SubscriptionPreview
currentPlan: any
- currentComputeSize: any
+ currentComputeSize: DatabaseAddon
+ currentPITRDuration: DatabaseAddon
selectedPlan?: any
- selectedComputeSize: any
+ selectedComputeSize: DatabaseAddon
+ selectedPITRDuration: DatabaseAddon
isSpendCapEnabled: boolean
paymentMethods?: any
selectedPaymentMethod: any
@@ -45,12 +48,14 @@ interface Props {
const PaymentSummaryPanel: FC<Props> = ({
isRefreshingPreview,
+ isSpendCapEnabled,
subscriptionPreview,
currentPlan,
- selectedPlan,
- isSpendCapEnabled,
currentComputeSize,
+ currentPITRDuration,
+ selectedPlan,
selectedComputeSize,
+ selectedPITRDuration,
paymentMethods,
selectedPaymentMethod,
isLoadingPaymentMethods,
@@ -78,10 +83,11 @@ 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
// If it's enterprise we only only changing of add-ons
const hasChangesToPlan = isEnterprise
- ? isChangingComputeSize
+ ? isChangingComputeSize || isChangingPITRDuration
: subscriptionPreview?.has_changes ?? false
const getPlanName = (plan: any) => {
@@ -123,32 +129,49 @@ const PaymentSummaryPanel: FC<Props> = ({
{projectRegion !== 'af-south-1' && (
<div className="space-y-1">
<p className="text-sm">Selected add-ons</p>
- {currentComputeSize === undefined && selectedComputeSize === undefined && (
- <p className="text-sm text-scale-1100">No add-ons selected</p>
+ <div className="flex items-center justify-between">
+ <p
+ className={`${isChangingComputeSize ? 'text-scale-1100 line-through' : ''} text-sm`}
+ >
+ {currentComputeSize.name}
+ </p>
+ <p
+ className={`${isChangingComputeSize ? 'text-scale-1100 line-through' : ''} text-sm`}
+ >
+ ${(getProductPrice(currentComputeSize).unit_amount / 100).toFixed(2)}
+ </p>
+ </div>
+ {isChangingComputeSize && (
+ <div className="flex items-center justify-between">
+ <p className="text-sm">{selectedComputeSize.name}</p>
+ <p className="text-sm">
+ ${(getProductPrice(selectedComputeSize).unit_amount / 100).toFixed(2)}
+ </p>
+ </div>
)}
- {currentComputeSize !== undefined && (
+ {currentPITRDuration.id !== 'pitr-disabled' && (
<div className="flex items-center justify-between">
<p
className={`${
- isChangingComputeSize ? 'text-scale-1100 line-through' : ''
+ isChangingPITRDuration ? 'text-scale-1100 line-through' : ''
} text-sm`}
>
- {currentComputeSize.name}
+ {currentPITRDuration.name}
</p>
<p
className={`${
- isChangingComputeSize ? 'text-scale-1100 line-through' : ''
+ isChangingPITRDuration ? 'text-scale-1100 line-through' : ''
} text-sm`}
>
- ${(getProductPrice(currentComputeSize).unit_amount / 100).toFixed(2)}
+ ${(getProductPrice(currentPITRDuration).unit_amount / 100).toFixed(2)}
</p>
</div>
)}
- {isChangingComputeSize && (
+ {isChangingPITRDuration && (
<div className="flex items-center justify-between">
- <p className="text-sm">{selectedComputeSize.name}</p>
+ <p className="text-sm">{selectedPITRDuration.name}</p>
<p className="text-sm">
- ${(getProductPrice(selectedComputeSize).unit_amount / 100).toFixed(2)}
+ ${(getProductPrice(selectedPITRDuration).unit_amount / 100).toFixed(2)}
</p>
</div>
)}
diff --git a/studio/components/interfaces/Billing/ProUpgrade.tsx b/studio/components/interfaces/Billing/ProUpgrade.tsx
index 8e38e1ecde0..aad76c8d6f0 100644
--- a/studio/components/interfaces/Billing/ProUpgrade.tsx
+++ b/studio/components/interfaces/Billing/ProUpgrade.tsx
@@ -12,21 +12,23 @@ import Divider from 'components/ui/Divider'
import {
PaymentSummaryPanel,
ComputeSizeSelection,
+ PITRDurationSelection,
StripeSubscription,
AddNewPaymentMethodModal,
} from './'
import { STRIPE_PRODUCT_IDS } from 'lib/constants'
-import { SubscriptionPreview } from './Billing.types'
-import { formSubscriptionUpdatePayload } from './Billing.utils'
import UpdateSuccess from './UpdateSuccess'
-import { formatComputeSizes } from './AddOns/AddOns.utils'
+import { PaymentMethod, SubscriptionPreview } from './Billing.types'
+import { formSubscriptionUpdatePayload, getCurrentAddons } from './Billing.utils'
+import { DatabaseAddon } from './AddOns/AddOns.types'
+import { formatComputeSizes, formatPITROptions } from './AddOns/AddOns.utils'
import BackButton from 'components/ui/BackButton'
// Do not allow compute size changes for af-south-1
interface Props {
- products: { tiers: any[]; addons: any[] }
- paymentMethods?: any[]
+ products: { tiers: any[]; addons: DatabaseAddon[] }
+ paymentMethods?: PaymentMethod[]
currentSubscription: StripeSubscription
isLoadingPaymentMethods: boolean
onSelectBack: () => void
@@ -44,15 +46,13 @@ const ProUpgrade: FC<Props> = ({
const { addons } = products
const computeSizes = formatComputeSizes(addons)
+ const pitrDurationOptions = formatPITROptions(addons)
+ const { currentComputeSize, currentPITRDuration } = getCurrentAddons(currentSubscription, addons)
const projectId = ui.selectedProject?.id ?? -1
const projectRef = ui.selectedProject?.ref
const projectRegion = ui.selectedProject?.region ?? ''
- const currentComputeSize =
- computeSizes.find((option: any) => option.id === currentSubscription?.addons[0]?.prod_id) ||
- computeSizes.find((option: any) => option.metadata.supabase_prod_id === 'addon_instance_micro')
-
const [isSpendCapEnabled, setIsSpendCapEnabled] = useState(
// If project is currently free, default to enabling spend caps
currentSubscription.tier.prod_id === STRIPE_PRODUCT_IDS.FREE ||
@@ -66,8 +66,10 @@ const ProUpgrade: FC<Props> = ({
const [showAddPaymentMethodModal, setShowAddPaymentMethodModal] = useState(false)
const [showSpendCapHelperModal, setShowSpendCapHelperModal] = useState(false)
- const [selectedPaymentMethod, setSelectedPaymentMethod] = useState<any>()
- const [selectedComputeSize, setSelectedComputeSize] = useState<any>(currentComputeSize)
+ const [selectedPaymentMethodId, setSelectedPaymentMethodId] = useState<string>('')
+ const [selectedComputeSize, setSelectedComputeSize] = useState<DatabaseAddon>(currentComputeSize)
+ const [selectedPITRDuration, setSelectedPITRDuration] =
+ useState<DatabaseAddon>(currentPITRDuration)
const [subscriptionPreview, setSubscriptionPreview] = useState<SubscriptionPreview>()
const selectedTier = isSpendCapEnabled
@@ -82,13 +84,13 @@ const ProUpgrade: FC<Props> = ({
useEffect(() => {
if (!isLoadingPaymentMethods && paymentMethods && paymentMethods.length > 0) {
- setSelectedPaymentMethod(paymentMethods[0].id)
+ setSelectedPaymentMethodId(paymentMethods[0].id)
}
}, [isLoadingPaymentMethods, paymentMethods])
useEffect(() => {
getSubscriptionPreview()
- }, [selectedComputeSize, isSpendCapEnabled])
+ }, [selectedComputeSize, selectedPITRDuration, isSpendCapEnabled])
const getSubscriptionPreview = async () => {
if (!selectedTier) return
@@ -96,7 +98,8 @@ const ProUpgrade: FC<Props> = ({
const payload = formSubscriptionUpdatePayload(
selectedTier,
selectedComputeSize,
- selectedPaymentMethod,
+ selectedPITRDuration,
+ selectedPaymentMethodId,
projectRegion
)
@@ -116,7 +119,8 @@ const ProUpgrade: FC<Props> = ({
const payload = formSubscriptionUpdatePayload(
selectedTier,
selectedComputeSize,
- selectedPaymentMethod,
+ selectedPITRDuration,
+ selectedPaymentMethodId,
projectRegion
)
@@ -187,9 +191,9 @@ const ProUpgrade: FC<Props> = ({
<h3 className="text-3xl">
Managing your <span className="text-brand-900">Pro</span> plan
</h3>
- <p className="text-base text-scale-1100">
+ {/* <p className="text-base text-scale-1100">
Your billing cycle will reset after payment
- </p>
+ </p> */}
</>
)}
</div>
@@ -215,12 +219,19 @@ const ProUpgrade: FC<Props> = ({
</div>
{projectRegion !== 'af-south-1' && (
<>
+ <Divider light />
+ <PITRDurationSelection
+ pitrDurationOptions={pitrDurationOptions || []}
+ currentPitrDuration={
+ isManagingProSubscription ? currentPITRDuration : undefined
+ }
+ selectedPitrDuration={selectedPITRDuration}
+ onSelectOption={setSelectedPITRDuration}
+ />
<Divider light />
<ComputeSizeSelection
computeSizes={computeSizes || []}
- currentComputeSize={
- isManagingProSubscription ? currentComputeSize : undefined
- }
+ currentComputeSize={currentComputeSize}
selectedComputeSize={selectedComputeSize}
onSelectOption={setSelectedComputeSize}
/>
@@ -234,15 +245,19 @@ const ProUpgrade: FC<Props> = ({
<PaymentSummaryPanel
isRefreshingPreview={isRefreshingPreview}
subscriptionPreview={subscriptionPreview}
- currentPlan={currentSubscription.tier}
- selectedPlan={selectedTier}
isSpendCapEnabled={isSpendCapEnabled}
+ // Current subscription configuration based on DB
+ currentPlan={currentSubscription.tier}
currentComputeSize={currentComputeSize}
+ currentPITRDuration={currentPITRDuration}
+ // Selected subscription configuration based on UI
+ selectedPlan={selectedTier}
selectedComputeSize={selectedComputeSize}
+ selectedPITRDuration={selectedPITRDuration}
paymentMethods={paymentMethods}
isLoadingPaymentMethods={isLoadingPaymentMethods}
- selectedPaymentMethod={selectedPaymentMethod}
- onSelectPaymentMethod={setSelectedPaymentMethod}
+ selectedPaymentMethod={selectedPaymentMethodId}
+ onSelectPaymentMethod={setSelectedPaymentMethodId}
onSelectAddNewPaymentMethod={() => {
setShowAddPaymentMethodModal(true)
}}
diff --git a/studio/components/interfaces/Billing/index.ts b/studio/components/interfaces/Billing/index.ts
index 908cd2a7314..afcd29a86aa 100644
--- a/studio/components/interfaces/Billing/index.ts
+++ b/studio/components/interfaces/Billing/index.ts
@@ -6,6 +6,7 @@ import ProUpgrade from './ProUpgrade'
import ExitSurvey from './ExitSurvey/ExitSurvey'
import PaymentSummaryPanel from './PaymentSummaryPanel/PaymentSummaryPanel'
import ComputeSizeSelection from './AddOns/ComputeSizeSelection'
+import PITRDurationSelection from './AddOns/PITRDurationSelection'
import AddNewPaymentMethodModal from './AddNewPaymentMethodModal/AddNewPaymentMethodModal'
import UpdateSuccess from './UpdateSuccess'
@@ -20,6 +21,7 @@ export {
ExitSurvey,
PaymentSummaryPanel,
ComputeSizeSelection,
+ PITRDurationSelection,
AddNewPaymentMethodModal,
UpdateSuccess,
Invoices,
diff --git a/studio/pages/project/[ref]/settings/billing/update/pro.tsx b/studio/pages/project/[ref]/settings/billing/update/pro.tsx
index 3ea5fd7c379..180e4f2ddc8 100644
--- a/studio/pages/project/[ref]/settings/billing/update/pro.tsx
+++ b/studio/pages/project/[ref]/settings/billing/update/pro.tsx
@@ -6,11 +6,13 @@ import { useStore, useFlag } from 'hooks'
import { get } from 'lib/common/fetch'
import { API_URL, PRICING_TIER_PRODUCT_IDS } from 'lib/constants'
+import { NextPageWithLayout } from 'types'
import { BillingLayout } from 'components/layouts'
import Connecting from 'components/ui/Loading/Loading'
import { StripeSubscription } from 'components/interfaces/Billing'
import { ProUpgrade } from 'components/interfaces/Billing'
-import { NextPageWithLayout } from 'types'
+import { PaymentMethod } from 'components/interfaces/Billing/Billing.types'
+import { DatabaseAddon } from 'components/interfaces/Billing/AddOns/AddOns.types'
const BillingUpdatePro: NextPageWithLayout = () => {
const { ui } = useStore()
@@ -22,8 +24,8 @@ const BillingUpdatePro: NextPageWithLayout = () => {
const projectUpdateDisabled = useFlag('disableProjectCreationAndUpdate')
const [subscription, setSubscription] = useState<StripeSubscription>()
- const [products, setProducts] = useState<{ tiers: any[]; addons: any[] }>()
- const [paymentMethods, setPaymentMethods] = useState<any>()
+ const [products, setProducts] = useState<{ tiers: any[]; addons: DatabaseAddon[] }>()
+ const [paymentMethods, setPaymentMethods] = useState<PaymentMethod[]>()
const [isLoadingPaymentMethods, setIsLoadingPaymentMethods] = useState(false)
const isEnterprise =