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 domains button

Steven Tey2688acffdaf4
diff --git a/apps/web/lib/auth/index.ts b/apps/web/lib/auth/index.ts
index d010ca3c82..f1d029c7c0 100644
--- a/apps/web/lib/auth/index.ts
+++ b/apps/web/lib/auth/index.ts
@@ -215,6 +215,7 @@ export const withAuth =
usageLimit: true,
linksUsage: true,
linksLimit: true,
+ domainsLimit: true,
plan: true,
stripeId: true,
billingCycleStart: true,
diff --git a/apps/web/lib/swr/use-project.ts b/apps/web/lib/swr/use-project.ts
index 1a76a62f04..fed65bb1f7 100644
--- a/apps/web/lib/swr/use-project.ts
+++ b/apps/web/lib/swr/use-project.ts
@@ -18,7 +18,8 @@ export default function useProject() {
isOwner: project?.users && project.users[0].role === "owner",
exceededClicks: project && project.usage >= project.usageLimit,
exceededLinks: project && project.linksUsage >= project.linksLimit,
- // exceededDomains: project?.domains && project.domains.length >=
+ exceededDomains:
+ project?.domains && project.domains.length >= project.domainsLimit,
error,
loading: slug && !project && !error,
};
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index 61ec6f3c02..99842a518f 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -45,6 +45,7 @@ export interface ProjectProps {
usageLimit: number;
linksUsage: number;
linksLimit: number;
+ domainsLimit: number;
plan: PlanProps;
stripeId?: string;
billingCycleStart: number;
diff --git a/apps/web/prisma/schema.prisma b/apps/web/prisma/schema.prisma
index 29f2626c7b..e1c43f5b8f 100644
--- a/apps/web/prisma/schema.prisma
+++ b/apps/web/prisma/schema.prisma
@@ -95,6 +95,7 @@ model Project {
usageLimit Int @default(1000)
linksUsage Int @default(0)
linksLimit Int @default(25)
+ domainsLimit Int @default(1)
monitoringId String? @unique // cron job ID for monitoring
sentEmails SentEmail[]
diff --git a/apps/web/ui/links/link-filters.tsx b/apps/web/ui/links/link-filters.tsx
index da9f592d44..cd6b75017a 100644
--- a/apps/web/ui/links/link-filters.tsx
+++ b/apps/web/ui/links/link-filters.tsx
@@ -176,7 +176,6 @@ const SearchBox = ({ searchInputRef }) => {
};
const DomainsFilter = ({ domains, primaryDomain }) => {
- const { slug } = useParams() as { slug?: string };
const searchParams = useSearchParams();
const { queryParams } = useRouterStuff();
@@ -196,9 +195,6 @@ const DomainsFilter = ({ domains, primaryDomain }) => {
}));
}, [domains, primaryDomain]);
- const { setShowAddEditDomainModal, setShowAddProjectModal } =
- useContext(ModalContext);
-
return (
<fieldset className="overflow-hidden py-6">
<div className="flex h-8 items-center justify-between">
@@ -213,21 +209,6 @@ const DomainsFilter = ({ domains, primaryDomain }) => {
/>
<h4 className="font-medium text-gray-900">Domains</h4>
</button>
- <button
- onClick={() => {
- if (slug) {
- setShowAddEditDomainModal(true);
- } else {
- setShowAddProjectModal(true);
- toast.error(
- "You can only add a domain to a custom project. Please create a new project or navigate to an existing one.",
- );
- }
- }}
- className="rounded-md border border-gray-200 px-3 py-1 transition-all hover:border-gray-600 active:bg-gray-100"
- >
- <p className="text-sm text-gray-500">Add</p>
- </button>
</div>
<AnimatePresence initial={false}>
{!collapsed && (
diff --git a/apps/web/ui/modals/add-edit-domain-modal.tsx b/apps/web/ui/modals/add-edit-domain-modal.tsx
index 6533aca2ec..3e0094358a 100644
--- a/apps/web/ui/modals/add-edit-domain-modal.tsx
+++ b/apps/web/ui/modals/add-edit-domain-modal.tsx
@@ -12,7 +12,11 @@ import {
TooltipContent,
useRouterStuff,
} from "@dub/ui";
-import { SHORT_DOMAIN, SWIPE_REVEAL_ANIMATION_SETTINGS } from "@dub/utils";
+import {
+ SHORT_DOMAIN,
+ SWIPE_REVEAL_ANIMATION_SETTINGS,
+ capitalize,
+} from "@dub/utils";
import { AnimatePresence, motion } from "framer-motion";
import { useParams, useRouter } from "next/navigation";
import {
@@ -400,13 +404,33 @@ function AddEditDomainButton({
}: {
setShowAddEditDomainModal: Dispatch<SetStateAction<boolean>>;
}) {
+ const { plan, domainsLimit, exceededDomains } = useProject();
+ const { queryParams } = useRouterStuff();
+
return (
- <button
- onClick={() => setShowAddEditDomainModal(true)}
- className="rounded-md border border-black bg-black px-5 py-2 text-sm font-medium text-white transition-all duration-75 hover:bg-white hover:text-black active:scale-95"
- >
- Add Domain
- </button>
+ <div>
+ <Button
+ text="Add Domain"
+ disabledTooltip={
+ exceededDomains ? (
+ <TooltipContent
+ title={`You can only add up to ${domainsLimit} domains on the ${capitalize(
+ plan,
+ )} plan. Upgrade to add more domains`}
+ cta="Upgrade"
+ onClick={() => {
+ queryParams({
+ set: {
+ upgrade: plan === "free" ? "pro" : "business",
+ },
+ });
+ }}
+ />
+ ) : undefined
+ }
+ onClick={() => setShowAddEditDomainModal(true)}
+ />
+ </div>
);
}