Skip to content

Commit 4984392

Browse files
authored
fix: prevent double submission of plan change (supabase#36765)
When changing the plan while also creating a payment method in the same breath, some customers double-clicked the confirm button leading to a double-submission and possibly leading to a state where the customer gets charged, but the plan change is not going through.
1 parent 3cf5c3a commit 4984392

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

apps/studio/components/interfaces/Organization/BillingSettings/Subscription/SubscriptionPlanUpdateDialog.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { useQueryClient } from '@tanstack/react-query'
21
import { Check, InfoIcon } from 'lucide-react'
32
import Link from 'next/link'
43
import { useMemo, useRef, useState } from 'react'
@@ -11,7 +10,6 @@ import {
1110
} from 'components/interfaces/Billing/Subscription/Subscription.utils'
1211
import AlertError from 'components/ui/AlertError'
1312
import ShimmeringLoader from 'components/ui/ShimmeringLoader'
14-
import { organizationKeys } from 'data/organizations/keys'
1513
import { OrganizationBillingSubscriptionPreviewResponse } from 'data/organizations/organization-billing-subscription-preview'
1614
import { ProjectInfo } from 'data/projects/projects-query'
1715
import { useOrgSubscriptionUpdateMutation } from 'data/subscriptions/org-subscription-update-mutation'
@@ -115,6 +113,7 @@ export const SubscriptionPlanUpdateDialog = ({
115113
)
116114

117115
const onSuccessfulPlanChange = () => {
116+
setPaymentConfirmationLoading(false)
118117
toast.success(
119118
`Successfully ${changeType === 'downgrade' ? 'downgraded' : 'upgraded'} subscription to ${subscriptionPlanMeta?.name}!`
120119
)
@@ -133,6 +132,7 @@ export const SubscriptionPlanUpdateDialog = ({
133132
onSuccessfulPlanChange()
134133
},
135134
onError: (error) => {
135+
setPaymentConfirmationLoading(false)
136136
toast.error(`Unable to update subscription: ${error.message}`)
137137
},
138138
}
@@ -168,9 +168,13 @@ export const SubscriptionPlanUpdateDialog = ({
168168
if (!selectedOrganization?.slug) return console.error('org slug is required')
169169
if (!selectedTier) return console.error('Selected plan is required')
170170

171+
setPaymentConfirmationLoading(true)
172+
171173
const paymentMethod = await paymentMethodSelection.current?.createPaymentMethod()
172174
if (paymentMethod) {
173175
setSelectedPaymentMethod(paymentMethod.id)
176+
} else {
177+
setPaymentConfirmationLoading(false)
174178
}
175179

176180
if (

0 commit comments

Comments
 (0)