sarlink-portal/components/ui/app-sidebar.tsx
i701 c6f45710ca Enhance dashboard functionality with new payment and device management features
- Added new PaymentPage component for processing payments and displaying devices to pay.
- Introduced DeviceDetails component for viewing individual device information.
- Implemented PriceCalculator component for calculating costs based on user input.
- Integrated Jotai for state management across components, including device cart functionality.
- Updated layout to include Jotai Provider for state management.
- Enhanced DevicesTable with AddDevicesToCartButton for adding devices to the cart.
- Refactored sidebar to include a link to the new Price Calculator page.
- Updated Prisma schema to include Payment and BillFormula models for better data handling.
- Added new UI components for device cart management and drawer functionality.
- Improved overall user experience with responsive design adjustments and new UI elements.
2024-12-06 14:16:05 +05:00

150 lines
3.3 KiB
TypeScript

import {
Calculator,
ChevronRight,
Coins,
CreditCard,
Handshake,
MonitorSpeaker,
Smartphone,
UsersRound,
} from "lucide-react";
import {
Collapsible,
CollapsibleContent,
CollapsibleTrigger,
} from "@/components/ui/collapsible";
import {
Sidebar,
SidebarContent,
SidebarGroup,
SidebarGroupContent,
SidebarGroupLabel,
SidebarHeader,
SidebarMenu,
SidebarMenuButton,
SidebarMenuItem,
SidebarRail,
} from "@/components/ui/sidebar";
import Link from "next/link";
const data = {
navMain: [
{
title: "MENU",
url: "#",
requiredRoles: ["ADMIN", "USER"],
items: [
{
title: "Devices",
url: "/devices",
icon: <Smartphone size={16} />,
},
{
title: "Payments",
url: "/payments",
icon: <CreditCard size={16} />,
},
{
title: "Agreements",
url: "/agreements",
icon: <Handshake size={16} />,
},
],
},
{
title: "ADMIN CONTROL",
url: "#",
requiredRoles: ["ADMIN"],
items: [
{
title: "Users",
url: "/users",
icon: <UsersRound size={16} />,
},
{
title: "User Devices",
url: "/user-devices",
icon: <MonitorSpeaker size={16} />,
},
{
title: "User Payments",
url: "/user-payments",
icon: <Coins size={16} />,
},
{
title: "Price Calculator",
url: "/price-calculator",
icon: <Calculator size={16} />,
},
],
},
],
};
export function AppSidebar({
role,
...props
}: React.ComponentProps<typeof Sidebar> & { role: string }) {
return (
<Sidebar {...props} className="z-50">
<SidebarHeader>
<h4 className="p-2 rounded title-bg border text-center uppercase ">
Sar Link Portal
</h4>
</SidebarHeader>
<SidebarContent className="gap-0">
{data.navMain
.filter(
(item) =>
!item.requiredRoles || item.requiredRoles.includes(role || ""),
)
.map((item) => {
if (item.requiredRoles?.includes(role)) {
return (
<Collapsible
key={item.title}
title={item.title}
defaultOpen
className="group/collapsible"
>
<SidebarGroup>
<SidebarGroupLabel
asChild
className="group/label text-sm text-sidebar-foreground hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"
>
<CollapsibleTrigger>
{item.title}{" "}
<ChevronRight className="ml-auto transition-transform group-data-[state=open]/collapsible:rotate-90" />
</CollapsibleTrigger>
</SidebarGroupLabel>
<CollapsibleContent>
<SidebarGroupContent>
<SidebarMenu>
{item.items.map((item) => (
<SidebarMenuItem key={item.title}>
<SidebarMenuButton className="py-6" asChild>
<Link className="text-md" href={item.url}>
{item.icon}
<span className="opacity-70 ml-2">
{item.title}
</span>
</Link>
</SidebarMenuButton>
</SidebarMenuItem>
))}
</SidebarMenu>
</SidebarGroupContent>
</CollapsibleContent>
</SidebarGroup>
</Collapsible>
);
}
})}
</SidebarContent>
<SidebarRail />
</Sidebar>
);
}