Skip to content

Commit 69ea1a4

Browse files
fix(billing): use onSuccess callback for Back to Billing navigation
The ManualTransferForm's internal submitted state was being reset by Server Component re-render errors, causing the Back to Billing button to reset the form instead of navigating. Now uses a dedicated onSuccess prop that always navigates to the billing page after successful submission. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ee74ef0 commit 69ea1a4

2 files changed

Lines changed: 9 additions & 10 deletions

File tree

app/[locale]/dashboard/admin/billing/upgrade/upgrade-page-client.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export function UpgradePageClient({ plans, currentPlan }: UpgradePageClientProps
2929
const locale = useLocale()
3030
const t = useTranslations('dashboard.admin.billing.upgrade')
3131
const [loading, setLoading] = useState(false)
32-
const [manualSubmitted, setManualSubmitted] = useState(false)
3332
const [manualTransfer, setManualTransfer] = useState<{
3433
planId: string
3534
planName: string
@@ -75,26 +74,24 @@ export function UpgradePageClient({ plans, currentPlan }: UpgradePageClientProps
7574
if (!manualTransfer) return
7675
try {
7776
await requestManualPlanUpgrade(manualTransfer.planId, manualTransfer.interval, bankReference, notes)
78-
setManualSubmitted(true)
7977
} catch (e: any) {
8078
toast.error(e.message || t('submitError'))
8179
}
8280
}
8381

82+
const navigateToBilling = () => {
83+
router.push(`/${locale}/dashboard/admin/billing`)
84+
}
85+
8486
if (manualTransfer) {
8587
return (
8688
<ManualTransferForm
8789
planName={manualTransfer.planName}
8890
amount={manualTransfer.amount}
8991
interval={manualTransfer.interval}
9092
onSubmit={handleManualSubmit}
91-
onCancel={() => {
92-
if (manualSubmitted) {
93-
router.push(`/${locale}/dashboard/admin/billing`)
94-
} else {
95-
setManualTransfer(null)
96-
}
97-
}}
93+
onSuccess={navigateToBilling}
94+
onCancel={() => setManualTransfer(null)}
9895
/>
9996
)
10097
}

components/admin/manual-transfer-form.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ interface ManualTransferFormProps {
1515
interval: string
1616
onSubmit: (bankReference: string, notes: string) => Promise<void>
1717
onProofUpload?: (file: File) => Promise<void>
18+
onSuccess?: () => void
1819
onCancel: () => void
1920
}
2021

@@ -24,6 +25,7 @@ export function ManualTransferForm({
2425
interval,
2526
onSubmit,
2627
onProofUpload,
28+
onSuccess,
2729
onCancel,
2830
}: ManualTransferFormProps) {
2931
const [bankReference, setBankReference] = useState('')
@@ -55,7 +57,7 @@ export function ManualTransferForm({
5557
Your upgrade request has been submitted. We&apos;ll send you bank transfer instructions shortly.
5658
</p>
5759
</div>
58-
<Button variant="outline" onClick={onCancel}>Back to Billing</Button>
60+
<Button variant="outline" onClick={onSuccess || onCancel}>Back to Billing</Button>
5961
</CardContent>
6062
</Card>
6163
)

0 commit comments

Comments
 (0)