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.

fix some more bugs

Steven Teybe655abaf3b5
diff --git a/apps/web/lib/api/links/process-link.ts b/apps/web/lib/api/links/process-link.ts
index 09de0967fd..028abe1c2c 100644
--- a/apps/web/lib/api/links/process-link.ts
+++ b/apps/web/lib/api/links/process-link.ts
@@ -10,7 +10,6 @@ import { isStored } from "@/lib/storage";
import { NewLinkProps, ProcessedLinkProps, WorkspaceProps } from "@/lib/types";
import {
DUB_DOMAINS,
- SHORT_DOMAIN,
combineWords,
getApexDomain,
getDomainWithoutWWW,
@@ -141,7 +140,7 @@ export async function processLink<T extends Record<string, any>>({
// if domain is not defined, set it to the workspace's primary domain
if (!domain) {
- domain = domains?.find((d) => d.primary)?.slug || SHORT_DOMAIN;
+ domain = domains?.find((d) => d.primary)?.slug || "dub.sh";
}
// checks for dub.sh links
diff --git a/apps/web/lib/api/links/utils.ts b/apps/web/lib/api/links/utils.ts
index 5699ae55b4..26a1f62630 100644
--- a/apps/web/lib/api/links/utils.ts
+++ b/apps/web/lib/api/links/utils.ts
@@ -7,7 +7,6 @@ import { checkIfKeyExists } from "@/lib/planetscale";
import { WorkspaceProps } from "@/lib/types";
import {
DEFAULT_REDIRECTS,
- SHORT_DOMAIN,
isDubDomain,
linkConstructor,
punyEncode,
@@ -46,7 +45,7 @@ export async function keyChecks({
key: string;
workspace?: Pick<WorkspaceProps, "plan">;
}): Promise<{ error: string | null; code?: DubApiError["code"] }> {
- if (key.length === 0) {
+ if (key.length === 0 || key === "_root") {
if (workspace?.plan === "free") {
return {
error:
@@ -71,7 +70,7 @@ export async function keyChecks({
}
if (isDubDomain(domain) && process.env.NEXT_PUBLIC_IS_DUB) {
- if (domain === SHORT_DOMAIN) {
+ if (domain === "dub.sh") {
if (DEFAULT_REDIRECTS[key] || (await isReservedKey(key))) {
return {
error: "Duplicate key: This short link already exists.",
@@ -92,6 +91,16 @@ export async function keyChecks({
code: "forbidden",
};
}
+ if (
+ domain === "dub.link" &&
+ key.length <= 5 &&
+ (!workspace || workspace.plan === "free" || workspace.plan === "pro")
+ ) {
+ return {
+ error: `You can only use dub.link with keys that are 5 characters or less on a Business plan and above. Upgrade to Business to register a ${key.length}-character dub.link key.`,
+ code: "forbidden",
+ };
+ }
if (
(await isReservedUsername(key)) &&
(!workspace || workspace.plan === "free")
diff --git a/apps/web/lib/swr/use-domains.ts b/apps/web/lib/swr/use-domains.ts
index 777579efa4..ef608ee667 100644
--- a/apps/web/lib/swr/use-domains.ts
+++ b/apps/web/lib/swr/use-domains.ts
@@ -3,7 +3,6 @@ import { useRouterStuff } from "@dub/ui";
import {
DUB_DOMAINS,
DUB_WORKSPACE_ID,
- PREMIUM_SHORT_DOMAIN,
SHORT_DOMAIN,
fetcher,
} from "@dub/utils";
@@ -59,10 +58,8 @@ export default function useDomains({
activeWorkspaceDomains.find(({ primary }) => primary)?.slug ||
activeWorkspaceDomains[0].slug
);
- } else if (
- activeDefaultDomains.find(({ slug }) => slug === PREMIUM_SHORT_DOMAIN)
- ) {
- return PREMIUM_SHORT_DOMAIN;
+ } else if (activeDefaultDomains.find(({ slug }) => slug === "dub.link")) {
+ return "dub.link";
}
return SHORT_DOMAIN;
}, [activeDefaultDomains, activeWorkspaceDomains]);
diff --git a/apps/web/ui/links/link-details-column.tsx b/apps/web/ui/links/link-details-column.tsx
index d1212c9d95..5ac02eb12c 100644
--- a/apps/web/ui/links/link-details-column.tsx
+++ b/apps/web/ui/links/link-details-column.tsx
@@ -10,7 +10,7 @@ import {
useMediaQuery,
useRouterStuff,
} from "@dub/ui";
-import { CursorRays, InvoiceDollar, LinesY } from "@dub/ui/src/icons";
+import { CursorRays, InvoiceDollar } from "@dub/ui/src/icons";
import { cn, fetcher, nFormatter, timeAgo } from "@dub/utils";
import Link from "next/link";
import { useSearchParams } from "next/navigation";
@@ -137,12 +137,14 @@ function AnalyticsBadge({ link }: { link: ResponseLink }) {
const { id: workspaceId, slug, exceededClicks } = useWorkspace();
const { isMobile } = useMediaQuery();
+ const { variant } = useContext(CardList.Context);
const { data: totalEvents } = useSWR<{
[key in CompositeAnalyticsResponseOptions]?: number;
}>(
// Only fetch data if there's a slug and the usage is not exceeded
workspaceId &&
+ variant === "loose" &&
!exceededClicks &&
`/api/analytics?event=composite&workspaceId=${workspaceId}&linkId=${id}&interval=all_unfiltered`,
fetcher,
@@ -159,14 +161,12 @@ function AnalyticsBadge({ link }: { link: ResponseLink }) {
const [hoveredId, setHoveredId] = useState<string>("clicks");
const hoveredValue = totalEvents?.[hoveredId];
- const { variant } = useContext(CardList.Context);
-
return isMobile ? (
<Link
href={`/${slug}/analytics?domain=${domain}&key=${key}`}
className="flex items-center gap-1 rounded-md border border-gray-200 bg-gray-50 px-2 py-0.5 text-sm text-gray-800"
>
- <LinesY className="h-4 w-4 text-gray-600" />
+ <CursorRays className="h-4 w-4 text-gray-600" />
{nFormatter(totalEvents?.clicks)}
</Link>
) : (
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 55e75df520..53e1d8a631 100644
--- a/apps/web/ui/modals/add-edit-link-modal/index.tsx
+++ b/apps/web/ui/modals/add-edit-link-modal/index.tsx
@@ -84,6 +84,7 @@ function AddEditLinkModal({
const { slug } = params;
const {
id: workspaceId,
+ nextPlan,
aiUsage,
aiLimit,
mutate: mutateWorkspace,
@@ -435,10 +436,10 @@ function AddEditLinkModal({
} else {
const { error } = await res.json();
if (error) {
- if (error.message.includes("Upgrade to Pro")) {
+ if (error.message.includes("Upgrade to")) {
toast.custom(() => (
<UpgradeRequiredToast
- title="You've discovered a Pro feature!"
+ title={`You've discovered a ${nextPlan.name} feature!`}
message={error.message}
/>
));
@@ -714,18 +715,20 @@ function AddEditLinkModal({
)}
</div>
{keyError ? (
- keyError.includes("Upgrade to Pro") ? (
+ keyError.includes("Upgrade to") ? (
<p className="mt-2 text-sm text-red-600" id="key-error">
- {keyError.split("Upgrade to Pro")[0]}
+ {keyError.split(`Upgrade to ${nextPlan.name}`)[0]}
<span
className="cursor-pointer underline"
onClick={() =>
- queryParams({ set: { upgrade: "pro" } })
+ queryParams({
+ set: { upgrade: nextPlan.name.toLowerCase() },
+ })
}
>
- Upgrade to Pro
+ Upgrade to {nextPlan.name}
</span>
- {keyError.split("Upgrade to Pro")[1]}
+ {keyError.split(`Upgrade to ${nextPlan.name}`)[1]}
</p>
) : (
<p className="mt-2 text-sm text-red-600" id="key-error">
diff --git a/packages/utils/src/constants/main.ts b/packages/utils/src/constants/main.ts
index 25b07ea10e..a598c86dbf 100644
--- a/packages/utils/src/constants/main.ts
+++ b/packages/utils/src/constants/main.ts
@@ -3,8 +3,6 @@ export const APP_NAME = process.env.NEXT_PUBLIC_APP_NAME || "Dub.co";
export const SHORT_DOMAIN =
process.env.NEXT_PUBLIC_APP_SHORT_DOMAIN || "dub.sh";
-export const PREMIUM_SHORT_DOMAIN = "dub.link";
-
export const HOME_DOMAIN = `https://${process.env.NEXT_PUBLIC_APP_DOMAIN}`;
export const APP_HOSTNAMES = new Set([