Skip to content

Commit be655ab

Browse files
committed
fix some more bugs
1 parent fb4a2f4 commit be655ab

File tree

6 files changed

+29
-23
lines changed

6 files changed

+29
-23
lines changed

apps/web/lib/api/links/process-link.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { isStored } from "@/lib/storage";
1010
import { NewLinkProps, ProcessedLinkProps, WorkspaceProps } from "@/lib/types";
1111
import {
1212
DUB_DOMAINS,
13-
SHORT_DOMAIN,
1413
combineWords,
1514
getApexDomain,
1615
getDomainWithoutWWW,
@@ -141,7 +140,7 @@ export async function processLink<T extends Record<string, any>>({
141140

142141
// if domain is not defined, set it to the workspace's primary domain
143142
if (!domain) {
144-
domain = domains?.find((d) => d.primary)?.slug || SHORT_DOMAIN;
143+
domain = domains?.find((d) => d.primary)?.slug || "dub.sh";
145144
}
146145

147146
// checks for dub.sh links

apps/web/lib/api/links/utils.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { checkIfKeyExists } from "@/lib/planetscale";
77
import { WorkspaceProps } from "@/lib/types";
88
import {
99
DEFAULT_REDIRECTS,
10-
SHORT_DOMAIN,
1110
isDubDomain,
1211
linkConstructor,
1312
punyEncode,
@@ -46,7 +45,7 @@ export async function keyChecks({
4645
key: string;
4746
workspace?: Pick<WorkspaceProps, "plan">;
4847
}): Promise<{ error: string | null; code?: DubApiError["code"] }> {
49-
if (key.length === 0) {
48+
if (key.length === 0 || key === "_root") {
5049
if (workspace?.plan === "free") {
5150
return {
5251
error:
@@ -71,7 +70,7 @@ export async function keyChecks({
7170
}
7271

7372
if (isDubDomain(domain) && process.env.NEXT_PUBLIC_IS_DUB) {
74-
if (domain === SHORT_DOMAIN) {
73+
if (domain === "dub.sh") {
7574
if (DEFAULT_REDIRECTS[key] || (await isReservedKey(key))) {
7675
return {
7776
error: "Duplicate key: This short link already exists.",
@@ -92,6 +91,16 @@ export async function keyChecks({
9291
code: "forbidden",
9392
};
9493
}
94+
if (
95+
domain === "dub.link" &&
96+
key.length <= 5 &&
97+
(!workspace || workspace.plan === "free" || workspace.plan === "pro")
98+
) {
99+
return {
100+
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.`,
101+
code: "forbidden",
102+
};
103+
}
95104
if (
96105
(await isReservedUsername(key)) &&
97106
(!workspace || workspace.plan === "free")

apps/web/lib/swr/use-domains.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { useRouterStuff } from "@dub/ui";
33
import {
44
DUB_DOMAINS,
55
DUB_WORKSPACE_ID,
6-
PREMIUM_SHORT_DOMAIN,
76
SHORT_DOMAIN,
87
fetcher,
98
} from "@dub/utils";
@@ -59,10 +58,8 @@ export default function useDomains({
5958
activeWorkspaceDomains.find(({ primary }) => primary)?.slug ||
6059
activeWorkspaceDomains[0].slug
6160
);
62-
} else if (
63-
activeDefaultDomains.find(({ slug }) => slug === PREMIUM_SHORT_DOMAIN)
64-
) {
65-
return PREMIUM_SHORT_DOMAIN;
61+
} else if (activeDefaultDomains.find(({ slug }) => slug === "dub.link")) {
62+
return "dub.link";
6663
}
6764
return SHORT_DOMAIN;
6865
}, [activeDefaultDomains, activeWorkspaceDomains]);

apps/web/ui/links/link-details-column.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
useMediaQuery,
1111
useRouterStuff,
1212
} from "@dub/ui";
13-
import { CursorRays, InvoiceDollar, LinesY } from "@dub/ui/src/icons";
13+
import { CursorRays, InvoiceDollar } from "@dub/ui/src/icons";
1414
import { cn, fetcher, nFormatter, timeAgo } from "@dub/utils";
1515
import Link from "next/link";
1616
import { useSearchParams } from "next/navigation";
@@ -137,12 +137,14 @@ function AnalyticsBadge({ link }: { link: ResponseLink }) {
137137

138138
const { id: workspaceId, slug, exceededClicks } = useWorkspace();
139139
const { isMobile } = useMediaQuery();
140+
const { variant } = useContext(CardList.Context);
140141

141142
const { data: totalEvents } = useSWR<{
142143
[key in CompositeAnalyticsResponseOptions]?: number;
143144
}>(
144145
// Only fetch data if there's a slug and the usage is not exceeded
145146
workspaceId &&
147+
variant === "loose" &&
146148
!exceededClicks &&
147149
`/api/analytics?event=composite&workspaceId=${workspaceId}&linkId=${id}&interval=all_unfiltered`,
148150
fetcher,
@@ -159,14 +161,12 @@ function AnalyticsBadge({ link }: { link: ResponseLink }) {
159161
const [hoveredId, setHoveredId] = useState<string>("clicks");
160162
const hoveredValue = totalEvents?.[hoveredId];
161163

162-
const { variant } = useContext(CardList.Context);
163-
164164
return isMobile ? (
165165
<Link
166166
href={`/${slug}/analytics?domain=${domain}&key=${key}`}
167167
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"
168168
>
169-
<LinesY className="h-4 w-4 text-gray-600" />
169+
<CursorRays className="h-4 w-4 text-gray-600" />
170170
{nFormatter(totalEvents?.clicks)}
171171
</Link>
172172
) : (

apps/web/ui/modals/add-edit-link-modal/index.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ function AddEditLinkModal({
8484
const { slug } = params;
8585
const {
8686
id: workspaceId,
87+
nextPlan,
8788
aiUsage,
8889
aiLimit,
8990
mutate: mutateWorkspace,
@@ -435,10 +436,10 @@ function AddEditLinkModal({
435436
} else {
436437
const { error } = await res.json();
437438
if (error) {
438-
if (error.message.includes("Upgrade to Pro")) {
439+
if (error.message.includes("Upgrade to")) {
439440
toast.custom(() => (
440441
<UpgradeRequiredToast
441-
title="You've discovered a Pro feature!"
442+
title={`You've discovered a ${nextPlan.name} feature!`}
442443
message={error.message}
443444
/>
444445
));
@@ -714,18 +715,20 @@ function AddEditLinkModal({
714715
)}
715716
</div>
716717
{keyError ? (
717-
keyError.includes("Upgrade to Pro") ? (
718+
keyError.includes("Upgrade to") ? (
718719
<p className="mt-2 text-sm text-red-600" id="key-error">
719-
{keyError.split("Upgrade to Pro")[0]}
720+
{keyError.split(`Upgrade to ${nextPlan.name}`)[0]}
720721
<span
721722
className="cursor-pointer underline"
722723
onClick={() =>
723-
queryParams({ set: { upgrade: "pro" } })
724+
queryParams({
725+
set: { upgrade: nextPlan.name.toLowerCase() },
726+
})
724727
}
725728
>
726-
Upgrade to Pro
729+
Upgrade to {nextPlan.name}
727730
</span>
728-
{keyError.split("Upgrade to Pro")[1]}
731+
{keyError.split(`Upgrade to ${nextPlan.name}`)[1]}
729732
</p>
730733
) : (
731734
<p className="mt-2 text-sm text-red-600" id="key-error">

packages/utils/src/constants/main.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ export const APP_NAME = process.env.NEXT_PUBLIC_APP_NAME || "Dub.co";
33
export const SHORT_DOMAIN =
44
process.env.NEXT_PUBLIC_APP_SHORT_DOMAIN || "dub.sh";
55

6-
export const PREMIUM_SHORT_DOMAIN = "dub.link";
7-
86
export const HOME_DOMAIN = `https://${process.env.NEXT_PUBLIC_APP_DOMAIN}`;
97

108
export const APP_HOSTNAMES = new Set([

0 commit comments

Comments
 (0)