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.

remove slug checks, fix ts errors

Steven Tey505b3c96c867
diff --git a/apps/web/app/api/links/route.ts b/apps/web/app/api/links/route.ts
index 2cffa57769..50a0c80225 100644
--- a/apps/web/app/api/links/route.ts
+++ b/apps/web/app/api/links/route.ts
@@ -10,33 +10,31 @@ import {
import { NextResponse } from "next/server";
// GET /api/links – get all user links
-export const GET = withAuth(
- async ({ headers, searchParams, project, session }) => {
- const { domain, tagId, search, sort, page, userId, showArchived } =
- searchParams as {
- domain?: string;
- tagId?: string;
- search?: string;
- sort?: "createdAt" | "clicks" | "lastClicked";
- page?: string;
- userId?: string;
- showArchived?: string;
- };
- const response = await getLinksForProject({
- projectId: project?.id || DUB_PROJECT_ID,
- domain,
- tagId,
- search,
- sort,
- page,
- userId: project?.id ? userId : session.user.id,
- showArchived: showArchived === "true" ? true : false,
- });
- return NextResponse.json(response, {
- headers,
- });
- },
-);
+export const GET = withAuth(async ({ headers, searchParams, project }) => {
+ const { domain, tagId, search, sort, page, userId, showArchived } =
+ searchParams as {
+ domain?: string;
+ tagId?: string;
+ search?: string;
+ sort?: "createdAt" | "clicks" | "lastClicked";
+ page?: string;
+ userId?: string;
+ showArchived?: string;
+ };
+ const response = await getLinksForProject({
+ projectId: project.id,
+ domain,
+ tagId,
+ search,
+ sort,
+ page,
+ userId,
+ showArchived: showArchived === "true" ? true : false,
+ });
+ return NextResponse.json(response, {
+ headers,
+ });
+});
// POST /api/links – create a new link
export const POST = withAuth(
diff --git a/apps/web/app/api/scim/v2.0/[...directory]/route.ts b/apps/web/app/api/scim/v2.0/[...directory]/route.ts
index 5110cbfa0b..c0f4491b5f 100644
--- a/apps/web/app/api/scim/v2.0/[...directory]/route.ts
+++ b/apps/web/app/api/scim/v2.0/[...directory]/route.ts
@@ -62,7 +62,7 @@ const handleEvents = async (event: DirectorySyncEvent) => {
where: {
id: projectId,
},
- })) as ProjectProps;
+ })) as unknown as ProjectProps;
if (!project || project.plan !== "enterprise" || !("email" in data)) {
return;
diff --git a/apps/web/lib/swr/use-links-count.ts b/apps/web/lib/swr/use-links-count.ts
index 7a61734e75..e151c68e15 100644
--- a/apps/web/lib/swr/use-links-count.ts
+++ b/apps/web/lib/swr/use-links-count.ts
@@ -12,15 +12,16 @@ export default function useLinksCount({
const { getQueryString } = useRouterStuff();
const { data, error } = useSWR<any>(
- `/api/links/count${getQueryString(
- {
- ...(slug && { projectSlug: slug }),
- ...(groupBy && { groupBy }),
- },
- {
- ignore: ["import", "upgrade"],
- },
- )}`,
+ slug &&
+ `/api/links/count${getQueryString(
+ {
+ projectSlug: slug,
+ ...(groupBy && { groupBy }),
+ },
+ {
+ ignore: ["import", "upgrade"],
+ },
+ )}`,
fetcher,
{
dedupingInterval: 30000,
diff --git a/apps/web/lib/swr/use-links.ts b/apps/web/lib/swr/use-links.ts
index 5eb8104b34..f9d673ea7b 100644
--- a/apps/web/lib/swr/use-links.ts
+++ b/apps/web/lib/swr/use-links.ts
@@ -14,9 +14,13 @@ export default function useLinks() {
user: UserProps;
})[]
>(
- `/api/links${getQueryString(slug ? { projectSlug: slug } : undefined, {
- ignore: ["import", "upgrade"],
- })}`,
+ slug &&
+ `/api/links${getQueryString(
+ { projectSlug: slug },
+ {
+ ignore: ["import", "upgrade"],
+ },
+ )}`,
fetcher,
{
dedupingInterval: 20000,
diff --git a/apps/web/lib/swr/use-tags.ts b/apps/web/lib/swr/use-tags.ts
index 8156e76394..7583d9b362 100644
--- a/apps/web/lib/swr/use-tags.ts
+++ b/apps/web/lib/swr/use-tags.ts
@@ -15,7 +15,7 @@ export default function useTags() {
);
return {
- tags: slug ? tags : [],
+ tags,
loading: tags ? false : true,
isValidating,
};
diff --git a/apps/web/ui/links/link-card.tsx b/apps/web/ui/links/link-card.tsx
index 60d18e5468..eaffafca01 100644
--- a/apps/web/ui/links/link-card.tsx
+++ b/apps/web/ui/links/link-card.tsx
@@ -87,9 +87,7 @@ export default function LinkCard({
const { data: clicks } = useSWR<number>(
isVisible &&
!exceededClicks &&
- `/api${
- slug ? `/projects/${slug}` : ""
- }/stats/clicks?domain=${domain}&key=${key}`,
+ `/api/projects/${slug}/stats/clicks?domain=${domain}&key=${key}`,
fetcher,
{
fallbackData: props.clicks,
@@ -399,9 +397,7 @@ export default function LinkCard({
<div className="flex items-center space-x-2">
<NumberTooltip value={clicks} lastClicked={lastClicked}>
<Link
- href={`${
- slug ? `/${slug}` : ""
- }/analytics?domain=${domain}&key=${key}`}
+ href={`/${slug}/analytics?domain=${domain}&key=${key}`}
className="flex items-center space-x-1 rounded-md bg-gray-100 px-2 py-0.5 transition-all duration-75 hover:scale-105 active:scale-100"
>
<Chart className="h-4 w-4" />
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 10b89308ac..0372bd283f 100644
--- a/apps/web/ui/modals/add-edit-link-modal/index.tsx
+++ b/apps/web/ui/modals/add-edit-link-modal/index.tsx
@@ -105,9 +105,7 @@ function AddEditLinkModal({
debouncedKey.toLowerCase() !== props?.key.toLowerCase()
) {
fetch(
- `/api/links/exists?domain=${domain}&key=${debouncedKey}${
- slug ? `&projectSlug=${slug}` : ""
- }`,
+ `/api/links/exists?domain=${domain}&key=${debouncedKey}&projectSlug=${slug}`,
).then(async (res) => {
if (res.status === 200) {
const exists = await res.json();
@@ -123,7 +121,7 @@ function AddEditLinkModal({
setKeyError(null);
setGeneratingKey(true);
const res = await fetch(
- `/api/links/random?domain=${domain}${slug ? `&projectSlug=${slug}` : ""}`,
+ `/api/links/random?domain=${domain}&projectSlug=${slug}`,
);
const key = await res.json();
setData((prev) => ({ ...prev, key }));
@@ -218,12 +216,12 @@ function AddEditLinkModal({
if (props?.key) {
return {
method: "PUT",
- url: `/api/links/${props.id}${slug ? `?projectSlug=${slug}` : ""}`,
+ url: `/api/links/${props.id}?projectSlug=${slug}`,
};
} else {
return {
method: "POST",
- url: `/api/links${slug ? `?projectSlug=${slug}` : ""}`,
+ url: `/api/links?projectSlug=${slug}`,
};
}
}, [props, slug, domain]);
diff --git a/apps/web/ui/modals/archive-link-modal.tsx b/apps/web/ui/modals/archive-link-modal.tsx
index 87b63d3fd8..5ae918f1b5 100644
--- a/apps/web/ui/modals/archive-link-modal.tsx
+++ b/apps/web/ui/modals/archive-link-modal.tsx
@@ -16,8 +16,7 @@ import { mutate } from "swr";
const sendArchiveRequest = (archived: boolean, id: string, slug?: string) => {
const baseUrl = `/api/links/${id}/archive`;
- const queryString = slug ? `?projectSlug=${slug}` : "";
- return fetch(`${baseUrl}${queryString}`, {
+ return fetch(`${baseUrl}?projectSlug=${slug}`, {
method: archived ? "POST" : "DELETE",
headers: {
"Content-Type": "application/json",
diff --git a/apps/web/ui/modals/delete-link-modal.tsx b/apps/web/ui/modals/delete-link-modal.tsx
index 707c7cbb0b..e26c7ca140 100644
--- a/apps/web/ui/modals/delete-link-modal.tsx
+++ b/apps/web/ui/modals/delete-link-modal.tsx
@@ -62,7 +62,7 @@ function DeleteLinkModal({
onSubmit={async (e) => {
e.preventDefault();
setDeleting(true);
- fetch(`/api/links/${props.id}${slug ? `?projectSlug=${slug}` : ""}`, {
+ fetch(`/api/links/${props.id}?projectSlug=${slug}`, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
diff --git a/apps/web/ui/modals/link-qr-modal.tsx b/apps/web/ui/modals/link-qr-modal.tsx
index 47f9ace444..1d04a1e90a 100644
--- a/apps/web/ui/modals/link-qr-modal.tsx
+++ b/apps/web/ui/modals/link-qr-modal.tsx
@@ -2,7 +2,6 @@
import { QRCodeSVG, getQRAsCanvas, getQRAsSVGDataUri } from "@/lib/qr";
import useProject from "@/lib/swr/use-project";
-import { ModalContext } from "@/ui/modals/provider";
import { BlurImage } from "@/ui/shared/blur-image";
import { Clipboard, Download } from "@/ui/shared/icons";
import {
@@ -32,7 +31,6 @@ import {
Dispatch,
SetStateAction,
useCallback,
- useContext,
useMemo,
useRef,
useState,
@@ -242,8 +240,6 @@ function AdvancedSettings({
setFgColor(color);
}, 100);
- const { setShowAddProjectModal } = useContext(ModalContext);
-
const { queryParams } = useRouterStuff();
return (
@@ -274,7 +270,7 @@ function AdvancedSettings({
className="flex items-center space-x-1"
>
<p className="text-sm font-medium text-gray-700">Logo</p>
- {plan && plan !== "free" && (
+ {plan !== "free" && (
<InfoTooltip
content={
<SimpleTooltipContent
@@ -286,7 +282,7 @@ function AdvancedSettings({
/>
)}
</label>
- {plan && plan !== "free" ? (
+ {plan !== "free" ? (
<div className="mt-1 flex items-center space-x-2">
<Switch
fn={setShowLogo}
@@ -304,21 +300,17 @@ function AdvancedSettings({
<Tooltip
content={
<TooltipContent
- title="You need to be on the Pro plan to customize your QR Code logo."
- cta={slug ? "Upgrade to Pro" : "Create a project"}
+ title="You need to be on the Pro plan and above to customize your QR Code logo."
+ cta="Upgrade to Pro"
{...(APP_HOSTNAMES.has(window.location.hostname)
? {
onClick: () => {
setShowLinkQRModal(false);
- if (slug) {
- queryParams({
- set: {
- upgrade: "pro",
- },
- });
- } else {
- setShowAddProjectModal(true);
- }
+ queryParams({
+ set: {
+ upgrade: "pro",
+ },
+ });
},
}
: { href: `${HOME_DOMAIN}/pricing` })}
diff --git a/apps/web/ui/stats/link-preview.tsx b/apps/web/ui/stats/link-preview.tsx
index 77469af101..4170b5e036 100644
--- a/apps/web/ui/stats/link-preview.tsx
+++ b/apps/web/ui/stats/link-preview.tsx
@@ -30,9 +30,7 @@ export default function LinkPreviewTooltip({
}
>(
key
- ? `/api/links/info?domain=${domain}&key=${key}${
- slug ? `&projectSlug=${slug}` : ""
- }`
+ ? `/api/links/info?domain=${domain}&key=${key}&projectSlug=${slug}`
: `/api/projects/${slug}/domains/${domain}`,
fetcher,
{
diff --git a/apps/web/ui/stats/toggle.tsx b/apps/web/ui/stats/toggle.tsx
index b5ca400304..3338a1d95a 100644
--- a/apps/web/ui/stats/toggle.tsx
+++ b/apps/web/ui/stats/toggle.tsx
@@ -71,44 +71,28 @@ export default function Toggle() {
})}
>
<div className="mx-auto flex h-20 max-w-4xl flex-col items-center justify-between space-y-3 px-2.5 md:h-10 md:flex-row md:space-y-0 lg:px-0">
- {slug ? (
- <div className="flex items-center space-x-2">
- <BlurImage
- alt={name || "Project Logo"}
- src={logo || DUB_LOGO}
- className="h-6 w-6 flex-shrink-0 overflow-hidden rounded-full"
- width={48}
- height={48}
- />
- <h2 className="text-lg font-semibold text-gray-800">
- {primaryDomain}
- </h2>
- {domains && domains?.length > 1 && (
- <Tooltip
- content={<DomainsFilterTooltip domains={domains} />}
- side="bottom"
- >
- <div className="cursor-pointer">
- <Badge variant="gray">+{domains.length - 1}</Badge>
- </div>
- </Tooltip>
- )}
- </div>
- ) : domain && key ? (
- <a
- className="group flex text-lg font-semibold text-gray-800 md:text-xl"
- href={linkConstructor({ domain, key })}
- target="_blank"
- rel="noreferrer"
- >
- {linkConstructor({
- domain: punycode.toUnicode(domain),
- key,
- pretty: true,
- })}
- <ExpandingArrow className="h-5 w-5" />
- </a>
- ) : null}
+ <div className="flex items-center space-x-2">
+ <BlurImage
+ alt={name || "Project Logo"}
+ src={logo || DUB_LOGO}
+ className="h-6 w-6 flex-shrink-0 overflow-hidden rounded-full"
+ width={48}
+ height={48}
+ />
+ <h2 className="text-lg font-semibold text-gray-800">
+ {primaryDomain}
+ </h2>
+ {domains && domains?.length > 1 && (
+ <Tooltip
+ content={<DomainsFilterTooltip domains={domains} />}
+ side="bottom"
+ >
+ <div className="cursor-pointer">
+ <Badge variant="gray">+{domains.length - 1}</Badge>
+ </div>
+ </Tooltip>
+ )}
+ </div>
<div className="flex items-center">
{!isPublicStatsPage && key && key !== "_root" && <SharePopover />}
<Popover
@@ -126,7 +110,7 @@ export default function Toggle() {
? `${display} stats can only be viewed on a Pro plan or higher. Upgrade now to view all-time stats.`
: `${display} stats can only be viewed on a project with a Pro plan or higher. Create a project or navigate to an existing project to upgrade.`
}
- cta={slug ? "Upgrade to Pro" : "Create Project"}
+ cta="Upgrade to Pro"
{...(isPublicStatsPage
? {
href: APP_DOMAIN,
@@ -134,16 +118,12 @@ export default function Toggle() {
: {
onClick: () => {
setOpenDatePopover(false);
- if (slug) {
- queryParams({
- set: {
- upgrade:
- plan === "free" ? "pro" : "business",
- },
- });
- } else {
- setShowAddProjectModal(true);
- }
+ queryParams({
+ set: {
+ upgrade:
+ plan === "free" ? "pro" : "business",
+ },
+ });
},
})}
/>