The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
address CR feedback
Steven Tey9052d0456964
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 688c587dc9..b29de7bf8b 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@@ -7,6 +7,7 @@ import {SELF_SERVE_PAID_PLANS,cn,getPlanDetails,+ getMonthlyLimitFromPeriod,getPlanLimitForPeriod,} from "@dub/utils";import NumberFlow from "@number-flow/react";@@ -123,8 +124,10 @@ function UsageSlider({}const currentLimit = workspace[workspaceLimitKey];- const monthlyCurrentLimit =- workspacePlanPeriod === "yearly" ? currentLimit / 12 : currentLimit;+ const monthlyCurrentLimit = getMonthlyLimitFromPeriod({+ limit: currentLimit,+ planPeriod: workspacePlanPeriod,+ });return usageSteps.reduce((prev, curr) =>Math.abs(curr - monthlyCurrentLimit) < Math.abs(prev - monthlyCurrentLimit)@@ -142,10 +145,10 @@ function UsageSlider({if (usageSteps.length < 2) return null;- const monthlyWorkspaceLimit =- workspacePlanPeriod === "yearly"- ? workspace[workspaceLimitKey] / 12- : workspace[workspaceLimitKey];+ const monthlyWorkspaceLimit = getMonthlyLimitFromPeriod({+ limit: workspace[workspaceLimitKey],+ planPeriod: workspacePlanPeriod,+ });return (<div className="flex flex-col">diff --git a/apps/web/ui/modals/manage-usage-modal.tsx b/apps/web/ui/modals/manage-usage-modal.tsxindex 102312d128..52d1ccfa20 100644--- a/apps/web/ui/modals/manage-usage-modal.tsx+++ b/apps/web/ui/modals/manage-usage-modal.tsx@@ -16,6 +16,7 @@ import {SELF_SERVE_PAID_PLANS,capitalize,cn,+ getMonthlyLimitFromPeriod,getPlanLimitForPeriod,getPlanPeriodSuffix,getSuggestedPlan,@@ -70,8 +71,10 @@ function ManageUsageModalContent({ type }: ManageUsageModalProps) {const defaultValue = useMemo(() => {const currentLimit =workspace[{ events: "usageLimit", links: "linksLimit" }[type]];- const monthlyCurrentLimit =- planPeriod === "yearly" ? currentLimit / 12 : currentLimit;+ const monthlyCurrentLimit = getMonthlyLimitFromPeriod({+ limit: currentLimit,+ planPeriod,+ });return usageSteps.reduce((prev, curr) =>Math.abs(curr - monthlyCurrentLimit) <@@ -98,9 +101,11 @@ function ManageUsageModalContent({ type }: ManageUsageModalProps) {storedPeriod?: string | null;targetPeriod: PlanPeriod;}) => {- const monthlyLimit = storedPeriod === "yearly" ? limit / 12 : limit;return getPlanLimitForPeriod({- limit: monthlyLimit,+ limit: getMonthlyLimitFromPeriod({+ limit,+ planPeriod: storedPeriod,+ }),planPeriod: targetPeriod,});},diff --git a/packages/utils/src/constants/pricing/plan-period-utils.ts b/packages/utils/src/constants/pricing/plan-period-utils.tsindex 431ccbe57f..75f9460c7b 100644--- a/packages/utils/src/constants/pricing/plan-period-utils.ts+++ b/packages/utils/src/constants/pricing/plan-period-utils.ts@@ -12,6 +12,16 @@ export function getPlanLimitForPeriod({return planPeriod === "yearly" ? limit * YEARLY_USAGE_MULTIPLIER : limit;}+export function getMonthlyLimitFromPeriod({+ limit,+ planPeriod = "monthly",+}: {+ limit: number;+ planPeriod?: PlanPeriod | string | null;+}) {+ return planPeriod === "yearly" ? limit / YEARLY_USAGE_MULTIPLIER : limit;+}+export function getPlanPeriodSuffix({planPeriod = "monthly",isUnlimited = false,