The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add plans page
Tim Wilsoncfb37bd537a7
diff --git a/apps/web/app/app.dub.co/(onboarding)/onboarding/(steps)/layout.tsx b/apps/web/app/app.dub.co/(onboarding)/onboarding/(steps)/layout.tsxindex 5e940130aa..69680ab8c9 100644--- a/apps/web/app/app.dub.co/(onboarding)/onboarding/(steps)/layout.tsx+++ b/apps/web/app/app.dub.co/(onboarding)/onboarding/(steps)/layout.tsx@@ -6,7 +6,7 @@ export default function Layout({ children }: PropsWithChildren) {<><div className="relative flex flex-col items-center"><Wordmark className="mt-6 h-8" />- <div className="mt-8 flex w-full flex-col items-center px-3 md:mt-20 lg:px-8">+ <div className="mt-8 flex w-full flex-col items-center px-3 pb-16 md:mt-20 lg:px-8">{children}</div></div>diff --git a/apps/web/app/app.dub.co/(onboarding)/onboarding/(steps)/plan/page.tsx b/apps/web/app/app.dub.co/(onboarding)/onboarding/(steps)/plan/page.tsxnew file mode 100644index 0000000000..1a5af4b018--- /dev/null+++ b/apps/web/app/app.dub.co/(onboarding)/onboarding/(steps)/plan/page.tsx@@ -0,0 +1,16 @@+import { CircleCheck } from "@dub/ui/src/icons";+import { StepPage } from "../step-page";+import { PlanSelector } from "./plan-selector";++export default function Plan() {+ return (+ <StepPage+ icon={CircleCheck}+ title="Choose your plan"+ description="Find a plan that fits your needs"+ className="max-w-2xl"+ >+ <PlanSelector />+ </StepPage>+ );+}diff --git a/apps/web/app/app.dub.co/(onboarding)/onboarding/(steps)/plan/plan-selector.tsx b/apps/web/app/app.dub.co/(onboarding)/onboarding/(steps)/plan/plan-selector.tsxnew file mode 100644index 0000000000..f985f05e11--- /dev/null+++ b/apps/web/app/app.dub.co/(onboarding)/onboarding/(steps)/plan/plan-selector.tsx@@ -0,0 +1,115 @@+"use client";++import useWorkspace from "@/lib/swr/use-workspace";+import { PlanFeatures } from "@/ui/workspaces/plan-features";+import { UpgradePlanButton } from "@/ui/workspaces/upgrade-plan-button";+import { Badge } from "@dub/ui";+import { ToggleGroup } from "@dub/ui/src/toggle-group";+import { PRO_PLAN, SELF_SERVE_PAID_PLANS } from "@dub/utils";+import { useState } from "react";+import { useOnboardingProgress } from "../../use-onboarding-progress";++export function PlanSelector() {+ const { finish } = useOnboardingProgress();++ const [periodTab, setPeriodTab] = useState<"monthly" | "yearly">("monthly");++ return (+ <div>+ <div className="flex justify-center">+ <ToggleGroup+ options={[+ { value: "monthly", label: "Pay monthly" },+ { value: "yearly", label: "Pay yearly" },+ ]}+ selected={periodTab}+ selectAction={(period) =>+ setPeriodTab(period as "monthly" | "yearly")+ }+ />+ </div>+ <div className="mt-8 grid gap-4 sm:grid-cols-2">+ <PlanCard name="Pro" plans={[PRO_PLAN]} period={periodTab} />+ <PlanCard+ name="Business"+ plans={SELF_SERVE_PAID_PLANS.filter(({ name }) =>+ name.startsWith("Business"),+ )}+ period={periodTab}+ />+ </div>+ <div className="mt-8 flex flex-col gap-3">+ <a+ href="https://dub.co/enterprise"+ target="_blank"+ className="w-full text-center text-sm text-gray-500 transition-colors hover:text-gray-700"+ >+ Looking for enterprise?+ </a>+ <button+ type="button"+ onClick={() => finish()}+ className="w-full text-center text-sm text-gray-500 transition-colors hover:text-gray-700"+ >+ I'll pick a plan later+ </button>+ </div>+ </div>+ );+}++function PlanCard({+ name,+ plans,+ period,+}: {+ name: string;+ plans: (typeof SELF_SERVE_PAID_PLANS)[number][];+ period: "monthly" | "yearly";+}) {+ const { slug } = useWorkspace();++ const [selectedPlanIndex, setSelectedPlanIndex] = useState(0);+ const selectedPlan = plans[selectedPlanIndex];++ return (+ <div className="flex flex-col rounded-lg border border-gray-200 bg-white p-6">+ <div className="flex items-center gap-2">+ <h2 className="text-lg font-medium text-gray-900">{name}</h2>+ {name === "Pro" && <Badge variant="blue">Most popular</Badge>}+ </div>+ <p className="mt-2 text-3xl font-medium text-gray-900">+ ${selectedPlan.price[period]}{" "}+ <span className="text-sm font-medium">+ per month+ {period === "yearly" && ", billed yearly"}+ </span>+ </p>+ {plans.length > 1 && (+ <div className="mt-4">+ <ToggleGroup+ className="grid grid-cols-4"+ style={{ gridTemplateColumns: "1fr ".repeat(plans.length) }}+ options={plans.map((plan) => ({+ value: plan.name,+ label: plan.name.replace(name, "").trim() || "Basic",+ }))}+ selected={selectedPlan.name}+ selectAction={(name) =>+ setSelectedPlanIndex(plans.findIndex((p) => p.name === name))+ }+ />+ </div>+ )}+ <PlanFeatures className="mt-4" plan={selectedPlan.name} />+ <div className="mt-10 flex grow flex-col justify-end">+ <UpgradePlanButton+ text={`Get started with ${selectedPlan.name}`}+ plan={selectedPlan.name}+ period={period}+ workspaceSlug={slug}+ />+ </div>+ </div>+ );+}diff --git a/apps/web/app/app.dub.co/(onboarding)/onboarding/use-onboarding-progress.ts b/apps/web/app/app.dub.co/(onboarding)/onboarding/use-onboarding-progress.tsindex 97facc550a..b2c9dadb26 100644--- a/apps/web/app/app.dub.co/(onboarding)/onboarding/use-onboarding-progress.ts+++ b/apps/web/app/app.dub.co/(onboarding)/onboarding/use-onboarding-progress.ts@@ -15,5 +15,6 @@ export function useOnboardingProgress() {: `?slug=${slugParam || slug}`;router.push(`/onboarding/${step}${queryParams}`);},+ finish: () => router.push(`/${slug}`),};}diff --git a/apps/web/ui/modals/upgrade-plan-modal.tsx b/apps/web/ui/modals/upgrade-plan-modal.tsxindex 1aae639a81..c3f6e184db 100644--- a/apps/web/ui/modals/upgrade-plan-modal.tsx+++ b/apps/web/ui/modals/upgrade-plan-modal.tsx@@ -1,9 +1,6 @@-import { getStripe } from "@/lib/stripe/client";import useWorkspace from "@/lib/swr/use-workspace";-import { CheckCircleFill } from "@/ui/shared/icons";import {Badge,- Button,IconMenu,LoadingSpinner,Logo,@@ -12,7 +9,6 @@ import {Tick,useRouterStuff,} from "@dub/ui";-import { SimpleTooltipContent, Tooltip } from "@dub/ui/src/tooltip";import {APP_DOMAIN,SELF_SERVE_PAID_PLANS,@@ -20,7 +16,6 @@ import {capitalize,cn,} from "@dub/utils";-import { trackEvent } from "fathom-client";import { motion } from "framer-motion";import { ChevronDown } from "lucide-react";import { usePlausible } from "next-plausible";@@ -31,7 +26,6 @@ import {useRouter,useSearchParams,} from "next/navigation";-import posthog from "posthog-js";import {Dispatch,SetStateAction,@@ -41,8 +35,10 @@ import {useState,} from "react";import Confetti from "react-dom-confetti";+import { PlanFeatures } from "../workspaces/plan-features";+import { UpgradePlanButton } from "../workspaces/upgrade-plan-button";-const PERIODS = ["monthly", "yearly"];+const PERIODS = ["monthly", "yearly"] as const;function UpgradePlanModal({showUpgradePlanModal,@@ -68,7 +64,6 @@ function UpgradePlanModal({const [period, setPeriod] = useState<(typeof PERIODS)[number]>("yearly");const [openPeriodSelector, setOpenPeriodSelector] = useState(false);- const [clicked, setClicked] = useState(false);const [clickedCompare, setClickedCompare] = useState(false);const { queryParams } = useRouterStuff();@@ -244,7 +239,7 @@ function UpgradePlanModal({variant="neutral"className="text-sm font-normal normal-case">- ${selectedPlan.price[period].toString()}+ ${selectedPlan.price[period]!.toString()}/mo<span className="hidden sm:inline-block">, billed {period}@@ -252,93 +247,11 @@ function UpgradePlanModal({</Badge></div></div>- <motion.div- variants={{- show: {- transition: {- staggerChildren: 0.08,- },- },- }}- initial="hidden"- animate="show"- className="my-4 flex flex-col space-y-2"- >- {selectedPlan.name.startsWith("Business") && (- <motion.div- key="business-plan-feature"- variants={STAGGER_CHILD_VARIANTS}- className="text-sm text-gray-500"- >- Everything in Pro, plus:- </motion.div>- )}- {selectedPlan.features.map(({ text, footnote }, i) => (- <motion.div- key={i}- variants={STAGGER_CHILD_VARIANTS}- className="flex items-center space-x-2 text-sm text-gray-500"- >- <CheckCircleFill className="h-5 w-5 text-green-500" />-- {footnote ? (- <Tooltip- content={- typeof footnote === "string" ? (- footnote- ) : (- <SimpleTooltipContent {...footnote} />- )- }- >- <p className="cursor-help text-gray-600 underline decoration-dotted underline-offset-2">- {text}- </p>- </Tooltip>- ) : (- <p className="text-gray-600">{text}</p>- )}- </motion.div>- ))}- </motion.div>- <Button- text={`Upgrade to ${selectedPlan.name} ${capitalize(period)}`}- loading={clicked}- onClick={() => {- setClicked(true);- fetch(`/api/workspaces/${slug}/billing/upgrade`, {- method: "POST",- headers: {- "Content-Type": "application/json",- },- body: JSON.stringify({- plan,- period,- baseUrl: `${APP_DOMAIN}${pathname}`,- }),- })- .then(async (res) => {- trackEvent("Opened Checkout");- plausible("Opened Checkout");- posthog.capture("checkout_opened", {- currentPlan: capitalize(currentPlan),- newPlan: selectedPlan.name,- });- if (currentPlan === "free") {- const data = await res.json();- const { id: sessionId } = data;- const stripe = await getStripe();- stripe?.redirectToCheckout({ sessionId });- } else {- const url = await res.json();- router.push(url);- }- })- .catch((err) => {- alert(err);- setClicked(false);- });- }}+ <PlanFeatures plan={selectedPlan.name} className="my-4" />+ <UpgradePlanButton+ plan={selectedPlan.name}+ period={period}+ workspaceSlug={slug ?? undefined}/><div className="mt-2 flex items-center justify-center space-x-2">{currentPlan === "free" ? (@@ -371,7 +284,7 @@ function UpgradePlanModal({}).catch((err) => {alert(err);- setClicked(false);+ setClickedCompare(false);});}}disabled={clickedCompare}diff --git a/apps/web/ui/workspaces/plan-features.tsx b/apps/web/ui/workspaces/plan-features.tsxnew file mode 100644index 0000000000..30f4412044--- /dev/null+++ b/apps/web/ui/workspaces/plan-features.tsx@@ -0,0 +1,69 @@+import { SimpleTooltipContent, Tooltip } from "@dub/ui";+import { cn, SELF_SERVE_PAID_PLANS, STAGGER_CHILD_VARIANTS } from "@dub/utils";+import { motion } from "framer-motion";+import { CheckCircleFill } from "../shared/icons";++export function PlanFeatures({+ plan,+ className,+}: {+ plan: string;+ className?: string;+}) {+ const selectedPlan =+ SELF_SERVE_PAID_PLANS.find(+ (p) => p.name.toLowerCase() === plan.toLowerCase(),+ ) ?? SELF_SERVE_PAID_PLANS[0];++ return (+ <motion.div+ variants={{+ show: {+ transition: {+ staggerChildren: 0.08,+ },+ },+ }}+ initial="hidden"+ animate="show"+ className={cn("flex flex-col gap-2", className)}+ >+ {selectedPlan.name.startsWith("Business") && (+ <motion.div+ key="business-plan-feature"+ variants={STAGGER_CHILD_VARIANTS}+ className="text-sm text-gray-500"+ >+ Everything in Pro, plus:+ </motion.div>+ )}+ {selectedPlan.features.map(({ text, footnote }, i) => (+ <motion.div+ key={i}+ variants={STAGGER_CHILD_VARIANTS}+ className="flex items-center space-x-2 text-sm text-gray-500"+ >+ <CheckCircleFill className="h-5 w-5 text-green-500" />++ {footnote ? (+ <Tooltip+ content={+ typeof footnote === "string" ? (+ footnote+ ) : (+ <SimpleTooltipContent {...footnote} />+ )+ }+ >+ <p className="cursor-help text-gray-600 underline decoration-dotted underline-offset-2">+ {text}+ </p>+ </Tooltip>+ ) : (+ <p className="text-gray-600">{text}</p>+ )}+ </motion.div>+ ))}+ </motion.div>+ );+}diff --git a/apps/web/ui/workspaces/upgrade-plan-button.tsx b/apps/web/ui/workspaces/upgrade-plan-button.tsxnew file mode 100644index 0000000000..f3acdf27f4--- /dev/null+++ b/apps/web/ui/workspaces/upgrade-plan-button.tsx@@ -0,0 +1,76 @@+"use client";++import { getStripe } from "@/lib/stripe/client";+import { Button } from "@dub/ui";+import { APP_DOMAIN, capitalize, SELF_SERVE_PAID_PLANS } from "@dub/utils";+import { trackEvent } from "fathom-client";+import { usePlausible } from "next-plausible";+import { usePathname, useRouter } from "next/navigation";+import posthog from "posthog-js";+import { useState } from "react";++export function UpgradePlanButton({+ plan,+ period,+ workspaceSlug,+ text,+}: {+ plan: string;+ period: "monthly" | "yearly";+ workspaceSlug?: string;+ text?: string;+}) {+ const router = useRouter();+ const pathname = usePathname();+ const plausible = usePlausible();++ const selectedPlan =+ SELF_SERVE_PAID_PLANS.find(+ (p) => p.name.toLowerCase() === plan.toLowerCase(),+ ) ?? SELF_SERVE_PAID_PLANS[0];++ const [clicked, setClicked] = useState(false);++ return (+ <Button+ text={text || `Upgrade to ${selectedPlan.name} ${capitalize(period)}`}+ loading={clicked}+ disabled={!workspaceSlug}+ onClick={() => {+ setClicked(true);+ fetch(`/api/workspaces/${workspaceSlug}/billing/upgrade`, {+ method: "POST",+ headers: {+ "Content-Type": "application/json",+ },+ body: JSON.stringify({+ plan,+ period,+ baseUrl: `${APP_DOMAIN}${pathname}`,+ }),+ })+ .then(async (res) => {+ trackEvent("Opened Checkout");+ plausible("Opened Checkout");+ posthog.capture("checkout_opened", {+ currentPlan: capitalize(plan),+ newPlan: selectedPlan.name,+ });+ if (plan === "free") {+ const data = await res.json();+ const { id: sessionId } = data;+ const stripe = await getStripe();+ stripe?.redirectToCheckout({ sessionId });+ } else {+ const url = await res.json();+ router.push(url);+ }+ })+ .catch((err) => {+ alert(err);+ setClicked(false);+ });+ }}+ />+ );+}diff --git a/packages/ui/src/toggle-group.tsx b/packages/ui/src/toggle-group.tsxindex b775b981fc..879edff93f 100644--- a/packages/ui/src/toggle-group.tsx+++ b/packages/ui/src/toggle-group.tsx@@ -13,10 +13,14 @@ export function ToggleGroup({options,selected,selectAction,+ className,+ style,}: {options: ToggleOption[];selected: string | null;selectAction: (option: string) => void;+ className?: string;+ style?: React.CSSProperties;}) {const layoutGroupId = useId();@@ -24,7 +28,11 @@ export function ToggleGroup({<LayoutGroup id={layoutGroupId}><motion.divlayout- className="relative inline-flex items-center gap-1 rounded-xl border border-gray-200 bg-white p-1"+ className={cn(+ "relative inline-flex items-center gap-1 rounded-xl border border-gray-200 bg-white p-1",+ className,+ )}+ style={style}>{options.map((option) => (<button