From 77814e6bb38e73f3f997aacdadf9c76cf60e7442 Mon Sep 17 00:00:00 2001 From: Josh Knapp Date: Wed, 2 Dec 2026 17:52:16 -0800 Subject: [PATCH] sitesmith: take the upgrade link from the panel (summary.upgrade_url) The panel now sends upgrade_url in the entitlement summary, derived from its billing_url setting. The banner uses it for the upgrade link and renders no link when it is empty or absent. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0185ukXiDeTw5Hbvm5fCmEsH --- .../panels/sitesmith/UpgradeBanner.test.tsx | 32 +++++++++++++++++++ craft/src/panels/sitesmith/UpgradeBanner.tsx | 10 +++--- craft/src/types/sitesmith.ts | 2 ++ 3 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 craft/src/panels/sitesmith/UpgradeBanner.test.tsx diff --git a/craft/src/panels/sitesmith/UpgradeBanner.test.tsx b/craft/src/panels/sitesmith/UpgradeBanner.test.tsx new file mode 100644 index 0000000..eb948e5 --- /dev/null +++ b/craft/src/panels/sitesmith/UpgradeBanner.test.tsx @@ -0,0 +1,32 @@ +import { describe, test, expect, beforeEach, afterEach } from 'vitest'; +import React from 'react'; +import { createRoot, Root } from 'react-dom/client'; +import { act } from 'react-dom/test-utils'; +import { UpgradeBanner } from './UpgradeBanner'; +import { SitesmithSummary } from '../../types/sitesmith'; + +let root: Root; let box: HTMLDivElement; +beforeEach(() => { box = document.createElement('div'); document.body.appendChild(box); root = createRoot(box); }); +afterEach(() => { act(() => root.unmount()); box.remove(); }); +const render = (el: React.ReactElement) => act(async () => { root.render(el); }); + +const summary = (extra: Partial = {}): SitesmithSummary => ({ + enabled: false, monthly_cap: 0, monthly_used: 0, bonus_credits: 0, resets_on: '', status: 'DISABLED', ...extra, +}); + +describe('UpgradeBanner upgrade link', () => { + test('renders the link with the url from the panel', async () => { + await render(); + const a = box.querySelector('a') as HTMLAnchorElement; + expect(a).not.toBeNull(); + expect(a.getAttribute('href')).toBe('https://billing.example/upgrade'); + expect(a.textContent).toContain('Upgrade your plan'); + }); + test('renders no link when upgrade_url is empty or absent', async () => { + await render(); + expect(box.querySelector('a')).toBeNull(); + expect(box.textContent).toContain('Sitesmith is a paid addon'); + await render(); + expect(box.querySelector('a')).toBeNull(); + }); +}); diff --git a/craft/src/panels/sitesmith/UpgradeBanner.tsx b/craft/src/panels/sitesmith/UpgradeBanner.tsx index feac803..d78ff2d 100644 --- a/craft/src/panels/sitesmith/UpgradeBanner.tsx +++ b/craft/src/panels/sitesmith/UpgradeBanner.tsx @@ -19,10 +19,12 @@ export const UpgradeBanner: React.FC = ({ summary }) => {
Describe the site you want and our AI builds it. You can edit everything afterward.
- - Upgrade your plan → - + {summary.upgrade_url && ( + + Upgrade your plan → + + )} )} {isCapped && (<>
Monthly cap reached
diff --git a/craft/src/types/sitesmith.ts b/craft/src/types/sitesmith.ts index 3d518c3..ae36cc1 100644 --- a/craft/src/types/sitesmith.ts +++ b/craft/src/types/sitesmith.ts @@ -47,6 +47,8 @@ export interface SitesmithSummary { bonus_credits: number; resets_on: string; status: SitesmithStatus; + /** Billing upgrade link from the panel's billing_url setting; empty = no link. */ + upgrade_url?: string; } export interface SitesmithMessage {