Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat(cloud): add self-serve pricing/checkout page (#857)

Marc Klingen5bf348b55e59
diff --git a/src/components/layouts/header.tsx b/src/components/layouts/header.tsx
index 8e554b4939..0fe06a8a55 100644
--- a/src/components/layouts/header.tsx
+++ b/src/components/layouts/header.tsx
@@ -4,13 +4,18 @@ import { useRouter } from "next/router";
import { useSession } from "next-auth/react";
import DocPopup from "@/src/components/layouts/doc-popup";
import { type Status, StatusBadge } from "./status-badge";
+import { cn } from "@/src/utils/tailwind";
-export default function Header(props: {
+export default function Header({
+ level = "h2",
+ ...props
+}: {
title: string;
breadcrumb?: { name: string; href?: string }[];
status?: Status;
help?: { description: string; href: string };
actionButtons?: React.ReactNode;
+ level?: "h2" | "h3";
}) {
const router = useRouter();
const session = useSession();
@@ -35,7 +40,7 @@ export default function Header(props: {
[...props.breadcrumb.map((i) => i.href).filter(Boolean)].pop();
return (
- <div className="mb-8">
+ <div className={cn(level === "h2" ? "mb-8" : "mb-1")}>
<div>
{backHref ? (
<nav className="sm:hidden" aria-label="Back">
@@ -51,7 +56,7 @@ export default function Header(props: {
</Link>
</nav>
) : null}
- {breadcrumb.length ? (
+ {(level === "h2" || props.breadcrumb) && breadcrumb.length ? (
<nav className="hidden sm:flex" aria-label="Breadcrumb">
<ol role="list" className="flex items-center space-x-4">
{breadcrumb.map(({ name, href }, index) => (
@@ -85,9 +90,15 @@ export default function Header(props: {
<div className="mt-2 flex flex-wrap items-center justify-between gap-2">
<div className="flex items-center gap-3 md:gap-5">
<div className="flex min-w-0 flex-row">
- <h2 className="text-2xl font-bold leading-7 text-gray-900 sm:truncate sm:text-3xl sm:tracking-tight">
- {props.title}
- </h2>
+ {level === "h2" ? (
+ <h2 className="text-2xl font-bold leading-7 text-gray-900 sm:truncate sm:text-3xl sm:tracking-tight">
+ {props.title}
+ </h2>
+ ) : (
+ <h3 className="text-lg font-bold leading-7 text-gray-900 sm:truncate sm:text-xl sm:tracking-tight">
+ {props.title}
+ </h3>
+ )}
{props.help ? (
<DocPopup
description={props.help.description}
diff --git a/src/features/pricing-page/PricingPage.tsx b/src/features/pricing-page/PricingPage.tsx
new file mode 100644
index 0000000000..5b4aa018b9
--- /dev/null
+++ b/src/features/pricing-page/PricingPage.tsx
@@ -0,0 +1,18 @@
+import { useSession } from "next-auth/react";
+import Script from "next/script";
+
+export function PricingPage(props: { className?: string }) {
+ const session = useSession();
+ return (
+ <>
+ <Script async src="https://js.stripe.com/v3/pricing-table.js" />
+ <div className={props.className}>
+ <stripe-pricing-table
+ client-reference-id={session.data?.user?.id}
+ pricing-table-id="prctbl_1OWhugAWilt2EAVVKHi8TEw7"
+ publishable-key="pk_live_51MPW00AWilt2EAVVFWfPTQhgmLA0EeacLSzAs6e3vECCcMBvwcMse81XgXO6k1bdBHbPBdpOmrXE8P1gBrxE7yhH00RPHQ8SyG"
+ ></stripe-pricing-table>
+ </div>
+ </>
+ );
+}
diff --git a/src/features/usage-metering/ProjectUsageChart.tsx b/src/features/usage-metering/ProjectUsageChart.tsx
index 3519f8007e..2616738890 100644
--- a/src/features/usage-metering/ProjectUsageChart.tsx
+++ b/src/features/usage-metering/ProjectUsageChart.tsx
@@ -4,12 +4,16 @@ import { Button } from "@/src/components/ui/button";
import { env } from "@/src/env.mjs";
import { api } from "@/src/utils/api";
import { Card, Flex, MarkerBar, Metric, Text } from "@tremor/react";
-import {
- chatAvailable,
- sendUserChatMessage,
- showAgentChatMessage,
-} from "@/src/features/support-chat/chat";
import Link from "next/link";
+import { PricingPage } from "@/src/features/pricing-page/PricingPage";
+import {
+ Dialog,
+ DialogContent,
+ DialogHeader,
+ DialogTrigger,
+} from "@/src/components/ui/dialog";
+import Header from "@/src/components/layouts/header";
+import { usePostHog } from "posthog-js/react";
export const ProjectUsageChart: React.FC<{ projectId: string }> = ({
projectId,
@@ -17,6 +21,7 @@ export const ProjectUsageChart: React.FC<{ projectId: string }> = ({
const usage = api.usageMetering.currentMonth.useQuery({
projectId,
});
+ const posthog = usePostHog();
const project = api.projects.byId.useQuery({ projectId });
const planLimit =
project.data?.cloudConfig?.monthlyObservationLimit ?? 100_000;
@@ -56,28 +61,38 @@ export const ProjectUsageChart: React.FC<{ projectId: string }> = ({
) : null}
</Card>
<div className="mt-4 flex flex-row items-center gap-2">
- {chatAvailable && (
- <Button
- variant="secondary"
- className=""
- onClick={() => {
- sendUserChatMessage(
- "I want to change my plan, project: " + projectId,
- );
- // wait for 2 seconds
- setTimeout(() => {
- showAgentChatMessage(
- "We're happy to help. Which plan would you like to change to? See https://langfuse.com/#pricing for details on available plans.",
- );
- }, 2000);
- }}
- >
- Request plan change
- </Button>
- )}
- <Button variant="secondary" asChild>
- <Link href="https://langfuse.com/pricing">View plans</Link>
- </Button>
+ <Dialog
+ onOpenChange={(open) => {
+ if (open) {
+ posthog.capture("project_settings:pricing_dialog_opened");
+ }
+ }}
+ >
+ <DialogTrigger asChild>
+ <Button variant="secondary">Change plans</Button>
+ </DialogTrigger>
+ <DialogContent className="max-w-3xl">
+ <DialogHeader>
+ <Header
+ title="Select plan"
+ level="h3"
+ actionButtons={
+ <Button variant="secondary" asChild>
+ <Link href="https://langfuse.com/pricing">
+ Pricing page ↗
+ </Link>
+ </Button>
+ }
+ />
+ </DialogHeader>
+ <p>
+ All plans offer a 7-day free trial. For more information about the
+ plans, please visit our pricing page or reach out to us via the
+ chat.
+ </p>
+ <PricingPage className="mb-5 mt-10 " />
+ </DialogContent>
+ </Dialog>
<div className="inline-block text-sm text-gray-500">
Currently: {plan}
</div>
diff --git a/tsconfig.json b/tsconfig.json
index a6cd8258df..bb5bf38727 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -29,7 +29,8 @@
"**/*.tsx",
"**/*.cjs",
"**/*.mjs",
- "src/features/navigate-detail-pages"
+ "src/features/navigate-detail-pages",
+ "types/global.d.ts"
],
"exclude": ["node_modules", "sdk"]
}
diff --git a/types/global.d.ts b/types/global.d.ts
new file mode 100644
index 0000000000..e7d93ea474
--- /dev/null
+++ b/types/global.d.ts
@@ -0,0 +1,8 @@
+declare namespace JSX {
+ interface IntrinsicElements {
+ "stripe-pricing-table": React.DetailedHTMLProps<
+ React.HTMLAttributes<HTMLElement>,
+ HTMLElement
+ >;
+ }
+}