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.

Add sidebar layout w/ nav items

Tim Wilson5eaede86626e
diff --git a/apps/web/app/app.dub.co/(dashboard)/layout.tsx b/apps/web/app/app.dub.co/(dashboard)/layout.tsx
index 5092c7f216..d8b7eaf4cf 100644
--- a/apps/web/app/app.dub.co/(dashboard)/layout.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/layout.tsx
@@ -1,4 +1,5 @@
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 { NewsRSC } from "@/ui/layout/sidebar/news-rsc";
import Toolbar from "@/ui/layout/toolbar/toolbar";
@@ -12,7 +13,11 @@ export default async function Layout({ children }: { children: ReactNode }) {
return (
<>
<div className="min-h-screen w-full bg-white">
- <MainNav toolContent={<HelpButtonRSC />} newsContent={<NewsRSC />}>
+ <MainNav
+ sidebar={AppSidebarNav}
+ toolContent={<HelpButtonRSC />}
+ newsContent={<NewsRSC />}
+ >
{children}
</MainNav>
</div>
diff --git a/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/[programId]/customers/page.tsx b/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/[programId]/customers/page.tsx
new file mode 100644
index 0000000000..b27b280f4f
--- /dev/null
+++ b/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/[programId]/customers/page.tsx
@@ -0,0 +1,3 @@
+export default function CustomersPage() {
+ return <div>Customers</div>;
+}
diff --git a/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/[programId]/events/page.tsx b/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/[programId]/events/page.tsx
new file mode 100644
index 0000000000..aca47869fc
--- /dev/null
+++ b/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/[programId]/events/page.tsx
@@ -0,0 +1,3 @@
+export default function EventsPage() {
+ return <div>Events</div>;
+}
diff --git a/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/[programId]/links/page.tsx b/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/[programId]/links/page.tsx
new file mode 100644
index 0000000000..04d16e08fd
--- /dev/null
+++ b/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/[programId]/links/page.tsx
@@ -0,0 +1,3 @@
+export default function LinksPage() {
+ return <div>Links</div>;
+}
diff --git a/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/[programId]/page.tsx b/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/[programId]/page.tsx
new file mode 100644
index 0000000000..c4c6b0829d
--- /dev/null
+++ b/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/[programId]/page.tsx
@@ -0,0 +1,3 @@
+export default function ProgramPage() {
+ return <div>Program Overview</div>;
+}
diff --git a/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/[programId]/payouts/page.tsx b/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/[programId]/payouts/page.tsx
new file mode 100644
index 0000000000..4364e3ef1d
--- /dev/null
+++ b/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/[programId]/payouts/page.tsx
@@ -0,0 +1,3 @@
+export default function PayoutsPage() {
+ return <div>Payouts</div>;
+}
diff --git a/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/[programId]/resources/page.tsx b/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/[programId]/resources/page.tsx
new file mode 100644
index 0000000000..fd1dc3f140
--- /dev/null
+++ b/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/[programId]/resources/page.tsx
@@ -0,0 +1,3 @@
+export default function ResourcesPage() {
+ return <div>Resources</div>;
+}
diff --git a/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/marketplace/page.tsx b/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/marketplace/page.tsx
new file mode 100644
index 0000000000..fa95a59fab
--- /dev/null
+++ b/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/marketplace/page.tsx
@@ -0,0 +1,3 @@
+export default function MarketplacePage() {
+ return <div>Marketplace</div>;
+}
diff --git a/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/page.tsx b/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/page.tsx
new file mode 100644
index 0000000000..4bb76745e7
--- /dev/null
+++ b/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/page.tsx
@@ -0,0 +1,3 @@
+export default function DashboardPage() {
+ return <div>Partner Dashboard</div>;
+}
diff --git a/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/settings/page.tsx b/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/settings/page.tsx
new file mode 100644
index 0000000000..29d9c79e91
--- /dev/null
+++ b/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/settings/page.tsx
@@ -0,0 +1,3 @@
+export default function ProfileSettingsPage() {
+ return <div>Profile Settings</div>;
+}
diff --git a/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/settings/payouts/page.tsx b/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/settings/payouts/page.tsx
new file mode 100644
index 0000000000..4364e3ef1d
--- /dev/null
+++ b/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/settings/payouts/page.tsx
@@ -0,0 +1,3 @@
+export default function PayoutsPage() {
+ return <div>Payouts</div>;
+}
diff --git a/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/settings/people/page.tsx b/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/settings/people/page.tsx
new file mode 100644
index 0000000000..930623db48
--- /dev/null
+++ b/apps/web/app/partners.dub.co/(dashboard)/[partnerId]/settings/people/page.tsx
@@ -0,0 +1,3 @@
+export default function PeoplePage() {
+ return <div>People</div>;
+}
diff --git a/apps/web/app/partners.dub.co/(dashboard)/layout.tsx b/apps/web/app/partners.dub.co/(dashboard)/layout.tsx
new file mode 100644
index 0000000000..82525639c2
--- /dev/null
+++ b/apps/web/app/partners.dub.co/(dashboard)/layout.tsx
@@ -0,0 +1,15 @@
+import { MainNav } from "@/ui/layout/main-nav";
+import { HelpButtonRSC } from "@/ui/layout/sidebar/help-button-rsc";
+import { PartnersSidebarNav } from "@/ui/layout/sidebar/partners-sidebar-nav";
+
+export default function DashboardLayout({
+ children,
+}: {
+ children: React.ReactNode;
+}) {
+ return (
+ <MainNav toolContent={<HelpButtonRSC />} sidebar={PartnersSidebarNav}>
+ {children}
+ </MainNav>
+ );
+}
diff --git a/apps/web/app/partners.dub.co/layout.tsx b/apps/web/app/partners.dub.co/layout.tsx
new file mode 100644
index 0000000000..9869d4f1f2
--- /dev/null
+++ b/apps/web/app/partners.dub.co/layout.tsx
@@ -0,0 +1,13 @@
+"use client";
+
+import { ModalProvider } from "@/ui/modals/modal-provider";
+import { SessionProvider } from "next-auth/react";
+import { ReactNode } from "react";
+
+export default function PartnersLayout({ children }: { children: ReactNode }) {
+ return (
+ <SessionProvider>
+ <ModalProvider>{children}</ModalProvider>
+ </SessionProvider>
+ );
+}
diff --git a/apps/web/app/partners.dub.co/onboarding/layout.tsx b/apps/web/app/partners.dub.co/onboarding/layout.tsx
index 3742bf6849..5e7a8601cf 100644
--- a/apps/web/app/partners.dub.co/onboarding/layout.tsx
+++ b/apps/web/app/partners.dub.co/onboarding/layout.tsx
@@ -1,7 +1,4 @@
-"use client";
-
import { Grid } from "@dub/ui";
-import { SessionProvider } from "next-auth/react";
export default function AdminAuthLayout({
children,
@@ -9,7 +6,7 @@ export default function AdminAuthLayout({
children: React.ReactNode;
}) {
return (
- <SessionProvider>
+ <>
<div className="fixed inset-0 [mask-image:radial-gradient(60%_60%_at_50%_0%,black,transparent)]">
<Grid className="text-neutral-200" />
<div className="absolute inset-0 -translate-y-1/2 -scale-x-100 bg-[conic-gradient(from_-32deg,#f00_0deg,#EAB308_99deg,#5CFF80_162deg,#00FFF9_216deg,#3A8BFD_288deg,#855AFC_360deg)] opacity-25 blur-[200px]" />
@@ -17,6 +14,6 @@ export default function AdminAuthLayout({
<div className="relative z-10 flex flex-col items-center justify-center">
{children}
</div>
- </SessionProvider>
+ </>
);
}
diff --git a/apps/web/app/partners.dub.co/onboarding/onboarding-form.tsx b/apps/web/app/partners.dub.co/onboarding/onboarding-form.tsx
index e70280e006..34f10e56a4 100644
--- a/apps/web/app/partners.dub.co/onboarding/onboarding-form.tsx
+++ b/apps/web/app/partners.dub.co/onboarding/onboarding-form.tsx
@@ -1,7 +1,6 @@
"use client";
import { onboardPartner } from "@/lib/actions/partners/onboard-partner";
-import { AlertCircleFill } from "@/ui/shared/icons";
import { Button, useMediaQuery } from "@dub/ui";
import { cn } from "@dub/utils/src/functions";
import { useRouter } from "next/navigation";
@@ -19,7 +18,6 @@ export function OnboardingForm() {
formState: { errors, isSubmitting, isSubmitSuccessful },
} = useForm<{
name: string;
- slug: string;
}>();
return (
@@ -27,15 +25,8 @@ export function OnboardingForm() {
onSubmit={handleSubmit(async (data) => {
try {
const result = await onboardPartner(data);
- if (!result?.data?.ok) {
- if (result?.data?.slugConflict)
- setError("slug", {
- message: `The slug "${data.slug}" is already in use.`,
- });
- else throw new Error("Failed to create partner");
- return;
- }
- router.push(`/${result?.data?.slug}`);
+ if (!result?.data?.ok) throw new Error("Failed to create partner");
+ router.push(`/${result?.data?.partnerId || ""}`);
} catch (error) {
console.error(error);
setError("root.serverError", {
@@ -57,48 +48,13 @@ export function OnboardingForm() {
: "border-gray-300 text-gray-900 placeholder-gray-400 focus:border-gray-500 focus:ring-gray-500",
)}
placeholder="Acme, Inc."
+ autoFocus={!isMobile}
{...register("name", {
required: true,
})}
/>
</label>
- <label>
- <span className="text-sm font-medium text-gray-800">Partner slug</span>
- <div className="relative mt-2 flex rounded-md shadow-sm">
- <span className="inline-flex items-center rounded-l-md border border-r-0 border-gray-300 bg-gray-50 px-3 text-gray-500 sm:text-sm">
- partners.{process.env.NEXT_PUBLIC_APP_DOMAIN}
- </span>
- <input
- type="text"
- autoComplete="off"
- className={`${
- errors.slug
- ? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"
- : "border-gray-300 text-gray-900 placeholder-gray-400 focus:border-gray-500 focus:ring-gray-500"
- } block w-full rounded-r-md focus:outline-none sm:text-sm`}
- placeholder="acme"
- {...register("slug", {
- required: true,
- minLength: 3,
- maxLength: 48,
- pattern: /^[a-zA-Z0-9\-]+$/,
- })}
- />
- {errors.slug && (
- <div className="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3">
- <AlertCircleFill
- className="h-5 w-5 text-red-500"
- aria-hidden="true"
- />
- </div>
- )}
- </div>
- {errors.slug && (
- <span className="text-xs text-red-600">{errors.slug.message}</span>
- )}
- </label>
-
<Button
type="submit"
text="Create partner account"
diff --git a/apps/web/lib/actions/partners/onboard-partner.ts b/apps/web/lib/actions/partners/onboard-partner.ts
index 49fea1025f..a084201b72 100644
--- a/apps/web/lib/actions/partners/onboard-partner.ts
+++ b/apps/web/lib/actions/partners/onboard-partner.ts
@@ -1,13 +1,12 @@
"use server";
+import { createId } from "@/lib/api/utils";
import { prisma } from "@/lib/prisma";
-import { Prisma } from "@prisma/client";
import z from "../../zod";
import { authUserActionClient } from "../safe-action";
const onboardPartnerSchema = z.object({
name: z.string(),
- slug: z.string(),
});
// Update the notification preference for a user in a workspace
@@ -15,13 +14,13 @@ export const onboardPartner = authUserActionClient
.schema(onboardPartnerSchema)
.action(async ({ ctx, parsedInput }) => {
const { user } = ctx;
- const { name, slug } = parsedInput;
+ const { name } = parsedInput;
try {
const partner = await prisma.partner.create({
data: {
+ id: createId({ prefix: "pn_" }),
name,
- slug,
users: {
create: {
userId: user.id,
@@ -30,13 +29,10 @@ export const onboardPartner = authUserActionClient
},
},
});
- return { ok: true, slug: partner.slug };
+ return { ok: true, partnerId: partner.id };
} catch (e) {
- const slugConflict =
- e instanceof Prisma.PrismaClientKnownRequestError && e.code === "P2002";
return {
ok: false,
- slugConflict,
};
}
});
diff --git a/apps/web/prisma/schema/partner.prisma b/apps/web/prisma/schema/partner.prisma
index 36ce2d06c2..0f9dba31b4 100644
--- a/apps/web/prisma/schema/partner.prisma
+++ b/apps/web/prisma/schema/partner.prisma
@@ -12,7 +12,6 @@ enum PartnerRole {
model Partner {
id String @id @default(cuid())
name String
- slug String @unique
logo String?
bio String? @db.LongText
country String?
diff --git a/apps/web/ui/layout/main-nav.tsx b/apps/web/ui/layout/main-nav.tsx
index c1427074e5..a9e4e98fd4 100644
--- a/apps/web/ui/layout/main-nav.tsx
+++ b/apps/web/ui/layout/main-nav.tsx
@@ -4,6 +4,7 @@ import { useMediaQuery } from "@dub/ui";
import { cn } from "@dub/utils";
import { usePathname } from "next/navigation";
import {
+ ComponentType,
createContext,
Dispatch,
PropsWithChildren,
@@ -12,7 +13,6 @@ import {
useEffect,
useState,
} from "react";
-import { SidebarNav } from "./sidebar/sidebar-nav";
type SideNavContext = {
isOpen: boolean;
@@ -26,9 +26,17 @@ export const SideNavContext = createContext<SideNavContext>({
export function MainNav({
children,
+ sidebar: Sidebar,
toolContent,
newsContent,
-}: PropsWithChildren<{ toolContent?: ReactNode; newsContent?: ReactNode }>) {
+}: PropsWithChildren<{
+ sidebar: ComponentType<{
+ toolContent?: ReactNode;
+ newsContent?: ReactNode;
+ }>;
+ toolContent?: ReactNode;
+ newsContent?: ReactNode;
+}>) {
const pathname = usePathname();
const { isMobile } = useMediaQuery();
@@ -76,7 +84,7 @@ export function MainNav({
)}
/>
</div>
- <SidebarNav toolContent={toolContent} newsContent={newsContent} />
+ <Sidebar toolContent={toolContent} newsContent={newsContent} />
</div>
</div>
<div className="bg-neutral-100 md:pt-1.5">
diff --git a/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx b/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx
new file mode 100644
index 0000000000..500257ddd4
--- /dev/null
+++ b/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx
@@ -0,0 +1,225 @@
+"use client";
+
+import useWorkspace from "@/lib/swr/use-workspace";
+import { BetaFeatures } from "@/lib/types";
+import {
+ Books2,
+ CircleInfo,
+ ConnectedDots,
+ CubeSettings,
+ Gear2,
+ Gift,
+ Globe,
+ Key,
+ Receipt2,
+ ShieldCheck,
+ Users6,
+ Webhook,
+} from "@dub/ui/src/icons";
+import { useParams, usePathname } from "next/navigation";
+import { ReactNode, useMemo } from "react";
+import UserSurveyButton from "../user-survey";
+import { CursorRays } from "./icons/cursor-rays";
+import { Gear } from "./icons/gear";
+import { Hyperlink } from "./icons/hyperlink";
+import { LinesY } from "./icons/lines-y";
+import { SidebarNav, SidebarNavAreas } from "./sidebar-nav";
+import { Usage } from "./usage";
+import { WorkspaceDropdown } from "./workspace-dropdown";
+
+const NAV_AREAS: SidebarNavAreas<{
+ slug: string;
+ flags?: Record<BetaFeatures, boolean>;
+}> = {
+ // Top-level
+ default: ({ slug }) => ({
+ showSwitcher: true,
+ showNews: true,
+ direction: "left",
+ content: [
+ {
+ items: [
+ {
+ name: "Links",
+ icon: Hyperlink,
+ href: `/${slug}`,
+ exact: true,
+ },
+ {
+ name: "Analytics",
+ icon: LinesY,
+ href: `/${slug}/analytics`,
+ },
+ {
+ name: "Events",
+ icon: CursorRays,
+ href: `/${slug}/events`,
+ },
+ {
+ name: "Settings",
+ icon: Gear,
+ href: `/${slug}/settings`,
+ },
+ ],
+ },
+ ],
+ }),
+
+ // Workspace settings
+ workspaceSettings: ({ slug, flags }) => ({
+ title: "Settings",
+ backHref: `/${slug}`,
+ content: [
+ {
+ name: "Workspace",
+ items: [
+ {
+ name: "General",
+ icon: Gear2,
+ href: `/${slug}/settings`,
+ exact: true,
+ },
+ {
+ name: "Domains",
+ icon: Globe,
+ href: `/${slug}/settings/domains`,
+ },
+ {
+ name: "Library",
+ icon: Books2,
+ href: `/${slug}/settings/library`,
+ },
+ {
+ name: "Billing",
+ icon: Receipt2,
+ href: `/${slug}/settings/billing`,
+ },
+ {
+ name: "People",
+ icon: Users6,
+ href: `/${slug}/settings/people`,
+ },
+ {
+ name: "Integrations",
+ icon: ConnectedDots,
+ href: `/${slug}/settings/integrations`,
+ },
+ {
+ name: "Security",
+ icon: ShieldCheck,
+ href: `/${slug}/settings/security`,
+ },
+ ...(flags?.referrals
+ ? [
+ {
+ name: "Referrals",
+ icon: Gift,
+ href: `/${slug}/settings/referrals`,
+ },
+ ]
+ : []),
+ ],
+ },
+ {
+ name: "Developer",
+ items: [
+ {
+ name: "API Keys",
+ icon: Key,
+ href: `/${slug}/settings/tokens`,
+ },
+ {
+ name: "OAuth Apps",
+ icon: CubeSettings,
+ href: `/${slug}/settings/oauth-apps`,
+ },
+ ...(flags?.webhooks
+ ? [
+ {
+ name: "Webhooks",
+ icon: Webhook,
+ href: `/${slug}/settings/webhooks`,
+ },
+ ]
+ : []),
+ ],
+ },
+ {
+ name: "Account",
+ items: [
+ {
+ name: "Notifications",
+ icon: CircleInfo,
+ href: `/${slug}/settings/notifications`,
+ },
+ ],
+ },
+ ],
+ }),
+
+ // User settings
+ userSettings: ({ slug }) => ({
+ title: "Settings",
+ backHref: `/${slug}`,
+ content: [
+ {
+ name: "Account",
+ items: [
+ {
+ name: "General",
+ icon: Gear2,
+ href: "/account/settings",
+ exact: true,
+ },
+ {
+ name: "Security",
+ icon: ShieldCheck,
+ href: "/account/settings/security",
+ },
+ {
+ name: "API Keys",
+ icon: Key,
+ href: "/account/settings/tokens",
+ },
+ ],
+ },
+ ],
+ }),
+};
+
+export function AppSidebarNav({
+ toolContent,
+ newsContent,
+}: {
+ toolContent?: ReactNode;
+ newsContent?: ReactNode;
+}) {
+ const { slug } = useParams() as { slug?: string };
+ const pathname = usePathname();
+ const { flags } = useWorkspace();
+
+ const currentArea = useMemo(() => {
+ return pathname.startsWith("/account/settings")
+ ? "userSettings"
+ : pathname.startsWith(`/${slug}/settings`)
+ ? "workspaceSettings"
+ : "default";
+ }, [slug, pathname]);
+
+ return (
+ <SidebarNav
+ areas={NAV_AREAS}
+ currentArea={currentArea}
+ data={{ slug: slug || "", flags }}
+ toolContent={toolContent}
+ newsContent={newsContent}
+ switcher={<WorkspaceDropdown />}
+ bottom={
+ <>
+ <UserSurveyButton />
+ <Usage />
+ </>
+ }
+ />
+ );
+}
diff --git a/apps/web/ui/layout/sidebar/items.ts b/apps/web/ui/layout/sidebar/items.ts
deleted file mode 100644
index 2d4008c4d4..0000000000
--- a/apps/web/ui/layout/sidebar/items.ts
+++ /dev/null
@@ -1,180 +0,0 @@
-import { BetaFeatures } from "@/lib/types";
-import { Icon } from "@dub/ui";
-import {
- Books2,
- CircleInfo,
- ConnectedDots,
- CubeSettings,
- Gear2,
- Gift,
- Globe,
- Key,
- Receipt2,
- ShieldCheck,
- Users6,
- Webhook,
-} from "@dub/ui/src/icons";
-import { CursorRays } from "./icons/cursor-rays";
-import { Gear } from "./icons/gear";
-import { Hyperlink } from "./icons/hyperlink";
-import { LinesY } from "./icons/lines-y";
-
-export type NavItem = {
- name: string;
- icon: Icon;
- href: string;
- exact?: boolean;
-};
-
-export const ITEMS: Record<
- string,
- {
- name?: string;
- items: (args: {
- slug: string;
- flags?: Record<BetaFeatures, boolean>;
- }) => NavItem[];
- }[]
-> = {
- // Top-level
- default: [
- {
- items: ({ slug }) => [
- {
- name: "Links",
- icon: Hyperlink,
- href: `/${slug}`,
- exact: true,
- },
- {
- name: "Analytics",
- icon: LinesY,
- href: `/${slug}/analytics`,
- },
- {
- name: "Events",
- icon: CursorRays,
- href: `/${slug}/events`,
- },
- {
- name: "Settings",
- icon: Gear,
- href: `/${slug}/settings`,
- },
- ],
- },
- ],
-
- // Workspace settings
- workspaceSettings: [
- {
- name: "Workspace",
- items: ({ slug, flags }) => [
- {
- name: "General",
- icon: Gear2,
- href: `/${slug}/settings`,
- exact: true,
- },
- {
- name: "Domains",
- icon: Globe,
- href: `/${slug}/settings/domains`,
- },
- {
- name: "Library",
- icon: Books2,
- href: `/${slug}/settings/library`,
- },
- {
- name: "Billing",
- icon: Receipt2,
- href: `/${slug}/settings/billing`,
- },
- {
- name: "People",
- icon: Users6,
- href: `/${slug}/settings/people`,
- },
- {
- name: "Integrations",
- icon: ConnectedDots,
- href: `/${slug}/settings/integrations`,
- },
- {
- name: "Security",
- icon: ShieldCheck,
- href: `/${slug}/settings/security`,
- },
- ...(flags?.referrals
- ? [
- {
- name: "Referrals",
- icon: Gift,
- href: `/${slug}/settings/referrals`,
- },
- ]
- : []),
- ],
- },
- {
- name: "Developer",
- items: ({ slug, flags }) => [
- {
- name: "API Keys",
- icon: Key,
- href: `/${slug}/settings/tokens`,
- },
- {
- name: "OAuth Apps",
- icon: CubeSettings,
- href: `/${slug}/settings/oauth-apps`,
- },
- ...(flags?.webhooks
- ? [
- {
- name: "Webhooks",
- icon: Webhook,
- href: `/${slug}/settings/webhooks`,
- },
- ]
- : []),
- ],
- },
- {
- name: "Account",
- items: ({ slug }) => [
- {
- name: "Notifications",
- icon: CircleInfo,
- href: `/${slug}/settings/notifications`,
- },
- ],
- },
- ],
-
- // User settings
- userSettings: [
- {
- name: "Account",
- items: () => [
- {
- name: "General",
- icon: Gear2,
- href: "/account/settings",
- exact: true,
- },
- {
- name: "Security",
- icon: ShieldCheck,
- href: "/account/settings/security",
- },
- {
- name: "API Keys",
- icon: Key,
- href: "/account/settings/tokens",
- },
- ],
- },
- ],
-};
diff --git a/apps/web/ui/layout/sidebar/partners-sidebar-nav.tsx b/apps/web/ui/layout/sidebar/partners-sidebar-nav.tsx
new file mode 100644
index 0000000000..1a0bf333ae
--- /dev/null
+++ b/apps/web/ui/layout/sidebar/partners-sidebar-nav.tsx
@@ -0,0 +1,160 @@
+"use client";
+
+import {
+ CursorRays,
+ Gauge6,
+ Gear,
+ GridIcon,
+ Hyperlink,
+ MoneyBills2,
+ User,
+ Users,
+} from "@dub/ui/src/icons";
+import { Store, SwatchBook } from "lucide-react";
+import { useParams, usePathname } from "next/navigation";
+import { ReactNode, useMemo } from "react";
+import UserSurveyButton from "../user-survey";
+import { SidebarNav, SidebarNavAreas } from "./sidebar-nav";
+import { Usage } from "./usage";
+
+const NAV_AREAS: SidebarNavAreas<{
+ partnerId: string;
+ programId?: string;
+}> = {
+ // Top-level
+ default: ({ partnerId }) => ({
+ showSwitcher: true,
+ showNews: true,
+ direction: "left",
+ content: [
+ {
+ items: [
+ {
+ name: "Programs",
+ icon: GridIcon,
+ href: `/${partnerId}`,
+ exact: true,
+ },
+ {
+ name: "Marketplace",
+ icon: Store,
+ href: `/${partnerId}/marketplace`,
+ },
+ {
+ name: "Settings",
+ icon: Gear,
+ href: `/${partnerId}/settings`,
+ },
+ ],
+ },
+ ],
+ }),
+
+ program: ({ partnerId, programId }) => ({
+ content: [
+ {
+ name: "Program",
+ items: [
+ {
+ name: "Overview",
+ icon: Gauge6,
+ href: `/${partnerId}/${programId}`,
+ exact: true,
+ },
+ {
+ name: "Customers",
+ icon: Users,
+ href: `/${partnerId}/${programId}/customers`,
+ },
+ {
+ name: "Events",
+ icon: CursorRays,
+ href: `/${partnerId}/${programId}/events`,
+ },
+ {
+ name: "Links",
+ icon: Hyperlink,
+ href: `/${partnerId}/${programId}/links`,
+ },
+ {
+ name: "Payouts",
+ icon: MoneyBills2,
+ href: `/${partnerId}/${programId}/payouts`,
+ },
+ {
+ name: "Resources",
+ icon: SwatchBook,
+ href: `/${partnerId}/${programId}/resources`,
+ },
+ ],
+ },
+ ],
+ }),
+
+ partnerSettings: ({ partnerId }) => ({
+ title: "Settings",
+ backHref: `/${partnerId}`,
+ content: [
+ {
+ name: "Partner",
+ items: [
+ {
+ name: "Profile",
+ icon: User,
+ href: `/${partnerId}/settings`,
+ exact: true,
+ },
+ {
+ name: "Payouts",
+ icon: MoneyBills2,
+ href: `/${partnerId}/settings/payouts`,
+ },
+ {
+ name: "People",
+ icon: Users,
+ href: `/${partnerId}/settings/people`,
+ },
+ ],
+ },
+ ],
+ }),
+};
+
+export function PartnersSidebarNav({
+ toolContent,
+ newsContent,
+}: {
+ toolContent?: ReactNode;
+ newsContent?: ReactNode;
+}) {
+ const { partnerId, programId } = useParams() as {
+ partnerId?: string;
+ programId?: string;
+ };
+ const pathname = usePathname();
+
+ const currentArea = useMemo(() => {
+ return pathname.startsWith(`/${partnerId}/settings`)
+ ? "partnerSettings"
+ : pathname.startsWith(`/${partnerId}/${programId}`)
+ ? "program"
+ : "default";
+ }, [partnerId, pathname, programId]);
+
+ return (
+ <SidebarNav
+ areas={NAV_AREAS}
+ currentArea={currentArea}
+ data={{ partnerId: partnerId || "", programId: programId || "" }}
+ toolContent={toolContent}
+ newsContent={newsContent}
+ //switcher={<WorkspaceDropdown />}
+ bottom={
+ <>
+ <UserSurveyButton />
+ <Usage />
+ </>
+ }
+ />
+ );
+}
diff --git a/apps/web/ui/layout/sidebar/sidebar-nav.tsx b/apps/web/ui/layout/sidebar/sidebar-nav.tsx
index fad25513c5..c66015811f 100644
--- a/apps/web/ui/layout/sidebar/sidebar-nav.tsx
+++ b/apps/web/ui/layout/sidebar/sidebar-nav.tsx
@@ -1,9 +1,8 @@
-import useWorkspace from "@/lib/swr/use-workspace";
-import { ClientOnly, NavWordmark } from "@dub/ui";
+import { ClientOnly, Icon, NavWordmark } from "@dub/ui";
import { cn } from "@dub/utils";
import { ChevronLeft } from "lucide-react";
import Link from "next/link";
-import { useParams, usePathname } from "next/navigation";
+import { usePathname } from "next/navigation";
import {
PropsWithChildren,
ReactNode,
@@ -11,104 +10,123 @@ import {
useMemo,
useState,
} from "react";
-import UserSurveyButton from "../user-survey";
-import { ITEMS, type NavItem as NavItemType } from "./items";
-import { Usage } from "./usage";
import UserDropdown from "./user-dropdown";
-import { WorkspaceDropdown } from "./workspace-dropdown";
-const AREAS = ["userSettings", "workspaceSettings", "default"] as const;
+export type NavItemType = {
+ name: string;
+ icon: Icon;
+ href: string;
+ exact?: boolean;
+};
-export function SidebarNav({
+export type SidebarNavAreas<T extends Record<any, any>> = Record<
+ string,
+ (args: T) => {
+ title?: string;
+ backHref?: string;
+ showSwitcher?: boolean;
+ showNews?: boolean;
+ direction?: "left" | "right";
+ content: {
+ name?: string;
+ items: NavItemType[];
+ }[];
+ }
+>;
+
+export function SidebarNav<T extends Record<any, any>>({
+ areas,
+ currentArea,
+ data,
toolContent,
newsContent,
+ switcher,
+ bottom,
}: {
+ areas: SidebarNavAreas<T>;
+ currentArea: string;
+ data: T;
toolContent?: ReactNode;
newsContent?: ReactNode;
+ switcher?: ReactNode;
+ bottom?: ReactNode;
}) {
- const { slug } = useParams() as { slug?: string };
- const { flags } = useWorkspace();
- const pathname = usePathname();
-
- const currentArea = useMemo(() => {
- return pathname.startsWith("/account/settings")
- ? "userSettings"
- : pathname.startsWith(`/${slug}/settings`)
- ? "workspaceSettings"
- : "default";
- }, [slug, pathname]);
-
return (
<ClientOnly className="scrollbar-hide relative flex h-full w-full flex-col overflow-y-auto overflow-x-hidden">
<nav className="relative flex grow flex-col p-3 text-gray-500">
<div className="relative flex items-start justify-between gap-1 pb-3">
- {AREAS.map((area) => (
- <Link
- key={area}
- href={slug ? `/${slug}` : "/"}
- className={cn(
- "rounded-md px-1 outline-none transition-opacity focus-visible:ring-2 focus-visible:ring-black/50",
- area === currentArea
- ? "relative opacity-100"
- : "pointer-events-none absolute opacity-0",
- area === "default" && "mb-1",
- )}
- aria-hidden={area !== currentArea ? true : undefined}
- {...{ inert: area !== currentArea ? "" : undefined }}
- >
- {area === "default" ? (
- <NavWordmark className="h-6" isInApp />
- ) : (
- <div className="py group -my-1 -ml-1 flex items-center gap-2 py-2 pr-1 text-sm font-medium text-neutral-900">
- <ChevronLeft className="size-4 text-neutral-500 transition-transform duration-100 group-hover:-translate-x-0.5" />
- Settings
- </div>
- )}
- </Link>
- ))}
+ {Object.entries(areas).map(([area, areaConfig]) => {
+ const { title, backHref } = areaConfig(data);
+
+ return (
+ <Link
+ key={area}
+ href={backHref ?? "/"}
+ className={cn(
+ "rounded-md px-1 outline-none transition-opacity focus-visible:ring-2 focus-visible:ring-black/50",
+ area === currentArea
+ ? "relative opacity-100"
+ : "pointer-events-none absolute opacity-0",
+ (!title || !backHref) && "mb-1",
+ )}
+ aria-hidden={area !== currentArea ? true : undefined}
+ {...{ inert: area !== currentArea ? "" : undefined }}
+ >
+ {title && backHref ? (
+ <div className="py group -my-1 -ml-1 flex items-center gap-2 py-2 pr-1 text-sm font-medium text-neutral-900">
+ <ChevronLeft className="size-4 text-neutral-500 transition-transform duration-100 group-hover:-translate-x-0.5" />
+ {title}
+ </div>
+ ) : (
+ <NavWordmark className="h-6" isInApp />
+ )}
+ </Link>
+ );
+ })}
<div className="hidden items-center gap-3 md:flex">
<Suspense fallback={null}>{toolContent}</Suspense>
<UserDropdown />
</div>
</div>
<div className="relative w-full grow">
- {AREAS.map((area) => (
- <Area
- key={area}
- visible={area === currentArea}
- direction={area === "default" ? "left" : "right"}
- >
- {area === "default" && (
- <div className="pt-2">
- <WorkspaceDropdown />
- </div>
- )}
+ {Object.entries(areas).map(([area, areaConfig]) => {
+ const { content, showSwitcher, showNews, direction } =
+ areaConfig(data);
+ return (
+ <Area
+ key={area}
+ visible={area === currentArea}
+ direction={direction ?? "right"}
+ >
+ {showSwitcher && switcher && (
+ <div className="pt-2">{switcher}</div>
+ )}
- <div className="flex flex-col gap-4 pt-4">
- {ITEMS[area].map(({ name, items }, idx) => (
- <div key={idx} className="flex flex-col gap-0.5">
- {name && (
- <div className="mb-2 pl-1 text-sm text-neutral-500">
- {name}
- </div>
- )}
- {items({ slug: slug || "", flags }).map((item) => (
- <NavItem key={item.name} item={item} />
- ))}
- </div>
- ))}
- </div>
- <div className="-mx-3 mt-6 flex grow flex-col justify-end">
- {area === "default" && newsContent}
- </div>
- </Area>
- ))}
+ <div className="flex flex-col gap-4 pt-4">
+ {content.map(({ name, items }, idx) => (
+ <div key={idx} className="flex flex-col gap-0.5">
+ {name && (
+ <div className="mb-2 pl-1 text-sm text-neutral-500">
+ {name}
+ </div>
+ )}
+ {items.map((item) => (
+ <NavItem key={item.name} item={item} />
+ ))}
+ </div>
+ ))}
+ </div>
+ <div className="-mx-3 mt-6 flex grow flex-col justify-end">
+ {showNews && newsContent}
+ </div>
+ </Area>
+ );
+ })}
</div>
</nav>
- <div className="relative flex flex-col justify-end">
- <UserSurveyButton />
- <Usage />
- </div>
+ {bottom && (
+ <div className="relative flex flex-col justify-end">{bottom}</div>
+ )}
</ClientOnly>
);
}
diff --git a/packages/ui/src/icons/nucleo/gauge6.tsx b/packages/ui/src/icons/nucleo/gauge6.tsx
new file mode 100644
index 0000000000..abf12f737d
--- /dev/null
+++ b/packages/ui/src/icons/nucleo/gauge6.tsx
@@ -0,0 +1,53 @@
+import { SVGProps } from "react";
+
+export function Gauge6(props: SVGProps<SVGSVGElement>) {
+ return (
+ <svg
+ height="18"
+ width="18"
+ viewBox="0 0 18 18"
+ xmlns="http://www.w3.org/2000/svg"
+ {...props}
+ >
+ <g fill="currentColor">
+ <circle cx="9" cy="4.75" fill="currentColor" r=".75" stroke="none" />
+ <circle
+ cx="12.005"
+ cy="5.995"
+ fill="currentColor"
+ r=".75"
+ stroke="none"
+ />
+ <circle cx="13.25" cy="9" fill="currentColor" r=".75" stroke="none" />
+ <circle
+ cx="5.995"
+ cy="5.995"
+ fill="currentColor"
+ r=".75"
+ stroke="none"
+ />
+ <path
+ d="M4.75,9.75c.414,0,.75-.336,.75-.75s-.336-.75-.75-.75-.75,.336-.75,.75,.336,.75,.75,.75Z"
+ fill="currentColor"
+ stroke="none"
+ />
+ <path
+ d="M12.968,15.063c1.975-1.295,3.282-3.525,3.282-6.063,0-4.004-3.246-7.25-7.25-7.25S1.75,4.996,1.75,9c0,2.538,1.307,4.768,3.282,6.063"
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ <path
+ d="M7.5,14.75c0-.828,1.5-7,1.5-7,0,0,1.5,6.172,1.5,7s-.672,1.5-1.5,1.5-1.5-.672-1.5-1.5Z"
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ </g>
+ </svg>
+ );
+}
diff --git a/packages/ui/src/icons/nucleo/grid.tsx b/packages/ui/src/icons/nucleo/grid.tsx
new file mode 100644
index 0000000000..d81929e6f7
--- /dev/null
+++ b/packages/ui/src/icons/nucleo/grid.tsx
@@ -0,0 +1,68 @@
+import { SVGProps } from "react";
+
+export function GridIcon(props: SVGProps<SVGSVGElement>) {
+ return (
+ <svg
+ height="18"
+ width="18"
+ viewBox="0 0 18 18"
+ xmlns="http://www.w3.org/2000/svg"
+ {...props}
+ >
+ <g fill="currentColor">
+ <rect
+ height="4.5"
+ width="4.5"
+ fill="none"
+ rx="1"
+ ry="1"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x="2.75"
+ y="2.75"
+ />
+ <rect
+ height="4.5"
+ width="4.5"
+ fill="none"
+ rx="1"
+ ry="1"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x="10.75"
+ y="2.75"
+ />
+ <rect
+ height="4.5"
+ width="4.5"
+ fill="none"
+ rx="1"
+ ry="1"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x="2.75"
+ y="10.75"
+ />
+ <rect
+ height="4.5"
+ width="4.5"
+ fill="none"
+ rx="1"
+ ry="1"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x="10.75"
+ y="10.75"
+ />
+ </g>
+ </svg>
+ );
+}
diff --git a/packages/ui/src/icons/nucleo/index.ts b/packages/ui/src/icons/nucleo/index.ts
index 66b0a59821..c08cc12a20 100644
--- a/packages/ui/src/icons/nucleo/index.ts
+++ b/packages/ui/src/icons/nucleo/index.ts
@@ -51,6 +51,7 @@ export * from "./flag-wavy";
export * from "./flag2";
export * from "./flag6";
export * from "./gaming-console";
+export * from "./gauge6";
export * from "./gear";
export * from "./gear2";
export * from "./gift";
@@ -59,6 +60,7 @@ export * from "./globe";
export * from "./globe-pointer";
export * from "./globe-search";
export * from "./globe2";
+export * from "./grid";
export * from "./grid-layout-rows";
export * from "./grid-plus";
export * from "./headset";
@@ -77,6 +79,7 @@ export * from "./magnifier";
export * from "./map-position";
export * from "./menu3";
export * from "./mobile-phone";
+export * from "./money-bills2";
export * from "./note";
export * from "./office-building";
export * from "./page2";
diff --git a/packages/ui/src/icons/nucleo/money-bills2.tsx b/packages/ui/src/icons/nucleo/money-bills2.tsx
new file mode 100644
index 0000000000..d4cb5736b8
--- /dev/null
+++ b/packages/ui/src/icons/nucleo/money-bills2.tsx
@@ -0,0 +1,52 @@
+import { SVGProps } from "react";
+
+export function MoneyBills2(props: SVGProps<SVGSVGElement>) {
+ return (
+ <svg
+ height="18"
+ width="18"
+ viewBox="0 0 18 18"
+ xmlns="http://www.w3.org/2000/svg"
+ {...props}
+ >
+ <g fill="currentColor">
+ <circle
+ cx="9"
+ cy="10"
+ fill="none"
+ r="2"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ />
+ <circle cx="4.25" cy="10" fill="currentColor" r=".75" stroke="none" />
+ <circle cx="13.75" cy="10" fill="currentColor" r=".75" stroke="none" />
+ <rect
+ height="10.5"
+ width="14.5"
+ fill="none"
+ rx="2"
+ ry="2"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x="1.75"
+ y="4.75"
+ />
+ <line
+ fill="none"
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ strokeWidth="1.5"
+ x1="3.75"
+ x2="14.25"
+ y1="1.75"
+ y2="1.75"
+ />
+ </g>
+ </svg>
+ );
+}