Open source CapCut alternative.
TypeScript
feat(site): open the upgrade dialog from reload credits
David Le83c1f7ae9fdb
diff --git a/site/src/cut/components/AiPanel.tsx b/site/src/cut/components/AiPanel.tsxindex 2aab71f1..6f82c560 100644--- a/site/src/cut/components/AiPanel.tsx+++ b/site/src/cut/components/AiPanel.tsx@@ -100,7 +100,6 @@ import {type AssetRef,} from "@/cut/lib/assetRef";import {- creditsUrl,useGenerate,useSignedIn,} from "@/cut/lib/generate";@@ -148,7 +147,7 @@ import { ComposerQueue, type QueuedMessage } from "./ComposerQueue";import { DictationBody } from "./MicDictation";import { RECORD_RUNNING_TTL_MS, ToolOutputAssets } from "./ChatAssets";import { attachedRefKeys, cardIsAttached } from "@/cut/lib/chatCards";-import { HostedErrorText } from "./hostedError";+import { HostedErrorText, openCreditsWall } from "./hostedError";import { useMicTranscription } from "@/cut/lib/micTranscribe";// Chat attachments are asset refs — anything in the project, the library, or@@ -2176,23 +2175,22 @@ function ChatSession({className="pointer-events-none absolute inset-x-0 bottom-full z-10 -mb-1 flex flex-col">{outOfCredits && (- <a+ <button+ type="button"className={cn(- "ai-credits-tab pointer-events-auto mx-1.5 flex items-center gap-1.5 rounded-t-lg border border-b-0 border-amber-500/30 bg-amber-50 px-3 pt-1.5 pb-2.5 text-[11px] text-amber-800",+ "ai-credits-tab pointer-events-auto mx-1.5 flex cursor-pointer items-center gap-1.5 rounded-t-lg border border-b-0 border-amber-500/30 bg-amber-50 px-3 pt-1.5 pb-2.5 text-[11px] text-amber-800",// With the tray below, the tab tucks under it the same way// the stack tucks under the composer.trayVisible && "-mb-1",)}- href={creditsUrl()}- target="_blank"- rel="noreferrer"+ onClick={openCreditsWall}><TriangleAlert className="size-3 shrink-0" /><span>Insufficient credits —{" "}<span className="font-medium underline">reload credits</span></span>- </a>+ </button>)}{!outOfCredits && notice && (// The credits tab's folder shape, borrowed for transientdiff --git a/site/src/cut/components/hostedError.tsx b/site/src/cut/components/hostedError.tsxindex a2410f78..be86d545 100644--- a/site/src/cut/components/hostedError.tsx+++ b/site/src/cut/components/hostedError.tsx@@ -1,10 +1,20 @@import { NO_CREDITS_MESSAGE } from "@/cut/lib/credits";import { creditsUrl } from "@/cut/lib/generate";import { useOutOfCredits } from "@/cut/lib/hosted";+import { openUpgrade } from "@/cut/lib/upgrade";++/** Opens the upgrade dialog on its credits wall. A surface without the dialog+ * (the ChatGPT card) opens the credits page. */+export function openCreditsWall(): void {+ if (openUpgrade("credits")) {+ return;+ }+ window.open(creditsUrl(), "_blank", "noreferrer");+}/** A hosted-inference error message (chat reply or generation tile). A balance- * failure reads "Insufficient credits, reload here" with the credits link- * inline; any other error (or a missing message) renders as plain text.+ * failure reads "Insufficient credits, reload here" with the link to the+ * credits wall inline; any other error (or a missing message) renders as plain text.* Surfaces inside the chat panel pass `link={false}` and lean on the composer's* credits tab for the link — but that tab only rises for an empty balance, so a* balance merely short of one generation keeps its link here. */@@ -15,14 +25,13 @@ export function HostedErrorText({ error, link = true }: { error?: string; link?:return (<>{error},{" "}- <a- className="font-medium underline hover:no-underline"- href={creditsUrl()}- target="_blank"- rel="noreferrer"+ <button+ type="button"+ className="cursor-pointer font-medium underline hover:no-underline"+ onClick={openCreditsWall}>reload here- </a>+ </button></>);}