Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Add upgrade modal

Tim Wilson0ad301d14ec9
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/groups/create-group-button.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/groups/create-group-button.tsx
index 6ac4bdca48..3272114c40 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/groups/create-group-button.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/groups/create-group-button.tsx
@@ -1,22 +1,45 @@
"use client";
+import useGroupsCount from "@/lib/swr/use-groups-count";
+import useWorkspace from "@/lib/swr/use-workspace";
+import { usePartnersUpgradeModal } from "@/ui/partners/partners-upgrade-modal";
import { Button, useKeyboardShortcut } from "@dub/ui";
import { useCreateGroupModal } from "./create-group-modal";
export function CreateGroupButton() {
+ const { groupsLimit, nextPlan } = useWorkspace();
+ const { groupsCount } = useGroupsCount();
+
+ const { partnersUpgradeModal, setShowPartnersUpgradeModal } =
+ usePartnersUpgradeModal({
+ plan: ["Advanced", "Enterprise"].includes(nextPlan.name)
+ ? nextPlan.name
+ : "Enterprise",
+ });
+
const { createGroupModal, setIsOpen: setShowCreateGroupSheet } =
useCreateGroupModal({});
- useKeyboardShortcut("c", () => setShowCreateGroupSheet(true));
+ const disabled = groupsCount === undefined || groupsLimit === undefined;
+
+ const handleCreateGroup = () => {
+ if (!disabled && groupsCount >= groupsLimit)
+ setShowPartnersUpgradeModal(true);
+ else setShowCreateGroupSheet(true);
+ };
+
+ useKeyboardShortcut("c", () => handleCreateGroup());
return (
<>
+ {partnersUpgradeModal}
{createGroupModal}
<Button
type="button"
- onClick={() => setShowCreateGroupSheet(true)}
+ onClick={handleCreateGroup}
text="Create group"
- shortcut="C"
+ shortcut={!disabled ? "C" : undefined}
+ disabled={disabled}
/>
</>
);
diff --git a/apps/web/ui/partners/partners-upgrade-modal.tsx b/apps/web/ui/partners/partners-upgrade-modal.tsx
new file mode 100644
index 0000000000..e9c6fe3708
--- /dev/null
+++ b/apps/web/ui/partners/partners-upgrade-modal.tsx
@@ -0,0 +1,266 @@
+import { UpgradePlanButton } from "@/ui/workspaces/upgrade-plan-button";
+import {
+ Button,
+ Check,
+ Grid,
+ Modal,
+ SimpleTooltipContent,
+ Switch,
+ Tooltip,
+} from "@dub/ui";
+import { cn, INFINITY_NUMBER, nFormatter, PLANS } from "@dub/utils";
+import NumberFlow from "@number-flow/react";
+import Link from "next/link";
+import { Dispatch, ReactNode, SetStateAction, useMemo, useState } from "react";
+
+const defaultDescriptions = {
+ Advanced:
+ "When you upgrade to Advanced, you'll get access to higher payout limits, advanced reward structures, white-labeling support, and more.",
+ Enterprise:
+ "When you upgrade to Enterprise, you'll get access to unlimited payouts, unlimited partner groups, and more.",
+};
+
+type PartnersUpgradeModalProps = {
+ plan?: string;
+ description?: ReactNode;
+ showPartnersUpgradeModal: boolean;
+ setShowPartnersUpgradeModal: Dispatch<SetStateAction<boolean>>;
+};
+
+export function PartnersUpgradeModal({
+ plan: planName = "Advanced",
+ description,
+ showPartnersUpgradeModal,
+ setShowPartnersUpgradeModal,
+}: PartnersUpgradeModalProps) {
+ const plan = PLANS.find(({ name }) => name === planName)!;
+
+ const [isAnnual, setIsAnnual] = useState(true);
+
+ const features = useMemo(
+ () => [
+ {
+ id: "payouts",
+ text:
+ plan.limits.payouts < INFINITY_NUMBER
+ ? `$${nFormatter(plan.limits.payouts / 100)} partner payouts/mo`
+ : "Unlimited partner payouts",
+ tooltip: {
+ title:
+ "Send payouts to your partners with 1-click (or automate it completely) – all across the world.",
+ cta: "Learn more.",
+ href: "https://dub.co/help/article/partner-payouts",
+ },
+ },
+ ...({
+ Advanced: [
+ {
+ id: "flexiblerewards",
+ text: "Advanced reward structures",
+ tooltip: {
+ title:
+ "Create dynamic click, lead, or sale-based rewards with country and product-specific modifiers.",
+ cta: "Learn more.",
+ href: "https://dub.co/help/article/partner-rewards",
+ },
+ },
+ {
+ id: "whitelabel",
+ text: "White-labeling support",
+ tooltip: {
+ title:
+ "Embed a white-labeled referral dashboard directly in your app in just a few lines of code.",
+ cta: "Learn more.",
+ href: "https://dub.co/docs/partners/white-labeling",
+ },
+ },
+ {
+ id: "groups",
+ text: `${plan.limits.groups} partner groups`,
+ },
+ {
+ id: "api",
+ text: "Partners API",
+ tooltip: {
+ title:
+ "Leverage our partners API to build a bespoke, white-labeled referral program that lives within your app.",
+ cta: "Learn more.",
+ href: "https://dub.co/docs/api-reference/endpoint/create-a-partner",
+ },
+ },
+ {
+ id: "slack",
+ text: "Priority Slack support",
+ },
+ ],
+ Enterprise: [
+ {
+ id: "groups",
+ text: "Unlimited partner groups",
+ },
+ {
+ id: "sso",
+ text: "SSO/SAML",
+ tooltip: {
+ title:
+ "Enable single sign-on (SSO) for your entire organization using SAML.",
+ cta: "Learn more.",
+ href: "https://dub.co/help/category/saml-sso",
+ },
+ },
+ {
+ id: "logs",
+ text: "Audit logs",
+ },
+ {
+ id: "sla",
+ text: "Custom SLA",
+ },
+ {
+ id: "success",
+ text: "Dedicated success manager",
+ },
+ ],
+ }[plan.name] ?? []),
+ ],
+ [plan],
+ );
+
+ return (
+ <Modal
+ showModal={showPartnersUpgradeModal}
+ setShowModal={setShowPartnersUpgradeModal}
+ >
+ <div className="scrollbar-hide relative max-h-[calc(100dvh-50px)] overflow-y-auto p-4 sm:p-8">
+ <div className="pointer-events-none absolute inset-y-0 left-1/2 hidden w-[640px] -translate-x-1/2 [mask-image:linear-gradient(black,transparent_280px)] sm:block">
+ <Grid cellSize={35} patternOffset={[-29, -10]} />
+ </div>
+
+ <div className="relative flex flex-col gap-2">
+ <div className="flex h-5 w-fit items-center justify-center rounded-md bg-violet-100 px-2 text-xs font-semibold text-violet-600">
+ Upgrade to unlock
+ </div>
+ <h2 className="text-content-emphasis text-lg font-semibold">
+ Get even more from your partner program
+ </h2>
+ <p className="text-content-subtle text-sm">
+ {description ?? defaultDescriptions[plan.name]}
+ </p>
+ </div>
+
+ <div className="border-default relative mt-6 flex flex-col rounded-xl border bg-white p-6">
+ <div className="flex items-center justify-between">
+ <span className="text-content-emphasis text-xl font-semibold">
+ {plan.name}
+ </span>
+ {plan.name !== "Enterprise" && (
+ <label className="flex items-center gap-1.5">
+ <span
+ className={cn(
+ "text-xs font-semibold text-neutral-500 transition-colors",
+ isAnnual && "text-neutral-600",
+ )}
+ >
+ Yearly
+ </span>
+ <Switch
+ checked={isAnnual}
+ fn={setIsAnnual}
+ trackDimensions="radix-state-checked:bg-black focus-visible:ring-black/20 w-7 h-4"
+ thumbDimensions="size-3"
+ thumbTranslate="translate-x-3"
+ />
+ </label>
+ )}
+ </div>
+
+ <div className="text-content-default mt-0.5 text-base font-medium tabular-nums">
+ {plan.name !== "Enterprise" ? (
+ <NumberFlow
+ value={plan.price[isAnnual ? "yearly" : "monthly"]!}
+ format={{
+ style: "currency",
+ currency: "USD",
+ minimumFractionDigits: 0,
+ }}
+ continuous
+ />
+ ) : (
+ "Custom"
+ )}
+ </div>
+ {plan.name !== "Enterprise" && (
+ <span className="text-content-muted text-sm font-medium">
+ per month{isAnnual && ", billed yearly"}
+ </span>
+ )}
+
+ <div className="mt-6 flex flex-col gap-2 text-sm">
+ {features.map(({ id, text, tooltip }) => (
+ <li key={id} className="flex items-center gap-2 text-neutral-600">
+ <Check className="size-2.5 shrink-0 [&_*]:stroke-2" />
+ {tooltip ? (
+ <Tooltip content={<SimpleTooltipContent {...tooltip} />}>
+ <span className="cursor-help underline decoration-dotted underline-offset-2">
+ {text}
+ </span>
+ </Tooltip>
+ ) : (
+ <p>{text}</p>
+ )}
+ </li>
+ ))}
+ </div>
+ </div>
+
+ <div className="relative mt-6 flex flex-col gap-3">
+ {plan.name !== "Enterprise" ? (
+ <UpgradePlanButton
+ plan={plan.name.toLowerCase()}
+ period={isAnnual ? "yearly" : "monthly"}
+ text={`Continue with ${plan.name}`}
+ variant="primary"
+ />
+ ) : (
+ <Link
+ href="https://dub.co/contact/sales"
+ target="_blank"
+ className={cn(
+ "flex h-10 w-full items-center justify-center rounded-md text-center text-sm transition-all duration-200 ease-in-out",
+ "hover:ring-border-subtle border border-black bg-black text-white shadow-sm hover:ring-4",
+ )}
+ >
+ Contact us
+ </Link>
+ )}
+ <Button
+ text="Maybe later"
+ variant="secondary"
+ onClick={() => setShowPartnersUpgradeModal(false)}
+ />
+ </div>
+ </div>
+ </Modal>
+ );
+}
+
+export function usePartnersUpgradeModal(
+ props: Omit<
+ PartnersUpgradeModalProps,
+ "showPartnersUpgradeModal" | "setShowPartnersUpgradeModal"
+ >,
+) {
+ const [showPartnersUpgradeModal, setShowPartnersUpgradeModal] =
+ useState(false);
+
+ return {
+ setShowPartnersUpgradeModal,
+ partnersUpgradeModal: (
+ <PartnersUpgradeModal
+ showPartnersUpgradeModal={showPartnersUpgradeModal}
+ setShowPartnersUpgradeModal={setShowPartnersUpgradeModal}
+ {...props}
+ />
+ ),
+ };
+}
diff --git a/apps/web/ui/partners/rewards/add-edit-reward-sheet.tsx b/apps/web/ui/partners/rewards/add-edit-reward-sheet.tsx
index e99f52404a..2744c63fbe 100644
--- a/apps/web/ui/partners/rewards/add-edit-reward-sheet.tsx
+++ b/apps/web/ui/partners/rewards/add-edit-reward-sheet.tsx
@@ -43,6 +43,7 @@ import { FormProvider, useForm, useFormContext } from "react-hook-form";
import { toast } from "sonner";
import { mutate } from "swr";
import { z } from "zod";
+import { usePartnersUpgradeModal } from "../partners-upgrade-modal";
import {
InlineBadgePopover,
InlineBadgePopoverContext,
@@ -50,7 +51,6 @@ import {
} from "./inline-badge-popover";
import { RewardIconSquare } from "./reward-icon-square";
import { RewardsLogic } from "./rewards-logic";
-import { useRewardsUpgradeModal } from "./rewards-upgrade-modal";
interface RewardSheetProps {
setIsOpen: Dispatch<SetStateAction<boolean>>;
@@ -225,12 +225,16 @@ function RewardSheetContent({ setIsOpen, event, reward }: RewardSheetProps) {
});
};
- const { rewardsUpgradeModal, setShowRewardsUpgradeModal } =
- useRewardsUpgradeModal();
+ const { partnersUpgradeModal, setShowPartnersUpgradeModal } =
+ usePartnersUpgradeModal({
+ plan: "Advanced",
+ description:
+ "When you upgrade to Advanced, you'll get access to higher payout limits, advanced reward structures, white-labeling support, and more.",
+ });
return (
<FormProvider {...form}>
- {rewardsUpgradeModal}
+ {partnersUpgradeModal}
<form
ref={formRef}
onSubmit={handleSubmit(onSubmit)}
@@ -386,7 +390,7 @@ function RewardSheetContent({ setIsOpen, event, reward }: RewardSheetProps) {
<TooltipContent
title="Advanced reward structures are only available on the Advanced plan and above."
cta="Upgrade to Advanced"
- onClick={() => setShowRewardsUpgradeModal(true)}
+ onClick={() => setShowPartnersUpgradeModal(true)}
/>
) : undefined
}
diff --git a/apps/web/ui/partners/rewards/rewards-upgrade-modal.tsx b/apps/web/ui/partners/rewards/rewards-upgrade-modal.tsx
deleted file mode 100644
index aca5e7fbf2..0000000000
--- a/apps/web/ui/partners/rewards/rewards-upgrade-modal.tsx
+++ /dev/null
@@ -1,190 +0,0 @@
-import { UpgradePlanButton } from "@/ui/workspaces/upgrade-plan-button";
-import {
- Button,
- Check,
- Grid,
- Modal,
- SimpleTooltipContent,
- Switch,
- Tooltip,
-} from "@dub/ui";
-import { cn, nFormatter, PLANS } from "@dub/utils";
-import NumberFlow from "@number-flow/react";
-import { Dispatch, SetStateAction, useMemo, useState } from "react";
-
-export function RewardsUpgradeModal({
- showRewardsUpgradeModal,
- setShowRewardsUpgradeModal,
-}: {
- showRewardsUpgradeModal: boolean;
- setShowRewardsUpgradeModal: Dispatch<SetStateAction<boolean>>;
-}) {
- const plan = PLANS.find(({ name }) => name === "Advanced")!;
-
- const [isAnnual, setIsAnnual] = useState(true);
-
- const features = useMemo(
- () => [
- {
- id: "payouts",
- text: `$${nFormatter(plan.limits.payouts / 100)} partner payouts/mo`,
- tooltip: {
- title:
- "Send payouts to your partners with 1-click (or automate it completely) – all across the world.",
- cta: "Learn more.",
- href: "https://dub.co/help/article/partner-payouts",
- },
- },
- {
- id: "flexiblerewards",
- text: "Advanced reward structures",
- tooltip: {
- title:
- "Create dynamic click, lead, or sale-based rewards with country and product-specific modifiers.",
- cta: "Learn more.",
- href: "https://dub.co/help/article/partner-rewards",
- },
- },
- {
- id: "whitelabel",
- text: "White-labeling support",
- tooltip: {
- title:
- "Embed a white-labeled referral dashboard directly in your app in just a few lines of code.",
- cta: "Learn more.",
- href: "https://dub.co/docs/partners/white-labeling",
- },
- },
- {
- id: "email",
- text: "Email campaigns (beta)",
- },
- {
- id: "api",
- text: "Partners API",
- tooltip: {
- title:
- "Leverage our partners API to build a bespoke, white-labeled referral program that lives within your app.",
- cta: "Learn more.",
- href: "https://dub.co/docs/api-reference/endpoint/create-a-partner",
- },
- },
- {
- id: "slack",
- text: "Priority Slack support",
- },
- ],
- [plan],
- );
-
- return (
- <Modal
- showModal={showRewardsUpgradeModal}
- setShowModal={setShowRewardsUpgradeModal}
- >
- <div className="scrollbar-hide relative max-h-[calc(100dvh-50px)] overflow-y-auto p-4 sm:p-8">
- <div className="pointer-events-none absolute inset-y-0 left-1/2 hidden w-[640px] -translate-x-1/2 [mask-image:linear-gradient(black,transparent_280px)] sm:block">
- <Grid cellSize={35} patternOffset={[-29, -10]} />
- </div>
-
- <div className="relative flex flex-col gap-2">
- <div className="flex h-5 w-fit items-center justify-center rounded-md bg-violet-100 px-2 text-xs font-semibold text-violet-600">
- Upgrade to unlock
- </div>
- <h2 className="text-content-emphasis text-lg font-semibold">
- Get even more from your partner program
- </h2>
- <p className="text-content-subtle text-sm">
- When you upgrade to Advanced, you&rsquo;ll get access higher payout
- limits, advanced reward structures, white-labeling support, and
- more.
- </p>
- </div>
-
- <div className="border-default relative mt-6 flex flex-col rounded-xl border bg-white p-6">
- <div className="flex items-center justify-between">
- <span className="text-content-emphasis text-xl font-semibold">
- {plan.name}
- </span>
- <label className="flex items-center gap-1.5">
- <span
- className={cn(
- "text-xs font-semibold text-neutral-500 transition-colors",
- isAnnual && "text-neutral-600",
- )}
- >
- Yearly
- </span>
- <Switch
- checked={isAnnual}
- fn={setIsAnnual}
- trackDimensions="radix-state-checked:bg-black focus-visible:ring-black/20 w-7 h-4"
- thumbDimensions="size-3"
- thumbTranslate="translate-x-3"
- />
- </label>
- </div>
-
- <NumberFlow
- value={plan.price[isAnnual ? "yearly" : "monthly"]!}
- className="text-content-default mt-0.5 text-base font-medium tabular-nums"
- format={{
- style: "currency",
- currency: "USD",
- minimumFractionDigits: 0,
- }}
- continuous
- />
- <span className="text-content-muted text-sm font-medium">
- per month{isAnnual && ", billed yearly"}
- </span>
-
- <div className="mt-6 flex flex-col gap-2 text-sm">
- {features.map(({ id, text, tooltip }) => (
- <li key={id} className="flex items-center gap-2 text-neutral-600">
- <Check className="size-2.5 shrink-0 [&_*]:stroke-2" />
- {tooltip ? (
- <Tooltip content={<SimpleTooltipContent {...tooltip} />}>
- <span className="cursor-help underline decoration-dotted underline-offset-2">
- {text}
- </span>
- </Tooltip>
- ) : (
- <p>{text}</p>
- )}
- </li>
- ))}
- </div>
- </div>
-
- <div className="relative mt-6 flex flex-col gap-3">
- <UpgradePlanButton
- plan={plan.name.toLowerCase()}
- period={isAnnual ? "yearly" : "monthly"}
- text={`Continue with ${plan.name}`}
- variant="primary"
- />
- <Button
- text="Maybe later"
- variant="secondary"
- onClick={() => setShowRewardsUpgradeModal(false)}
- />
- </div>
- </div>
- </Modal>
- );
-}
-
-export function useRewardsUpgradeModal() {
- const [showRewardsUpgradeModal, setShowRewardsUpgradeModal] = useState(false);
-
- return {
- setShowRewardsUpgradeModal,
- rewardsUpgradeModal: (
- <RewardsUpgradeModal
- showRewardsUpgradeModal={showRewardsUpgradeModal}
- setShowRewardsUpgradeModal={setShowRewardsUpgradeModal}
- />
- ),
- };
-}