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.

use dynamic params instead

Steven Teyaa2f7531fb10
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
new file mode 100644
index 0000000000..811d13970a
--- /dev/null
+++ b/apps/web/app/(ee)/app.dub.co/(new-program)/[slug]/program/new/connect/[[...guide]]/page.tsx
@@ -0,0 +1,53 @@
+import { getIntegrationGuideMarkdown } from "@/lib/get-integration-guide-markdown";
+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 { StepPage } from "../../step-page";
+
+export default async function ConnectGuidesPage({
+ params,
+}: {
+ params: {
+ guide?: string[];
+ };
+}) {
+ const { guide } = params;
+ console.log("guide", guide);
+ let selectedGuide: IntegrationGuide | null = null;
+ let markdownContent: string | null = null;
+
+ if (guide && guide.length === 1) {
+ selectedGuide =
+ guides.find((g) => g.key === guide[0].toLowerCase()) ?? null;
+
+ if (!selectedGuide) {
+ notFound();
+ }
+
+ markdownContent = await getIntegrationGuideMarkdown(selectedGuide.key);
+ console.log("markdown", markdownContent?.slice(0, 100));
+
+ if (!markdownContent) {
+ notFound();
+ }
+ }
+
+ return (
+ <StepPage title="Connecting Dub">
+ <div>
+ <p className="mb-6 text-sm text-neutral-600">
+ Ensure Dub is connected to your app, so you can track your clicks,
+ leads, and sales on your program. A developer might be required to
+ complete.
+ </p>
+
+ {selectedGuide && markdownContent ? (
+ <Guide markdown={markdownContent} />
+ ) : (
+ <GuideList />
+ )}
+ </div>
+ </StepPage>
+ );
+}
diff --git a/apps/web/app/(ee)/app.dub.co/(new-program)/[slug]/program/new/connect/page.tsx b/apps/web/app/(ee)/app.dub.co/(new-program)/[slug]/program/new/connect/page.tsx
deleted file mode 100644
index b75de0eb6a..0000000000
--- a/apps/web/app/(ee)/app.dub.co/(new-program)/[slug]/program/new/connect/page.tsx
+++ /dev/null
@@ -1,51 +0,0 @@
-import { getIntegrationGuideMarkdown } from "@/lib/get-integration-guide-markdown";
-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 { Suspense } from "react";
-import { StepPage } from "../step-page";
-
-export default async function Page({
- searchParams,
-}: {
- searchParams: {
- guide?: string;
- };
-}) {
- let { guide } = searchParams;
- let selectedGuide: IntegrationGuide | null = null;
- let markdown: string | null = null;
-
- if (guide) {
- selectedGuide = guides.find((g) => g.key === guide.toLowerCase()) ?? null;
-
- if (!selectedGuide) {
- notFound();
- }
-
- markdown = await getIntegrationGuideMarkdown(selectedGuide.key);
-
- if (!markdown) {
- notFound();
- }
- }
-
- return (
- <StepPage title="Connecting Dub">
- <Suspense fallback={<div>Loading...</div>}>
- <div>
- <p className="mb-6 text-sm text-neutral-600">
- Ensure Dub is connected to your app, so you can track your clicks,
- leads, and sales on your program. A developer might be required to
- complete.
- </p>
-
- <div>
- {selectedGuide ? <Guide markdown={markdown} /> : <GuideList />}
- </div>
- </div>
- </Suspense>
- </StepPage>
- );
-}
diff --git a/apps/web/lib/get-integration-guide-markdown.ts b/apps/web/lib/get-integration-guide-markdown.ts
index 8bd8b031eb..4fd603284a 100644
--- a/apps/web/lib/get-integration-guide-markdown.ts
+++ b/apps/web/lib/get-integration-guide-markdown.ts
@@ -1,7 +1,7 @@
"server-only";
import { readFile } from "fs/promises";
-import { join, normalize } from "path";
+import { join } from "path";
export async function getIntegrationGuideMarkdown(
guideKey: string,
@@ -12,22 +12,17 @@ export async function getIntegrationGuideMarkdown(
return null;
}
- const markdownPath = join(
- process.cwd(),
- "integration-guides",
- `${sanitizedKey}.md`,
- );
+ // Use a more explicit path construction to satisfy the linter
+ const integrationGuidesDir = join(process.cwd(), "integration-guides");
+ const markdownPath = join(integrationGuidesDir, `${sanitizedKey}.md`);
// Additional security check: ensure the path is within the expected directory
- const normalizedPath = normalize(markdownPath);
- const expectedBase = normalize(join(process.cwd(), "integration-guides"));
-
- if (!normalizedPath.startsWith(expectedBase)) {
+ if (!markdownPath.startsWith(integrationGuidesDir)) {
return null;
}
try {
- return await readFile(normalizedPath, "utf-8");
+ return await readFile(markdownPath, "utf-8");
} catch (error) {
return null;
}
diff --git a/apps/web/ui/guides/guide-list.tsx b/apps/web/ui/guides/guide-list.tsx
index 7e8e294c74..8fbe9da175 100644
--- a/apps/web/ui/guides/guide-list.tsx
+++ b/apps/web/ui/guides/guide-list.tsx
@@ -112,7 +112,7 @@ export function GuideList({ showConnectLaterButton = true }: GuideListProps) {
{(guidesByType[section.type] || []).map((guide) => (
<Link
prefetch={true}
- href={`${pathname}?guide=${guide.key}`}
+ href={`${pathname}/${guide.key}`}
key={guide.title}
className="group relative flex h-[140px] cursor-pointer flex-col items-center justify-center gap-3 rounded-lg bg-neutral-100 px-2 py-4 text-center"
>
diff --git a/apps/web/ui/guides/guide.tsx b/apps/web/ui/guides/guide.tsx
index e84e86643e..ab7c2945b9 100644
--- a/apps/web/ui/guides/guide.tsx
+++ b/apps/web/ui/guides/guide.tsx
@@ -3,14 +3,10 @@
import { buttonVariants } from "@dub/ui";
import { cn } from "@dub/utils";
import Link from "next/link";
-import { notFound, usePathname, useSearchParams } from "next/navigation";
+import { useParams, usePathname } from "next/navigation";
import { guides, IntegrationType } from "./integrations";
import { Markdown } from "./markdown";
-interface GuideProps {
- markdown: string | null;
-}
-
const integrationTypeToTitle: Record<IntegrationType, string> = {
"client-sdk": "client-side script",
"server-sdk": "server-side script",
@@ -18,25 +14,11 @@ const integrationTypeToTitle: Record<IntegrationType, string> = {
"track-sales": "tracking sale events",
};
-export function Guide({ markdown }: GuideProps) {
+export function Guide({ markdown }: { markdown: string }) {
+ const { guide } = useParams() as { guide: string[] };
const pathname = usePathname();
- const searchParams = useSearchParams();
-
- const guide = searchParams.get("guide");
-
- if (!guide) {
- notFound();
- }
- const selectedGuide = guides.find((g) => g.key === guide);
-
- if (!selectedGuide) {
- notFound();
- }
-
- if (!markdown) {
- notFound();
- }
+ const selectedGuide = guides.find((g) => g.key === guide[0])!;
const Icon = selectedGuide.icon;
@@ -48,7 +30,7 @@ export function Guide({ markdown }: GuideProps) {
<Icon className="size-8" />
<Link
- href={pathname}
+ href={pathname.split("/").slice(0, -1).join("/")}
className={cn(
buttonVariants({
variant: "secondary",