The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
improved upgrade modal
Steven Teya12ddeefd4f1
diff --git a/apps/web/app/api/cron/usage/utils.ts b/apps/web/app/api/cron/usage/utils.tsindex 6a0121a1cf..d1b5816ae1 100644--- a/apps/web/app/api/cron/usage/utils.ts+++ b/apps/web/app/api/cron/usage/utils.ts@@ -176,6 +176,7 @@ export const updateUsage = async (skip?: number) => {...((plan !== "free" || usage <= usageLimit) && {usage: 0,}),+ // always reset linksUsage since folks can never create more links than their limitlinksUsage: 0,sentEmails: {deleteMany: {diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/page-client.tsxindex 87c47c70dc..7820c79d07 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/page-client.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/page-client.tsx@@ -3,7 +3,6 @@import LinksContainer from "@/ui/links/links-container";import { useAddEditLinkModal } from "@/ui/modals/add-edit-link-modal";import {- Button,IconMenu,MaxWidthWrapper,Popover,@@ -24,7 +23,7 @@ export default function ProjectLinksClient() {<AddEditLinkModal /><div className="flex h-36 items-center border-b border-gray-200 bg-white"><MaxWidthWrapper>- <div className="flex flex-col items-center justify-between sm:flex-row">+ <div className="flex items-center justify-between"><h1 className="text-2xl text-gray-600">Links</h1><div className="flex"><AddEditLinkButton />diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/security/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/security/page-client.tsxindex 242c2916be..1bf6e26c75 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/security/page-client.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/security/page-client.tsx@@ -71,7 +71,7 @@ const SAMLSection = () => {<div className="flex flex-col space-y-3"><h2 className="text-xl font-medium">SAML Single Sign-On</h2><p className="text-sm text-gray-500">- Set up SAML Single Sign-On (SSO) to allow your team to sign in to+ Set up SAML Single Sign-On (SSO) to allow your team to sign in to{" "}{process.env.NEXT_PUBLIC_APP_NAME} with your identity provider.</p></div>diff --git a/apps/web/lib/swr/use-project.ts b/apps/web/lib/swr/use-project.tsindex 649e7fde5b..1a76a62f04 100644--- a/apps/web/lib/swr/use-project.ts+++ b/apps/web/lib/swr/use-project.ts@@ -1,7 +1,6 @@import { ProjectProps } from "@/lib/types";import { fetcher } from "@dub/utils";import { useParams } from "next/navigation";-import { useMemo } from "react";import useSWR from "swr";export default function useProject() {@@ -17,8 +16,9 @@ export default function useProject() {return {...project,isOwner: project?.users && project.users[0].role === "owner",- exceededClicks: project && project.usage > project.usageLimit,- exceededLinks: project && project.linksUsage > project.linksLimit,+ exceededClicks: project && project.usage >= project.usageLimit,+ exceededLinks: project && project.linksUsage >= project.linksLimit,+ // exceededDomains: project?.domains && project.domains.length >=error,loading: slug && !project && !error,};diff --git a/apps/web/ui/modals/delete-project-modal.tsx b/apps/web/ui/modals/delete-project-modal.tsxindex 94c47c0c34..ceadba8884 100644--- a/apps/web/ui/modals/delete-project-modal.tsx+++ b/apps/web/ui/modals/delete-project-modal.tsx@@ -1,7 +1,7 @@import useProject from "@/lib/swr/use-project";import { BlurImage } from "@/ui/shared/blur-image";-import { Button, Modal } from "@dub/ui";-import { cn } from "@dub/utils";+import { Button, Logo, Modal } from "@dub/ui";+import { GOOGLE_FAVICON_URL, cn } from "@dub/utils";import { useParams, useRouter } from "next/navigation";import {Dispatch,@@ -54,13 +54,7 @@ function DeleteProjectModal({setShowModal={setShowDeleteProjectModal}><div className="flex flex-col items-center justify-center space-y-3 border-b border-gray-200 px-4 py-4 pt-8 sm:px-16">- <BlurImage- src={logo || `https://avatar.vercel.sh/${id}`}- alt={id || "Delete Project"}- className="h-10 w-10 rounded-full border border-gray-200"- width={20}- height={20}- />+ <Logo /><h3 className="text-lg font-medium">Delete Project</h3><p className="text-center text-sm text-gray-500">Warning: This will permanently delete your project, custom domain, anddiff --git a/apps/web/ui/modals/upgrade-plan-modal.tsx b/apps/web/ui/modals/upgrade-plan-modal.tsxindex 89da78ad23..3a3f14f375 100644--- a/apps/web/ui/modals/upgrade-plan-modal.tsx+++ b/apps/web/ui/modals/upgrade-plan-modal.tsx@@ -1,13 +1,24 @@import { getStripe } from "@/lib/stripe/client";import { CheckCircleFill } from "@/ui/shared/icons";-import { Badge, Button, Logo, Modal, useRouterStuff } from "@dub/ui";+import {+ Badge,+ Button,+ IconMenu,+ Logo,+ Modal,+ Popover,+ Tick,+ useRouterStuff,+} from "@dub/ui";import {HOME_DOMAIN,- PLANS,+ SELF_SERVE_PAID_PLANS,STAGGER_CHILD_VARIANTS,capitalize,+ cn,} from "@dub/utils";import { motion } from "framer-motion";+import { ChevronDown } from "lucide-react";import Link from "next/link";import {useParams,@@ -25,14 +36,14 @@ import {} from "react";import Confetti from "react-dom-confetti";+const PERIODS = ["monthly", "yearly"];+function UpgradePlanModal({showUpgradePlanModal,setShowUpgradePlanModal,- defaultPlan,}: {showUpgradePlanModal: boolean;setShowUpgradePlanModal: Dispatch<SetStateAction<boolean>>;- defaultPlan: "Pro" | "Business";}) {const router = useRouter();const params = useParams() as { slug: string };@@ -41,10 +52,15 @@ function UpgradePlanModal({const welcomeFlow = pathname === "/welcome";const slug = welcomeFlow ? searchParams?.get("slug") : params.slug;- const [plan, setPlan] = useState<"Pro" | "Business">(defaultPlan);- const [period, setPeriod] = useState<"monthly" | "yearly">("yearly");- const currentPlan = PLANS.find((p) => p.name === plan) ?? PLANS[0];- const features = PLANS.find((p) => p.name === plan)?.features ?? [];+ const plan = searchParams.get("upgrade") ?? "pro";+ const currentPlan =+ SELF_SERVE_PAID_PLANS.find((p) => p.name.toLowerCase() === plan) ??+ SELF_SERVE_PAID_PLANS[0];+ const [openPlanSelector, setOpenPlanSelector] = useState(false);++ const [period, setPeriod] = useState<typeof PERIODS[number]>("yearly");+ const [openPeriodSelector, setOpenPeriodSelector] = useState(false);+const [clicked, setClicked] = useState(false);const { queryParams } = useRouterStuff();@@ -83,86 +99,170 @@ function UpgradePlanModal({className="text-lg font-medium"variants={STAGGER_CHILD_VARIANTS}>- Upgrade to {plan}+ Upgrade to {currentPlan.name}</motion.h3><motion.pclassName="text-center text-sm text-gray-500"variants={STAGGER_CHILD_VARIANTS}>- Enjoy higher limits and extra features with Dub.co {plan}+ Enjoy higher limits and extra features with Dub.co {currentPlan.name}</motion.p></motion.div>- <div className="bg-gray-50 px-4 py-8 text-left sm:px-16">+ <div className="bg-gray-50 px-4 py-6 text-left sm:px-16">+ <div className="flex w-full">+ <Popover+ content={+ <div className="w-full p-2 md:w-56">+ {SELF_SERVE_PAID_PLANS.map(({ name, colors }, i) => (+ <button+ key={i}+ onClick={() => {+ queryParams({+ set: {+ upgrade: name.toLowerCase(),+ },+ });+ setOpenPlanSelector(false);+ }}+ className="flex w-full items-center justify-between space-x-2 rounded-md p-2 hover:bg-gray-100 active:bg-gray-200"+ >+ <IconMenu+ text={name}+ icon={+ <div+ className={cn("h-2 w-2 rounded-full", colors.bg)}+ />+ }+ />+ {plan === name.toLowerCase() && (+ <Tick className="h-4 w-4" aria-hidden="true" />+ )}+ </button>+ ))}+ </div>+ }+ openPopover={openPlanSelector}+ setOpenPopover={setOpenPlanSelector}+ >+ <button+ onClick={() => setOpenPlanSelector(!openPlanSelector)}+ className="mr-2 flex w-56 items-center justify-between space-x-2 rounded-md bg-white px-3 py-2.5 shadow transition-all duration-75 hover:shadow-md active:scale-[98%]"+ >+ <IconMenu+ text={currentPlan.name}+ icon={+ <div+ className={cn(+ "h-2 w-2 rounded-full",+ currentPlan.colors.bg,+ )}+ />+ }+ />+ <ChevronDown+ className={`h-5 w-5 text-gray-400 ${+ openPlanSelector ? "rotate-180 transform" : ""+ } transition-all duration-75`}+ />+ </button>+ </Popover>+ <Confetti+ active={period === "yearly"}+ config={{ elementCount: 200, spread: 90 }}+ />+ <Popover+ content={+ <div className="w-full p-2 md:w-36">+ {PERIODS.map((p, i) => (+ <button+ key={i}+ onClick={() => {+ setPeriod(p);+ setOpenPeriodSelector(false);+ }}+ className="flex w-full items-center justify-between space-x-2 rounded-md p-2 hover:bg-gray-100 active:bg-gray-200"+ >+ <span className="text-sm text-gray-500">+ {capitalize(p)}+ </span>+ {period === p && (+ <Tick className="h-4 w-4" aria-hidden="true" />+ )}+ </button>+ ))}+ </div>+ }+ openPopover={openPeriodSelector}+ setOpenPopover={setOpenPeriodSelector}+ >+ <button+ onClick={() => setOpenPeriodSelector(!openPeriodSelector)}+ className="flex flex-1 items-center justify-between space-x-2 rounded-md bg-white px-3 py-2.5 shadow transition-all duration-75 hover:shadow-md active:scale-[98%]"+ >+ <span className="text-sm text-gray-500">+ {capitalize(period)}+ </span>+ <ChevronDown+ className={`h-5 w-5 text-gray-400 ${+ openPeriodSelector ? "rotate-180 transform" : ""+ } transition-all duration-75`}+ />+ </button>+ </Popover>+ </div><motion.div- className="flex flex-col space-y-3"+ className="mt-6 mb-4 flex flex-col"variants={STAGGER_CHILD_VARIANTS}initial="hidden"animate="show">- <div className="mb-4">- <div className="mb-4 flex items-center justify-between">- <div className="flex items-center space-x-2">- <h4 className="font-medium text-gray-900">- {plan} {capitalize(period)}- </h4>- <Badge- variant="neutral"- className="text-sm font-normal normal-case"- >- $- {(period === "yearly"- ? currentPlan.price[period]! * 12- : currentPlan.price[period]!- ).toString()}- /{period.replace("ly", "")}- </Badge>- </div>- <Confetti- active={period === "yearly"}- config={{ elementCount: 200, spread: 90 }}- />- <button- onClick={() => {- setPeriod(period === "monthly" ? "yearly" : "monthly");- }}- className="text-xs text-gray-500 underline underline-offset-4 transition-colors hover:text-gray-800"+ <div className="flex items-center justify-between">+ <div className="flex items-center space-x-2">+ <h4 className="font-medium text-gray-900">+ {currentPlan.name} {capitalize(period)}+ </h4>+ <Badge+ variant="neutral"+ className="text-sm font-normal normal-case">- {period === "monthly"- ? "🎁 Save 20% with yearly"- : "Switch to monthly"}- </button>+ ${currentPlan.price[period].toString()}+ /mo+ <span className="hidden sm:inline-block">+ , billed {period}+ </span>+ </Badge></div>- <motion.div- variants={{- show: {- transition: {- staggerChildren: 0.08,- },- },- }}- initial="hidden"- animate="show"- className="flex flex-col space-y-2"- >- {features.map(({ text }, 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" />- <span>{text}</span>- </motion.div>- ))}- </motion.div></div>+ <motion.div+ variants={{+ show: {+ transition: {+ staggerChildren: 0.08,+ },+ },+ }}+ initial="hidden"+ animate="show"+ className="my-4 flex flex-col space-y-2"+ >+ {currentPlan.features.map(({ text }, 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" />+ <span>{text}</span>+ </motion.div>+ ))}+ </motion.div><Button- text={`Upgrade to ${plan} ${capitalize(period)}`}+ text={`Upgrade to ${currentPlan.name} ${capitalize(period)}`}loading={clicked}onClick={() => {setClicked(true);fetch(- `/api/projects/${slug}/billing/upgrade?plan=${plan.toLowerCase()}_${period}`,+ `/api/projects/${slug}/billing/upgrade?plan=${plan}_${period}`,{method: "POST",},@@ -179,46 +279,39 @@ function UpgradePlanModal({});}}/>- {welcomeFlow ? (- <Link- href={`/${slug}`}- className="text-center text-xs text-gray-500 underline underline-offset-4 transition-colors hover:text-gray-800"+ <div className="mt-2 flex items-center justify-center space-x-2">+ <a+ href={`${HOME_DOMAIN}/pricing`}+ target="_blank"+ className="text-center text-xs text-gray-500 underline-offset-4 transition-all hover:text-gray-800 hover:underline">- Skip for now- </Link>- ) : (- <div className="flex items-center justify-center space-x-2">- <button- onClick={() => {- setPlan(plan === "Pro" ? "Business" : "Pro");- }}+ Compare plans+ </a>+ <p className="text-gray-500">•</p>+ {welcomeFlow ? (+ <Link+ href={`/${slug}`}className="text-center text-xs text-gray-500 underline-offset-4 transition-all hover:text-gray-800 hover:underline">- {process.env.NEXT_PUBLIC_APP_NAME}{" "}- {plan === "Pro" ? "Business" : "Pro"}- </button>- <p className="text-gray-500">•</p>+ Skip for now+ </Link>+ ) : (<a- href={`${HOME_DOMAIN}/pricing`}+ href={`${HOME_DOMAIN}/enterprise`}target="_blank"- rel="noopener noreferrer"className="text-center text-xs text-gray-500 underline-offset-4 transition-all hover:text-gray-800 hover:underline">- Compare plans+ Looking for enterprise?</a>- </div>- )}+ )}+ </div></motion.div></div></Modal>);}-export function useUpgradePlanModal(- { defaultPlan } = { defaultPlan: "Pro" } as {- defaultPlan: "Pro" | "Business";- },-) {+export function useUpgradePlanModal() {const [showUpgradePlanModal, setShowUpgradePlanModal] = useState(false);const searchParams = useSearchParams();useEffect(() => {@@ -232,13 +325,9 @@ export function useUpgradePlanModal(<UpgradePlanModalshowUpgradePlanModal={showUpgradePlanModal}setShowUpgradePlanModal={setShowUpgradePlanModal}- defaultPlan={- (capitalize(searchParams?.get("upgrade")) as "Pro" | "Business") ||- defaultPlan- }/>);- }, [showUpgradePlanModal, setShowUpgradePlanModal, defaultPlan]);+ }, [showUpgradePlanModal, setShowUpgradePlanModal]);return useMemo(() => ({diff --git a/packages/ui/src/modal.tsx b/packages/ui/src/modal.tsxindex f03eade8ec..ba90bb8036 100644--- a/packages/ui/src/modal.tsx+++ b/packages/ui/src/modal.tsx@@ -71,6 +71,7 @@ export function Modal({</Drawer.Root>);}+return (<Dialog.Rootopen={setShowModal ? showModal : true}@@ -90,7 +91,7 @@ export function Modal({onOpenAutoFocus={(e) => e.preventDefault()}onCloseAutoFocus={(e) => e.preventDefault()}className={cn(- "animate-scale-in fixed inset-0 z-40 m-auto max-h-fit w-full max-w-md overflow-hidden border border-gray-200 bg-white p-0 shadow-xl md:rounded-2xl",+ "animate-scale-in fixed inset-0 z-40 m-auto max-h-fit w-full max-w-md overflow-hidden border border-gray-200 bg-white p-0 shadow-xl sm:rounded-2xl",className,)}>diff --git a/packages/ui/src/popover.tsx b/packages/ui/src/popover.tsxindex 9f40ad7223..35e3025e3c 100644--- a/packages/ui/src/popover.tsx+++ b/packages/ui/src/popover.tsx@@ -25,7 +25,9 @@ export function Popover({if (mobileOnly || isMobile) {return (<Drawer.Root open={openPopover} onOpenChange={setOpenPopover}>- <div className="sm:hidden">{children}</div>+ <Drawer.Trigger className="sm:hidden" asChild>+ {children}+ </Drawer.Trigger><Drawer.Overlay className="fixed inset-0 z-40 bg-gray-100 bg-opacity-10 backdrop-blur" /><Drawer.Portal><Drawer.Content className="fixed bottom-0 left-0 right-0 z-50 mt-24 rounded-t-[10px] border-t border-gray-200 bg-white">diff --git a/packages/utils/src/constants/index.ts b/packages/utils/src/constants/index.tsindex cb2d1d4782..ecbfdcee68 100644--- a/packages/utils/src/constants/index.ts+++ b/packages/utils/src/constants/index.ts@@ -1,6 +1,6 @@export { default as ccTLDs } from "./cctlds";export { default as COUNTRIES } from "./countries";-export { PLANS } from "./pricing";+export * from "./pricing";export const LOCALHOST_GEO_DATA = {city: "San Francisco",diff --git a/packages/utils/src/constants/pricing.tsx b/packages/utils/src/constants/pricing.tsxindex bee7448cf7..528bebed44 100644--- a/packages/utils/src/constants/pricing.tsx+++ b/packages/utils/src/constants/pricing.tsx@@ -175,3 +175,7 @@ export const PLANS = [],},];++export const SELF_SERVE_PAID_PLANS = PLANS.filter(+ (p) => p.name === "Pro" || p.name === "Business",+);