Skip to content

Commit ab4e755

Browse files
committed
address comments
1 parent d7a87bd commit ab4e755

3 files changed

Lines changed: 40 additions & 17 deletions

File tree

apps/sim/app/account/settings/billing/credit-usage/page.test.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@
33
*/
44
import { beforeEach, describe, expect, it, vi } from 'vitest'
55

6-
const { mockGetPersonalSubscription, mockGetSession, mockIsEnterprise, mockRedirect } = vi.hoisted(
7-
() => ({
8-
mockGetPersonalSubscription: vi.fn(),
9-
mockGetSession: vi.fn(),
10-
mockIsEnterprise: vi.fn(),
11-
mockRedirect: vi.fn(),
12-
})
13-
)
6+
const {
7+
mockCreditUsageLoading,
8+
mockGetPersonalSubscription,
9+
mockGetSession,
10+
mockIsEnterprise,
11+
mockRedirect,
12+
} = vi.hoisted(() => ({
13+
mockCreditUsageLoading: vi.fn(() => null),
14+
mockGetPersonalSubscription: vi.fn(),
15+
mockGetSession: vi.fn(),
16+
mockIsEnterprise: vi.fn(),
17+
mockRedirect: vi.fn(),
18+
}))
1419

1520
vi.mock('next/navigation', () => ({
1621
redirect: mockRedirect,
@@ -34,6 +39,7 @@ vi.mock('@/app/workspace/[workspaceId]/settings/billing/credit-usage/credit-usag
3439

3540
vi.mock('@/app/workspace/[workspaceId]/settings/billing/credit-usage/loading', () => ({
3641
default: () => null,
42+
CreditUsageLoading: mockCreditUsageLoading,
3743
}))
3844

3945
import AccountCreditUsagePage from '@/app/account/settings/billing/credit-usage/page'
@@ -52,4 +58,13 @@ describe('AccountCreditUsagePage', () => {
5258
expect(mockGetPersonalSubscription).toHaveBeenCalledWith('viewer-a')
5359
expect(mockRedirect).not.toHaveBeenCalled()
5460
})
61+
62+
it('uses an account-scoped back link while credit usage is loading', async () => {
63+
const page = await AccountCreditUsagePage()
64+
65+
expect(page.props.fallback).toMatchObject({
66+
type: mockCreditUsageLoading,
67+
props: { backHref: '/account/settings/billing' },
68+
})
69+
})
5570
})

apps/sim/app/account/settings/billing/credit-usage/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { getSession } from '@/lib/auth'
66
import { getHighestPriorityPersonalSubscription } from '@/lib/billing/core/plan'
77
import { isEnterprise } from '@/lib/billing/plan-helpers'
88
import { CreditUsageView } from '@/app/workspace/[workspaceId]/settings/billing/credit-usage/credit-usage-view'
9-
import CreditUsageLoading from '@/app/workspace/[workspaceId]/settings/billing/credit-usage/loading'
9+
import { CreditUsageLoading } from '@/app/workspace/[workspaceId]/settings/billing/credit-usage/loading'
1010

1111
export const metadata: Metadata = {
1212
title: 'Credit usage - Account settings',
@@ -20,7 +20,7 @@ export default async function AccountCreditUsagePage() {
2020
if (isEnterprise(subscription?.plan)) redirect(getAccountSettingsHref('billing'))
2121

2222
return (
23-
<Suspense fallback={<CreditUsageLoading />}>
23+
<Suspense fallback={<CreditUsageLoading backHref={getAccountSettingsHref('billing')} />}>
2424
<CreditUsageView />
2525
</Suspense>
2626
)

apps/sim/app/workspace/[workspaceId]/settings/billing/credit-usage/loading.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,33 @@ import { ArrowLeft } from '@sim/emcn/icons'
44
import { useParams, useRouter } from 'next/navigation'
55
import { SettingsPanel } from '@/app/workspace/[workspaceId]/settings/components/settings-panel'
66

7+
interface CreditUsageLoadingProps {
8+
backHref: string
9+
}
10+
711
/**
8-
* Route-level loading fallback (Next.js convention) and the `Suspense`
9-
* fallback in `page.tsx` — `CreditUsageView` reads `useSearchParams` via
10-
* nuqs, so it must suspend behind a boundary. Rendering the real chrome
11-
* here means a suspend never flashes a blank frame.
12+
* Shared credit-usage loading chrome with an explicit navigation destination.
1213
*/
13-
export default function CreditUsageLoading() {
14+
export function CreditUsageLoading({ backHref }: CreditUsageLoadingProps) {
1415
const router = useRouter()
15-
const { workspaceId } = useParams<{ workspaceId: string }>()
1616

1717
return (
1818
<SettingsPanel
1919
back={{
2020
text: 'Billing',
2121
icon: ArrowLeft,
22-
onSelect: () => router.push(`/workspace/${workspaceId}/settings/billing`),
22+
onSelect: () => router.push(backHref),
2323
}}
2424
title='Credit usage'
2525
description='Every credit-consuming event behind your usage.'
2626
/>
2727
)
2828
}
29+
30+
/**
31+
* Workspace route-level loading fallback used by Next.js and `page.tsx`.
32+
*/
33+
export default function WorkspaceCreditUsageLoading() {
34+
const { workspaceId } = useParams<{ workspaceId: string }>()
35+
return <CreditUsageLoading backHref={`/workspace/${workspaceId}/settings/billing`} />
36+
}

0 commit comments

Comments
 (0)