From 1abbd740a361a0e9037c5db08de0901d00f73691 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 29 May 2026 15:32:21 +0800 Subject: [PATCH] refactor: flatten admin settings actions --- .../_components/admin-settings-navigation.tsx | 133 ++++-------------- 1 file changed, 27 insertions(+), 106 deletions(-) diff --git a/app/(admin)/settings/_components/admin-settings-navigation.tsx b/app/(admin)/settings/_components/admin-settings-navigation.tsx index bcb82ae70..36542b703 100644 --- a/app/(admin)/settings/_components/admin-settings-navigation.tsx +++ b/app/(admin)/settings/_components/admin-settings-navigation.tsx @@ -2,72 +2,20 @@ import Link from "next/link"; import { ArrowLeft } from "lucide-react"; +import { useRouter } from "next/navigation"; import { Button } from "@/components/ui/button"; import { Select, SelectContent, - SelectGroup, SelectItem, - SelectLabel, - SelectSeparator, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Separator } from "@/components/ui/separator"; import { ADMIN_SETTINGS_NAV_GROUPS } from "../_lib/settings-navigation"; -import type { AdminSettingsNavGroup, AdminSettingsNavItem } from "../_lib/types"; -import { cn } from "@/lib/utils"; +import type { AdminSettingsNavItem } from "../_lib/types"; -function getActiveGroup(activeTab: string) { - return ADMIN_SETTINGS_NAV_GROUPS.find((group) => - group.items.some((item) => item.value === activeTab) - ); -} - -function SettingsGroupTab({ - group, - isActive, - onTabChange, -}: { - group: AdminSettingsNavGroup; - isActive: boolean; - onTabChange: (value: string) => void; -}) { - const defaultItem = group.items[0]; - const hasHref = Boolean(defaultItem?.href); - const className = cn( - "h-10 w-full justify-center rounded-2xl border px-4 text-sm font-medium shadow-none transition-colors", - isActive - ? "border-foreground/10 bg-foreground text-background hover:bg-foreground/90 hover:text-background dark:border-white/20 dark:bg-white dark:text-black dark:hover:bg-white/90" - : "border-border/70 bg-zinc-50/80 text-muted-foreground hover:bg-background hover:text-foreground" - ); - - if (!defaultItem) return null; - - if (hasHref) { - return ( - - ); - } - - return ( - - ); -} +const ALL_SETTINGS_ITEMS = ADMIN_SETTINGS_NAV_GROUPS.flatMap((group) => group.items); function SettingsQuickAction({ activeTab, @@ -125,35 +73,30 @@ export function AdminSettingsNavigation({ activeTab: string; onTabChange: (value: string) => void; }) { - const activeGroup = getActiveGroup(activeTab); - const groupButtons = ADMIN_SETTINGS_NAV_GROUPS.map((group) => ({ - group, - isActive: group.items.some((item) => item.value === activeTab), - })); + const router = useRouter(); + const activeItem = ALL_SETTINGS_ITEMS.find((item) => item.value === activeTab); + const handleSelectChange = (value: string) => { + const nextItem = ALL_SETTINGS_ITEMS.find((item) => item.value === value); + if (nextItem?.href) { + router.push(nextItem.href); + return; + } + onTabChange(value); + }; return (
- - + - {ADMIN_SETTINGS_NAV_GROUPS.map((group, groupIndex) => ( - - {group.title} - {group.items - .filter((item) => !item.href) - .map((item) => ( - - {item.label} - - ))} - {groupIndex < ADMIN_SETTINGS_NAV_GROUPS.length - 1 ? ( - - ) : null} - + {ALL_SETTINGS_ITEMS.map((item) => ( + + {item.label} + ))} @@ -172,7 +115,7 @@ export function AdminSettingsNavigation({
- {(activeGroup?.items ?? []).map((item) => ( + {ALL_SETTINGS_ITEMS.map((item) => ( - {activeGroup ? ( + {activeItem ? ( <> - {activeGroup.title} + {activeItem.label} ) : null} -
-
- {groupButtons.map(({ group, isActive }) => ( - - ))} -
- - - -
- {(activeGroup?.items ?? []).map((item) => ( +
+ {ALL_SETTINGS_ITEMS.map((item) => ( +
- ))} -
+
+ ))}