Skip to content

Commit cbf676c

Browse files
refactor(billing): show success toast for 202 accepted response from subscription confirm endpoints (supabase#39823)
* refactor(billing): show success toast if backend returns 202 Accepted status code * don't need to check slug for sub confirm endpoint
1 parent c41a5be commit cbf676c

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

apps/studio/data/subscriptions/org-subscription-confirm-pending-change.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { toast } from 'sonner'
33

44
import { handleError, post } from 'data/fetchers'
55
import type { ResponseError } from 'types'
6+
import type { components } from 'api-types'
67
import { organizationKeys } from 'data/organizations/keys'
78
import { subscriptionKeys } from './keys'
89
import { usageKeys } from 'data/usage/keys'
@@ -63,6 +64,17 @@ export const useConfirmPendingSubscriptionChangeMutation = ({
6364
async onSuccess(data, variables, context) {
6465
const { slug } = variables
6566

67+
// Handle 202 Accepted - show toast and skip query invalidation
68+
// The 200 success response returns void, so if data exists it must be 202
69+
if (data && 'message' in data) {
70+
const pendingResponse = data as components['schemas']['PendingConfirmationResponse']
71+
toast.success(pendingResponse.message, {
72+
dismissible: true,
73+
duration: 10_000,
74+
})
75+
return
76+
}
77+
6678
// [Kevin] Backend can return stale data as it's waiting for the Stripe-sync to complete. Until that's solved in the backend
6779
// we are going back to monkey here and delay the invalidation
6880
await new Promise((resolve) => setTimeout(resolve, 2000))

apps/studio/data/subscriptions/org-subscription-confirm-pending-create.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { toast } from 'sonner'
33

44
import { handleError, post } from 'data/fetchers'
55
import type { ResponseError } from 'types'
6+
import type { components } from 'api-types'
67
import { organizationKeys } from 'data/organizations/keys'
78
import { permissionKeys } from 'data/permissions/keys'
89
import { castOrganizationResponseToOrganization } from 'data/organizations/organizations-query'
9-
import type { components } from 'api-types'
1010

1111
export type PendingSubscriptionCreateVariables = {
1212
payment_intent_id: string
@@ -56,6 +56,16 @@ export const useConfirmPendingSubscriptionCreateMutation = ({
5656
PendingSubscriptionCreateVariables
5757
>((vars) => confirmPendingSubscriptionCreate(vars), {
5858
async onSuccess(data, variables, context) {
59+
// Handle 202 Accepted - show toast and skip query updates
60+
if (data && 'message' in data && !('slug' in data)) {
61+
const pendingResponse = data as components['schemas']['PendingConfirmationResponse']
62+
toast.success(pendingResponse.message, {
63+
dismissible: true,
64+
duration: 10_000,
65+
})
66+
return
67+
}
68+
5969
// [Joshen] We're manually updating the query client here as the org's subscription is
6070
// created async, and the invalidation will happen too quick where the GET organizations
6171
// endpoint will error out with a 500 since the subscription isn't created yet.

packages/api-types/types/platform.d.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7612,6 +7612,9 @@ export interface components {
76127612
}[]
76137613
defaultPaymentMethodId: string | null
76147614
}
7615+
PendingConfirmationResponse: {
7616+
message: string
7617+
}
76157618
PgbouncerConfigResponse: {
76167619
connection_string: string
76177620
db_dns_name: string
@@ -13831,6 +13834,14 @@ export interface operations {
1383113834
}
1383213835
content?: never
1383313836
}
13837+
202: {
13838+
headers: {
13839+
[name: string]: unknown
13840+
}
13841+
content: {
13842+
'application/json': components['schemas']['PendingConfirmationResponse']
13843+
}
13844+
}
1383413845
/** @description Unauthorized */
1383513846
401: {
1383613847
headers: {
@@ -16169,6 +16180,14 @@ export interface operations {
1616916180
'application/json': components['schemas']['CreateOrganizationResponse']
1617016181
}
1617116182
}
16183+
202: {
16184+
headers: {
16185+
[name: string]: unknown
16186+
}
16187+
content: {
16188+
'application/json': components['schemas']['PendingConfirmationResponse']
16189+
}
16190+
}
1617216191
/** @description Failed to confirm subscription changes */
1617316192
500: {
1617416193
headers: {

0 commit comments

Comments
 (0)