Skip to content

Commit 2531d2c

Browse files
waleedlatif1claude
andcommitted
refactor(upgrade): surface billing errors via toast instead of native alert()
The upgrade flow used native alert() for upgrade / switch-plan / switch-interval failures. Route them through the unified toast (toast.error) like the rest of the app — it's inside the ToastProvider tree. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 74e0bf8 commit 2531d2c

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

apps/sim/app/workspace/[workspaceId]/upgrade/hooks/use-upgrade-state.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use client'
22
import { useCallback, useEffect, useRef, useState } from 'react'
33
import { getErrorMessage } from '@sim/utils/errors'
4+
import { toast } from '@/components/emcn'
45
import { requestJson } from '@/lib/api/client/request'
56
import { billingSwitchPlanContract } from '@/lib/api/contracts/subscription'
67
import { useSubscriptionUpgrade } from '@/lib/billing/client/upgrade'
@@ -129,7 +130,7 @@ export function useUpgradeState(): UpgradeState {
129130
...(seats ? { seats } : {}),
130131
})
131132
} catch (error) {
132-
alert(getErrorMessage(error, 'Unknown error occurred'))
133+
toast.error(getErrorMessage(error, 'Unknown error occurred'))
133134
}
134135
},
135136
[handleUpgrade, isAnnual]
@@ -180,7 +181,7 @@ export function useUpgradeState(): UpgradeState {
180181
})
181182
await refetchSubscription()
182183
} catch (e) {
183-
alert(getErrorMessage(e, 'Failed to upgrade'))
184+
toast.error(getErrorMessage(e, 'Failed to upgrade'))
184185
}
185186
}, [subscription.isTeam, isAnnual, refetchSubscription])
186187

@@ -196,7 +197,7 @@ export function useUpgradeState(): UpgradeState {
196197
})
197198
await refetchSubscription()
198199
} catch (e) {
199-
alert(getErrorMessage(e, 'Failed to switch plan'))
200+
toast.error(getErrorMessage(e, 'Failed to switch plan'))
200201
}
201202
}, [subscription.plan, subscription.isTeam, refetchSubscription])
202203

apps/sim/app/workspace/[workspaceId]/upgrade/upgrade.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { useCallback, useEffect, useState } from 'react'
44
import { getErrorMessage } from '@sim/utils/errors'
55
import { useRouter } from 'next/navigation'
6-
import { ArrowLeft, Chip } from '@/components/emcn'
6+
import { ArrowLeft, Chip, toast } from '@/components/emcn'
77
import {
88
getUpgradeCardCta,
99
type PlanCardCta,
@@ -91,7 +91,7 @@ export function Upgrade({ workspaceId }: UpgradeProps) {
9191
onClick: () =>
9292
state
9393
.handleSwitchInterval(state.isAnnual ? 'year' : 'month')
94-
.catch((e) => alert(getErrorMessage(e, 'Failed to switch interval'))),
94+
.catch((e) => toast.error(getErrorMessage(e, 'Failed to switch interval'))),
9595
}
9696
}
9797
return { ...cta, onClick: () => {}, disabled: true }

0 commit comments

Comments
 (0)