From 53cfe46a04273347311f8c00b0b892106f850c5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kevin=20Gr=C3=BCneberg?= Date: Wed, 2 Aug 2023 19:51:14 +0200 Subject: [PATCH] chore: keep spend cap disabled on downgrade team -> pro --- .../Subscription/PlanUpdateSidePanel.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/studio/components/interfaces/Organization/BillingSettingsV2/Subscription/PlanUpdateSidePanel.tsx b/studio/components/interfaces/Organization/BillingSettingsV2/Subscription/PlanUpdateSidePanel.tsx index d91951a27a5..9ec255913b8 100644 --- a/studio/components/interfaces/Organization/BillingSettingsV2/Subscription/PlanUpdateSidePanel.tsx +++ b/studio/components/interfaces/Organization/BillingSettingsV2/Subscription/PlanUpdateSidePanel.tsx @@ -7,7 +7,7 @@ import { useEffect, useState } from 'react' import ShimmeringLoader from 'components/ui/ShimmeringLoader' import { useOrgPlansQuery } from 'data/subscriptions/org-plans-query' import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query' -import { useOrgSubscriptionUpdateMutation } from 'data/subscriptions/org-subscription-update-mutation' +import { SubscriptionTier, useOrgSubscriptionUpdateMutation } from 'data/subscriptions/org-subscription-update-mutation' import { useCheckPermissions, useSelectedOrganization, useStore } from 'hooks' import { PRICING_TIER_PRODUCT_IDS } from 'lib/constants' import Telemetry from 'lib/telemetry' @@ -110,9 +110,14 @@ const PlanUpdateSidePanel = () => { return ui.setNotification({ category: 'error', message: 'Please select a payment method' }) } - updateOrgSubscription({ slug, tier: selectedTier, paymentMethod: selectedPaymentMethod }) + // If the user is downgrading from team, should have spend cap disabled by default + const tier = subscription?.plan?.id === 'team' && selectedTier === PRICING_TIER_PRODUCT_IDS.PRO ? PRICING_TIER_PRODUCT_IDS.PAYG as SubscriptionTier : selectedTier + + updateOrgSubscription({ slug, tier, paymentMethod: selectedPaymentMethod }) } + const planMeta = selectedTier ? availablePlans.find((p) => p.id === selectedTier.split('tier_')[1]) : null + return ( <> { onCancel={() => setSelectedTier(undefined)} onConfirm={onUpdateSubscription} overlayClassName="pointer-events-none" - header={`Confirm to upgrade to ${subscriptionPlanMeta?.name}`} + header={`Confirm ${planMeta?.change_type === 'downgrade' ? 'downgrade' : 'upgrade'} to ${subscriptionPlanMeta?.name}`} >