Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

refactor(frontend): build the admin and settings section navigation from one shared sidebar and mobile menu (#15921)

Reinier van der Leer9ec843621b58
diff --git a/autogpt_platform/frontend/src/app/(platform)/admin/components/AdminMobileNav/AdminMobileNav.tsx b/autogpt_platform/frontend/src/app/(platform)/admin/components/AdminMobileNav/AdminMobileNav.tsx
index e9652d72bd..60e155345a 100644
--- a/autogpt_platform/frontend/src/app/(platform)/admin/components/AdminMobileNav/AdminMobileNav.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/admin/components/AdminMobileNav/AdminMobileNav.tsx
@@ -1,98 +1,9 @@
"use client";
-import { useState } from "react";
-import Link from "next/link";
-import { ArrowDown01Icon, ArrowLeft02Icon } from "@hugeicons/core-free-icons";
-import { Icon as UIIcon } from "@/components/atoms/Icon/Icon";
-import {
- Popover,
- PopoverContent,
- PopoverTrigger,
-} from "@/components/molecules/Popover/Popover";
-import { Text } from "@/components/atoms/Text/Text";
-import { cn } from "@/lib/utils";
+import { SectionMobileNav } from "@/components/layout/SectionNav/SectionMobileNav";
import { useAdminSidebar } from "../AdminSidebar/useAdminSidebar";
export function AdminMobileNav() {
const { items } = useAdminSidebar();
- const [open, setOpen] = useState(false);
- const current = items.find((i) => i.isActive) ?? items[0];
-
- return (
- <div className="flex items-center gap-2 bg-[#F9F9FA] px-4 py-3 md:hidden">
- <Link
- href="/copilot"
- aria-label="Back to home"
- className="flex items-center gap-1 rounded-[8px] py-1 pr-2 text-[#505057] transition-colors hover:text-[#1F1F20]"
- >
- <UIIcon icon={ArrowLeft02Icon} size={16} />
- </Link>
- <Popover open={open} onOpenChange={setOpen}>
- <PopoverTrigger asChild>
- <button
- type="button"
- className="flex w-fit items-center gap-2 rounded-full border border-[#DADADC] bg-white px-3 py-2 outline-none focus-visible:ring-2 focus-visible:ring-[#3E3E43]"
- aria-label={`Admin navigation, current: ${current.label}`}
- >
- <span className="flex items-center gap-2">
- <UIIcon icon={current.Icon} size={16} className="text-black" />
- <Text
- variant="body"
- as="span"
- className="font-medium text-[#1F1F20]"
- >
- {current.label}
- </Text>
- </span>
- <UIIcon
- icon={ArrowDown01Icon}
- size={16}
- className={cn(
- "text-[#505057] transition-transform",
- open && "rotate-180",
- )}
- />
- </button>
- </PopoverTrigger>
- <PopoverContent
- align="start"
- sideOffset={8}
- className="w-[calc(100vw-32px)] max-w-sm p-2"
- >
- <nav className="flex flex-col gap-[4px]">
- {items.map(({ label, href, Icon, isActive }) => (
- <Link
- key={href}
- href={href}
- aria-current={isActive ? "page" : undefined}
- onClick={() => setOpen(false)}
- className={cn(
- "flex h-[38px] items-center gap-2 rounded-[8px] px-3",
- isActive ? "bg-[#EFEFF0]" : "hover:bg-[#F5F5F6]",
- )}
- >
- <UIIcon
- icon={Icon}
- size={16}
- className={isActive ? "text-black" : "text-[#1F1F20]"}
- />
- <Text
- variant="body"
- as="span"
- className={cn(
- "flex-1",
- isActive
- ? "font-medium text-[#1F1F20]"
- : "font-normal text-[#505057]",
- )}
- >
- {label}
- </Text>
- </Link>
- ))}
- </nav>
- </PopoverContent>
- </Popover>
- </div>
- );
+ return <SectionMobileNav items={items} sectionName="Admin" showBackLink />;
}
diff --git a/autogpt_platform/frontend/src/app/(platform)/admin/components/AdminSidebar/AdminSidebar.tsx b/autogpt_platform/frontend/src/app/(platform)/admin/components/AdminSidebar/AdminSidebar.tsx
index 22e628c468..1bc28ecece 100644
--- a/autogpt_platform/frontend/src/app/(platform)/admin/components/AdminSidebar/AdminSidebar.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/admin/components/AdminSidebar/AdminSidebar.tsx
@@ -1,58 +1,9 @@
"use client";
-import { SettingsNavItem } from "@/app/(platform)/settings/components/SettingsSidebar/SettingsNavItem";
-import { Text } from "@/components/atoms/Text/Text";
-import { Icon } from "@/components/atoms/Icon/Icon";
-import { ArrowLeft02Icon } from "@hugeicons/core-free-icons";
-import { motion, useReducedMotion } from "framer-motion";
-import Link from "next/link";
+import { SectionSidebar } from "@/components/layout/SectionNav/SectionSidebar";
import { useAdminSidebar } from "./useAdminSidebar";
export function AdminSidebar() {
const { items } = useAdminSidebar();
- const reduceMotion = useReducedMotion();
-
- const container = {
- hidden: {},
- show: {
- transition: {
- staggerChildren: reduceMotion ? 0 : 0.04,
- delayChildren: 0.08,
- },
- },
- };
-
- return (
- <motion.aside
- initial={reduceMotion ? { opacity: 0 } : { opacity: 0, x: -10 }}
- animate={{ opacity: 1, x: 0 }}
- transition={{ duration: 0.25, ease: [0, 0, 0.2, 1] as const }}
- className="hidden h-full w-[268px] shrink-0 overflow-y-auto border-r border-[#DADADC] bg-[#F9F9FA] px-[10px] pt-[13px] md:block"
- >
- <Link
- href="/copilot"
- aria-label="Back to home"
- className="mb-[16px] flex w-fit items-center gap-2 rounded-[8px] px-4 py-1 text-[#505057] transition-colors hover:text-[#1F1F20]"
- >
- <Icon icon={ArrowLeft02Icon} size={16} />
- <Text variant="body" as="span" className="font-medium">
- Back
- </Text>
- </Link>
- <motion.nav
- variants={container}
- initial="hidden"
- animate="show"
- className="flex flex-col items-start gap-[7px]"
- >
- {items.map((item) => (
- <SettingsNavItem
- key={item.href}
- item={item}
- isActive={item.isActive}
- />
- ))}
- </motion.nav>
- </motion.aside>
- );
+ return <SectionSidebar items={items} className="w-[268px]" />;
}
diff --git a/autogpt_platform/frontend/src/app/(platform)/settings/__tests__/SettingsMobileNav.test.tsx b/autogpt_platform/frontend/src/app/(platform)/settings/__tests__/SettingsMobileNav.test.tsx
index 4a980d3930..944e359d36 100644
--- a/autogpt_platform/frontend/src/app/(platform)/settings/__tests__/SettingsMobileNav.test.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/settings/__tests__/SettingsMobileNav.test.tsx
@@ -97,7 +97,9 @@ describe("SettingsMobileNav", () => {
fireEvent.click(profileLink);
await waitFor(() => {
- expect(screen.queryByRole("link", { name: /oauth apps/i })).toBeNull();
+ expect(
+ screen.queryByRole("link", { name: /creator dashboard/i }),
+ ).toBeNull();
});
});
});
diff --git a/autogpt_platform/frontend/src/app/(platform)/settings/components/SettingsMobileNav/SettingsMobileNav.tsx b/autogpt_platform/frontend/src/app/(platform)/settings/components/SettingsMobileNav/SettingsMobileNav.tsx
index c933112855..3dd7b4e21b 100644
--- a/autogpt_platform/frontend/src/app/(platform)/settings/components/SettingsMobileNav/SettingsMobileNav.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/settings/components/SettingsMobileNav/SettingsMobileNav.tsx
@@ -1,91 +1,9 @@
"use client";
-import { useState } from "react";
-import Link from "next/link";
-import {
- Popover,
- PopoverContent,
- PopoverTrigger,
-} from "@/components/molecules/Popover/Popover";
-import { Text } from "@/components/atoms/Text/Text";
-import { cn } from "@/lib/utils";
+import { SectionMobileNav } from "@/components/layout/SectionNav/SectionMobileNav";
import { useSettingsSidebar } from "../SettingsSidebar/useSettingsSidebar";
-import { ArrowDown01Icon } from "@hugeicons/core-free-icons";
-import { Icon as UIIcon } from "@/components/atoms/Icon/Icon";
export function SettingsMobileNav() {
const { items } = useSettingsSidebar();
- const [open, setOpen] = useState(false);
- const current = items.find((i) => i.isActive) ?? items[0];
-
- return (
- <div className="bg-[#F9F9FA] px-4 py-3 md:hidden">
- <Popover open={open} onOpenChange={setOpen}>
- <PopoverTrigger asChild>
- <button
- type="button"
- className="flex w-fit items-center gap-2 rounded-full border border-[#DADADC] bg-white px-3 py-2 outline-none focus-visible:ring-2 focus-visible:ring-[#3E3E43]"
- aria-label={`Settings navigation, current: ${current.label}`}
- >
- <span className="flex items-center gap-2">
- <UIIcon icon={current.Icon} size={16} className="text-black" />
- <Text
- variant="body"
- as="span"
- className="font-medium text-[#1F1F20]"
- >
- {current.label}
- </Text>
- </span>
- <UIIcon
- icon={ArrowDown01Icon}
- size={16}
- className={cn(
- "text-[#505057] transition-transform",
- open && "rotate-180",
- )}
- />
- </button>
- </PopoverTrigger>
- <PopoverContent
- align="start"
- sideOffset={8}
- className="w-[calc(100vw-32px)] max-w-sm p-2"
- >
- <nav className="flex flex-col gap-[4px]">
- {items.map(({ label, href, Icon, isActive }) => (
- <Link
- key={href}
- href={href}
- aria-current={isActive ? "page" : undefined}
- onClick={() => setOpen(false)}
- className={cn(
- "flex h-[38px] items-center gap-2 rounded-[8px] px-3",
- isActive ? "bg-[#EFEFF0]" : "hover:bg-[#F5F5F6]",
- )}
- >
- <UIIcon
- icon={Icon}
- size={16}
- className={isActive ? "text-black" : "text-[#1F1F20]"}
- />
- <Text
- variant="body"
- as="span"
- className={cn(
- "flex-1",
- isActive
- ? "font-medium text-[#1F1F20]"
- : "font-normal text-[#505057]",
- )}
- >
- {label}
- </Text>
- </Link>
- ))}
- </nav>
- </PopoverContent>
- </Popover>
- </div>
- );
+ return <SectionMobileNav items={items} sectionName="Settings" />;
}
diff --git a/autogpt_platform/frontend/src/app/(platform)/settings/components/SettingsSidebar/SettingsSidebar.tsx b/autogpt_platform/frontend/src/app/(platform)/settings/components/SettingsSidebar/SettingsSidebar.tsx
index cf3c84f639..cf9aaadc00 100644
--- a/autogpt_platform/frontend/src/app/(platform)/settings/components/SettingsSidebar/SettingsSidebar.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/settings/components/SettingsSidebar/SettingsSidebar.tsx
@@ -1,58 +1,9 @@
"use client";
-import { motion, useReducedMotion } from "framer-motion";
-import Link from "next/link";
-import { Text } from "@/components/atoms/Text/Text";
+import { SectionSidebar } from "@/components/layout/SectionNav/SectionSidebar";
import { useSettingsSidebar } from "./useSettingsSidebar";
-import { SettingsNavItem } from "./SettingsNavItem";
-import { ArrowLeft02Icon } from "@hugeicons/core-free-icons";
-import { Icon } from "@/components/atoms/Icon/Icon";
export function SettingsSidebar() {
const { items } = useSettingsSidebar();
- const reduceMotion = useReducedMotion();
-
- const container = {
- hidden: {},
- show: {
- transition: {
- staggerChildren: reduceMotion ? 0 : 0.04,
- delayChildren: 0.08,
- },
- },
- };
-
- return (
- <motion.aside
- initial={reduceMotion ? { opacity: 0 } : { opacity: 0, x: -10 }}
- animate={{ opacity: 1, x: 0 }}
- transition={{ duration: 0.25, ease: [0, 0, 0.2, 1] as const }}
- className="hidden h-full w-[237px] shrink-0 overflow-y-auto border-r border-[#DADADC] bg-[#F9F9FA] px-[10px] pt-[13px] md:block"
- >
- <Link
- href="/copilot"
- aria-label="Back to home"
- className="mb-[16px] flex w-fit items-center gap-2 rounded-[8px] px-4 py-1 text-[#505057] transition-colors hover:text-[#1F1F20]"
- >
- <Icon icon={ArrowLeft02Icon} size={16} />
- <Text variant="body" as="span" className="font-medium">
- Back
- </Text>
- </Link>
- <motion.nav
- variants={container}
- initial="hidden"
- animate="show"
- className="flex flex-col items-start gap-[7px]"
- >
- {items.map((item) => (
- <SettingsNavItem
- key={item.href}
- item={item}
- isActive={item.isActive}
- />
- ))}
- </motion.nav>
- </motion.aside>
- );
+ return <SectionSidebar items={items} className="w-[237px]" />;
}
diff --git a/autogpt_platform/frontend/src/components/layout/SectionNav/SectionMobileNav.tsx b/autogpt_platform/frontend/src/components/layout/SectionNav/SectionMobileNav.tsx
new file mode 100644
index 0000000000..2e9f602e92
--- /dev/null
+++ b/autogpt_platform/frontend/src/components/layout/SectionNav/SectionMobileNav.tsx
@@ -0,0 +1,110 @@
+"use client";
+
+import { useState } from "react";
+import Link from "next/link";
+import { ArrowDown01Icon, ArrowLeft02Icon } from "@hugeicons/core-free-icons";
+import { Icon as UIIcon } from "@/components/atoms/Icon/Icon";
+import {
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+} from "@/components/molecules/Popover/Popover";
+import { Text } from "@/components/atoms/Text/Text";
+import { cn } from "@/lib/utils";
+import type { SectionNavLink } from "./SectionNavItem";
+
+interface Props {
+ items: (SectionNavLink & { isActive: boolean })[];
+ sectionName: string;
+ showBackLink?: boolean;
+}
+
+export function SectionMobileNav({ items, sectionName, showBackLink }: Props) {
+ const [open, setOpen] = useState(false);
+ const current = items.find((i) => i.isActive) ?? items[0];
+
+ return (
+ <div
+ className={cn(
+ "bg-[#F9F9FA] px-4 py-3 md:hidden",
+ showBackLink && "flex items-center gap-2",
+ )}
+ >
+ {showBackLink ? (
+ <Link
+ href="/copilot"
+ aria-label="Back to home"
+ className="flex items-center gap-1 rounded-[8px] py-1 pr-2 text-[#505057] transition-colors hover:text-[#1F1F20]"
+ >
+ <UIIcon icon={ArrowLeft02Icon} size={16} />
+ </Link>
+ ) : null}
+ <Popover open={open} onOpenChange={setOpen}>
+ <PopoverTrigger asChild>
+ <button
+ type="button"
+ className="flex w-fit items-center gap-2 rounded-full border border-[#DADADC] bg-white px-3 py-2 outline-none focus-visible:ring-2 focus-visible:ring-[#3E3E43]"
+ aria-label={`${sectionName} navigation, current: ${current.label}`}
+ >
+ <span className="flex items-center gap-2">
+ <UIIcon icon={current.Icon} size={16} className="text-black" />
+ <Text
+ variant="body"
+ as="span"
+ className="font-medium text-[#1F1F20]"
+ >
+ {current.label}
+ </Text>
+ </span>
+ <UIIcon
+ icon={ArrowDown01Icon}
+ size={16}
+ className={cn(
+ "text-[#505057] transition-transform",
+ open && "rotate-180",
+ )}
+ />
+ </button>
+ </PopoverTrigger>
+ <PopoverContent
+ align="start"
+ sideOffset={8}
+ className="w-[calc(100vw-32px)] max-w-sm p-2"
+ >
+ <nav className="flex flex-col gap-[4px]">
+ {items.map(({ label, href, Icon, isActive }) => (
+ <Link
+ key={href}
+ href={href}
+ aria-current={isActive ? "page" : undefined}
+ onClick={() => setOpen(false)}
+ className={cn(
+ "flex h-[38px] items-center gap-2 rounded-[8px] px-3",
+ isActive ? "bg-[#EFEFF0]" : "hover:bg-[#F5F5F6]",
+ )}
+ >
+ <UIIcon
+ icon={Icon}
+ size={16}
+ className={isActive ? "text-black" : "text-[#1F1F20]"}
+ />
+ <Text
+ variant="body"
+ as="span"
+ className={cn(
+ "flex-1",
+ isActive
+ ? "font-medium text-[#1F1F20]"
+ : "font-normal text-[#505057]",
+ )}
+ >
+ {label}
+ </Text>
+ </Link>
+ ))}
+ </nav>
+ </PopoverContent>
+ </Popover>
+ </div>
+ );
+}
diff --git a/autogpt_platform/frontend/src/app/(platform)/settings/components/SettingsSidebar/SettingsNavItem.tsx b/autogpt_platform/frontend/src/components/layout/SectionNav/SectionNavItem.tsx
similarity index 88%
rename from autogpt_platform/frontend/src/app/(platform)/settings/components/SettingsSidebar/SettingsNavItem.tsx
rename to autogpt_platform/frontend/src/components/layout/SectionNav/SectionNavItem.tsx
index 015efbc9b8..9907d4bfd8 100644
--- a/autogpt_platform/frontend/src/app/(platform)/settings/components/SettingsSidebar/SettingsNavItem.tsx
+++ b/autogpt_platform/frontend/src/components/layout/SectionNav/SectionNavItem.tsx
@@ -6,10 +6,16 @@ import { cn } from "@/lib/utils";
import { Text } from "@/components/atoms/Text/Text";
import { LoadingSpinner } from "@/components/atoms/LoadingSpinner/LoadingSpinner";
import { Icon as UIIcon } from "@/components/atoms/Icon/Icon";
-import type { SettingsNavItem as SettingsNavItemType } from "./helpers";
+import type { IconSvgElement } from "@hugeicons/react";
+
+export interface SectionNavLink {
+ label: string;
+ href: string;
+ Icon: IconSvgElement;
+}
type Props = {
- item: SettingsNavItemType;
+ item: SectionNavLink;
isActive: boolean;
};
@@ -19,7 +25,7 @@ function NavItemContent({
isActive,
}: {
label: string;
- Icon: SettingsNavItemType["Icon"];
+ Icon: IconSvgElement;
isActive: boolean;
}) {
const { pending } = useLinkStatus();
@@ -48,7 +54,7 @@ function NavItemContent({
);
}
-export function SettingsNavItem({ item, isActive }: Props) {
+export function SectionNavItem({ item, isActive }: Props) {
const reduceMotion = useReducedMotion();
const variants: Variants = reduceMotion
diff --git a/autogpt_platform/frontend/src/components/layout/SectionNav/SectionSidebar.tsx b/autogpt_platform/frontend/src/components/layout/SectionNav/SectionSidebar.tsx
new file mode 100644
index 0000000000..0fc241d1ae
--- /dev/null
+++ b/autogpt_platform/frontend/src/components/layout/SectionNav/SectionSidebar.tsx
@@ -0,0 +1,65 @@
+"use client";
+
+import { motion, useReducedMotion } from "framer-motion";
+import Link from "next/link";
+import { ArrowLeft02Icon } from "@hugeicons/core-free-icons";
+import { Icon } from "@/components/atoms/Icon/Icon";
+import { Text } from "@/components/atoms/Text/Text";
+import { cn } from "@/lib/utils";
+import { SectionNavItem, type SectionNavLink } from "./SectionNavItem";
+
+interface Props {
+ items: (SectionNavLink & { isActive: boolean })[];
+ className: string;
+}
+
+export function SectionSidebar({ items, className }: Props) {
+ const reduceMotion = useReducedMotion();
+
+ const container = {
+ hidden: {},
+ show: {
+ transition: {
+ staggerChildren: reduceMotion ? 0 : 0.04,
+ delayChildren: 0.08,
+ },
+ },
+ };
+
+ return (
+ <motion.aside
+ initial={reduceMotion ? { opacity: 0 } : { opacity: 0, x: -10 }}
+ animate={{ opacity: 1, x: 0 }}
+ transition={{ duration: 0.25, ease: [0, 0, 0.2, 1] as const }}
+ className={cn(
+ "hidden h-full shrink-0 overflow-y-auto border-r border-[#DADADC] bg-[#F9F9FA] px-[10px] pt-[13px] md:block",
+ className,
+ )}
+ >
+ <Link
+ href="/copilot"
+ aria-label="Back to home"
+ className="mb-[16px] flex w-fit items-center gap-2 rounded-[8px] px-4 py-1 text-[#505057] transition-colors hover:text-[#1F1F20]"
+ >
+ <Icon icon={ArrowLeft02Icon} size={16} />
+ <Text variant="body" as="span" className="font-medium">
+ Back
+ </Text>
+ </Link>
+ <motion.nav
+ variants={container}
+ initial="hidden"
+ animate="show"
+ className="flex flex-col items-start gap-[7px]"
+ >
+ {items.map((item) => (
+ <SectionNavItem
+ key={item.href}
+ item={item}
+ isActive={item.isActive}
+ />
+ ))}
+ </motion.nav>
+ </motion.aside>
+ );
+}