Skip to content

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

Extract logic to retrieve price of product from subscription

Joshen Lim905e543c8a62
diff --git a/studio/components/interfaces/Billing/PaymentSummaryPanel/PaymentSummaryPanel.tsx b/studio/components/interfaces/Billing/PaymentSummaryPanel/PaymentSummaryPanel.tsx
index f18a40f0bdd..078d2a067d2 100644
--- a/studio/components/interfaces/Billing/PaymentSummaryPanel/PaymentSummaryPanel.tsx
+++ b/studio/components/interfaces/Billing/PaymentSummaryPanel/PaymentSummaryPanel.tsx
@@ -111,6 +111,15 @@ const PaymentSummaryPanel: FC<Props> = ({
} else return plan.name
}
+ const getAddonPriceFromSubscription = (
+ key: 'computeSize' | 'pitrDuration' | 'customDomains' | 'supportPlan'
+ ) => {
+ return (
+ ((currentSubscription?.addons ?? []).find((addon) => addon.prod_id === currentAddons[key]?.id)
+ ?.unit_amount ?? 0) / 100
+ ).toFixed(2)
+ }
+
const validateOrder = () => {
const error = validateSubscriptionUpdatePayload(selectedAddons)
if (error) {
@@ -170,12 +179,7 @@ const PaymentSummaryPanel: FC<Props> = ({
<p
className={`${isChangingComputeSize ? 'text-scale-1100 line-through' : ''} text-sm`}
>
- $
- {(
- ((currentSubscription?.addons ?? []).find(
- (addon) => addon.prod_id === currentAddons.computeSize.id
- )?.unit_amount ?? 0) / 100
- ).toFixed(2)}
+ ${getAddonPriceFromSubscription('computeSize')}
</p>
</div>
{isChangingComputeSize && (
@@ -202,12 +206,7 @@ const PaymentSummaryPanel: FC<Props> = ({
isChangingPITRDuration ? 'text-scale-1100 line-through' : ''
} text-sm`}
>
- $
- {(
- ((currentSubscription?.addons ?? []).find(
- (addon) => addon.prod_id === currentAddons.pitrDuration.id
- )?.unit_amount ?? 0) / 100
- ).toFixed(2)}
+ ${getAddonPriceFromSubscription('pitrDuration')}
</p>
</div>
)}
@@ -235,12 +234,7 @@ const PaymentSummaryPanel: FC<Props> = ({
isChangingCustomDomains ? 'text-scale-1100 line-through' : ''
} text-sm`}
>
- $
- {(
- ((currentSubscription?.addons ?? []).find(
- (addon) => addon.prod_id === currentAddons.customDomains.id
- )?.unit_amount ?? 0) / 100
- ).toFixed(2)}
+ ${getAddonPriceFromSubscription('customDomains')}
</p>
</div>
)}
@@ -257,14 +251,7 @@ const PaymentSummaryPanel: FC<Props> = ({
{currentAddons.supportPlan !== undefined && (
<div className="flex items-center justify-between">
<p className="text-sm">{currentAddons.supportPlan?.name}</p>
- <p className="text-sm">
- $
- {(
- ((currentSubscription?.addons ?? []).find(
- (addon) => addon.prod_id === currentAddons.supportPlan?.id
- )?.unit_amount ?? 0) / 100
- ).toFixed(2)}
- </p>
+ <p className="text-sm">${getAddonPriceFromSubscription('supportPlan')}</p>
</div>
)}
diff --git a/studio/components/interfaces/Billing/ProUpgrade.tsx b/studio/components/interfaces/Billing/ProUpgrade.tsx
index 372c16bb56a..2a9f6134004 100644
--- a/studio/components/interfaces/Billing/ProUpgrade.tsx
+++ b/studio/components/interfaces/Billing/ProUpgrade.tsx
@@ -306,6 +306,7 @@ const ProUpgrade: FC<Props> = ({
// Current subscription configuration based on DB
currentPlan={currentSubscription.tier}
currentAddons={currentAddons}
+ currentSubscription={currentSubscription}
// Selected subscription configuration based on UI
selectedPlan={selectedTier}
selectedAddons={selectedAddons}