The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
yearly vs monthly usage amount
Steven Tey9f90624c6e40
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/plan-usage.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/plan-usage.tsxindex a6a33720c5..b5f8083c0e 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/plan-usage.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/plan-usage.tsx@@ -284,7 +284,9 @@ export default function PlanUsage() {: capitalize(plan)}{" "}Plan</span>- <Badge variant="gray">{capitalize(planPeriod)}</Badge>+ {planPeriod && (+ <Badge variant="gray">{capitalize(planPeriod)}</Badge>+ )}</h2>{billingStart && billingEnd && (<p className="mt-1.5 text-balance text-sm font-medium leading-normal text-neutral-700">diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/upgrade/adjust-usage-row.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/upgrade/adjust-usage-row.tsxindex fac36ed118..688c587dc9 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/upgrade/adjust-usage-row.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/upgrade/adjust-usage-row.tsx@@ -3,9 +3,11 @@ import { Button, Grid, Slider } from "@dub/ui";import {BUSINESS_PLAN,ENTERPRISE_PLAN,+ PlanPeriod,SELF_SERVE_PAID_PLANS,cn,getPlanDetails,+ getPlanLimitForPeriod,} from "@dub/utils";import NumberFlow from "@number-flow/react";import { motion } from "motion/react";@@ -13,9 +15,11 @@ import { useSearchParams } from "next/navigation";import { useEffect, useMemo, useState } from "react";export function AdjustUsageRow({+ planPeriod,onEventsUsageChange,onLinksUsageChange,}: {+ planPeriod: PlanPeriod;onEventsUsageChange: (value: number) => void;onLinksUsageChange: (value: number) => void;}) {@@ -34,8 +38,16 @@ export function AdjustUsageRow({)}><div className="grid grid-cols-1 gap-10 p-6 lg:grid-cols-2">- <UsageSlider type="links" onChange={onLinksUsageChange} />- <UsageSlider type="events" onChange={onEventsUsageChange} />+ <UsageSlider+ type="links"+ planPeriod={planPeriod}+ onChange={onLinksUsageChange}+ />+ <UsageSlider+ type="events"+ planPeriod={planPeriod}+ onChange={onEventsUsageChange}+ /></div></motion.div><div className="relative flex items-center justify-center overflow-hidden rounded-b-[12px] py-2">@@ -60,12 +72,15 @@ export function AdjustUsageRow({function UsageSlider({type,+ planPeriod,onChange,}: {type: "links" | "events";+ planPeriod: PlanPeriod;onChange: (value: number) => void;}) {const workspace = useWorkspace();+ const { planPeriod: workspacePlanPeriod } = workspace;const limitKey = { events: "clicks" }[type] ?? type;const workspaceLimitKey = { events: "usageLimit", links: "linksLimit" }[type];@@ -108,41 +123,55 @@ function UsageSlider({}const currentLimit = workspace[workspaceLimitKey];+ const monthlyCurrentLimit =+ workspacePlanPeriod === "yearly" ? currentLimit / 12 : currentLimit;+return usageSteps.reduce((prev, curr) =>- Math.abs(curr - currentLimit) < Math.abs(prev - currentLimit)+ Math.abs(curr - monthlyCurrentLimit) < Math.abs(prev - monthlyCurrentLimit)? curr: prev,);- }, [usageSteps, workspace, workspaceLimitKey]);+ }, [usageSteps, workspace, workspaceLimitKey, workspacePlanPeriod]);const [selectedValue, setSelectedValue] = useState<number | null>(null);+ const monthlySelectedValue = selectedValue ?? defaultValue;useEffect(() => {- onChange(selectedValue ?? defaultValue);- }, [selectedValue, defaultValue, onChange]);+ onChange(monthlySelectedValue);+ }, [monthlySelectedValue, onChange]);if (usageSteps.length < 2) return null;+ const monthlyWorkspaceLimit =+ workspacePlanPeriod === "yearly"+ ? workspace[workspaceLimitKey] / 12+ : workspace[workspaceLimitKey];+return (<div className="flex flex-col"><span className="text-content-default text-sm font-medium">{{- events: "Events tracked per month",- links: "Links created per month",+ events: `Events tracked per ${planPeriod === "yearly" ? "year" : "month"}`,+ links: `Links created per ${planPeriod === "yearly" ? "year" : "month"}`,}[type]}</span><span className="text-content-emphasis text-lg font-semibold">- <NumberFlow value={selectedValue ?? defaultValue} />- {workspace[workspaceLimitKey] === (selectedValue ?? defaultValue) && (+ <NumberFlow+ value={getPlanLimitForPeriod({+ limit: monthlySelectedValue,+ planPeriod,+ })}+ />+ {monthlyWorkspaceLimit === monthlySelectedValue && (<span className="animate-fade-in"> (current plan)</span>)}</span><div className="mt-1"><Slider- value={usageSteps.indexOf(selectedValue ?? defaultValue)}+ value={usageSteps.indexOf(monthlySelectedValue)}min={0}max={usageSteps.length - 1}onChange={(idx) => setSelectedValue(usageSteps[idx])}diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/upgrade/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/upgrade/page.tsxindex 5cf870fdda..953c98d839 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/upgrade/page.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/upgrade/page.tsx@@ -334,6 +334,7 @@ export default function WorkspaceBillingUpgradePage() {<div className="bg-bg-muted border-subtle absolute inset-x-0 -top-2.5 bottom-0 rounded-b-[12px] border" /><AdjustUsageRow+ planPeriod={period}onEventsUsageChange={(value) => setEventsUsage(value)}onLinksUsageChange={(value) => setLinksUsage(value)}/>@@ -350,6 +351,7 @@ export default function WorkspaceBillingUpgradePage() {features={section.features}mobilePlanIndex={mobilePlanIndex}plans={plans}+ planPeriod={period}/>))}</div>@@ -404,9 +406,11 @@ function BillingCompareSection({features,mobilePlanIndex,plans,+ planPeriod,}: (typeof PRICING_PLAN_COMPARE_FEATURES)[number] & {mobilePlanIndex: number;plans: { plan: PlanDetails; planTier: number }[];+ planPeriod: "monthly" | "yearly";}) {const [isExpanded, setIsExpanded] = useState(true);const { defaultProgramId } = useWorkspace();@@ -520,6 +524,7 @@ function BillingCompareSection({? (text({id,plan,+ planPeriod,}) as React.ReactNode): text}</As>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.tsxindex e68e7c4341..c61dbc3bb1 100644--- 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.tsx@@ -16,7 +16,7 @@ import {BUSINESS_PLAN,cn,ENTERPRISE_PLAN,- PRICING_PLAN_MAIN_FEATURES,+ getPricingPlanMainFeatures,PRICING_PLAN_TAGLINES,PRO_PLAN,} from "@dub/utils";@@ -81,7 +81,7 @@ export function PlanSelector({ product }: { product: OnboardingProduct }) {>{plans.map((plan) => {const features =- PRICING_PLAN_MAIN_FEATURES[product][plan.name] || [];+ getPricingPlanMainFeatures(period)[product][plan.name] || [];return (<divdiff --git a/apps/web/ui/modals/manage-usage-modal.tsx b/apps/web/ui/modals/manage-usage-modal.tsxindex f0a357cea5..102312d128 100644--- a/apps/web/ui/modals/manage-usage-modal.tsx+++ b/apps/web/ui/modals/manage-usage-modal.tsx@@ -12,9 +12,12 @@ import {import {DUB_TRIAL_PERIOD_DAYS,ENTERPRISE_PLAN,+ PlanPeriod,SELF_SERVE_PAID_PLANS,capitalize,cn,+ getPlanLimitForPeriod,+ getPlanPeriodSuffix,getSuggestedPlan,isDowngradePlan,} from "@dub/utils";@@ -67,19 +70,46 @@ function ManageUsageModalContent({ type }: ManageUsageModalProps) {const defaultValue = useMemo(() => {const currentLimit =workspace[{ events: "usageLimit", links: "linksLimit" }[type]];+ const monthlyCurrentLimit =+ planPeriod === "yearly" ? currentLimit / 12 : currentLimit;+return usageSteps.reduce((prev, curr) =>- Math.abs(curr - currentLimit) < Math.abs(prev - currentLimit)+ Math.abs(curr - monthlyCurrentLimit) <+ Math.abs(prev - monthlyCurrentLimit)? curr: prev,);- }, [usageSteps, workspace]);+ }, [usageSteps, workspace, type, planPeriod]);const [selectedValue, setSelectedValue] = useState<number | null>(null);- const [period, setPeriod] = useState<"monthly" | "yearly">("monthly");+ const [period, setPeriod] = useState<PlanPeriod>(+ planPeriod === "yearly" ? "yearly" : "monthly",+ );++ const monthlySelectedValue = selectedValue ?? defaultValue;++ const getLimitInPeriod = useCallback(+ ({+ limit,+ storedPeriod,+ targetPeriod,+ }: {+ limit: number;+ storedPeriod?: string | null;+ targetPeriod: PlanPeriod;+ }) => {+ const monthlyLimit = storedPeriod === "yearly" ? limit / 12 : limit;+ return getPlanLimitForPeriod({+ limit: monthlyLimit,+ planPeriod: targetPeriod,+ });+ },+ [],+ );const { plan: suggestedPlan, planTier: suggestedPlanTier } = getSuggestedPlan({- [type]: selectedValue ?? defaultValue,+ [type]: monthlySelectedValue,},);@@ -109,18 +139,21 @@ function ManageUsageModalContent({ type }: ManageUsageModalProps) {<p className="text-content-default text-sm font-medium">{{- events: "Events tracked per month",- links: "Links created per month",+ events: `Events tracked per ${period === "yearly" ? "year" : "month"}`,+ links: `Links created per ${period === "yearly" ? "year" : "month"}`,}[type]}</p><NumberFlow- value={selectedValue ?? defaultValue}+ value={getPlanLimitForPeriod({+ limit: monthlySelectedValue,+ planPeriod: period,+ })}className="text-content-emphasis mb-4 text-lg font-semibold"/><Slider- value={usageSteps.indexOf(selectedValue ?? defaultValue)}+ value={usageSteps.indexOf(monthlySelectedValue)}min={0}max={usageSteps.length - 1}onChange={(idx) => setSelectedValue(usageSteps[idx])}@@ -217,15 +250,39 @@ function ManageUsageModalContent({ type }: ManageUsageModalProps) {{[{icon: CursorRays,- value: suggestedPlan.limits.clicks,- label: `total tracked events/mo`,- difference: suggestedPlan.limits.clicks - (usageLimit ?? 0),+ value: getPlanLimitForPeriod({+ limit: suggestedPlan.limits.clicks,+ planPeriod: period,+ }),+ label: `total tracked events${getPlanPeriodSuffix({ planPeriod: period })}`,+ difference:+ getPlanLimitForPeriod({+ limit: suggestedPlan.limits.clicks,+ planPeriod: period,+ }) -+ getLimitInPeriod({+ limit: usageLimit ?? 0,+ storedPeriod: planPeriod,+ targetPeriod: period,+ }),},{icon: Hyperlink,- value: suggestedPlan.limits.links,- label: `new links/mo`,- difference: suggestedPlan.limits.links - (linksLimit ?? 0),+ value: getPlanLimitForPeriod({+ limit: suggestedPlan.limits.links,+ planPeriod: period,+ }),+ label: `new links${getPlanPeriodSuffix({ planPeriod: period })}`,+ difference:+ getPlanLimitForPeriod({+ limit: suggestedPlan.limits.links,+ planPeriod: period,+ }) -+ getLimitInPeriod({+ limit: linksLimit ?? 0,+ storedPeriod: planPeriod,+ targetPeriod: period,+ }),},].map(({ icon: Icon, value, label, difference }) => (<divdiff --git a/packages/utils/src/constants/index.ts b/packages/utils/src/constants/index.tsindex 54c7dee0f3..1e8a7abeec 100644--- a/packages/utils/src/constants/index.ts+++ b/packages/utils/src/constants/index.ts@@ -20,6 +20,7 @@ export * from "./stablecoin-supported-countries";export * from "./tremendous-supported-countries";// pricing copy & values+export * from "./pricing/plan-period-utils";export * from "./pricing/pricing-plan-compare-features";export * from "./pricing/pricing-plan-main-features";export * from "./pricing/pricing-plan-taglines";diff --git a/packages/utils/src/constants/pricing/plan-period-utils.ts b/packages/utils/src/constants/pricing/plan-period-utils.tsnew file mode 100644index 0000000000..431ccbe57f--- /dev/null+++ b/packages/utils/src/constants/pricing/plan-period-utils.ts@@ -0,0 +1,24 @@+export type PlanPeriod = "monthly" | "yearly";++const YEARLY_USAGE_MULTIPLIER = 12;++export function getPlanLimitForPeriod({+ limit,+ planPeriod = "monthly",+}: {+ limit: number;+ planPeriod?: PlanPeriod;+}) {+ return planPeriod === "yearly" ? limit * YEARLY_USAGE_MULTIPLIER : limit;+}++export function getPlanPeriodSuffix({+ planPeriod = "monthly",+ isUnlimited = false,+}: {+ planPeriod?: PlanPeriod;+ isUnlimited?: boolean;+}) {+ if (isUnlimited) return "";+ return planPeriod === "yearly" ? "/year" : "/month";+}diff --git a/packages/utils/src/constants/pricing/pricing-plan-compare-features.tsx b/packages/utils/src/constants/pricing/pricing-plan-compare-features.tsxindex b0deca02b7..b503c07b1a 100644--- a/packages/utils/src/constants/pricing/pricing-plan-compare-features.tsx+++ b/packages/utils/src/constants/pricing/pricing-plan-compare-features.tsx@@ -1,6 +1,11 @@import { ReactNode } from "react";import { nFormatter } from "../../functions/nformatter";import { INFINITY_NUMBER } from "../misc";+import {+ getPlanLimitForPeriod,+ getPlanPeriodSuffix,+ PlanPeriod,+} from "./plan-period-utils";import { PLANS } from "./pricing-plans";export const PRICING_PLAN_COMPARE_FEATURES: {@@ -9,7 +14,11 @@ export const PRICING_PLAN_COMPARE_FEATURES: {features: {text:| string- | ((d: { id: string; plan: (typeof PLANS)[number] }) => ReactNode);+ | ((d: {+ id: string;+ plan: (typeof PLANS)[number];+ planPeriod?: PlanPeriod;+ }) => ReactNode);href?: string;check?:| boolean@@ -28,15 +37,23 @@ export const PRICING_PLAN_COMPARE_FEATURES: {href: "https://dub.co/links",features: [{- text: ({ plan }) => (+ text: ({ plan, planPeriod = "monthly" }) => (<><strong>{plan.name === "Enterprise"? "Unlimited"- : nFormatter(plan.limits.links)}+ : nFormatter(+ getPlanLimitForPeriod({+ limit: plan.limits.links,+ planPeriod,+ }),+ )}</strong>{" "}new links- {plan.name === "Enterprise" ? "" : "/mo"}+ {getPlanPeriodSuffix({+ planPeriod,+ isUnlimited: plan.name === "Enterprise",+ })}</>),},@@ -165,7 +182,7 @@ export const PRICING_PLAN_COMPARE_FEATURES: {advanced: true,enterprise: true,},- text: ({ id, plan }) =>+ text: ({ id, plan, planPeriod = "monthly" }) =>id === "free" || id === "pro" ? ("No partner payouts") : (@@ -173,10 +190,18 @@ export const PRICING_PLAN_COMPARE_FEATURES: {<strong>{plan.name === "Enterprise"? "Unlimited"- : `$${nFormatter(plan.limits.payouts / 100)}`}+ : `$${nFormatter(+ getPlanLimitForPeriod({+ limit: plan.limits.payouts,+ planPeriod,+ }) / 100,+ )}`}</strong>{" "}partner payouts- {plan.name === "Enterprise" ? "" : "/mo"}+ {getPlanPeriodSuffix({+ planPeriod,+ isUnlimited: plan.name === "Enterprise",+ })}</>),},@@ -389,15 +414,23 @@ export const PRICING_PLAN_COMPARE_FEATURES: {href: "https://dub.co/help/article/dub-analytics",},{- text: ({ plan }) => (+ text: ({ plan, planPeriod = "monthly" }) => (<><strong>{plan.name === "Enterprise"? "Unlimited"- : nFormatter(plan.limits.clicks)}+ : nFormatter(+ getPlanLimitForPeriod({+ limit: plan.limits.clicks,+ planPeriod,+ }),+ )}</strong>{" "}tracked events- {plan.name === "Enterprise" ? "" : "/mo"}+ {getPlanPeriodSuffix({+ planPeriod,+ isUnlimited: plan.name === "Enterprise",+ })}</>),href: "https://dub.co/help/article/dub-analytics-limits",diff --git a/packages/utils/src/constants/pricing/pricing-plan-main-features.ts b/packages/utils/src/constants/pricing/pricing-plan-main-features.tsindex c32188ca1e..a803035255 100644--- a/packages/utils/src/constants/pricing/pricing-plan-main-features.ts+++ b/packages/utils/src/constants/pricing/pricing-plan-main-features.ts@@ -1,5 +1,10 @@import { ReactNode } from "react";import { nFormatter } from "../../functions/nformatter";+import {+ getPlanLimitForPeriod,+ getPlanPeriodSuffix,+ PlanPeriod,+} from "./plan-period-utils";import { PLANS } from "./pricing-plans";type Plan = (typeof PLANS)[number];@@ -17,7 +22,10 @@ type HeroFeature = {};};-const getLinksStandards = (plan: Plan): HeroFeature[] => {+const getLinksStandards = (+ plan: Plan,+ planPeriod: PlanPeriod = "monthly",+): HeroFeature[] => {return [// Tracked events{@@ -25,7 +33,12 @@ const getLinksStandards = (plan: Plan): HeroFeature[] => {text:plan.name === "Enterprise"? "Unlimited tracked events"- : `${nFormatter(plan.limits.clicks)} tracked events/mo`,+ : `${nFormatter(+ getPlanLimitForPeriod({+ limit: plan.limits.clicks,+ planPeriod,+ }),+ )} tracked events${getPlanPeriodSuffix({ planPeriod })}`,},// New links{@@ -33,7 +46,12 @@ const getLinksStandards = (plan: Plan): HeroFeature[] => {text:plan.name === "Enterprise"? "Unlimited new links"- : `${nFormatter(plan.limits.links)} new links/mo`,+ : `${nFormatter(+ getPlanLimitForPeriod({+ limit: plan.limits.links,+ planPeriod,+ }),+ )} new links${getPlanPeriodSuffix({ planPeriod })}`,},...(plan.name !== "Enterprise"? [@@ -46,13 +64,21 @@ const getLinksStandards = (plan: Plan): HeroFeature[] => {];};-const getPartnersStandards = (plan: Plan): HeroFeature[] => [+const getPartnersStandards = (+ plan: Plan,+ planPeriod: PlanPeriod = "monthly",+): HeroFeature[] => [{id: "payouts",text:plan.name === "Enterprise"? "Unlimited partner payouts"- : `$${nFormatter(plan.limits.payouts / 100)} partner payouts/mo`,+ : `$${nFormatter(+ getPlanLimitForPeriod({+ limit: plan.limits.payouts,+ planPeriod,+ }) / 100,+ )} partner payouts${getPlanPeriodSuffix({ planPeriod })}`,tooltip: {title:"Send payouts to your partners with 1-click (or automate it completely) – all across the world.",@@ -62,12 +88,17 @@ const getPartnersStandards = (plan: Plan): HeroFeature[] => [},];-export const PRICING_PLAN_MAIN_FEATURES = {+export const getPricingPlanMainFeatures = (+ planPeriod: PlanPeriod = "monthly",+) => ({links: {Pro: [{features: [- ...getLinksStandards(PLANS.find((p) => p.name === "Pro")!),+ ...getLinksStandards(+ PLANS.find((p) => p.name === "Pro")!,+ planPeriod,+ ),{id: "advanced",text: "Advanced link features",@@ -112,7 +143,10 @@ export const PRICING_PLAN_MAIN_FEATURES = {Business: [{features: [- ...getLinksStandards(PLANS.find((p) => p.name === "Business")!),+ ...getLinksStandards(+ PLANS.find((p) => p.name === "Business")!,+ planPeriod,+ ),{id: "conversions",text: "Conversion tracking",@@ -159,7 +193,10 @@ export const PRICING_PLAN_MAIN_FEATURES = {Advanced: [{features: [- ...getLinksStandards(PLANS.find((p) => p.name === "Advanced")!),+ ...getLinksStandards(+ PLANS.find((p) => p.name === "Advanced")!,+ planPeriod,+ ),{id: "api",text: "Elevated API rate limits",@@ -178,7 +215,10 @@ export const PRICING_PLAN_MAIN_FEATURES = {Enterprise: [{features: [- ...getLinksStandards(PLANS.find((p) => p.name === "Enterprise")!),+ ...getLinksStandards(+ PLANS.find((p) => p.name === "Enterprise")!,+ planPeriod,+ ),{id: "sso",text: "SSO/SAML",@@ -199,7 +239,10 @@ export const PRICING_PLAN_MAIN_FEATURES = {Business: [{features: [- ...getPartnersStandards(PLANS.find((p) => p.name === "Business")!),+ ...getPartnersStandards(+ PLANS.find((p) => p.name === "Business")!,+ planPeriod,+ ),{id: "basicrewards",text: "Basic reward structures",@@ -270,7 +313,10 @@ export const PRICING_PLAN_MAIN_FEATURES = {Advanced: [{features: [- ...getPartnersStandards(PLANS.find((p) => p.name === "Advanced")!),+ ...getPartnersStandards(+ PLANS.find((p) => p.name === "Advanced")!,+ planPeriod,+ ),{id: "flexiblerewards",text: "Advanced reward structures",@@ -339,7 +385,10 @@ export const PRICING_PLAN_MAIN_FEATURES = {Enterprise: [{features: [- ...getPartnersStandards(PLANS.find((p) => p.name === "Enterprise")!),+ ...getPartnersStandards(+ PLANS.find((p) => p.name === "Enterprise")!,+ planPeriod,+ ),{id: "volume",text: "Volume discounts",@@ -392,4 +441,4 @@ export const PRICING_PLAN_MAIN_FEATURES = {},],},-};+});