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.

include step

Steven Tey298fc0738bc2
diff --git a/apps/web/ui/guides/guide-list.tsx b/apps/web/ui/guides/guide-list.tsx
index c54a36e485..c1068ce78d 100644
--- a/apps/web/ui/guides/guide-list.tsx
+++ b/apps/web/ui/guides/guide-list.tsx
@@ -8,11 +8,9 @@ import {
ProgramSheetAccordionItem,
ProgramSheetAccordionTrigger,
} from "@/ui/partners/program-sheet-accordion";
-import { Button } from "@dub/ui";
-import { Check } from "lucide-react";
+import { Button, useRouterStuff } from "@dub/ui";
import Link from "next/link";
import { usePathname } from "next/navigation";
-import { useState } from "react";
import {
guides,
IntegrationGuide,
@@ -33,34 +31,10 @@ const guidesByType = guides.reduce(
export function GuideList() {
const pathname = usePathname();
+ const { router, searchParams, queryParams } = useRouterStuff();
const { slug: workspaceSlug } = useWorkspace();
- const [completedSections, setCompletedSections] = useState<
- Set<IntegrationType>
- >(new Set());
-
- const [currentOpenSection, setCurrentOpenSection] = useState<string>(
- sections[0].type,
- );
-
- const handleComplete = (type: IntegrationType) => {
- setCompletedSections((prev) => {
- const newSet = new Set(prev);
- newSet.add(type);
- return newSet;
- });
-
- const completedSectionIndex = sections.findIndex((s) => s.type === type);
-
- // Auto-open next section if available
- if (completedSectionIndex < sections.length - 1) {
- const nextSection = sections[completedSectionIndex + 1];
- setCurrentOpenSection(nextSection.type);
- } else {
- // If it's the last section, close the accordion
- setCurrentOpenSection("");
- }
- };
+ const currentStep = searchParams.get("step") ?? sections[0].type;
const showConnectLaterButton = pathname.includes("/program/new/connect");
@@ -69,93 +43,100 @@ export function GuideList() {
<ProgramSheetAccordion
type="single"
collapsible
- value={currentOpenSection}
- onValueChange={setCurrentOpenSection}
+ value={currentStep}
+ onValueChange={(value) => {
+ queryParams({
+ set: {
+ step: value,
+ },
+ scroll: false,
+ });
+ }}
className="space-y-4"
>
- {sections.map((section, index) => {
- const isCompleted = completedSections.has(section.type);
- const isOpen = currentOpenSection === section.type;
-
- return (
- <ProgramSheetAccordionItem key={section.type} value={section.type}>
- <ProgramSheetAccordionTrigger className="bg-neutral-100 px-4 py-2.5">
- <div className="flex items-center gap-2">
- {isCompleted && !isOpen ? (
- <div className="flex size-5 items-center justify-center rounded-full bg-black text-white">
- <Check className="size-3" />
- </div>
- ) : (
- <div className="flex size-5 items-center justify-center rounded-full bg-white text-sm font-semibold leading-6 text-neutral-900">
- {index + 1}
- </div>
- )}
-
- <h3 className="text-base font-semibold leading-6 text-neutral-900">
- {section.title}
- </h3>
+ {sections.map((section, index) => (
+ <ProgramSheetAccordionItem key={section.type} value={section.type}>
+ <ProgramSheetAccordionTrigger className="bg-neutral-100 px-4 py-2.5">
+ <div className="flex items-center gap-2">
+ <div className="flex size-5 items-center justify-center rounded-full bg-white text-sm font-semibold leading-6 text-neutral-900">
+ {index + 1}
</div>
- </ProgramSheetAccordionTrigger>
-
- <ProgramSheetAccordionContent>
- <div className="space-y-6">
- <p className="text-sm font-medium text-neutral-600">
- {section.description}
- </p>
- <div className="grid grid-cols-1 gap-4 sm:grid-cols-2 md:grid-cols-3">
- {(guidesByType[section.type] || []).map((guide) => (
- <Link
- key={guide.title}
- href={`${pathname}/${guide.key}`}
- 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 transition-colors hover:bg-neutral-200/75"
- >
- <div className="flex h-16 w-full items-center justify-center">
- <guide.icon className="size-10" />
+ <h3 className="text-base font-semibold leading-6 text-neutral-900">
+ {section.title}
+ </h3>
+ </div>
+ </ProgramSheetAccordionTrigger>
+
+ <ProgramSheetAccordionContent>
+ <div className="space-y-6">
+ <p className="text-sm font-medium text-neutral-600">
+ {section.description}
+ </p>
+
+ <div className="grid grid-cols-1 gap-4 sm:grid-cols-2 md:grid-cols-3">
+ {(guidesByType[section.type] || []).map((guide) => (
+ <Link
+ key={guide.title}
+ href={`${pathname}/${guide.key}`}
+ 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 transition-colors hover:bg-neutral-200/75"
+ >
+ <div className="flex h-16 w-full items-center justify-center">
+ <guide.icon className="size-10" />
+ </div>
+
+ <div>
+ <div className="w-full text-sm font-semibold leading-5 text-neutral-900">
+ {guide.title}
</div>
- <div>
- <div className="w-full text-sm font-semibold leading-5 text-neutral-900">
- {guide.title}
+ {guide.subtitle && (
+ <div className="w-full text-sm font-medium leading-5 text-neutral-500">
+ {guide.subtitle}
</div>
+ )}
+ </div>
+ </Link>
+ ))}
+ </div>
- {guide.subtitle && (
- <div className="w-full text-sm font-medium leading-5 text-neutral-500">
- {guide.subtitle}
- </div>
- )}
- </div>
+ <div className="flex flex-col items-center justify-center space-y-3">
+ <Button
+ text="I've completed this"
+ className="rounded-lg"
+ onClick={() => {
+ if (sections.length - 1 === index) {
+ router.push(`/${workspaceSlug}/events`);
+ return;
+ }
+ queryParams({
+ set: {
+ step: sections[index + 1].type,
+ },
+ scroll: false,
+ });
+ }}
+ />
+
+ {["track-leads", "track-sales"].includes(section.type) && (
+ <p className="flex items-center justify-center gap-2 text-center text-sm font-medium leading-5 text-neutral-500">
+ <Shopify className="inline size-4" />
+ If you're using Shopify, you can skip this step.{" "}
+ <Link
+ href="https://dub.co/docs/conversions/sales/shopify"
+ className="text-neutral-500 underline underline-offset-2"
+ target="_blank"
+ rel="noreferrer"
+ >
+ Read the guide.
</Link>
- ))}
- </div>
-
- <div className="flex flex-col items-center justify-center space-y-3">
- <Button
- text="I've completed this"
- className="rounded-lg"
- onClick={() => handleComplete(section.type)}
- />
-
- {["track-leads", "track-sales"].includes(section.type) && (
- <p className="flex items-center justify-center gap-2 text-center text-sm font-medium leading-5 text-neutral-500">
- <Shopify className="inline size-4" />
- If you're using Shopify, you can skip this step.{" "}
- <Link
- href="https://dub.co/docs/conversions/sales/shopify"
- className="text-neutral-500 underline underline-offset-2"
- target="_blank"
- rel="noreferrer"
- >
- Read the guide.
- </Link>
- </p>
- )}
- </div>
+ </p>
+ )}
</div>
- </ProgramSheetAccordionContent>
- </ProgramSheetAccordionItem>
- );
- })}
+ </div>
+ </ProgramSheetAccordionContent>
+ </ProgramSheetAccordionItem>
+ ))}
</ProgramSheetAccordion>
{showConnectLaterButton && (
diff --git a/apps/web/ui/guides/guide.tsx b/apps/web/ui/guides/guide.tsx
index baf6096741..db8ce0a7c9 100644
--- a/apps/web/ui/guides/guide.tsx
+++ b/apps/web/ui/guides/guide.tsx
@@ -14,19 +14,20 @@ const integrationTypeToTitle: Record<IntegrationType, string> = {
};
export function Guide({ markdown }: { markdown: string }) {
- const pathname = usePathname();
const { guide } = useParams() as { guide: string[] };
-
const guideKey = guide[0];
const selectedGuide = guides.find((g) => g.key === guideKey)!;
const Icon = selectedGuide.icon;
+ const pathname = usePathname();
+ const backHref = `${pathname.replace(`/${guideKey}`, "")}?step=${selectedGuide.type}`;
+
return (
<>
<hr className="mb-6 border-neutral-200" />
<div className="mx-auto max-w-2xl space-y-5">
<div className="flex items-center justify-between">
- <Link href={pathname.replace(`/${guideKey}`, "")}>
+ <Link href={backHref}>
<Button
variant="secondary"
className="h-8 w-fit rounded-lg border-none bg-neutral-100 px-2"
@@ -61,7 +62,7 @@ export function Guide({ markdown }: { markdown: string }) {
<Markdown>{markdown}</Markdown>
<Link
- href={pathname.replace(`/${guideKey}`, "")}
+ href={backHref}
className={cn(
buttonVariants({
variant: "primary",