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.

improve styles

Steven Tey5f1de08afdf7
diff --git a/apps/web/app/app.dub.co/(dashboard)/layout.tsx b/apps/web/app/app.dub.co/(dashboard)/layout.tsx
index 021ab8660e..390c5930bf 100644
--- a/apps/web/app/app.dub.co/(dashboard)/layout.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/layout.tsx
@@ -1,4 +1,4 @@
-import { HelpButton } from "@/ui/layout/help";
+import HelpPortal from "@/ui/layout/help";
import NavTabs from "@/ui/layout/nav-tabs";
import UpgradeBanner from "@/ui/layout/upgrade-banner";
import UserDropdown from "@/ui/layout/user-dropdown";
@@ -53,9 +53,7 @@ export default function Layout({ children }: { children: ReactNode }) {
</div>
{children}
</div>
- <div className="fixed bottom-0 right-0 m-5">
- <HelpButton />
- </div>
+ <HelpPortal />
</Providers>
);
}
diff --git a/apps/web/ui/layout/help/contact-form.tsx b/apps/web/ui/layout/help/contact-form.tsx
index c1494bbdbb..71b5d2165d 100644
--- a/apps/web/ui/layout/help/contact-form.tsx
+++ b/apps/web/ui/layout/help/contact-form.tsx
@@ -31,7 +31,7 @@ export function ContactForm({
value={message}
autoComplete="off"
onChange={(e) => setMessage(e.target.value)}
- minRows={8}
+ minRows={12}
className={`${
false
? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
@@ -40,12 +40,12 @@ export function ContactForm({
/>
</label>
{/* TODO */}
- <label className="mt-3 flex cursor-pointer items-center space-x-1 py-1">
+ <div className="mt-3 flex h-[4rem] cursor-pointer items-center justify-center space-x-1 rounded-md border border-dashed border-gray-400 py-1">
<p className="text-sm text-gray-500 hover:text-gray-700 hover:underline">
Upload attachment
</p>
<Upload className="h-3 w-3" />
- </label>
+ </div>
<Button className="mt-3 h-9" disabled={!message} text="Send message" />
</div>
);
diff --git a/apps/web/ui/layout/help/index.tsx b/apps/web/ui/layout/help/index.tsx
index e65beac466..9f7127b3bb 100644
--- a/apps/web/ui/layout/help/index.tsx
+++ b/apps/web/ui/layout/help/index.tsx
@@ -1,69 +1,32 @@
-"use client";
+import { Suspense } from "react";
+import { HelpButton } from "./portal";
-import { Popover } from "@dub/ui";
-import { AnimatePresence, motion } from "framer-motion";
-import { XIcon } from "lucide-react";
-import { useEffect, useRef, useState } from "react";
-import { ContactForm } from "./contact-form";
-import { MainScreen } from "./main-screen";
-
-export function HelpButton() {
- const [isOpen, setIsOpen] = useState(false);
+export interface HelpArticle {
+ title: string;
+ summary: string;
+ searchableSummary?: string;
+ slug: string;
+}
+export default function HelpPortal() {
return (
- <Popover
- content={
- <div className="w-full overflow-hidden">
- <HelpSection />
- </div>
- }
- openPopover={isOpen}
- setOpenPopover={setIsOpen}
- align="end"
- >
- <button
- type="button"
- onClick={() => 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"
- >
- <AnimatePresence>
- <motion.div
- key={isOpen ? "open" : "closed"}
- className="absolute inset-0 flex items-center justify-center font-medium text-gray-700 hover:text-gray-700"
- initial={{ opacity: 0, scale: 0 }}
- animate={{ opacity: 1, scale: 1 }}
- exit={{ opacity: 0, scale: 0 }}
- >
- {isOpen ? <XIcon className="h-4 w-4" strokeWidth={2} /> : "?"}
- </motion.div>
- </AnimatePresence>
- </button>
- </Popover>
+ <Suspense fallback={null}>
+ <div className="fixed bottom-0 right-0 m-5">
+ <HelpPortalRSC />
+ </div>
+ </Suspense>
);
}
-function HelpSection() {
- const [screen, setScreen] = useState<"main" | "contact">("main");
-
- const ref = useRef<HTMLDivElement>(null);
- const [contentHeight, setContentHeight] = useState(0);
-
- useEffect(() => {
- if (ref.current) {
- setContentHeight(ref.current.offsetHeight);
- }
- });
+async function HelpPortalRSC() {
+ const { popularHelpArticles, allHelpArticles } = await fetch(
+ "https://dub-site-git-content-api-elegance.vercel.app/api/content",
+ ).then((res) => res.json());
return (
- <motion.div
- className="max-w-full sm:w-[24rem]"
- animate={{ height: contentHeight }}
- transition={{ ease: "easeInOut" }}
- >
- <div ref={ref}>
- {screen === "main" && <MainScreen setScreen={setScreen} />}
- {screen === "contact" && <ContactForm setScreen={setScreen} />}
- </div>
- </motion.div>
+ <HelpButton
+ popularHelpArticles={popularHelpArticles}
+ allHelpArticles={allHelpArticles}
+ />
);
}
diff --git a/apps/web/ui/layout/help/main-screen.tsx b/apps/web/ui/layout/help/main-screen.tsx
index a3ff051b6b..e07638c4fa 100644
--- a/apps/web/ui/layout/help/main-screen.tsx
+++ b/apps/web/ui/layout/help/main-screen.tsx
@@ -1,19 +1,65 @@
+import { ExpandingArrow } from "@dub/ui";
+import va from "@vercel/analytics";
+import { Command, useCommandState } from "cmdk";
+import Fuse from "fuse.js";
import { ExternalLink, MessageSquareText } from "lucide-react";
-import { Dispatch, SetStateAction } from "react";
+import { Dispatch, SetStateAction, useContext, useMemo, useRef } from "react";
+import Highlighter from "react-highlight-words";
+import { useDebouncedCallback } from "use-debounce";
+import { HelpContext } from "./portal";
export function MainScreen({
setScreen,
}: {
setScreen: Dispatch<SetStateAction<"main" | "contact">>;
}) {
+ const commandListRef = useRef<HTMLDivElement>(null);
+ const debouncedTrackSearch = useDebouncedCallback((query: string) => {
+ va.track("CMDK Search", {
+ query,
+ });
+ }, 1000);
return (
- <div className="w-full">
- <div className="px-6 py-5">
- <h3 className="font-semibold">Need help?</h3>
- <p className="mt-2 text-sm text-gray-600">
- Check out our help center or get in touch for more assistance.
- </p>
- <div className="mt-3 flex h-[200px] flex-col space-y-1"></div>
+ <div>
+ <div className="p-4">
+ <div className="p-2">
+ <h3 className="font-semibold">How can we help?</h3>
+ </div>
+ <Command label="help-portal" loop shouldFilter={false}>
+ <Command.Input
+ autoFocus
+ onInput={(e) => {
+ // hack to scroll to top of list when input changes (for some reason beyond my comprehension, setTimeout is needed)
+ setTimeout(() => {
+ commandListRef.current?.scrollTo(0, 0);
+ }, 0);
+ debouncedTrackSearch(e.currentTarget.value);
+ }}
+ placeholder="Search articles, guides, and more..."
+ className="w-full border-none p-2 text-sm placeholder-gray-400 focus:outline-none focus:ring-0"
+ />
+ <Command.List
+ ref={commandListRef}
+ className="scrollbar-hide h-[22rem] overflow-scroll border-t border-gray-200 py-2 transition-all"
+ >
+ <Command.Empty
+ onClick={() => setScreen("contact")}
+ className="flex cursor-pointer items-center space-x-2 rounded-md bg-gray-100 px-4 py-2 text-sm text-gray-600"
+ >
+ <MessageSquareText className="h-4 w-4 text-gray-400" />
+ <div className="flex flex-col space-y-1">
+ <p className="text-sm font-medium text-purple-600">
+ Can't find what you're looking for?
+ </p>
+ <p className="text-xs text-gray-400">
+ Send us a message and we'll get back to you as soon as
+ possible.
+ </p>
+ </div>
+ </Command.Empty>
+ <CommandResults />
+ </Command.List>
+ </Command>
</div>
<div className="flex justify-between border-t border-gray-200 px-5 py-4">
<button
@@ -35,3 +81,60 @@ export function MainScreen({
</div>
);
}
+
+const CommandResults = () => {
+ const {
+ popularHelpArticles: POPULAR_HELP_CONTENT,
+ allHelpArticles: ALL_HELP_CONTENT,
+ } = useContext(HelpContext);
+
+ const fuse = useMemo(
+ () =>
+ new Fuse(ALL_HELP_CONTENT, {
+ keys: ["title", "searchableSummary"],
+ }),
+ [ALL_HELP_CONTENT],
+ );
+
+ const search = useCommandState((state) => state.search);
+
+ const results = useMemo(() => {
+ if (search.length === 0) {
+ return POPULAR_HELP_CONTENT;
+ }
+ return fuse.search(search).map((r) => r.item);
+ }, [search, POPULAR_HELP_CONTENT]);
+
+ return results.map(({ slug, title, summary }) => (
+ <Command.Item
+ key={slug}
+ value={title}
+ onSelect={() => {
+ va.track("CMDK Search Selected", {
+ query: search,
+ slug,
+ });
+ window.open(`https://dub.co/help/article/${slug}`);
+ }}
+ className="group flex cursor-pointer items-center justify-between space-x-2 rounded-md px-4 py-2 hover:bg-gray-100 active:bg-gray-200 aria-selected:bg-gray-100"
+ >
+ <div className="flex flex-col space-y-1">
+ <Highlighter
+ highlightClassName="underline bg-transparent text-purple-500"
+ searchWords={search.split(" ")}
+ autoEscape={true}
+ textToHighlight={title}
+ className="text-sm font-medium text-gray-600 group-aria-selected:text-purple-600 sm:group-hover:text-purple-600"
+ />
+ <Highlighter
+ highlightClassName="underline bg-transparent text-purple-500"
+ searchWords={search.split(" ")}
+ autoEscape={true}
+ textToHighlight={summary}
+ className="line-clamp-1 text-xs text-gray-400"
+ />
+ </div>
+ <ExpandingArrow className="invisible -ml-4 h-4 w-4 text-purple-600 group-aria-selected:visible sm:group-hover:visible" />
+ </Command.Item>
+ ));
+};
diff --git a/apps/web/ui/layout/help/portal.tsx b/apps/web/ui/layout/help/portal.tsx
new file mode 100644
index 0000000000..3bde639434
--- /dev/null
+++ b/apps/web/ui/layout/help/portal.tsx
@@ -0,0 +1,82 @@
+"use client";
+
+import { Popover } from "@dub/ui";
+import { AnimatePresence, motion } from "framer-motion";
+import { XIcon } from "lucide-react";
+import { createContext, useEffect, useRef, useState } from "react";
+import { HelpArticle } from ".";
+import { ContactForm } from "./contact-form";
+import { MainScreen } from "./main-screen";
+
+export const HelpContext = createContext<{
+ popularHelpArticles: HelpArticle[];
+ allHelpArticles: HelpArticle[];
+}>({
+ popularHelpArticles: [],
+ allHelpArticles: [],
+});
+
+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="end"
+ >
+ <button
+ type="button"
+ onClick={() => 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"
+ >
+ <AnimatePresence>
+ <motion.div
+ key={isOpen ? "open" : "closed"}
+ className="absolute inset-0 flex items-center justify-center font-medium text-gray-700 hover:text-gray-700"
+ initial={{ opacity: 0, scale: 0 }}
+ animate={{ opacity: 1, scale: 1 }}
+ exit={{ opacity: 0, scale: 0 }}
+ >
+ {isOpen ? <XIcon className="h-4 w-4" strokeWidth={2} /> : "?"}
+ </motion.div>
+ </AnimatePresence>
+ </button>
+ </Popover>
+ </HelpContext.Provider>
+ );
+}
+
+function HelpSection() {
+ const [screen, setScreen] = useState<"main" | "contact">("main");
+
+ const ref = useRef<HTMLDivElement>(null);
+ const [contentHeight, setContentHeight] = useState(0);
+
+ useEffect(() => {
+ if (ref.current) {
+ setContentHeight(ref.current.offsetHeight);
+ }
+ });
+
+ return (
+ <motion.div
+ className="w-full overflow-hidden sm:w-[32rem]"
+ animate={{ height: contentHeight }}
+ transition={{ ease: "easeInOut" }}
+ >
+ <div ref={ref}>
+ {screen === "main" && <MainScreen setScreen={setScreen} />}
+ {screen === "contact" && <ContactForm setScreen={setScreen} />}
+ </div>
+ </motion.div>
+ );
+}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 1ca31034f1..9044445160 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -13105,7 +13105,7 @@ packages:
optional: true
dependencies:
prettier: 3.2.5
- prettier-plugin-organize-imports: 3.2.4([email protected])([email protected])
+ prettier-plugin-organize-imports: 3.2.4([email protected])([email protected])
dev: true