The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
redirect support
Steven Tey42dc78e74191
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/layout.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/layout.tsxindex bf65248a1e..d6d455778c 100644--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/layout.tsx+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/layout.tsx@@ -1,6 +1,6 @@import { MainNav } from "@/ui/layout/main-nav";+import { HelpButton } from "@/ui/layout/sidebar/help-button";import { PartnersSidebarNav } from "@/ui/layout/sidebar/partners-sidebar-nav";-import { CircleQuestion } from "@dub/ui";import { PartnerProfileAuth } from "./auth";export default function PartnerDashboardLayout({@@ -9,18 +9,7 @@ export default function PartnerDashboardLayout({children: React.ReactNode;}) {return (- <MainNav- toolContent={- <a- href="https://dub.co/help/category/programs"- target="_blank"- className="text-content-default hover:bg-bg-inverted/5 flex size-11 shrink-0 items-center justify-center rounded-lg"- >- <CircleQuestion className="size-5" strokeWidth={2} />- </a>- }- sidebar={PartnersSidebarNav}- >+ <MainNav toolContent={<HelpButton />} sidebar={PartnersSidebarNav}><PartnerProfileAuth>{children}</PartnerProfileAuth></MainNav>);diff --git a/apps/web/app/api/support/route.ts b/apps/web/app/api/support/route.tsdeleted file mode 100644index df0dbc058b..0000000000--- a/apps/web/app/api/support/route.ts+++ /dev/null@@ -1,65 +0,0 @@-import { withSession } from "@/lib/auth";-import { plain, upsertPlainCustomer } from "@/lib/plain";-import { NextResponse } from "next/server";-import { z } from "zod";--const supportRequestQuerySchema = z.object({- message: z.string().min(1),- attachmentIds: z.array(z.string()),-});--// POST /api/support – file a support request-export const POST = withSession(async ({ req, session }) => {- const { message, attachmentIds } = supportRequestQuerySchema.parse(- await req.json(),- );-- if (!session.user.email) {- return NextResponse.json({- error: "Invalid user email",- });- }-- let plainCustomerId: string | null = null;-- const plainCustomer = await plain.getCustomerByEmail({- email: session.user.email,- });-- if (plainCustomer.data) {- plainCustomerId = plainCustomer.data.id;- } else {- const { data, error } = await upsertPlainCustomer(session.user);- if (error) {- return NextResponse.json({- error: error.message,- });- }-- if (data) {- plainCustomerId = data.customer.id;- }- }-- if (!plainCustomerId) {- return NextResponse.json({- error: "Plain customer not found",- });- }-- const res = await plain.createThread({- customerIdentifier: {- customerId: plainCustomerId,- },- components: [- {- componentText: {- text: message,- },- },- ],- attachmentIds,- });-- return NextResponse.json(res);-});diff --git a/apps/web/app/api/support/upload/route.ts b/apps/web/app/api/support/upload/route.tsdeleted file mode 100644index 2ff40352b5..0000000000--- a/apps/web/app/api/support/upload/route.ts+++ /dev/null@@ -1,57 +0,0 @@-import { withSession } from "@/lib/auth";-import { plain, upsertPlainCustomer } from "@/lib/plain";-import { AttachmentType } from "@team-plain/typescript-sdk";-import { NextResponse } from "next/server";--// POST /api/support/upload – get a signed URL to upload an attachment-export const GET = withSession(async ({ searchParams, session }) => {- if (!session.user.email) {- return NextResponse.json({- error: "Invalid user email",- });- }-- let plainCustomerId: string | null = null;-- const plainCustomer = await plain.getCustomerByEmail({- email: session.user.email,- });-- if (plainCustomer.data) {- plainCustomerId = plainCustomer.data.id;- } else {- const { data, error } = await upsertPlainCustomer(session.user);-- if (error) {- return NextResponse.json({- error: error.message,- });- }-- if (data) {- plainCustomerId = data.customer.id;- }- }-- if (!plainCustomerId) {- return NextResponse.json({- error: "Plain customer not found",- });- }-- const res = await plain.createAttachmentUploadUrl({- customerId: plainCustomerId,- fileName: searchParams.name,- fileSizeBytes: parseInt(searchParams.size),- attachmentType: AttachmentType.CustomTimelineEntry,- });-- if (res.error) {- return NextResponse.json({- error: res.error,- });- } else {- console.log("Attachment upload stuff:", res.data);- return NextResponse.json(res.data);- }-});diff --git a/apps/web/app/app.dub.co/(dashboard)/layout.tsx b/apps/web/app/app.dub.co/(dashboard)/layout.tsxindex d64f922daa..588a3e39d3 100644--- a/apps/web/app/app.dub.co/(dashboard)/layout.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/layout.tsx@@ -1,6 +1,6 @@import { MainNav } from "@/ui/layout/main-nav";import { AppSidebarNav } from "@/ui/layout/sidebar/app-sidebar-nav";-import { HelpButtonRSC } from "@/ui/layout/sidebar/help-button-rsc";+import { HelpButton } from "@/ui/layout/sidebar/help-button";import { NewsRSC } from "@/ui/layout/sidebar/news-rsc";import { ReferButton } from "@/ui/layout/sidebar/refer-button";import Toolbar from "@/ui/layout/toolbar/toolbar";@@ -21,7 +21,7 @@ export default async function Layout({ children }: { children: ReactNode }) {toolContent={<><ReferButton />- <HelpButtonRSC />+ <HelpButton /></>}newsContent={<NewsRSC />}diff --git a/apps/web/ui/layout/help/contact-form.tsx b/apps/web/ui/layout/help/contact-form.tsxdeleted file mode 100644index 91757319c8..0000000000--- a/apps/web/ui/layout/help/contact-form.tsx+++ /dev/null@@ -1,217 +0,0 @@-import { CheckCircleFill } from "@/ui/shared/icons";-import {- Button,- FileUpload,- LoadingSpinner,- useEnterSubmit,- useMediaQuery,-} from "@dub/ui";-import { ChevronLeft, Paperclip, Trash2 } from "lucide-react";-import { AnimatePresence, motion } from "motion/react";-import { Dispatch, SetStateAction, useRef, useState } from "react";-import TextareaAutosize from "react-textarea-autosize";-import { toast } from "sonner";--export function ContactForm({- setScreen,-}: {- setScreen: Dispatch<SetStateAction<"main" | "contact">>;-}) {- const [data, setData] = useState<{- message: string;- attachmentIds: string[];- }>({- message: "",- attachmentIds: [],- });-- const [uploads, setUploads] = useState<- {- file: File;- uploading: boolean;- attachmentId?: string;- }[]- >([]);-- const handleUpload = async (file: File) => {- setUploads((prev) => [...prev, { file, uploading: true }]);-- const {- attachment: { id: attachmentId },- uploadFormUrl,- uploadFormData,- } = await fetch(`/api/support/upload?name=${file.name}&size=${file.size}`, {- method: "GET",- }).then((res) => res.json());-- const form = new FormData();- uploadFormData.forEach(({ key, value }) => {- form.append(key, value);- });- form.append("file", file);-- fetch(uploadFormUrl, {- method: "POST",- body: form,- })- .then((res) => {- if (!res.ok) {- toast.error(res.statusText);- }- })- .catch((err) => {- console.error("Error uploading file:", err.message ? err.message : err);- });-- setUploads((prev) =>- prev.map((upload) =>- upload.file === file- ? { ...upload, uploading: false, attachmentId }- : upload,- ),- );- setData((prev) => ({- ...prev,- attachmentIds: [...prev.attachmentIds, attachmentId],- }));- };-- const { isMobile } = useMediaQuery();-- const formRef = useRef<HTMLFormElement>(null);- const [formStatus, setFormStatus] = useState<"idle" | "loading" | "success">(- "idle",- );-- const { handleKeyDown } = useEnterSubmit(formRef);-- return (- <div className="relative w-full px-3 pb-16 pt-5 sm:px-6">- <button- type="button"- className="-ml-2 flex items-center space-x-1 px-2 py-1"- onClick={() => setScreen("main")}- >- <ChevronLeft className="h-5 w-5" />- <h3 className="text-lg font-semibold text-neutral-700">- Contact support- </h3>- </button>-- <AnimatePresence>- {formStatus === "success" ? (- <motion.div- className="flex h-[280px] flex-col items-center justify-center space-y-3 text-center"- initial={{ opacity: 0, y: 10 }}- animate={{ opacity: 1, y: 0 }}- >- <CheckCircleFill className="h-8 w-8 text-green-500" />- <p className="text-neutral-500">- Thanks for reaching out! <br /> We'll get back to you as soon as- possible.- </p>- </motion.div>- ) : (- <motion.form- ref={formRef}- className="mt-5 grid gap-2"- onSubmit={async (e) => {- e.preventDefault();- setFormStatus("loading");- const res = await fetch("/api/support", {- method: "POST",- body: JSON.stringify(data),- }).then((res) => res.json());- if (res.error) {- toast.error(res.error);- setFormStatus("idle");- } else {- setData({ message: "", attachmentIds: [] });- setFormStatus("success");- }- }}- initial={{ opacity: 1, y: 0 }}- exit={{ opacity: 0, y: -10 }}- >- <label>- <span className="text-sm font-medium text-neutral-700">- Describe the issue- </span>- <TextareaAutosize- name="message"- required- placeholder="E.g. My custom domain is not working."- minRows={8}- autoFocus={!isMobile}- autoComplete="off"- value={data.message}- onChange={(e) =>- setData((prev) => ({ ...prev, message: e.target.value }))- }- onKeyDown={handleKeyDown}- className={`${- false- ? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"- : "border-neutral-300 text-neutral-900 placeholder-neutral-300 focus:border-neutral-500 focus:ring-neutral-500"- } mt-1 block w-full resize-none rounded-md focus:outline-none sm:text-sm`}- />- </label>-- <div className="grid w-full gap-2">- {uploads.map((upload) => (- <div- key={upload.attachmentId}- className="flex w-full items-center justify-between rounded-md border border-neutral-200"- >- <div className="flex flex-1 items-center space-x-2 p-2">- {upload.uploading ? (- <LoadingSpinner className="h-4 w-4" />- ) : (- <Paperclip className="h-4 w-4 text-neutral-500" />- )}- <p className="text-center text-sm text-neutral-500">- {upload.file.name}- </p>- </div>- <button- className="h-full rounded-r-md border-l border-neutral-200 p-2"- onClick={() => {- setUploads((prev) =>- prev.filter((i) => i.file.name !== upload.file.name),- );- setData((prev) => ({- ...prev,- attachmentIds: prev.attachmentIds.filter(- (id) => id !== upload.attachmentId,- ),- }));- }}- >- <Trash2 className="h-4 w-4 text-neutral-500" />- </button>- </div>- ))}- </div>- <FileUpload- accept="any"- className="aspect-[5/1] w-full rounded-md border border-dashed border-neutral-300"- iconClassName="w-5 h-5"- variant="plain"- onChange={async ({ file }) => await handleUpload(file)}- content="Drag and drop or click to upload."- />-- <div className="fixed bottom-0 left-0 z-10 flex h-16 w-full items-center justify-center rounded-b-lg bg-white px-3 sm:px-6">- <Button- className="h-9"- disabled={!data.message}- loading={formStatus === "loading"}- text="Send message"- />- </div>- </motion.form>- )}- </AnimatePresence>- </div>- );-}diff --git a/apps/web/ui/layout/help/help-articles.tsx b/apps/web/ui/layout/help/help-articles.tsxdeleted file mode 100644index b5efcd8f11..0000000000--- a/apps/web/ui/layout/help/help-articles.tsx+++ /dev/null@@ -1,150 +0,0 @@-import { ExpandingArrow, useMediaQuery } from "@dub/ui";-import { Command, useCommandState } from "cmdk";-import Fuse from "fuse.js";-import { ExternalLink, MessageSquareText } from "lucide-react";-import { useSession } from "next-auth/react";-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 ".";--export function HelpArticles({- setScreen,-}: {- setScreen: Dispatch<SetStateAction<"main" | "contact">>;-}) {- const { data: session } = useSession();- const commandListRef = useRef<HTMLDivElement>(null);- const debouncedTrackSearch = useDebouncedCallback((query: string) => {- posthog.capture("help_articles_searched", {- query,- });- }, 1000);- const { isMobile } = useMediaQuery();-- return (- <div>- <div className="p-2 sm:p-4">- <div className="p-2">- <h3 className="text-lg font-semibold text-neutral-700">- 👋 How can we help?- </h3>- </div>- <Command label="help-portal" loop shouldFilter={false}>- <Command.Input- autoFocus={!isMobile}- 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-neutral-400 focus:outline-none focus:ring-0 sm:text-base"- />- <Command.List- ref={commandListRef}- className="scrollbar-hide h-[22rem] overflow-scroll border-t border-neutral-200 py-2 transition-all"- >- <Command.Empty- onClick={() => setScreen("contact")}- className="flex cursor-pointer items-center space-x-2 rounded-md bg-neutral-100 px-4 py-2 text-sm text-neutral-600"- >- <MessageSquareText className="h-4 w-4 text-neutral-400" />- <div className="flex flex-col space-y-1">- <p className="text-sm font-medium text-blue-600">- Can't find what you're looking for?- </p>- <p className="text-xs text-neutral-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-neutral-200 px-3 py-4 sm:px-6">- {session ? (- <button- onClick={() => setScreen("contact")}- className="flex items-center space-x-2 hover:underline"- >- <MessageSquareText className="h-4 w-4" />- <p className="text-sm">Contact us</p>- </button>- ) : (- <div />- )}- <a- href="https://dub.co/help"- target="_blank"- className="flex items-center space-x-2 hover:underline"- >- <p className="text-sm">Help center</p>- <ExternalLink className="h-4 w-4" />- </a>- </div>- </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={() => {- posthog.capture("help_article_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-neutral-100 active:bg-neutral-200 aria-selected:bg-neutral-100"- >- <div className="flex flex-col space-y-1">- <Highlighter- highlightClassName="underline bg-transparent text-blue-600"- searchWords={search.split(" ")}- autoEscape={true}- textToHighlight={title}- className="text-sm font-medium text-neutral-600 group-aria-selected:text-blue-600 sm:group-hover:text-blue-600"- />- <Highlighter- highlightClassName="underline bg-transparent text-blue-600"- searchWords={search.split(" ")}- autoEscape={true}- textToHighlight={summary}- className="line-clamp-1 text-xs text-neutral-400"- />- </div>- <ExpandingArrow className="invisible -ml-4 h-4 w-4 text-blue-600 group-aria-selected:visible sm:group-hover:visible" />- </Command.Item>- ));-};diff --git a/apps/web/ui/layout/help/help-section.tsx b/apps/web/ui/layout/help/help-section.tsxdeleted file mode 100644index 3d4c082df1..0000000000--- a/apps/web/ui/layout/help/help-section.tsx+++ /dev/null@@ -1,30 +0,0 @@-"use client";--import { useResizeObserver } from "@dub/ui";-import { motion } from "motion/react";-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-y-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.tsxdeleted file mode 100644index 1495ba3cfc..0000000000--- a/apps/web/ui/layout/help/index.tsx+++ /dev/null@@ -1,16 +0,0 @@-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/page-content/page-content-old.tsx b/apps/web/ui/layout/page-content/page-content-old.tsxindex cde4b21339..e3c0bc22d8 100644--- a/apps/web/ui/layout/page-content/page-content-old.tsx+++ b/apps/web/ui/layout/page-content/page-content-old.tsx@@ -3,7 +3,7 @@ import { cn } from "@dub/utils";import { ChevronLeft } from "lucide-react";import Link from "next/link";import { PropsWithChildren, ReactNode } from "react";-import { HelpButtonRSC } from "../sidebar/help-button-rsc";+import { HelpButtonRSC } from "../sidebar/help-button";import UserDropdown from "../sidebar/user-dropdown";import { NavButton } from "./nav-button";diff --git a/apps/web/ui/layout/sidebar/help-button-rsc.tsx b/apps/web/ui/layout/sidebar/help-button-rsc.tsxdeleted file mode 100644index fdf869a202..0000000000--- a/apps/web/ui/layout/sidebar/help-button-rsc.tsx+++ /dev/null@@ -1,13 +0,0 @@-import { getContentAPI } from "@/lib/fetchers/get-content-api";-import { HelpButton } from "./help-button";--export async function HelpButtonRSC() {- const { popularHelpArticles, allHelpArticles } = await getContentAPI();-- 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.tsxindex 14b6cc05ea..a3b692d05c 100644--- a/apps/web/ui/layout/sidebar/help-button.tsx+++ b/apps/web/ui/layout/sidebar/help-button.tsx@@ -1,63 +1,13 @@-"use client";--import { X } from "@/ui/shared/icons";-import { CircleQuestion, Popover } from "@dub/ui";-import { cn } from "@dub/utils";-import { AnimatePresence, motion } from "motion/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);+import { CircleQuestion } from "@dub/ui";+export async function HelpButton() {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={cn(- "relative",- "text-content-default flex size-11 shrink-0 items-center justify-center rounded-lg",- "hover:bg-bg-inverted/5 active:bg-bg-inverted/10 data-[state=open]:bg-bg-inverted/10 transition-colors duration-150",- "outline-none focus-visible:ring-2 focus-visible:ring-black/50",- )}- >- <AnimatePresence>- <motion.div- key={isOpen ? "open" : "closed"}- className="absolute inset-0 flex items-center justify-center font-medium"- initial={{ opacity: 0, scale: 0 }}- animate={{ opacity: 1, scale: 1 }}- exit={{ opacity: 0, scale: 0 }}- >- {isOpen ? (- <X className="size-5" strokeWidth={2} />- ) : (- <CircleQuestion className="size-5" />- )}- </motion.div>- </AnimatePresence>- </button>- </Popover>- </HelpContext.Provider>+ <a+ href="https://dub.co/contact/support"+ target="_blank"+ className="text-content-default hover:bg-bg-inverted/5 flex size-11 shrink-0 items-center justify-center rounded-lg"+ >+ <CircleQuestion className="size-5" strokeWidth={2} />+ </a>);}