mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 11:06:29 +00:00
Move auth config and build admin menus
Extract NextAuth configuration into a shared library, load admin sidebar items from role permissions, and update related RBAC types and UI.
This commit is contained in:
@@ -15,12 +15,12 @@ import { CalendarDateRangePicker } from "../components/DaterangePicker"
|
||||
import { Button } from "@/components/ui/button"
|
||||
// import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
||||
import { authOptions } from "@/pages/api/auth/[...nextauth]"
|
||||
import { titleCase } from "@/lib/helper"
|
||||
import { fetchDataWithPost } from "@/lib/fetchData"
|
||||
// import { ToggleTheme } from "../admin/components/ToggleTheme"
|
||||
// import Notification from "../admin/components/Notification"
|
||||
import duration from 'dayjs/plugin/duration'
|
||||
import { authOptions } from "@/lib/auth"
|
||||
dayjs.extend(duration)
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ import Link from "next/link"
|
||||
import { getServerSession } from "next-auth"
|
||||
import dayjs from "dayjs"
|
||||
|
||||
import { authOptions } from "@/pages/api/auth/[...nextauth]"
|
||||
import { generateHourMinutes, titleCase } from "@/lib/helper"
|
||||
import { fetchDataWithPost } from "@/lib/fetchData"
|
||||
|
||||
@@ -12,6 +11,7 @@ import { Button } from "@/components/ui/button"
|
||||
import { Card900, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
||||
|
||||
import LazyLoading from "@/components/loader/LazyLoading"
|
||||
import { authOptions } from "@/lib/auth"
|
||||
|
||||
// const LastPresence = lazy(() => import("./components/LastPresence"))
|
||||
const WorkingHours = lazy(() => import("../components/WorkingHours"))
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Suspense, lazy } from 'react';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import dayjs from 'dayjs';
|
||||
import { authOptions } from '@/pages/api/auth/[...nextauth]';
|
||||
import { fetchDataWithPost } from '@/lib/fetchData';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { type IHistory } from '../components/type';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
|
||||
const DataTable = lazy(() => import('./DataTable'));
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { Suspense, lazy } from 'react';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import dayjs from 'dayjs';
|
||||
import { authOptions } from '@/pages/api/auth/[...nextauth]';
|
||||
import { fetchDataWithPost } from '@/lib/fetchData';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { type ILeaveSickPermit } from '../components/type';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
|
||||
const DataTable = lazy(() => import('./DataTable'));
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import { Suspense, lazy } from "react";
|
||||
import SkeletonTable from "@/components/skeleton/SkeletonTable";
|
||||
import TabsComponent from "./components/Tabs";
|
||||
import { getServerSession } from "next-auth";
|
||||
import { authOptions } from "@/pages/api/auth/[...nextauth]";
|
||||
import { authOptions } from "@/lib/auth";
|
||||
|
||||
const AttendanceHistory = lazy(() => import("./attendance"));
|
||||
const LeavePermitHistory = lazy(() => import("./leave-permit"));
|
||||
|
||||
@@ -5,8 +5,8 @@ import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import PageLoading from '@/components/loader/PageLoading';
|
||||
import { fetchDataWithPost } from '@/lib/fetchData';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { authOptions } from '@/pages/api/auth/[...nextauth]';
|
||||
import { redirect } from 'next/navigation';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
|
||||
const FormComponent = lazy(() => import('./components/FormComponent'))
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { type IProfile } from './components/type';
|
||||
import { type IUser } from '@/app/admin/administration/user/component/type';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { authOptions } from '@/pages/api/auth/[...nextauth]';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
|
||||
const ForgotPassword = lazy(() => import('./components/ForgotPassword'));
|
||||
const ChangeTheme = lazy(() => import("./components/ChangeTheme"))
|
||||
|
||||
@@ -3,9 +3,9 @@ import InterceptModal from '@/components/modal/InterceptModal';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import DateRangePicker from '@/app/performance/[id]/components/DateRangePicker';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { authOptions } from '@/pages/api/auth/[...nextauth]';
|
||||
import { Metadata } from 'next';
|
||||
import dayjs from 'dayjs';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
|
||||
const PerformanceComponent = lazy(() => import('@/app/performance/[id]/components'));
|
||||
|
||||
|
||||
+1
-1
@@ -1,8 +1,8 @@
|
||||
"use server"
|
||||
|
||||
import { authOptions } from "@/lib/auth";
|
||||
import axios from "@/lib/axios";
|
||||
import { serverApiCall } from "@/lib/server-api";
|
||||
import { authOptions } from "@/pages/api/auth/[...nextauth]";
|
||||
import { getServerSession } from "next-auth";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@ import { type Metadata } from 'next';
|
||||
import { FC, Suspense, lazy } from 'react';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { Download } from 'lucide-react'
|
||||
import { authOptions } from '@/pages/api/auth/[...nextauth]';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { type ResponseData } from '@/types/types';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@ import { type Metadata } from 'next';
|
||||
import { Suspense, lazy } from 'react';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { Download } from 'lucide-react'
|
||||
import { authOptions } from '@/pages/api/auth/[...nextauth]';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { type ResponseData } from '@/types/types';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@ import { type Metadata } from 'next';
|
||||
import { Suspense, lazy } from 'react';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { Download } from 'lucide-react'
|
||||
import { authOptions } from '@/pages/api/auth/[...nextauth]';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { type ResponseData } from '@/types/types';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { type Metadata } from 'next';
|
||||
import { Suspense, lazy } from 'react';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { authOptions } from '@/pages/api/auth/[...nextauth]';
|
||||
import { type ResponseData } from '@/types/types';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import ExportComponent from './component/Export';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@ import { type Metadata } from 'next';
|
||||
import { Suspense, lazy } from 'react';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { Download } from 'lucide-react'
|
||||
import { authOptions } from '@/pages/api/auth/[...nextauth]';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { type ResponseData } from '@/types/types';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ export default function AdminBreadcrumb() {
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex items-center text-xs font-medium text-muted-foreground flex-wrap">
|
||||
<div className="flex items-center text-xs md:text-sm font-medium text-muted-foreground flex-wrap">
|
||||
<Link href="/admin" className="hover:text-zinc-900 dark:hover:text-zinc-100 transition-colors">
|
||||
Pages
|
||||
</Link>
|
||||
@@ -63,9 +63,9 @@ export default function AdminBreadcrumb() {
|
||||
{formatSegment(seg)}
|
||||
</span>
|
||||
) : (
|
||||
<Link href={href} className="hover:text-zinc-900 dark:hover:text-zinc-100 transition-colors">
|
||||
<span className="hover:text-zinc-900 dark:hover:text-zinc-100 transition-colors">
|
||||
{formatSegment(seg)}
|
||||
</Link>
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
);
|
||||
|
||||
@@ -19,9 +19,11 @@ const SidebarItem = dynamic(() => import("./SidebarItem"), {
|
||||
ssr: false
|
||||
})
|
||||
|
||||
type Props = {};
|
||||
type Props = {
|
||||
menuList: ISideMenu[]
|
||||
};
|
||||
|
||||
const Sidebar: FC<Props> = ({ }) => {
|
||||
const Sidebar: FC<Props> = ({ menuList }) => {
|
||||
const [expand, setExpand] = useState(true)
|
||||
const [sidebarOpen, setSidebarOpen] = useState(false)
|
||||
const [search, setSearch] = useState('')
|
||||
@@ -30,7 +32,8 @@ const Sidebar: FC<Props> = ({ }) => {
|
||||
const sidebar = useRef<any>(null);
|
||||
const router = useRouter()
|
||||
|
||||
const menu: ISideMenu[] = SIDEBAR_MENU
|
||||
// const menu: ISideMenu[] = SIDEBAR_MENU
|
||||
const menu: ISideMenu[] = menuList
|
||||
|
||||
// close on click outside
|
||||
useEffect(() => {
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { FC } from 'react';
|
||||
|
||||
type Props = {};
|
||||
|
||||
const SkeletonSidebar: FC<Props> = () => {
|
||||
return (
|
||||
<>
|
||||
<div className='hidden lg:block bg-[#FAF8F5] dark:bg-[#1C1814]/95 text-[#4A3F35] dark:text-[#F6F1E8] w-72 h-full rounded-2xl shadow-[4px_0_24px_rgba(74,63,53,0.06)] border border-[#E5DDD1] dark:border-[#3D342C] p-5'>
|
||||
<div className='p-4 border-b border-[#E5DDD1]/70 dark:border-[#3D342C] w-full'>
|
||||
<Skeleton className='w-full h-7 2xl:h-8' />
|
||||
</div>
|
||||
<div className='mt-5 space-y-5 flex flex-col w-full'>
|
||||
<Skeleton className='w-full h-7 2xl:h-8' />
|
||||
<Skeleton className='w-full h-7 2xl:h-8' />
|
||||
<Skeleton className='w-full h-7 2xl:h-8' />
|
||||
<Skeleton className='w-full h-7 2xl:h-8' />
|
||||
<Skeleton className='w-full h-7 2xl:h-8' />
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default SkeletonSidebar;
|
||||
@@ -2,11 +2,11 @@ import { type Metadata } from 'next';
|
||||
import { Suspense, lazy } from 'react';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { Download } from 'lucide-react'
|
||||
import { authOptions } from '@/pages/api/auth/[...nextauth]';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { type ResponseData } from '@/types/types';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@ import { type Metadata } from 'next';
|
||||
import { Suspense, lazy } from 'react';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { Download } from 'lucide-react'
|
||||
import { authOptions } from '@/pages/api/auth/[...nextauth]';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { type ResponseData } from '@/types/types';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@ import { type Metadata } from 'next';
|
||||
import { Suspense, lazy } from 'react';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { Download } from 'lucide-react'
|
||||
import { authOptions } from '@/pages/api/auth/[...nextauth]';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { type ResponseData } from '@/types/types';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { type Metadata } from 'next';
|
||||
import { Suspense, lazy } from 'react';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { authOptions } from '@/pages/api/auth/[...nextauth]';
|
||||
import { type ResponseData } from '@/types/types';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { type Metadata } from 'next';
|
||||
import { Suspense, lazy } from 'react';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { authOptions } from '@/pages/api/auth/[...nextauth]';
|
||||
import { type ResponseData } from '@/types/types';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { type Metadata } from 'next';
|
||||
import { Suspense, lazy } from 'react';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { authOptions } from '@/pages/api/auth/[...nextauth]';
|
||||
import { type ResponseData } from '@/types/types';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { type Metadata } from 'next';
|
||||
import { Suspense, lazy } from 'react';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import { authOptions } from '@/pages/api/auth/[...nextauth]';
|
||||
import { type ResponseData } from '@/types/types';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
|
||||
const ComponentPage = lazy(() => import('./component'));
|
||||
|
||||
|
||||
+74
-7
@@ -2,27 +2,94 @@ import { Metadata } from "next";
|
||||
import Link from "next/link";
|
||||
import { ToggleTheme } from "./components/ToggleTheme";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import Sidebar from "./components/Sidebar";
|
||||
import Notification from "./components/Notification";
|
||||
import { UserNav } from "../(dashboard)/components/UserNav";
|
||||
import { House } from "lucide-react";
|
||||
import AdminBreadcrumb from "./components/Breadcrumb";
|
||||
import { getAccessData } from "@/lib/get-access-data";
|
||||
import { IRoleDetail } from "@/types/rbac";
|
||||
import { ISideMenu } from "./components/SidebarItem";
|
||||
import { lazy, Suspense } from "react";
|
||||
import SkeletonSidebar from "./components/SkeletonSidebar";
|
||||
|
||||
const Sidebar = lazy(() => import("./components/Sidebar"));
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Admin Panel",
|
||||
description: "H.A.T.s admin panel page",
|
||||
}
|
||||
|
||||
export default async function AdminLayout({
|
||||
children, // will be a page or nested layout
|
||||
}: {
|
||||
children: React.ReactNode
|
||||
}) {
|
||||
export default async function AdminLayout({ children }: { children: React.ReactNode }) {
|
||||
const data = await getAccessData()
|
||||
|
||||
const cleanPath = (path: string): string => {
|
||||
if (!path || path === '/') return ''
|
||||
const sanitized = path.replace(/\/+/g, '/')
|
||||
return sanitized.startsWith('/') ? sanitized : `/${sanitized}`
|
||||
}
|
||||
|
||||
const buildSidebarMenu = (items: IRoleDetail[]): ISideMenu[] => {
|
||||
// 1. Filter out deleted, inactive, or hidden items
|
||||
const adminMenus = items.filter(item => item.menu?.is_admin_menu === true)
|
||||
const activeItems = adminMenus.filter((item) => item.menu && !item.menu.deleted_at && item.menu.status_id === 1)
|
||||
|
||||
const parents: IRoleDetail[] = []
|
||||
const childrenMap = new Map<number, IRoleDetail[]>()
|
||||
|
||||
// 2. Group into parent items and children
|
||||
for (const item of activeItems) {
|
||||
const parentId = item.menu?.menu_parent_id
|
||||
if (parentId === null) {
|
||||
parents.push(item)
|
||||
} else {
|
||||
const children = childrenMap.get(parentId!) || []
|
||||
children.push(item)
|
||||
childrenMap.set(parentId!, children)
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Sorting helper (sort ascending, null values last, fallback to id)
|
||||
const sortByOrder = (a: IRoleDetail, b: IRoleDetail) => {
|
||||
const sortA = a.menu?.sort ?? Number.MAX_SAFE_INTEGER
|
||||
const sortB = b.menu?.sort ?? Number.MAX_SAFE_INTEGER
|
||||
if (sortA !== sortB) return sortA - sortB
|
||||
return a.menu?.id! - b.menu?.id!
|
||||
}
|
||||
|
||||
parents.sort(sortByOrder)
|
||||
|
||||
// 4. Map to target structure
|
||||
// @ts-ignore
|
||||
return parents.map((parent) => {
|
||||
const children = childrenMap.get(parent.menu?.id!) || []
|
||||
|
||||
if (children.length > 0) {
|
||||
children.sort(sortByOrder)
|
||||
return {
|
||||
title: parent.menu?.name!,
|
||||
Icon: <i className={`${parent.menu?.icon} text-base`}></i>,
|
||||
submenuId: parent.menu?.id,
|
||||
submenuItems: children.map((child) => ({
|
||||
title: child.menu?.name,
|
||||
path: cleanPath(child.menu?.path_url!),
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
title: parent.menu?.name!,
|
||||
Icon: <i className={`${parent.menu?.icon} text-base`}></i>,
|
||||
path: cleanPath(parent.menu?.path_url!),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<main className="flex flex-col lg:flex-row h-screen overflow-hidden text-sm bg-soft dark:bg-zinc-900">
|
||||
<Sidebar />
|
||||
<Suspense fallback={<SkeletonSidebar />}>
|
||||
<Sidebar menuList={buildSidebarMenu(data.role_detail) || []} />
|
||||
</Suspense>
|
||||
|
||||
{/* CONTENT */}
|
||||
<div className="overflow-x-hidden overflow-y-auto h-screen flex flex-col z-0 w-full px-5 pt-5">
|
||||
|
||||
@@ -6,7 +6,7 @@ import fetchData from '@/lib/fetchData';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { type IRole } from '../component/type';
|
||||
import RolePermissionRow from "../component/role-permission-row";
|
||||
import { PencilLine } from 'lucide-react';
|
||||
import { PencilLine, ShieldCheck } from 'lucide-react';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
@@ -179,7 +179,7 @@ const UserRoleDetailPage: FC<Props> = async ({ params }) => {
|
||||
<CardHeader className="pb-3 border-b border-zinc-200 dark:border-zinc-800">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
<i className="ti ti-checklist text-lg text-his" />
|
||||
<ShieldCheck className='text-his' />
|
||||
<CardTitle className="text-base font-semibold">
|
||||
Authorized Menu Permissions ({orderedDetails.length} Menus Allowed)
|
||||
</CardTitle>
|
||||
|
||||
@@ -81,9 +81,7 @@ export const RoleForm: FC<Props> = ({ isUpdate, roleId, initialData }) => {
|
||||
|
||||
const rawDetails = Array.isArray(initialData.role_detail)
|
||||
? initialData.role_detail
|
||||
: Array.isArray(initialData.privilege)
|
||||
? initialData.privilege
|
||||
: [];
|
||||
: [];
|
||||
|
||||
rawDetails.forEach((item: any) => {
|
||||
// Support both new API format (item.menu.id) and legacy format (item.menu_id)
|
||||
@@ -421,7 +419,7 @@ export const RoleForm: FC<Props> = ({ isUpdate, roleId, initialData }) => {
|
||||
{/* Bottom Action Bar */}
|
||||
<div className="mt-6 flex justify-end items-center gap-3">
|
||||
<Link href="/admin/rbac/user-role">
|
||||
<Button variant="outline" type="button" disabled={isLoading} className='text-zinc-800! dark:text-white'>
|
||||
<Button variant="outline" type="button" disabled={isLoading} >
|
||||
Cancel
|
||||
</Button>
|
||||
</Link>
|
||||
|
||||
@@ -118,9 +118,7 @@ const ComponentRolePage: FC<Props> = ({ data }) => {
|
||||
render: (details: any, record: IRole) => {
|
||||
const count = Array.isArray(details)
|
||||
? details.length
|
||||
: Array.isArray(record.privilege)
|
||||
? record.privilege.length
|
||||
: 0;
|
||||
: 0;
|
||||
return (
|
||||
<span className="inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-zinc-100 dark:bg-zinc-800 text-zinc-700 dark:text-zinc-300">
|
||||
{count} menus
|
||||
|
||||
+1
-1
@@ -5,7 +5,6 @@ import type { Metadata, Viewport } from 'next'
|
||||
import { Plus_Jakarta_Sans } from 'next/font/google'
|
||||
|
||||
import { getServerSession } from 'next-auth'
|
||||
import { authOptions } from '@/pages/api/auth/[...nextauth]'
|
||||
|
||||
import { ThemeProvider } from '@/providers/ThemeProvider'
|
||||
import SessionProvider from '@/providers/SessionProvider'
|
||||
@@ -14,6 +13,7 @@ import AntdConfigProvider from '@/providers/AntdConfigProvider';
|
||||
import ProgressBarProviders from '@/providers/ProgressBarProvider';
|
||||
import { TooltipProvider } from '@/components/ui/tooltip';
|
||||
import ServiceWorkerRegister from '@/components/pwa/ServiceWorkerRegister';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
|
||||
|
||||
const jakarta = Plus_Jakarta_Sans({ subsets: ['latin'] })
|
||||
|
||||
@@ -2,12 +2,12 @@ import { FC, Suspense, lazy } from 'react';
|
||||
import { redirect } from 'next/navigation';
|
||||
import { getServerSession } from 'next-auth';
|
||||
import dayjs from 'dayjs';
|
||||
import { authOptions } from '@/pages/api/auth/[...nextauth]';
|
||||
import { Card, Card900, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import LazyLoading from '@/components/loader/LazyLoading';
|
||||
import fetchData, { fetchDataWithPost } from '@/lib/fetchData';
|
||||
import { generateHourMinutes } from '@/lib/helper';
|
||||
import ViewAvatar from '@/components/ViewAvatar';
|
||||
import { authOptions } from '@/lib/auth';
|
||||
|
||||
const DonutChart = lazy(() => import('./DonutChart'));
|
||||
const AreaChart = lazy(() => import('./AreaChart'))
|
||||
|
||||
Reference in New Issue
Block a user