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.

allow creating link for a domain

Kiran K6f8a89fa89b1
diff --git a/apps/web/lib/api/links/process-link.ts b/apps/web/lib/api/links/process-link.ts
index 76880f8c73..79a1c44a4c 100644
--- a/apps/web/lib/api/links/process-link.ts
+++ b/apps/web/lib/api/links/process-link.ts
@@ -92,6 +92,15 @@ export async function processLink<T extends Record<string, any>>({
(!workspace || workspace.plan === "free") &&
(!createdAt || new Date(createdAt) > new Date("2024-01-19"))
) {
+ if (key === "_root") {
+ return {
+ link: payload,
+ error:
+ "You can only create root links on a Pro plan and above. Upgrade to Pro to use this feature.",
+ code: "unprocessable_entity",
+ };
+ }
+
if (proxy || password || rewrite || expiresAt || ios || android || geo) {
const proFeaturesString = [
proxy && "custom social media cards",
diff --git a/apps/web/lib/api/links/utils.ts b/apps/web/lib/api/links/utils.ts
index 0490580a8d..19490912be 100644
--- a/apps/web/lib/api/links/utils.ts
+++ b/apps/web/lib/api/links/utils.ts
@@ -109,6 +109,11 @@ export async function keyChecks({
}
export function processKey(key: string) {
+ // Skip if root domain
+ if (key === "_root") {
+ return key;
+ }
+
if (!validKeyRegex.test(key)) {
return null;
}
diff --git a/apps/web/ui/domains/domain-card.tsx b/apps/web/ui/domains/domain-card.tsx
index 88d1bfdb84..196358bcd4 100644
--- a/apps/web/ui/domains/domain-card.tsx
+++ b/apps/web/ui/domains/domain-card.tsx
@@ -47,7 +47,7 @@ import { useTransferDomainModal } from "../modals/transfer-domain-modal";
import DomainConfiguration from "./domain-configuration";
export default function DomainCard({ props }: { props: DomainProps }) {
- const { id: workspaceId, slug } = useWorkspace();
+ const { id: workspaceId, slug, plan } = useWorkspace();
const { activeWorkspaceDomains } = useDomains();
const { slug: domain, primary, archived } = props || {};
@@ -60,7 +60,7 @@ export default function DomainCard({ props }: { props: DomainProps }) {
);
const { setShowAddEditLinkModal, AddEditLinkModal } = useAddEditLinkModal({
- props: linkProps || DEFAULT_LINK_PROPS,
+ props: linkProps || { ...DEFAULT_LINK_PROPS, key: "_root", domain },
});
const { setShowLinkQRModal, LinkQRModal } = useLinkQRModal({
@@ -188,39 +188,63 @@ export default function DomainCard({ props }: { props: DomainProps }) {
content={
<div className="w-full sm:w-44">
<div className="grid gap-px p-2">
- <Button
- text="Edit Link"
- variant="outline"
- onClick={() => {
- setOpenPopover(false);
- setShowAddEditLinkModal(true);
- }}
- icon={<Edit3 className="h-4 w-4" />}
- className="h-9 justify-start px-2 font-medium"
- />
- <Button
- text="QR Code"
- variant="outline"
- onClick={() => {
- setOpenPopover(false);
- setShowLinkQRModal(true);
- }}
- icon={<QrCode className="h-4 w-4" />}
- className="h-9 justify-start px-2 font-medium"
- />
- <Button
- text="Copy Link ID"
- variant="outline"
- onClick={() => copyLinkId()}
- icon={
- copiedLinkId ? (
- <CheckCircleFill className="h-4 w-4" />
- ) : (
- <Copy className="h-4 w-4" />
- )
- }
- className="h-9 justify-start px-2 font-medium"
- />
+ {linkProps?.url ? (
+ <>
+ <Button
+ text="Edit Link"
+ variant="outline"
+ onClick={() => {
+ setOpenPopover(false);
+ setShowAddEditLinkModal(true);
+ }}
+ icon={<Edit3 className="h-4 w-4" />}
+ className="h-9 justify-start px-2 font-medium"
+ />
+ <Button
+ text="QR Code"
+ variant="outline"
+ onClick={() => {
+ setOpenPopover(false);
+ setShowLinkQRModal(true);
+ }}
+ icon={<QrCode className="h-4 w-4" />}
+ className="h-9 justify-start px-2 font-medium"
+ />
+ <Button
+ text="Copy Link ID"
+ variant="outline"
+ onClick={() => copyLinkId()}
+ icon={
+ copiedLinkId ? (
+ <CheckCircleFill className="h-4 w-4" />
+ ) : (
+ <Copy className="h-4 w-4" />
+ )
+ }
+ className="h-9 justify-start px-2 font-medium"
+ />
+ </>
+ ) : (
+ <Button
+ text="Create Link"
+ variant="outline"
+ icon={<Edit3 className="h-4 w-4" />}
+ className="h-9 justify-start px-2 font-medium"
+ onClick={() => {
+ setOpenPopover(false);
+ setShowAddEditLinkModal(true);
+ }}
+ {...(plan === "free" && {
+ disabledTooltip: (
+ <SimpleTooltipContent
+ title="You can only create root links on a Pro plan and above. Upgrade to Pro to use this feature."
+ cta="Learn more."
+ href="https://dub.co/help/article/how-to-redirect-root-domain"
+ />
+ ),
+ })}
+ />
+ )}
</div>
<div className="border-t border-gray-200" />
<div className="grid gap-px p-2">
diff --git a/apps/web/ui/modals/add-edit-link-modal/index.tsx b/apps/web/ui/modals/add-edit-link-modal/index.tsx
index f1f5b6352a..5c26d730f5 100644
--- a/apps/web/ui/modals/add-edit-link-modal/index.tsx
+++ b/apps/web/ui/modals/add-edit-link-modal/index.tsx
@@ -260,7 +260,7 @@ function AddEditLinkModal({
}, [debouncedUrl, password, showAddEditLinkModal]);
const endpoint = useMemo(() => {
- if (props?.key) {
+ if (props?.id) {
return {
method: "PATCH",
url: `/api/links/${props.id}?workspaceId=${workspaceId}`,