Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getBountyRewardDescription } from "@/lib/partners/get-bounty-reward-description";
import { getBillingUpgradePathForFeature } from "@/lib/billing/upgrade-url";
import { getPlanCapabilities } from "@/lib/plan-capabilities";
import useGroups from "@/lib/swr/use-groups";
import { usePartnersCountByGroupIds } from "@/lib/swr/use-partners-count-by-groupids";
Expand Down Expand Up @@ -176,7 +177,11 @@ function ConfirmCreateBountyModal({
<TooltipContent
title="New bounty notifications are only available on Advanced plans and above."
cta="Upgrade to Advanced"
href={`/${workspaceSlug}/upgrade?showPartnersUpgradeModal=true`}
href={getBillingUpgradePathForFeature({
slug: workspaceSlug,
feature: "partners",
showPartnersUpgradeModal: true,
})}
target="_blank"
/>
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use client";

import { getBillingUpgradePathForFeature } from "@/lib/billing/upgrade-url";
import { getPlanCapabilities } from "@/lib/plan-capabilities";
import useWorkspace from "@/lib/swr/use-workspace";
import { buttonVariants } from "@dub/ui";
Expand All @@ -22,7 +23,10 @@ export function PartnersUpgradeCTA({
if (!canManageProgram || isLegacyBusinessPlan({ plan, payoutsLimit })) {
return {
cta: "Upgrade plan",
href: `/${slug}/upgrade`,
href: getBillingUpgradePathForFeature({
slug,
feature: "partners",
}),
};
} else {
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";

import { clientAccessCheck } from "@/lib/client-access-check";
import { getBillingUpgradePathForFeature } from "@/lib/billing/upgrade-url";
import { getPlanCapabilities } from "@/lib/plan-capabilities";
import useWorkspace from "@/lib/swr/use-workspace";
import {
Expand Down Expand Up @@ -84,7 +85,10 @@ export function ConversionTrackingToggle() {
<TooltipContent
title="You can only enable conversion tracking on Business plans and above."
cta="Upgrade to Business"
href={`/${workspaceSlug}/upgrade`}
href={getBillingUpgradePathForFeature({
slug: workspaceSlug,
feature: "business",
})}
/>
) : (
permissionsError || (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";

import { MEGA_WORKSPACE_LINKS_LIMIT } from "@/lib/constants/misc";
import { getBillingUpgradePath, getBillingUpgradePathForFeature } from "@/lib/billing/upgrade-url";
import useGroupsCount from "@/lib/swr/use-groups-count";
import usePartnersCount from "@/lib/swr/use-partners-count";
import useTagsCount from "@/lib/swr/use-tags-count";
Expand Down Expand Up @@ -32,6 +33,7 @@ import {
capitalize,
cn,
getFirstAndLastDay,
getNextPlan,
INFINITY_NUMBER,
isLegacyBusinessPlan,
nFormatter,
Expand Down Expand Up @@ -66,6 +68,7 @@ export default function PlanUsage() {
usersLimit,
billingCycleStart,
} = useWorkspace();
const nextPlan = getNextPlan(plan);

const { data: tags } = useTagsCount();
const { users } = useWorkspaceUsers();
Expand Down Expand Up @@ -174,7 +177,16 @@ export default function PlanUsage() {
</div>
<div className="flex items-center gap-2">
{plan !== "enterprise" && (
<Link href={`/${slug}/settings/billing/upgrade`}>
<Link
href={getBillingUpgradePath({
slug,
recommendation: nextPlan
? {
plan: nextPlan.name.toLowerCase(),
}
: undefined,
})}
>
<Button
text={plan === "free" ? "Upgrade" : "Manage plan"}
variant="primary"
Expand Down Expand Up @@ -362,7 +374,10 @@ function UsageTabCard({
<div className="max-w-xs px-4 py-2 text-center text-sm text-neutral-600">
Upgrade to Business to unlock conversion tracking.{" "}
<Link
href={`/${slug}/upgrade`}
href={getBillingUpgradePathForFeature({
slug,
feature: "business",
})}
className="underline underline-offset-2 hover:text-neutral-800"
>
View pricing plans
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";

import { clientAccessCheck } from "@/lib/client-access-check";
import { getBillingUpgradePathForFeature } from "@/lib/billing/upgrade-url";
import useDefaultDomains from "@/lib/swr/use-default-domains";
import useWorkspace from "@/lib/swr/use-workspace";
import { DomainCardTitleColumn } from "@/ui/domains/domain-card-title-column";
Expand Down Expand Up @@ -42,7 +43,7 @@ function DubDomainsIcon(domain: string) {
}

export function DefaultDomains() {
const { id, plan, role, flags } = useWorkspace();
const { id, slug: workspaceSlug, plan, role, flags } = useWorkspace();
const [submitting, setSubmitting] = useState(false);
const [defaultDomains, setDefaultDomains] = useState<string[]>([]);
const { defaultDomains: initialDefaultDomains, mutate } = useDefaultDomains();
Expand Down Expand Up @@ -97,7 +98,10 @@ export function DefaultDomains() {
<TooltipContent
title="You can only use dub.link on a Pro plan and above. Upgrade to Pro to use this domain."
cta="Upgrade to Pro"
href={`/${slug}/upgrade`}
href={getBillingUpgradePathForFeature({
slug: workspaceSlug,
feature: "pro",
})}
/>
) : undefined)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use client";

import { getBillingUpgradePathForFeature } from "@/lib/billing/upgrade-url";
import { getPlanCapabilities } from "@/lib/plan-capabilities";
import { useEmailDomains } from "@/lib/swr/use-email-domains";
import useWorkspace from "@/lib/swr/use-workspace";
Expand Down Expand Up @@ -41,7 +42,10 @@ export function EmailDomains() {
}
addButton={
<Link
href={`/${slug}/upgrade`}
href={getBillingUpgradePathForFeature({
slug,
feature: "advanced",
})}
className={cn(
buttonVariants({ variant: "primary" }),
"flex h-9 items-center justify-center whitespace-nowrap rounded-lg border px-4 text-sm",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";

import { getIntegrationInstallUrl } from "@/lib/actions/get-integration-install-url";
import { getBillingUpgradePathForFeature } from "@/lib/billing/upgrade-url";
import { clientAccessCheck } from "@/lib/client-access-check";
import { HubSpotSettings } from "@/lib/integrations/hubspot/ui/settings";
import { SegmentSettings } from "@/lib/integrations/segment/ui/settings";
Expand Down Expand Up @@ -288,7 +289,10 @@ export default function IntegrationPageClient({
<TooltipContent
title="Hubspot integration is only available on Business plans and above. Upgrade to get started."
cta="Upgrade to Business"
href={`/${slug}/settings/billing/upgrade`}
href={getBillingUpgradePathForFeature({
slug,
feature: "business",
})}
/>
) : null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import useWebhooks from "@/lib/swr/use-webhooks";
import useWorkspace from "@/lib/swr/use-workspace";
import { getBillingUpgradePathForFeature } from "@/lib/billing/upgrade-url";
import EmptyState from "@/ui/shared/empty-state";
import WebhookCard from "@/ui/webhooks/webhook-card";
import WebhookPlaceholder from "@/ui/webhooks/webhook-placeholder";
Expand All @@ -23,7 +24,10 @@ export default function WebhooksPageClient() {
description="Webhooks allow you to receive HTTP requests whenever a specific event (eg: someone clicked your link) occurs in Dub."
learnMore="https://d.to/webhooks"
buttonText="Upgrade to Business"
buttonLink={`/${slug}/upgrade`}
buttonLink={getBillingUpgradePathForFeature({
slug,
feature: "business",
})}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from "@/lib/swr/use-folder-permissions";
import useLinks from "@/lib/swr/use-links";
import useWorkspace from "@/lib/swr/use-workspace";
import { getBillingUpgradePath } from "@/lib/billing/upgrade-url";
import { useWorkspaceStore } from "@/lib/swr/use-workspace-store";
import { FolderDropdown } from "@/ui/folders/folder-dropdown";
import {
Expand Down Expand Up @@ -412,7 +413,14 @@ function ImportOption({
<TooltipContent
title="Your workspace has exceeded its monthly links limit. We're still collecting data on your existing links, but you need to upgrade to create more links."
cta={nextPlan ? `Upgrade to ${nextPlan.name}` : "Contact support"}
href={`/${slug}/upgrade`}
href={getBillingUpgradePath({
slug,
recommendation: nextPlan
? {
plan: nextPlan.name.toLowerCase(),
}
: undefined,
})}
/>
}
>
Expand Down
66 changes: 66 additions & 0 deletions apps/web/lib/billing/upgrade-url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
type UpgradeRecommendation = {
plan: string;
planTier?: number;
};

const FEATURE_RECOMMENDATIONS: Record<string, UpgradeRecommendation> = {
pro: {
plan: "pro",
},
business: {
plan: "business",
},
advanced: {
plan: "advanced",
},
partners: {
plan: "advanced",
planTier: 2,
},
};

export function getBillingUpgradePath({
slug,
recommendation,
showPartnersUpgradeModal,
}: {
slug?: string;
recommendation?: UpgradeRecommendation;
showPartnersUpgradeModal?: boolean;
}) {
if (!slug) {
return "https://dub.co/pricing";
}

const queryParams = new URLSearchParams();

if (recommendation) {
queryParams.set("plan", recommendation.plan);
if (recommendation.planTier && recommendation.planTier > 1) {
queryParams.set("planTier", recommendation.planTier.toString());
}
}

if (showPartnersUpgradeModal) {
queryParams.set("showPartnersUpgradeModal", "true");
}

const query = queryParams.toString();
return `/${slug}/settings/billing/upgrade${query ? `?${query}` : ""}`;
}

export function getBillingUpgradePathForFeature({
slug,
feature,
showPartnersUpgradeModal,
}: {
slug?: string;
feature: keyof typeof FEATURE_RECOMMENDATIONS;
showPartnersUpgradeModal?: boolean;
}) {
return getBillingUpgradePath({
slug,
recommendation: FEATURE_RECOMMENDATIONS[feature],
showPartnersUpgradeModal,
});
}
6 changes: 5 additions & 1 deletion apps/web/lib/integrations/segment/ui/set-write-key.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";

import useWorkspace from "@/lib/swr/use-workspace";
import { getBillingUpgradePathForFeature } from "@/lib/billing/upgrade-url";
import { SegmentIntegrationCredentials } from "@/lib/types";
import { Lock } from "@/ui/shared/icons";
import { Button, Tooltip, TooltipContent } from "@dub/ui";
Expand Down Expand Up @@ -50,7 +51,10 @@ export function SetWriteKey({
<TooltipContent
title="You can only install the Segment integration on the Business plan and above."
cta="Upgrade to Business"
href={`/${slug}/upgrade`}
href={getBillingUpgradePathForFeature({
slug,
feature: "business",
})}
/>
);

Expand Down
8 changes: 7 additions & 1 deletion apps/web/ui/analytics/analytics-loading-spinner.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import useWorkspace from "@/lib/swr/use-workspace";
import { getBillingUpgradePath } from "@/lib/billing/upgrade-url";
import { LoadingSpinner } from "@dub/ui";
import { Lock } from "lucide-react";
import Link from "next/link";
Expand All @@ -18,7 +19,12 @@ export function AnalyticsLoadingSpinner() {
{nextPlan.name} plan required to view more analytics
</p>
<Link
href={slug ? `/${slug}/upgrade` : "https://dub.co/pricing"}
href={getBillingUpgradePath({
slug,
recommendation: {
plan: nextPlan.name.toLowerCase(),
},
})}
{...(slug ? {} : { target: "_blank" })}
className="w-full rounded-md border border-black bg-black px-3 py-1.5 text-center text-sm text-white transition-all hover:bg-neutral-800 hover:ring-4 hover:ring-neutral-200"
>
Expand Down
6 changes: 5 additions & 1 deletion apps/web/ui/analytics/chart-section.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { EventType } from "@/lib/analytics/types";
import useWorkspace from "@/lib/swr/use-workspace";
import { getBillingUpgradePathForFeature } from "@/lib/billing/upgrade-url";
import {
BlurImage,
buttonVariants,
Expand Down Expand Up @@ -182,7 +183,10 @@ function ConversionTrackingPaywall() {
</Link>
</p>
<Link
href={`/${slug}/upgrade`}
href={getBillingUpgradePathForFeature({
slug,
feature: "business",
})}
className={cn(
buttonVariants({ variant: "primary" }),
"mt-4 flex h-8 items-center justify-center whitespace-nowrap rounded-lg border px-3 text-sm",
Expand Down
6 changes: 5 additions & 1 deletion apps/web/ui/analytics/events/events-export-button.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import useWorkspace from "@/lib/swr/use-workspace";
import { getBillingUpgradePathForFeature } from "@/lib/billing/upgrade-url";
import { Button, Download, TooltipContent } from "@dub/ui";
import { useSession } from "next-auth/react";
import { Dispatch, SetStateAction, useContext } from "react";
Expand Down Expand Up @@ -65,7 +66,10 @@ export function EventsExportButton({
<TooltipContent
title="Upgrade to our Business Plan to enable CSV downloads for events in your workspace."
cta="Upgrade to Business"
href={`/${slug}/upgrade`}
href={getBillingUpgradePathForFeature({
slug,
feature: "business",
})}
/>
)
}
Expand Down
6 changes: 5 additions & 1 deletion apps/web/ui/analytics/events/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";

import useWorkspace from "@/lib/swr/use-workspace";
import { getBillingUpgradePathForFeature } from "@/lib/billing/upgrade-url";
import EmptyState from "@/ui/shared/empty-state";
import { Menu3 } from "@dub/ui/icons";
import { cn } from "@dub/utils";
Expand Down Expand Up @@ -59,7 +60,10 @@ function EventsTableContainer() {
description={`Want more data on your link ${selectedTab === "clicks" ? "clicks & QR code scans" : selectedTab}? Upgrade to our Business Plan to get a detailed, real-time stream of events in your workspace.`}
learnMore="https://d.to/events"
buttonText="Upgrade to Business"
buttonLink={`/${slug}/upgrade`}
buttonLink={getBillingUpgradePathForFeature({
slug,
feature: "business",
})}
/>
}
/>
Expand Down
Loading
Loading