mirror of
https://github.com/massbug/judge4c.git
synced 2025-05-18 07:16:34 +00:00
refactor(components): extract NavUserProps and NavMainProps type and optimize type definitions
This commit is contained in:
parent
cb966297e1
commit
b403a0f977
@ -16,6 +16,7 @@ import { User } from "@prisma/client";
|
|||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import { AppSidebar } from "@/components/app-sidebar";
|
import { AppSidebar } from "@/components/app-sidebar";
|
||||||
import { Separator } from "@/components/ui/separator";
|
import { Separator } from "@/components/ui/separator";
|
||||||
|
import { type NavUserProps } from "@/components/nav-user";
|
||||||
|
|
||||||
interface AdminDashboardLayoutProps {
|
interface AdminDashboardLayoutProps {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
@ -30,7 +31,7 @@ export default async function AdminDashboardLayout({
|
|||||||
redirect("/sign-in");
|
redirect("/sign-in");
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = (({ name, email, image }) => ({
|
const user: NavUserProps["user"] = (({ name, email, image }) => ({
|
||||||
name: name ?? "",
|
name: name ?? "",
|
||||||
email: email ?? "",
|
email: email ?? "",
|
||||||
avatar: image ?? "",
|
avatar: image ?? "",
|
||||||
|
@ -13,10 +13,6 @@ import {
|
|||||||
SquareTerminal,
|
SquareTerminal,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { NavMain } from "@/components/nav-main";
|
|
||||||
import { NavUser } from "@/components/nav-user";
|
|
||||||
import { NavProjects } from "@/components/nav-projects";
|
|
||||||
import { TeamSwitcher } from "@/components/team-switcher";
|
|
||||||
import {
|
import {
|
||||||
Sidebar,
|
Sidebar,
|
||||||
SidebarContent,
|
SidebarContent,
|
||||||
@ -24,6 +20,10 @@ import {
|
|||||||
SidebarHeader,
|
SidebarHeader,
|
||||||
SidebarRail,
|
SidebarRail,
|
||||||
} from "@/components/ui/sidebar";
|
} from "@/components/ui/sidebar";
|
||||||
|
import { NavMain } from "@/components/nav-main";
|
||||||
|
import { NavProjects } from "@/components/nav-projects";
|
||||||
|
import { TeamSwitcher } from "@/components/team-switcher";
|
||||||
|
import { NavUser, type NavUserProps } from "@/components/nav-user";
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
teams: [
|
teams: [
|
||||||
@ -150,14 +150,13 @@ const data = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
interface AppSidebarProps extends React.ComponentProps<typeof Sidebar> {
|
interface AppSidebarProps extends React.ComponentProps<typeof Sidebar> {
|
||||||
user: {
|
user: NavUserProps["user"];
|
||||||
name: string;
|
|
||||||
email: string;
|
|
||||||
avatar: string;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function AppSidebar({ user, ...props }: AppSidebarProps) {
|
export function AppSidebar({
|
||||||
|
user,
|
||||||
|
...props
|
||||||
|
}: AppSidebarProps) {
|
||||||
return (
|
return (
|
||||||
<Sidebar collapsible="icon" {...props}>
|
<Sidebar collapsible="icon" {...props}>
|
||||||
<SidebarHeader>
|
<SidebarHeader>
|
||||||
|
@ -1,12 +1,5 @@
|
|||||||
"use client"
|
"use client";
|
||||||
|
|
||||||
import { ChevronRight, type LucideIcon } from "lucide-react"
|
|
||||||
|
|
||||||
import {
|
|
||||||
Collapsible,
|
|
||||||
CollapsibleContent,
|
|
||||||
CollapsibleTrigger,
|
|
||||||
} from "@/components/ui/collapsible"
|
|
||||||
import {
|
import {
|
||||||
SidebarGroup,
|
SidebarGroup,
|
||||||
SidebarGroupLabel,
|
SidebarGroupLabel,
|
||||||
@ -16,22 +9,30 @@ import {
|
|||||||
SidebarMenuSub,
|
SidebarMenuSub,
|
||||||
SidebarMenuSubButton,
|
SidebarMenuSubButton,
|
||||||
SidebarMenuSubItem,
|
SidebarMenuSubItem,
|
||||||
} from "@/components/ui/sidebar"
|
} from "@/components/ui/sidebar";
|
||||||
|
import {
|
||||||
|
Collapsible,
|
||||||
|
CollapsibleContent,
|
||||||
|
CollapsibleTrigger,
|
||||||
|
} from "@/components/ui/collapsible";
|
||||||
|
import { ChevronRight, type LucideIcon } from "lucide-react";
|
||||||
|
|
||||||
|
export interface NavMainProps {
|
||||||
|
items: {
|
||||||
|
title: string;
|
||||||
|
url: string;
|
||||||
|
icon?: LucideIcon;
|
||||||
|
isActive?: boolean;
|
||||||
|
items?: {
|
||||||
|
title: string;
|
||||||
|
url: string;
|
||||||
|
}[];
|
||||||
|
}[];
|
||||||
|
}
|
||||||
|
|
||||||
export function NavMain({
|
export function NavMain({
|
||||||
items,
|
items,
|
||||||
}: {
|
}: NavMainProps) {
|
||||||
items: {
|
|
||||||
title: string
|
|
||||||
url: string
|
|
||||||
icon?: LucideIcon
|
|
||||||
isActive?: boolean
|
|
||||||
items?: {
|
|
||||||
title: string
|
|
||||||
url: string
|
|
||||||
}[]
|
|
||||||
}[]
|
|
||||||
}) {
|
|
||||||
return (
|
return (
|
||||||
<SidebarGroup>
|
<SidebarGroup>
|
||||||
<SidebarGroupLabel>Platform</SidebarGroupLabel>
|
<SidebarGroupLabel>Platform</SidebarGroupLabel>
|
||||||
@ -69,5 +70,5 @@ export function NavMain({
|
|||||||
))}
|
))}
|
||||||
</SidebarMenu>
|
</SidebarMenu>
|
||||||
</SidebarGroup>
|
</SidebarGroup>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
"use client"
|
"use client";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
BadgeCheck,
|
BadgeCheck,
|
||||||
@ -7,13 +7,13 @@ import {
|
|||||||
CreditCard,
|
CreditCard,
|
||||||
LogOut,
|
LogOut,
|
||||||
Sparkles,
|
Sparkles,
|
||||||
} from "lucide-react"
|
} from "lucide-react";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Avatar,
|
SidebarMenu,
|
||||||
AvatarFallback,
|
SidebarMenuButton,
|
||||||
AvatarImage,
|
SidebarMenuItem,
|
||||||
} from "@/components/ui/avatar"
|
useSidebar,
|
||||||
|
} from "@/components/ui/sidebar";
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
@ -22,24 +22,21 @@ import {
|
|||||||
DropdownMenuLabel,
|
DropdownMenuLabel,
|
||||||
DropdownMenuSeparator,
|
DropdownMenuSeparator,
|
||||||
DropdownMenuTrigger,
|
DropdownMenuTrigger,
|
||||||
} from "@/components/ui/dropdown-menu"
|
} from "@/components/ui/dropdown-menu";
|
||||||
import {
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
||||||
SidebarMenu,
|
|
||||||
SidebarMenuButton,
|
export interface NavUserProps {
|
||||||
SidebarMenuItem,
|
user: {
|
||||||
useSidebar,
|
name: string;
|
||||||
} from "@/components/ui/sidebar"
|
email: string;
|
||||||
|
avatar: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function NavUser({
|
export function NavUser({
|
||||||
user,
|
user,
|
||||||
}: {
|
}: NavUserProps) {
|
||||||
user: {
|
const { isMobile } = useSidebar();
|
||||||
name: string
|
|
||||||
email: string
|
|
||||||
avatar: string
|
|
||||||
}
|
|
||||||
}) {
|
|
||||||
const { isMobile } = useSidebar()
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SidebarMenu>
|
<SidebarMenu>
|
||||||
@ -110,5 +107,5 @@ export function NavUser({
|
|||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
</SidebarMenuItem>
|
</SidebarMenuItem>
|
||||||
</SidebarMenu>
|
</SidebarMenu>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user