The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
improved getNextPlan
Steven Tey3512b7a67f9d
diff --git a/apps/web/app/api/callback/stripe/route.ts b/apps/web/app/api/callback/stripe/route.tsindex 7bf82a13c4..cd13ec4d95 100644--- a/apps/web/app/api/callback/stripe/route.ts+++ b/apps/web/app/api/callback/stripe/route.ts@@ -3,7 +3,6 @@ import prisma from "@/lib/prisma";import { stripe } from "@/lib/stripe";import { redis } from "@/lib/upstash";import { FREE_PLAN, getPlanFromPriceId, log } from "@dub/utils";-import slugify from "@sindresorhus/slugify";import { sendEmail } from "emails";import UpgradeEmail from "emails/upgrade-email";import { NextResponse } from "next/server";@@ -79,7 +78,7 @@ export const POST = async (req: Request) => {domainsLimit: plan.limits.domains!,tagsLimit: plan.limits.tags!,usersLimit: plan.limits.users!,- plan: slugify(plan.name),+ plan: plan.name.toLowerCase(),},select: {users: {@@ -109,7 +108,7 @@ export const POST = async (req: Request) => {react: UpgradeEmail({name: user.name,email: user.email as string,- plan: slugify(plan.name),+ plan: plan.name.toLowerCase(),}),marketing: true,}),@@ -163,7 +162,7 @@ export const POST = async (req: Request) => {domainsLimit: plan.limits.domains!,tagsLimit: plan.limits.tags!,usersLimit: plan.limits.users!,- plan: slugify(plan.name),+ plan: plan.name.toLowerCase(),},select: {users: {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 cf582fee34..9e90e46e0f 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@@ -11,6 +11,7 @@ import {TooltipContent,useRouterStuff,} from "@dub/ui";+import { getNextPlan } from "@dub/utils";import { ChevronDown, FilePlus2, Sheet } from "lucide-react";import { useRouter } from "next/navigation";import { useState } from "react";@@ -39,7 +40,7 @@ export default function ProjectLinksClient() {const AddLinkOptions = () => {const router = useRouter();- const { slug, plan, exceededLinks } = useProject();+ const { slug, nextPlan, exceededLinks } = useProject();const [openPopover, setOpenPopover] = useState(false);const { queryParams } = useRouterStuff();@@ -53,12 +54,12 @@ const AddLinkOptions = () => {content={<TooltipContenttitle="Your project has exceeded its monthly links limit. We're still collecting data on your existing links, but you need to upgrade to add more links."- cta={`Upgrade to ${plan === "free" ? "Pro" : "Business"}`}+ cta={`Upgrade to ${nextPlan.name}`}onClick={() => {setOpenPopover(false);queryParams({set: {- upgrade: plan === "free" ? "pro" : "business",+ upgrade: nextPlan.name.toLowerCase(),},});}}@@ -103,12 +104,12 @@ const AddLinkOptions = () => {content={<TooltipContenttitle="Your project has exceeded its monthly links limit. We're still collecting data on your existing links, but you need to upgrade to add more links."- cta={`Upgrade to ${plan === "free" ? "Pro" : "Business"}`}+ cta={`Upgrade to ${nextPlan.name}`}onClick={() => {setOpenPopover(false);queryParams({set: {- upgrade: plan === "free" ? "pro" : "business",+ upgrade: nextPlan.name.toLowerCase(),},});}}@@ -153,12 +154,12 @@ const AddLinkOptions = () => {content={<TooltipContenttitle="Your project has exceeded its monthly links limit. We're still collecting data on your existing links, but you need to upgrade to add more links."- cta={`Upgrade to ${plan === "free" ? "Pro" : "Business"}`}+ cta={`Upgrade to ${nextPlan.name}`}onClick={() => {setOpenPopover(false);queryParams({set: {- upgrade: plan === "free" ? "pro" : "business",+ upgrade: nextPlan.name.toLowerCase(),},});}}diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/page-client.tsxindex 500e756641..3f6cd97606 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/page-client.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/page-client.tsx@@ -7,13 +7,7 @@ import PlanBadge from "@/ui/projects/plan-badge";import { Divider } from "@/ui/shared/icons";import ProgressBar from "@/ui/shared/progress-bar";import { Button, InfoTooltip, NumberTooltip, useRouterStuff } from "@dub/ui";-import {- HOME_DOMAIN,- PLANS,- getFirstAndLastDay,- getNextPlan,- nFormatter,-} from "@dub/utils";+import { HOME_DOMAIN, getFirstAndLastDay, nFormatter } from "@dub/utils";import va from "@vercel/analytics";import { useRouter, useSearchParams } from "next/navigation";import { useEffect, useMemo, useState } from "react";@@ -28,6 +22,7 @@ export default function ProjectBillingClient() {const {slug,plan,+ nextPlan,usage,usageLimit,linksUsage,@@ -78,8 +73,6 @@ export default function ProjectBillingClient() {}}, [searchParams, plan]);- const nextPlan = getNextPlan(plan as string);-return (<><Confetti active={confetti} config={{ elementCount: 200, spread: 90 }} />@@ -157,7 +150,7 @@ export default function ProjectBillingClient() {<p className="text-sm text-gray-500">{plan === "enterprise"? "You're on the Enterprise plan."- : plan === "business-max"+ : plan === "business max"? "Need more clicks or links? Contact us for an Enterprise quote.": `For higher limits, upgrade to the ${nextPlan.name} plan.`}</p>@@ -178,7 +171,7 @@ export default function ProjectBillingClient() {}variant="success"/>- ) : plan === "business-max" ? (+ ) : plan === "business max" ? (<ahref={`${HOME_DOMAIN}/enterprise`}target="_blank"diff --git a/apps/web/emails/clicks-exceeded.tsx b/apps/web/emails/clicks-exceeded.tsxindex 341f271d70..d47d57a60d 100644--- a/apps/web/emails/clicks-exceeded.tsx+++ b/apps/web/emails/clicks-exceeded.tsx@@ -1,10 +1,4 @@-import {- DUB_LOGO,- PLANS,- capitalize,- getNextPlan,- nFormatter,-} from "@dub/utils";+import { DUB_LOGO, capitalize, getNextPlan, nFormatter } from "@dub/utils";import {Body,Container,@@ -38,7 +32,7 @@ export default function ClicksExceeded({type: "first" | "second";}) {const { slug, name, usage, usageLimit, plan } = project;- const nextPlan = getNextPlan(plan as string);+ const nextPlan = getNextPlan(plan);return (<Html>diff --git a/apps/web/lib/auth/index.ts b/apps/web/lib/auth/index.tsindex 63a720cdf1..da2466adae 100644--- a/apps/web/lib/auth/index.ts+++ b/apps/web/lib/auth/index.ts@@ -60,7 +60,15 @@ export const withAuth =(handler: WithAuthHandler,{- requiredPlan = ["free", "pro", "business", "enterprise"], // if the action needs a specific plan+ requiredPlan = [+ "free",+ "pro",+ "business",+ "business plus",+ "business max",+ "business extra",+ "enterprise",+ ], // if the action needs a specific planrequiredRole = ["owner", "member"],needNotExceededClicks, // if the action needs the user to not have exceeded their clicks usageneedNotExceededLinks, // if the action needs the user to not have exceeded their links usagediff --git a/apps/web/lib/swr/use-project.ts b/apps/web/lib/swr/use-project.tsindex ea37054f51..451811e1c1 100644--- a/apps/web/lib/swr/use-project.ts+++ b/apps/web/lib/swr/use-project.ts@@ -1,5 +1,5 @@import { ProjectProps } from "@/lib/types";-import { fetcher } from "@dub/utils";+import { fetcher, getNextPlan } from "@dub/utils";import { useParams } from "next/navigation";import useSWR from "swr";@@ -16,6 +16,7 @@ export default function useProject() {return {...project,+ nextPlan: getNextPlan(project?.plan),defaultDomains: project?.metadata?.defaultDomains || [],isOwner: project?.users && project.users[0].role === "owner",exceededClicks: project && project.usage >= project.usageLimit,diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.tsindex a3fca2f337..83e94052fb 100644--- a/apps/web/lib/types.ts+++ b/apps/web/lib/types.ts@@ -72,9 +72,9 @@ export type PlanProps =| "free"| "pro"| "business"- | "business-plus"- | "business-extra"- | "business-max"+ | "business plus"+ | "business extra"+ | "business max"| "enterprise";export interface ProjectProps {diff --git a/apps/web/ui/analytics/toggle.tsx b/apps/web/ui/analytics/toggle.tsxindex 21fc04cc9d..1d8a433cfa 100644--- a/apps/web/ui/analytics/toggle.tsx+++ b/apps/web/ui/analytics/toggle.tsx@@ -131,8 +131,7 @@ export default function Toggle() {setOpenDatePopover(false);queryParams({set: {- upgrade:- plan === "free" ? "pro" : "business",+ upgrade: "pro",},});},diff --git a/apps/web/ui/modals/add-edit-domain-modal/index.tsx b/apps/web/ui/modals/add-edit-domain-modal/index.tsxindex 6ce5117d3b..f33ba3d3d1 100644--- a/apps/web/ui/modals/add-edit-domain-modal/index.tsx+++ b/apps/web/ui/modals/add-edit-domain-modal/index.tsx@@ -374,7 +374,7 @@ function AddDomainButton({setShowAddEditDomainModal: Dispatch<SetStateAction<boolean>>;buttonProps?: Partial<ButtonProps>;}) {- const { plan, domainsLimit, exceededDomains } = useProject();+ const { plan, nextPlan, domainsLimit, exceededDomains } = useProject();const { queryParams } = useRouterStuff();return (@@ -391,7 +391,7 @@ function AddDomainButton({onClick={() => {queryParams({set: {- upgrade: plan === "free" ? "pro" : "business",+ upgrade: nextPlan.name.toLowerCase(),},});}}diff --git a/apps/web/ui/modals/add-edit-link-modal/index.tsx b/apps/web/ui/modals/add-edit-link-modal/index.tsxindex 1e24c67f10..369e2ee58c 100644--- a/apps/web/ui/modals/add-edit-link-modal/index.tsx+++ b/apps/web/ui/modals/add-edit-link-modal/index.tsx@@ -643,7 +643,7 @@ function AddEditLinkButton({}: {setShowAddEditLinkModal: Dispatch<SetStateAction<boolean>>;}) {- const { plan, exceededLinks } = useProject();+ const { plan, nextPlan, exceededLinks } = useProject();const { queryParams } = useRouterStuff();const onKeyDown = useCallback((e: KeyboardEvent) => {@@ -709,11 +709,11 @@ function AddEditLinkButton({exceededLinks ? (<TooltipContenttitle="Your project has exceeded its monthly links limit. We're still collecting data on your existing links, but you need to upgrade to add more links."- cta={`Upgrade to ${plan === "free" ? "Pro" : "Business"}`}+ cta={`Upgrade to ${nextPlan.name}`}onClick={() => {queryParams({set: {- upgrade: plan === "free" ? "pro" : "business",+ upgrade: nextPlan.name.toLowerCase(),},});}}diff --git a/apps/web/ui/modals/add-edit-tag-modal.tsx b/apps/web/ui/modals/add-edit-tag-modal.tsxindex 847e96d568..947cc04e1b 100644--- a/apps/web/ui/modals/add-edit-tag-modal.tsx+++ b/apps/web/ui/modals/add-edit-tag-modal.tsx@@ -209,10 +209,9 @@ function AddTagButton({}: {setShowAddEditTagModal: Dispatch<SetStateAction<boolean>>;}) {- const { plan, tagsLimit } = useProject();+ const { plan, nextPlan, tagsLimit } = useProject();const { tags } = useTags();const { queryParams } = useRouterStuff();-const exceededTags = tags && tagsLimit && tags.length >= tagsLimit;return (@@ -231,7 +230,7 @@ function AddTagButton({onClick={() => {queryParams({set: {- upgrade: plan === "free" ? "pro" : "business",+ upgrade: nextPlan.name.toLowerCase(),},});}}diff --git a/apps/web/ui/projects/project-exceeded-clicks.tsx b/apps/web/ui/projects/project-exceeded-clicks.tsxindex 1a4f3374e2..79008c069d 100644--- a/apps/web/ui/projects/project-exceeded-clicks.tsx+++ b/apps/web/ui/projects/project-exceeded-clicks.tsx@@ -2,13 +2,11 @@import useProject from "@/lib/swr/use-project";import { MaxWidthWrapper, useRouterStuff } from "@dub/ui";-import { getNextPlan } from "@dub/utils";import { Lock } from "lucide-react";export default function ProjectExceededClicks() {- const { plan } = useProject();+ const { nextPlan } = useProject();const { queryParams } = useRouterStuff();- const nextPlan = getNextPlan(plan as string);return (<MaxWidthWrapper>diff --git a/packages/utils/src/constants/pricing.tsx b/packages/utils/src/constants/pricing.tsxindex 30bd3d7cb6..9500a5e920 100644--- a/packages/utils/src/constants/pricing.tsx+++ b/packages/utils/src/constants/pricing.tsx@@ -284,6 +284,8 @@ export const getPlanFromPriceId = (priceId: string) => {return PLANS.find((plan) => plan.price.ids?.includes(priceId)) || null;};-export const getNextPlan = (plan: string) => {- return PLANS[PLANS.findIndex((p) => p.name.toLowerCase() === plan) + 1];+export const getNextPlan = (plan: any) => {+ return (+ PLANS[PLANS.findIndex((p) => p.name.toLowerCase() === plan) + 1] || PLANS[1]+ );};