From 1e2329e7f1084f0010a4a6364f3207704d8724eb Mon Sep 17 00:00:00 2001 From: i701 Date: Sat, 20 Sep 2025 11:14:38 +0500 Subject: [PATCH] =?UTF-8?q?refactor(sidebar):=20re=20arrange=20sidebar=20l?= =?UTF-8?q?inks=20=F0=9F=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/ui/app-sidebar.tsx | 400 +++++++++++++++++----------------- 1 file changed, 201 insertions(+), 199 deletions(-) diff --git a/components/ui/app-sidebar.tsx b/components/ui/app-sidebar.tsx index 7eba979..1e757d8 100644 --- a/components/ui/app-sidebar.tsx +++ b/components/ui/app-sidebar.tsx @@ -1,224 +1,226 @@ import { - BadgePlus, - Calculator, - ChevronRight, - Coins, - CreditCard, - Handshake, - MonitorSpeaker, - Smartphone, - UsersRound, - Wallet2Icon, + BadgePlus, + Calculator, + ChevronRight, + Coins, + CreditCard, + Handshake, + MonitorSpeaker, + Smartphone, + UsersRound, + Wallet2Icon, } from "lucide-react"; import Link from "next/link"; import { getServerSession } from "next-auth"; import { authOptions } from "@/app/auth"; import { - Collapsible, - CollapsibleContent, - CollapsibleTrigger, + Collapsible, + CollapsibleContent, + CollapsibleTrigger, } from "@/components/ui/collapsible"; import { - Sidebar, - SidebarContent, - SidebarGroup, - SidebarGroupContent, - SidebarGroupLabel, - SidebarHeader, - SidebarMenu, - SidebarMenuButton, - SidebarMenuItem, - SidebarRail, + Sidebar, + SidebarContent, + SidebarGroup, + SidebarGroupContent, + SidebarGroupLabel, + SidebarHeader, + SidebarMenu, + SidebarMenuButton, + SidebarMenuItem, + SidebarRail, } from "@/components/ui/sidebar"; type Permission = { - id: number; - name: string; + id: number; + name: string; }; type Categories = { - id: string; - children: ( - | { - title: string; - link: string; - perm_identifier: string; - icon: React.JSX.Element; - } - | { - title: string; - link: string; - icon: React.JSX.Element; - perm_identifier?: undefined; - } - )[]; + id: string; + children: ( + | { + title: string; + link: string; + perm_identifier: string; + icon: React.JSX.Element; + } + | { + title: string; + link: string; + icon: React.JSX.Element; + perm_identifier?: undefined; + } + )[]; }[]; export async function AppSidebar({ - ...props + ...props }: React.ComponentProps) { - const categories = [ - { - id: "MENU", - url: "#", - children: [ - { - title: "Devices", - link: "/devices?page=1", - perm_identifier: "device", - icon: , - }, - { - title: "Payments", - link: "/payments?page=1", - icon: , - perm_identifier: "payment", - }, - { - title: "Top Ups", - link: "/top-ups?page=1", - icon: , - perm_identifier: "topup", - }, - { - title: "Parental Control", - link: "/parental-control?page=1", - icon: , - perm_identifier: "device", - }, - { - title: "Agreements", - link: "/agreements", - icon: , - perm_identifier: "device", - }, - { - title: "Wallet", - link: "/wallet", - icon: , - perm_identifier: "wallet transaction", - }, - ], - }, - { - id: "ADMIN CONTROL", - url: "#", - children: [ - { - title: "Users", - link: "/users", - icon: , - perm_identifier: "device", - }, - { - title: "User Devices", - link: "/user-devices", - icon: , - perm_identifier: "device", - }, - { - title: "User Payments", - link: "/user-payments", - icon: , - perm_identifier: "payment", - }, - { - title: "User Topups", - link: "/user-topups", - icon: , - perm_identifier: "topup", - }, - { - title: "Price Calculator", - link: "/price-calculator", - icon: , - perm_identifier: "device", - }, - ], - }, - ]; + const categories = [ + { + id: "MENU", + url: "#", + children: [ + { + title: "Devices", + link: "/devices?page=1", + perm_identifier: "device", + icon: , + }, + { + title: "Parental Control", + link: "/parental-control?page=1", + icon: , + perm_identifier: "device", + }, + { + title: "Subscriptions", + link: "/payments?page=1", + icon: , + perm_identifier: "payment", + }, + { + title: "Top Ups", + link: "/top-ups?page=1", + icon: , + perm_identifier: "topup", + }, + { + title: "Transaction History", + link: "/wallet", + icon: , + perm_identifier: "wallet transaction", + }, + { + title: "Agreements", + link: "/agreements", + icon: , + perm_identifier: "device", + }, + ], + }, + { + id: "ADMIN CONTROL", + url: "#", + children: [ + { + title: "Users", + link: "/users", + icon: , + perm_identifier: "device", + }, + { + title: "User Devices", + link: "/user-devices", + icon: , + perm_identifier: "device", + }, + { + title: "User Payments", + link: "/user-payments", + icon: , + perm_identifier: "payment", + }, + { + title: "User Topups", + link: "/user-topups", + icon: , + perm_identifier: "topup", + }, + { + title: "Price Calculator", + link: "/price-calculator", + icon: , + perm_identifier: "device", + }, + ], + }, + ]; - const session = await getServerSession(authOptions); + const session = await getServerSession(authOptions); - let CATEGORIES: Categories; - if (session?.user?.is_admin) { - CATEGORIES = categories; - } else { - // Filter out ADMIN CONTROL category for non-admin users - const nonAdminCategories = categories.filter( - (category) => category.id !== "ADMIN CONTROL", - ); + let CATEGORIES: Categories; + if (session?.user?.is_admin) { + CATEGORIES = categories; + } else { + // Filter out ADMIN CONTROL category for non-admin users + const nonAdminCategories = categories.filter( + (category) => category.id !== "ADMIN CONTROL", + ); - const filteredCategories = nonAdminCategories.map((category) => { - const filteredChildren = category.children.filter((child) => { - const permIdentifier = child.perm_identifier; - return session?.user?.user_permissions?.some( - (permission: Permission) => { - const permissionParts = permission.name.split(" "); - const modelNameFromPermission = permissionParts.slice(2).join(" "); - return modelNameFromPermission === permIdentifier; - }, - ); - }); + const filteredCategories = nonAdminCategories.map((category) => { + const filteredChildren = category.children.filter((child) => { + const permIdentifier = child.perm_identifier; + return session?.user?.user_permissions?.some( + (permission: Permission) => { + const permissionParts = permission.name.split(" "); + const modelNameFromPermission = permissionParts.slice(2).join(" "); + return modelNameFromPermission === permIdentifier; + }, + ); + }); - return { ...category, children: filteredChildren }; - }); + return { ...category, children: filteredChildren }; + }); - CATEGORIES = filteredCategories.filter( - (category) => category.children.length > 0, - ); - } + CATEGORIES = filteredCategories.filter( + (category) => category.children.length > 0, + ); + } - return ( - - -

- Sar Link Portal -

-
- - {CATEGORIES.map((item) => { - return ( - - - - - {item.id}{" "} - - - - - - - {item.children.map((item) => ( - - - - {item.icon} - - {item.title} - - - - - ))} - - - - - - ); - })} - - -
- ); + return ( + + +

+ Sar Link Portal +

+
+ + {CATEGORIES.map((item) => { + return ( + + + + + {item.id}{" "} + + + + + + + {item.children.map((item) => ( + + + + {item.icon} + + {item.title} + + + + + ))} + + + + + + ); + })} + + +
+ ); }