The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add help button to side nav
Tim Wilson2e337115912a
diff --git a/apps/web/app/app.dub.co/(dashboard)/layout.tsx b/apps/web/app/app.dub.co/(dashboard)/layout.tsxindex cce2df3982..6b6e0f9df1 100644--- a/apps/web/app/app.dub.co/(dashboard)/layout.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/layout.tsx@@ -1,6 +1,7 @@import { getSession } from "@/lib/auth";import { getFeatureFlags } from "@/lib/edge-config";import { MainNav } from "@/ui/layout/main-nav";+import { HelpButtonRSC } from "@/ui/layout/sidebar/help-button-rsc";import Toolbar from "@/ui/layout/toolbar/toolbar";import UserSurveyPopup from "@/ui/layout/user-survey";import { constructMetadata } from "@dub/utils";@@ -19,11 +20,13 @@ export default async function Layout({ children }: { children: ReactNode }) {return (<Providers><div className="min-h-screen w-full bg-gray-50/80">- <MainNav sidenav={sidenav}>{children}</MainNav>+ <MainNav sidenav={sidenav} toolContent={<HelpButtonRSC />}>+ {children}+ </MainNav></div><UserSurveyPopup />{/* <ChangelogPopup /> */}- <Toolbar />+ <Toolbar show={sidenav ? ["onboarding"] : ["onboarding", "help"]} /></Providers>);}diff --git a/apps/web/ui/layout/toolbar/help/contact-form.tsx b/apps/web/ui/layout/help/contact-form.tsxsimilarity index 100%rename from apps/web/ui/layout/toolbar/help/contact-form.tsxrename to apps/web/ui/layout/help/contact-form.tsxdiff --git a/apps/web/ui/layout/toolbar/help/help-articles.tsx b/apps/web/ui/layout/help/help-articles.tsxsimilarity index 99%rename from apps/web/ui/layout/toolbar/help/help-articles.tsxrename to apps/web/ui/layout/help/help-articles.tsxindex c999db8ec2..e83301533e 100644--- a/apps/web/ui/layout/toolbar/help/help-articles.tsx+++ b/apps/web/ui/layout/help/help-articles.tsx@@ -7,7 +7,7 @@ import posthog from "posthog-js";import { Dispatch, SetStateAction, useContext, useMemo, useRef } from "react";import Highlighter from "react-highlight-words";import { useDebouncedCallback } from "use-debounce";-import { HelpContext } from "./help-button";+import { HelpContext } from ".";export function HelpArticles({setScreen,diff --git a/apps/web/ui/layout/help/help-section.tsx b/apps/web/ui/layout/help/help-section.tsxnew file mode 100644index 0000000000..71f040f92f--- /dev/null+++ b/apps/web/ui/layout/help/help-section.tsx@@ -0,0 +1,30 @@+"use client";++import { useResizeObserver } from "@dub/ui";+import { motion } from "framer-motion";+import { useRef, useState } from "react";+import { ContactForm } from "./contact-form";+import { HelpArticles } from "./help-articles";++export function HelpSection() {+ const [screen, setScreen] = useState<"main" | "contact">("main");++ const containerRef = useRef<HTMLDivElement>(null);+ const resizeObserverEntry = useResizeObserver(containerRef);++ return (+ <motion.div+ className="w-full overflow-scroll sm:w-[32rem]"+ animate={{+ height: resizeObserverEntry?.borderBoxSize[0].blockSize ?? "auto",+ maxHeight: "calc(100vh - 10rem)",+ }}+ transition={{ type: "spring", duration: 0.3 }}+ >+ <div ref={containerRef}>+ {screen === "main" && <HelpArticles setScreen={setScreen} />}+ {screen === "contact" && <ContactForm setScreen={setScreen} />}+ </div>+ </motion.div>+ );+}diff --git a/apps/web/ui/layout/help/index.tsx b/apps/web/ui/layout/help/index.tsxnew file mode 100644index 0000000000..1495ba3cfc--- /dev/null+++ b/apps/web/ui/layout/help/index.tsx@@ -0,0 +1,16 @@+import { createContext } from "react";++export interface HelpArticle {+ title: string;+ summary: string;+ searchableSummary?: string;+ slug: string;+}++export const HelpContext = createContext<{+ popularHelpArticles: HelpArticle[];+ allHelpArticles: HelpArticle[];+}>({+ popularHelpArticles: [],+ allHelpArticles: [],+});diff --git a/apps/web/ui/layout/main-nav.tsx b/apps/web/ui/layout/main-nav.tsxindex 56581b3013..42cc3f221f 100644--- a/apps/web/ui/layout/main-nav.tsx+++ b/apps/web/ui/layout/main-nav.tsx@@ -14,6 +14,7 @@ import {createContext,Dispatch,PropsWithChildren,+ ReactNode,SetStateAction,Suspense,useEffect,@@ -39,7 +40,8 @@ const SideNavContext = createContext<SideNavContext>({export function MainNav({sidenav,children,-}: PropsWithChildren<{ sidenav: boolean }>) {+ toolContent,+}: PropsWithChildren<{ sidenav: boolean; toolContent?: ReactNode }>) {const { slug } = useParams() as { slug?: string };const scrolled = useScroll(80);@@ -78,7 +80,7 @@ export function MainNav({!isOpen && "-translate-x-full",)}>- <SidebarNav />+ <SidebarNav toolContent={toolContent} /></nav></div><div className="bg-neutral-100">diff --git a/apps/web/ui/layout/sidebar/help-button-rsc.tsx b/apps/web/ui/layout/sidebar/help-button-rsc.tsxnew file mode 100644index 0000000000..315497d919--- /dev/null+++ b/apps/web/ui/layout/sidebar/help-button-rsc.tsx@@ -0,0 +1,19 @@+import { HelpButton } from "./help-button";++export async function HelpButtonRSC() {+ const { popularHelpArticles, allHelpArticles } = await fetch(+ "https://dub.co/api/content",+ {+ next: {+ revalidate: 60 * 60 * 24, // cache for 24 hours+ },+ },+ ).then((res) => res.json());++ return (+ <HelpButton+ popularHelpArticles={popularHelpArticles}+ allHelpArticles={allHelpArticles}+ />+ );+}diff --git a/apps/web/ui/layout/sidebar/help-button.tsx b/apps/web/ui/layout/sidebar/help-button.tsxnew file mode 100644index 0000000000..762d7ef5bf--- /dev/null+++ b/apps/web/ui/layout/sidebar/help-button.tsx@@ -0,0 +1,57 @@+"use client";++import { Popover } from "@dub/ui";+import { AnimatePresence, motion } from "framer-motion";+import { CircleHelp, XIcon } from "lucide-react";+import posthog from "posthog-js";+import { useState } from "react";+import { HelpArticle, HelpContext } from "../help";+import { HelpSection } from "../help/help-section";++export function HelpButton({+ popularHelpArticles,+ allHelpArticles,+}: {+ popularHelpArticles: HelpArticle[];+ allHelpArticles: HelpArticle[];+}) {+ const [isOpen, setIsOpen] = useState(false);++ return (+ <HelpContext.Provider value={{ popularHelpArticles, allHelpArticles }}>+ <Popover+ content={<HelpSection />}+ openPopover={isOpen}+ setOpenPopover={setIsOpen}+ align="start"+ >+ <button+ type="button"+ onClick={() => {+ if (!isOpen) {+ posthog.capture("help_portal_opened");+ }+ setIsOpen((o) => !o);+ }}+ className="font-lg relative size-4 shrink-0 overflow-hidden rounded-full active:bg-gray-50"+ >+ <AnimatePresence>+ <motion.div+ key={isOpen ? "open" : "closed"}+ className="absolute inset-0 flex items-center justify-center font-medium text-neutral-500 hover:text-neutral-700"+ initial={{ opacity: 0, scale: 0 }}+ animate={{ opacity: 1, scale: 1 }}+ exit={{ opacity: 0, scale: 0 }}+ >+ {isOpen ? (+ <XIcon className="size-4" strokeWidth={2} />+ ) : (+ <CircleHelp className="size-4" />+ )}+ </motion.div>+ </AnimatePresence>+ </button>+ </Popover>+ </HelpContext.Provider>+ );+}diff --git a/apps/web/ui/layout/sidebar/sidebar-nav.tsx b/apps/web/ui/layout/sidebar/sidebar-nav.tsxindex c4cba5fcd0..39eaedad6d 100644--- a/apps/web/ui/layout/sidebar/sidebar-nav.tsx+++ b/apps/web/ui/layout/sidebar/sidebar-nav.tsx@@ -3,11 +3,11 @@ import { CursorRays, Hyperlink, LinesY } from "@dub/ui/src";import { cn } from "@dub/utils";import Link from "next/link";import { useParams, usePathname } from "next/navigation";-import { useMemo } from "react";+import { ReactNode, Suspense, useMemo } from "react";import UserDropdown from "./user-dropdown";import { WorkspaceDropdown } from "./workspace-dropdown";-export function SidebarNav() {+export function SidebarNav({ toolContent }: { toolContent?: ReactNode }) {const { slug } = useParams() as { slug?: string };const pathname = usePathname();@@ -24,7 +24,10 @@ export function SidebarNav() {<div className="p-3 text-gray-500"><div className="flex items-start justify-between gap-1"><Wordmark className="ml-1 h-6" />- <UserDropdown />+ <div className="flex items-center gap-3">+ <Suspense fallback={null}>{toolContent}</Suspense>+ <UserDropdown />+ </div></div><div className="mt-7">diff --git a/apps/web/ui/layout/sidebar/user-dropdown.tsx b/apps/web/ui/layout/sidebar/user-dropdown.tsxindex e7c669bfe1..0a84ed68dc 100644--- a/apps/web/ui/layout/sidebar/user-dropdown.tsx+++ b/apps/web/ui/layout/sidebar/user-dropdown.tsx@@ -100,10 +100,10 @@ export default function UserDropdown() {{session?.user ? (<Avataruser={session.user}- className="size-7 border-none duration-75 sm:size-7"+ className="size-6 border-none duration-75 sm:size-6"/>) : (- <div className="size-7 animate-pulse rounded-full bg-gray-100 sm:size-7" />+ <div className="size-6 animate-pulse rounded-full bg-gray-100 sm:size-6" />)}{unreadChangelogs > 0 && (<div className="absolute -bottom-0.5 -right-0.5 size-3 rounded-full border-2 border-white bg-blue-500" />diff --git a/apps/web/ui/layout/toolbar/help/help-button.tsx b/apps/web/ui/layout/toolbar/help-button.tsxsimilarity index 52%rename from apps/web/ui/layout/toolbar/help/help-button.tsxrename to apps/web/ui/layout/toolbar/help-button.tsxindex 93baef9000..69a7c6866e 100644--- a/apps/web/ui/layout/toolbar/help/help-button.tsx+++ b/apps/web/ui/layout/toolbar/help-button.tsx@@ -1,21 +1,12 @@"use client";-import { Popover, useResizeObserver } from "@dub/ui";+import { Popover } from "@dub/ui";import { AnimatePresence, motion } from "framer-motion";import { XIcon } from "lucide-react";import posthog from "posthog-js";-import { createContext, useRef, useState } from "react";-import { HelpArticle } from ".";-import { ContactForm } from "./contact-form";-import { HelpArticles } from "./help-articles";--export const HelpContext = createContext<{- popularHelpArticles: HelpArticle[];- allHelpArticles: HelpArticle[];-}>({- popularHelpArticles: [],- allHelpArticles: [],-});+import { useState } from "react";+import { HelpArticle, HelpContext } from "../help";+import { HelpSection } from "../help/help-section";export function HelpButton({popularHelpArticles,@@ -42,7 +33,7 @@ export function HelpButton({}setIsOpen((o) => !o);}}- className="font-lg relative h-12 w-12 overflow-hidden rounded-full border border-gray-200 bg-white shadow-md active:bg-gray-50"+ className="animate-fade-in font-lg relative h-12 w-12 overflow-hidden rounded-full border border-gray-200 bg-white shadow-md active:bg-gray-50"><AnimatePresence><motion.div@@ -51,6 +42,7 @@ export function HelpButton({initial={{ opacity: 0, scale: 0 }}animate={{ opacity: 1, scale: 1 }}exit={{ opacity: 0, scale: 0 }}+ transition={{ ease: "easeInOut", duration: 0.1 }}>{isOpen ? <XIcon className="h-4 w-4" strokeWidth={2} /> : "?"}</motion.div>@@ -60,26 +52,3 @@ export function HelpButton({</HelpContext.Provider>);}--function HelpSection() {- const [screen, setScreen] = useState<"main" | "contact">("main");-- const containerRef = useRef<HTMLDivElement>(null);- const resizeObserverEntry = useResizeObserver(containerRef);-- return (- <motion.div- className="w-full overflow-scroll sm:w-[32rem]"- animate={{- height: resizeObserverEntry?.borderBoxSize[0].blockSize ?? "auto",- maxHeight: "calc(100vh - 10rem)",- }}- transition={{ type: "spring", duration: 0.3 }}- >- <div ref={containerRef}>- {screen === "main" && <HelpArticles setScreen={setScreen} />}- {screen === "contact" && <ContactForm setScreen={setScreen} />}- </div>- </motion.div>- );-}diff --git a/apps/web/ui/layout/toolbar/help/index.tsx b/apps/web/ui/layout/toolbar/help/index.tsxdeleted file mode 100644index 730aaa67f2..0000000000--- a/apps/web/ui/layout/toolbar/help/index.tsx+++ /dev/null@@ -1,6 +0,0 @@-export interface HelpArticle {- title: string;- summary: string;- searchableSummary?: string;- slug: string;-}diff --git a/apps/web/ui/layout/toolbar/toolbar.tsx b/apps/web/ui/layout/toolbar/toolbar.tsxindex 1a81bd8607..adf1de563c 100644--- a/apps/web/ui/layout/toolbar/toolbar.tsx+++ b/apps/web/ui/layout/toolbar/toolbar.tsx@@ -1,5 +1,5 @@import { Suspense } from "react";-import { HelpButton } from "./help/help-button";+import { HelpButton } from "./help-button";import { OnboardingButton } from "./onboarding/onboarding-button";const toolbarItems = ["onboarding", "help"] as const;