Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions apps/desktop/src/app/settings/billing/auto-reload-row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,7 @@ export function AutoReloadRow({
</div>
<div className="mt-3 grid [grid-template-areas:'stack']">
{/* EDIT layer — always in layout (reserves exact height); hidden until editing. */}
<div
aria-hidden={!editing}
className={cn('space-y-2 [grid-area:stack]', !editing && 'invisible')}
>
<div aria-hidden={!editing} className={cn('space-y-2 [grid-area:stack]', !editing && 'invisible')}>
<div className="grid gap-2 @2xl:grid-cols-2">
<label className="min-w-0 text-[length:var(--conversation-caption-font-size)] text-(--ui-text-tertiary)">
Threshold
Expand Down Expand Up @@ -225,7 +222,13 @@ export function AutoReloadRow({
<Button disabled={busy} onClick={() => void disable()} size="sm" type="button" variant="outline">
Turn off
</Button>
<Button disabled={busy} onClick={() => setConfirmDisable(false)} size="sm" type="button" variant="ghost">
<Button
disabled={busy}
onClick={() => setConfirmDisable(false)}
size="sm"
type="button"
variant="ghost"
>
Cancel
</Button>
</div>
Expand Down
48 changes: 38 additions & 10 deletions apps/desktop/src/app/settings/billing/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -304,18 +304,14 @@ describe('BillingSettings', () => {

fireEvent.click(await screen.findByRole('button', { name: 'Downgrade' }))

await waitFor(() =>
expect(apiMocks.previewSubscriptionChange).toHaveBeenCalledWith('cltier000free0000personal')
)
await waitFor(() => expect(apiMocks.previewSubscriptionChange).toHaveBeenCalledWith('cltier000free0000personal'))
expect(await screen.findByText(/No charge now/)).toBeTruthy()
// Credits delta renders as signed dollars, not the raw wire string "-88".
expect(screen.getByText(/Monthly credits change: −\$88\/mo\./)).toBeTruthy()

fireEvent.click(screen.getByRole('button', { name: 'Confirm downgrade' }))

await waitFor(() =>
expect(apiMocks.scheduleSubscriptionChange).toHaveBeenCalledWith('cltier000free0000personal')
)
await waitFor(() => expect(apiMocks.scheduleSubscriptionChange).toHaveBeenCalledWith('cltier000free0000personal'))
await waitFor(() => expect(invalidate).toHaveBeenCalledWith({ queryKey: ['billing', 'subscription'] }))
// Scheduled → back on the overview.
expect(await screen.findByText('Payment')).toBeTruthy()
Expand Down Expand Up @@ -392,10 +388,42 @@ describe('BillingSettings', () => {
context: 'personal',
current: { ...todaySubscriptionState.current, tier_id: 't_ultra', tier_name: 'Ultra' },
tiers: [
{ dollars_per_month_display: '$0', is_current: false, is_enabled: true, monthly_credits: '0.1', name: 'Free', tier_id: 't_free', tier_order: 0 },
{ dollars_per_month_display: '$20', is_current: false, is_enabled: true, monthly_credits: '22', name: 'Plus', tier_id: 't_plus', tier_order: 1 },
{ dollars_per_month_display: '$100', is_current: false, is_enabled: true, monthly_credits: '110', name: 'Super', tier_id: 't_super', tier_order: 2 },
{ dollars_per_month_display: '$200', is_current: true, is_enabled: true, monthly_credits: '220', name: 'Ultra', tier_id: 't_ultra', tier_order: 3 }
{
dollars_per_month_display: '$0',
is_current: false,
is_enabled: true,
monthly_credits: '0.1',
name: 'Free',
tier_id: 't_free',
tier_order: 0
},
{
dollars_per_month_display: '$20',
is_current: false,
is_enabled: true,
monthly_credits: '22',
name: 'Plus',
tier_id: 't_plus',
tier_order: 1
},
{
dollars_per_month_display: '$100',
is_current: false,
is_enabled: true,
monthly_credits: '110',
name: 'Super',
tier_id: 't_super',
tier_order: 2
},
{
dollars_per_month_display: '$200',
is_current: true,
is_enabled: true,
monthly_credits: '220',
name: 'Ultra',
tier_id: 't_ultra',
tier_order: 3
}
]
})
)
Expand Down
13 changes: 11 additions & 2 deletions apps/desktop/src/app/settings/billing/plans-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ function DowngradeConfirm({ flow, tier }: { flow: DowngradeFlow; tier: BillingPl
</Button>
) : canConfirm ? (
<Button disabled={busy} onClick={() => void flow.confirm()} size="sm" type="button">
{phase.kind === 'scheduling' ? 'Scheduling…' : phase.kind === 'scheduleFailed' ? 'Try again' : 'Confirm downgrade'}
{phase.kind === 'scheduling'
? 'Scheduling…'
: phase.kind === 'scheduleFailed'
? 'Try again'
: 'Confirm downgrade'}
</Button>
) : null}
<Button disabled={busy} onClick={flow.cancel} size="sm" type="button" variant="outline">
Expand Down Expand Up @@ -155,7 +159,12 @@ function PlanCard({ flow, tier }: { flow: DowngradeFlow; tier: BillingPlanTierVi
{tier.state === 'scheduled' && <Pill>Scheduled</Pill>}

{tier.state === 'upgrade' && (
<Button onClick={() => tier.action && openExternalLink(tier.action.url)} size="sm" type="button" variant="outline">
<Button
onClick={() => tier.action && openExternalLink(tier.action.url)}
size="sm"
type="button"
variant="outline"
>
{tier.action.label}
<ExternalLink className="size-3.5" />
</Button>
Expand Down
6 changes: 1 addition & 5 deletions apps/desktop/src/app/settings/billing/simulated-api.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import type { BillingApi, BillingResult } from './api'
import type {
BillingStateResponse,
SubscriptionPreviewResponse,
SubscriptionStateResponse
} from './types'
import type { BillingStateResponse, SubscriptionPreviewResponse, SubscriptionStateResponse } from './types'

/** The shape of one `billingDevFixtures` entry — a canned billing + subscription pair. */
export interface SimulatedFixture {
Expand Down
7 changes: 1 addition & 6 deletions apps/desktop/src/app/settings/billing/use-billing-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@ import { fmtDate } from '@/lib/time'
import type { BillingRefusal, BillingResult } from './api'
import { useBillingApi } from './api'
import { resolveRefusal } from './errors'
import type {
BillingStateResponse,
SubscriptionStateResponse,
SubscriptionTierOption,
UsageModelData
} from './types'
import type { BillingStateResponse, SubscriptionStateResponse, SubscriptionTierOption, UsageModelData } from './types'

export const EMPTY_BILLING_VALUE = '—'
export const FALLBACK_PORTAL_BILLING_URL = 'https://portal.nousresearch.com/billing'
Expand Down
Loading