videogen/apps/web/components/marketing/DiscountBanner.tsx
caelum0x d56639a594
Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Menivor — open source release (MIT), free to use and fork
Paid, hosted product at menivor.com, now retired as a company project.
Fresh squashed history of the cleaned working tree (secret-scanned,
no .env, no customer data, no outreach logs). Built on
MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
2026-12-04 02:10:26 +03:00

88 lines
3.0 KiB
TypeScript

"use client";
import * as React from "react";
import { Check, Copy, Tag } from "lucide-react";
import { getActiveDiscount } from "@/lib/api";
import type { ActiveDiscount } from "@/lib/types";
/**
* The public `/pricing` promo banner — renders only when the backend has a
* code flagged `is_public_banner` that is still live (active, within its date
* window, under its redemption cap). Resolves to nothing rendered on any
* fetch failure or "no active promo", so a missing/misconfigured promo never
* breaks the pricing page.
*
* Deliberately NOT an input: this is a read-only announcement with a
* copy-to-clipboard affordance. The code is actually applied in
* {@link CheckoutPlans}'s own discount-code field.
*/
export function DiscountBanner() {
const [promo, setPromo] = React.useState<ActiveDiscount | null>(null);
const [copied, setCopied] = React.useState(false);
React.useEffect(() => {
let active = true;
void getActiveDiscount()
.then((result) => {
if (active && result.active) setPromo(result);
})
.catch(() => {
// No banner is a perfectly fine outcome; never surface this error.
});
return () => {
active = false;
};
}, []);
if (!promo?.code) return null;
const amountLabel =
promo.kind === "flat" && promo.amount_off_cents
? `$${(promo.amount_off_cents / 100).toFixed(2)} off`
: promo.percent_off
? `${promo.percent_off}% off`
: "A discount";
const handleCopy = () => {
if (!promo.code) return;
void navigator.clipboard
.writeText(promo.code)
.then(() => {
setCopied(true);
window.setTimeout(() => setCopied(false), 2000);
})
.catch(() => {
// Clipboard permission denied — the code is still visible to copy by hand.
});
};
return (
<div
role="status"
className="mx-auto mb-10 flex w-full max-w-5xl flex-col items-center gap-3 rounded-2xl border border-primary/30 bg-primary/5 px-5 py-4 text-center sm:flex-row sm:justify-between sm:text-left"
>
<div className="flex items-center gap-3">
<Tag className="size-5 shrink-0 text-primary" aria-hidden />
<p className="text-sm">
<span className="font-semibold">{amountLabel}</span>{" "}
<span className="text-muted-foreground">
{promo.banner_text || "your first credit pack"}
</span>
</p>
</div>
<button
type="button"
onClick={handleCopy}
className="inline-flex items-center gap-2 rounded-lg border border-border bg-background px-3 py-1.5 text-sm font-medium transition-colors hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
>
<code className="font-mono tracking-wide">{promo.code}</code>
{copied ? (
<Check className="size-3.5 text-primary" aria-hidden />
) : (
<Copy className="size-3.5 text-muted-foreground" aria-hidden />
)}
</button>
</div>
);
}