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.

Convert `notFound()` to `redirect()`

Steven Tey6de9933326b4
diff --git a/apps/web/app/(ee)/app.dub.co/(new-program)/[slug]/program/new/connect/[[...guide]]/page.tsx b/apps/web/app/(ee)/app.dub.co/(new-program)/[slug]/program/new/connect/[[...guide]]/page.tsx
index 8e51076e5c..b8f7fb1ab7 100644
--- a/apps/web/app/(ee)/app.dub.co/(new-program)/[slug]/program/new/connect/[[...guide]]/page.tsx
+++ b/apps/web/app/(ee)/app.dub.co/(new-program)/[slug]/program/new/connect/[[...guide]]/page.tsx
@@ -2,13 +2,14 @@ import { getIntegrationGuideMarkdown } from "@/lib/get-integration-guide-markdow
import { Guide } from "@/ui/guides/guide";
import { GuideList } from "@/ui/guides/guide-list";
import { guides, IntegrationGuide } from "@/ui/guides/integrations";
-import { notFound } from "next/navigation";
+import { redirect } from "next/navigation";
import { StepPage } from "../../step-page";
export default async function ConnectGuidesPage({
- params: { guide },
+ params: { slug, guide },
}: {
params: {
+ slug: string;
guide?: string[];
};
}) {
@@ -20,13 +21,13 @@ export default async function ConnectGuidesPage({
guides.find((g) => g.key === guide[0].toLowerCase()) ?? null;
if (!selectedGuide) {
- notFound();
+ redirect(`/${slug}/program/new/connect`);
}
markdownContent = await getIntegrationGuideMarkdown(selectedGuide.key);
if (!markdownContent) {
- notFound();
+ redirect(`/${slug}/program/new/connect`);
}
}
diff --git a/apps/web/app/(ee)/app.dub.co/(new-program)/sidebar-context.tsx b/apps/web/app/(ee)/app.dub.co/(new-program)/sidebar-context.tsx
index fcf37f4072..be1a8eff49 100644
--- a/apps/web/app/(ee)/app.dub.co/(new-program)/sidebar-context.tsx
+++ b/apps/web/app/(ee)/app.dub.co/(new-program)/sidebar-context.tsx
@@ -2,7 +2,7 @@
import useWorkspace from "@/lib/swr/use-workspace";
import LayoutLoader from "@/ui/layout/layout-loader";
-import { notFound, useRouter } from "next/navigation";
+import { redirect } from "next/navigation";
import { createContext, ReactNode, useContext, useState } from "react";
interface SidebarContextType {
@@ -14,7 +14,6 @@ const SidebarContext = createContext<SidebarContextType | undefined>(undefined);
export function SidebarProvider({ children }: { children: ReactNode }) {
const [isOpen, setIsOpen] = useState(false);
- const router = useRouter();
const {
slug: workspaceSlug,
@@ -24,13 +23,13 @@ export function SidebarProvider({ children }: { children: ReactNode }) {
} = useWorkspace();
if (workspaceError && workspaceError.status === 404) {
- notFound();
+ redirect("/account/settings");
} else if (workspaceLoading) {
return <LayoutLoader />;
}
if (defaultProgramId) {
- router.push(`/${workspaceSlug}/program`);
+ redirect(`/${workspaceSlug}/program`);
}
return (
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/[customerId]/page-client.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/[customerId]/page-client.tsx
index b421c124ac..fef95b58b0 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/[customerId]/page-client.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/(enrolled)/customers/[customerId]/page-client.tsx
@@ -12,7 +12,7 @@ import { BackLink } from "@/ui/shared/back-link";
import { Button, MoneyBill2, Tooltip } from "@dub/ui";
import { fetcher, OG_AVATAR_URL } from "@dub/utils";
import Link from "next/link";
-import { notFound, useParams } from "next/navigation";
+import { redirect, useParams } from "next/navigation";
import { memo } from "react";
import useSWR from "swr";
@@ -27,7 +27,7 @@ export function ProgramCustomerPageClient() {
customerId,
});
- if (!customer && !isLoading) notFound();
+ if (!customer && !isLoading) redirect(`/programs/${programSlug}`);
return (
<div className="mb-10 mt-2">
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/apply/page.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/apply/page.tsx
index ea587f64db..d7a3aa9f02 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/apply/page.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/programs/[programSlug]/apply/page.tsx
@@ -5,7 +5,7 @@ import { PageContent } from "@/ui/layout/page-content";
import { PageWidthWrapper } from "@/ui/layout/page-width-wrapper";
import { BLOCK_COMPONENTS } from "@/ui/partners/lander/blocks";
import { BackLink } from "@/ui/shared/back-link";
-import { notFound } from "next/navigation";
+import { redirect } from "next/navigation";
import { CSSProperties } from "react";
import { ProgramSidebar } from "./program-sidebar";
@@ -20,7 +20,7 @@ export default async function ProgramDetailsPage({
});
if (!program) {
- notFound();
+ redirect("/programs");
}
return (
diff --git a/apps/web/app/[domain]/stats/[key]/page.tsx b/apps/web/app/[domain]/stats/[key]/page.tsx
index 3047583b45..da344b2497 100644
--- a/apps/web/app/[domain]/stats/[key]/page.tsx
+++ b/apps/web/app/[domain]/stats/[key]/page.tsx
@@ -1,6 +1,6 @@
import { prismaEdge } from "@dub/prisma/edge";
import { APP_DOMAIN } from "@dub/utils";
-import { notFound, redirect } from "next/navigation";
+import { redirect } from "next/navigation";
export const runtime = "edge";
@@ -22,7 +22,7 @@ export default async function OldStatsPage({
});
if (!link?.dashboard) {
- notFound();
+ redirect("/");
}
redirect(`${APP_DOMAIN}/share/${link.dashboard.id}`);
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/customers/[customerId]/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/customers/[customerId]/page-client.tsx
index 8de4075e52..5832014f3e 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/customers/[customerId]/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/customers/[customerId]/page-client.tsx
@@ -17,7 +17,7 @@ import { BackLink } from "@/ui/shared/back-link";
import { ArrowUpRight, Button, CopyButton } from "@dub/ui";
import { OG_AVATAR_URL, fetcher } from "@dub/utils";
import Link from "next/link";
-import { notFound, useParams } from "next/navigation";
+import { redirect, useParams } from "next/navigation";
import { memo } from "react";
import useSWR from "swr";
@@ -37,7 +37,7 @@ export function CustomerPageClient() {
fetcher,
);
- if (!customer && !isLoading) notFound();
+ if (!customer && !isLoading) redirect("/customers");
return (
<div className="mb-10 mt-2">
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/links/[...link]/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/links/[...link]/page-client.tsx
index e8da62b7e5..286b7ce440 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/links/[...link]/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/links/[...link]/page-client.tsx
@@ -39,16 +39,20 @@ import {
useMediaQuery,
} from "@dub/ui";
import { cn } from "@dub/utils";
-import { notFound, useParams, useRouter } from "next/navigation";
+import { redirect, useParams, useRouter } from "next/navigation";
import { memo, useEffect, useRef, useState } from "react";
import { useFormContext, useFormState } from "react-hook-form";
import { toast } from "sonner";
export function LinkPageClient() {
- const params = useParams<{ link: string | string[] }>();
+ const { slug: workspaceSlug, link: linkParams } = useParams<{
+ slug: string;
+ link: string | string[];
+ }>();
- const linkParts = Array.isArray(params.link) ? params.link : null;
- if (!linkParts) notFound();
+ const linkParts = Array.isArray(linkParams) ? linkParams : null;
+
+ if (!linkParts) redirect(`/${workspaceSlug}/links`);
const domain = linkParts[0];
const slug = linkParts.length > 1 ? linkParts.slice(1).join("/") : "_root";
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/links/folders/[folderId]/members/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/links/folders/[folderId]/members/page-client.tsx
index e037ff480a..e1e326f02f 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/links/folders/[folderId]/members/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/links/folders/[folderId]/members/page-client.tsx
@@ -22,7 +22,7 @@ import { ChevronLeft } from "lucide-react";
import { useSession } from "next-auth/react";
import { useAction } from "next-safe-action/hooks";
import Link from "next/link";
-import { notFound, redirect } from "next/navigation";
+import { redirect } from "next/navigation";
import { useState } from "react";
import { toast } from "sonner";
import useSWR from "swr";
@@ -94,16 +94,16 @@ export const FolderUsersPageClient = ({ folderId }: { folderId: string }) => {
};
if (!isFolderLoading && !folder) {
- notFound();
+ redirect(`/${workspace.slug}/links/folders`);
}
if (!canManageFolderPermissions) {
- redirect(`/${workspace.slug}/settings/library/folders`);
+ redirect(`/${workspace.slug}/links/folders`);
}
return (
<>
<Link
- href={`/${workspace.slug}/settings/library/folders`}
+ href={`/${workspace.slug}/links/folders`}
className="flex items-center gap-x-1"
>
<ChevronLeft className="size-4" />
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/integrations/[integrationSlug]/manage/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/integrations/[integrationSlug]/manage/page.tsx
index 913fd19e80..53b359e6d4 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/integrations/[integrationSlug]/manage/page.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/integrations/[integrationSlug]/manage/page.tsx
@@ -2,7 +2,7 @@ import AddEditIntegrationForm from "@/ui/oauth-apps/add-edit-integration-form";
import { BackLink } from "@/ui/shared/back-link";
import { prisma } from "@dub/prisma";
import { MaxWidthWrapper } from "@dub/ui";
-import { notFound } from "next/navigation";
+import { redirect } from "next/navigation";
export const revalidate = 0;
@@ -14,7 +14,7 @@ export default async function IntegrationManagePage({
// this is only available for Dub workspace for now
// we might open this up to other workspaces in the future
if (params.slug !== "dub") {
- notFound();
+ redirect(`/${params.slug}/settings/integrations`);
}
const integration = await prisma.integration.findUnique({
where: {
@@ -22,7 +22,7 @@ export default async function IntegrationManagePage({
},
});
if (!integration) {
- notFound();
+ redirect(`/${params.slug}/settings/integrations`);
}
return (
<MaxWidthWrapper className="grid max-w-screen-lg gap-8">
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/integrations/[integrationSlug]/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/integrations/[integrationSlug]/page.tsx
index 240b1da62f..fac652181f 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/integrations/[integrationSlug]/page.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/integrations/[integrationSlug]/page.tsx
@@ -1,5 +1,5 @@
import { prisma } from "@dub/prisma";
-import { notFound, redirect } from "next/navigation";
+import { redirect } from "next/navigation";
import IntegrationPageClient from "./page-client";
export const revalidate = 0;
@@ -44,11 +44,7 @@ export default async function IntegrationPage({
},
});
- if (!integration) {
- notFound();
- }
-
- if (integration.comingSoon) {
+ if (!integration || integration.comingSoon) {
redirect(`/${params.slug}/settings/integrations`);
}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/integrations/new/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/integrations/new/page.tsx
index 70efe32f5d..d19291a378 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/integrations/new/page.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/integrations/new/page.tsx
@@ -1,7 +1,7 @@
import AddEditIntegrationForm from "@/ui/oauth-apps/add-edit-integration-form";
import { BackLink } from "@/ui/shared/back-link";
import { MaxWidthWrapper } from "@dub/ui";
-import { notFound } from "next/navigation";
+import { redirect } from "next/navigation";
export default function NewIntegrationsPage({
params,
@@ -11,7 +11,7 @@ export default function NewIntegrationsPage({
// this is only available for Dub workspace for now
// we might open this up to other workspaces in the future
if (params.slug !== "dub") {
- notFound();
+ redirect(`/${params.slug}/settings/integrations`);
}
return (
<MaxWidthWrapper className="grid max-w-screen-lg gap-8">
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/oauth-apps/[appId]/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/oauth-apps/[appId]/page-client.tsx
index c37abfad18..a16c94f1fc 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/oauth-apps/[appId]/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/oauth-apps/[appId]/page-client.tsx
@@ -21,7 +21,7 @@ import {
import { fetcher } from "@dub/utils";
import { Trash, Upload } from "lucide-react";
import { useAction } from "next-safe-action/hooks";
-import { notFound, useSearchParams } from "next/navigation";
+import { redirect, useSearchParams } from "next/navigation";
import { useState } from "react";
import { toast } from "sonner";
import useSWR from "swr";
@@ -60,7 +60,7 @@ export default function OAuthAppManagePageClient({ appId }: { appId: string }) {
});
if (!isLoading && !oAuthApp) {
- notFound();
+ redirect(`/${slug}/settings/oauth-apps`);
}
return (
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/[webhookId]/edit/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/[webhookId]/edit/page-client.tsx
index 6c528a7589..50d18ce682 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/[webhookId]/edit/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/webhooks/[webhookId]/edit/page-client.tsx
@@ -5,7 +5,7 @@ import { WebhookProps } from "@/lib/types";
import AddEditWebhookForm from "@/ui/webhooks/add-edit-webhook-form";
import { MaxWidthWrapper } from "@dub/ui";
import { fetcher } from "@dub/utils";
-import { notFound } from "next/navigation";
+import { redirect } from "next/navigation";
import useSWR from "swr";
export default function UpdateWebhookPageClient({
@@ -13,7 +13,7 @@ export default function UpdateWebhookPageClient({
}: {
webhookId: string;
}) {
- const { id: workspaceId } = useWorkspace();
+ const { id: workspaceId, slug } = useWorkspace();
const { data: webhook, isLoading } = useSWR<WebhookProps>(
`/api/webhooks/${webhookId}?workspaceId=${workspaceId}`,
@@ -21,7 +21,7 @@ export default function UpdateWebhookPageClient({
);
if (!isLoading && !webhook) {
- notFound();
+ redirect(`/${slug}/settings/webhooks`);
}
return (
diff --git a/apps/web/app/app.dub.co/(share)/share/[dashboardId]/page.tsx b/apps/web/app/app.dub.co/(share)/share/[dashboardId]/page.tsx
index 9467f31076..0924ffd40c 100644
--- a/apps/web/app/app.dub.co/(share)/share/[dashboardId]/page.tsx
+++ b/apps/web/app/app.dub.co/(share)/share/[dashboardId]/page.tsx
@@ -30,7 +30,7 @@ export async function generateMetadata({
});
}
-export default async function dashboardPage({
+export default async function DashboardPage({
params,
}: {
params: { dashboardId: string };
diff --git a/apps/web/app/deeplink/[domain]/[key]/page.tsx b/apps/web/app/deeplink/[domain]/[key]/page.tsx
index 2863de6d22..eb39e36f33 100644
--- a/apps/web/app/deeplink/[domain]/[key]/page.tsx
+++ b/apps/web/app/deeplink/[domain]/[key]/page.tsx
@@ -8,7 +8,6 @@ import { DeepLinkActionButtons } from "./action-buttons";
export const runtime = "edge";
-// /deeplink/[domain]/[key]
export default async function DeepLinkPage({
params,
}: {
diff --git a/apps/web/ui/webhooks/webhook-header.tsx b/apps/web/ui/webhooks/webhook-header.tsx
index 49298d4db0..662f6063c8 100644
--- a/apps/web/ui/webhooks/webhook-header.tsx
+++ b/apps/web/ui/webhooks/webhook-header.tsx
@@ -17,7 +17,7 @@ import {
} from "@dub/ui";
import { CircleX, Send, Trash } from "lucide-react";
import { useAction } from "next-safe-action/hooks";
-import { notFound, useRouter, useSelectedLayoutSegment } from "next/navigation";
+import { redirect, useRouter, useSelectedLayoutSegment } from "next/navigation";
import { useState } from "react";
import { toast } from "sonner";
import { useDeleteWebhookModal } from "../modals/delete-webhook-modal";
@@ -62,7 +62,7 @@ export default function WebhookHeader({ webhookId }: { webhookId: string }) {
});
if (!isLoading && !webhook) {
- return notFound();
+ redirect(`/${slug}/settings/webhooks`);
}
const copyWebhookId = () => {