import { groupPermissions } from "@/lib/groupPermission"; import { Anchor, Flex, Stack, Text } from "@mantine/core"; import { useState } from "react"; interface Node { label: string; children: any; actions: string[]; } function RenderNode({ node }: { node: Node }) { const sub = Object.values(node.children || {}); return ( {/* Title */} - {node.label} {/* Children */} {sub.map((child: any, i) => ( ))} ); } function RenderNode2({ node }: { node: Node }) { const sub = Object.values(node.children || {}); return ( {/* Title */} {node.label}, {/* Children */} {sub.map((child: any, i) => ( ))} ); } export default function PermissionRole({ permissions, }: { permissions: string[]; }) { const [showAll, setShowAll] = useState(false); if (!permissions?.length) return -; const groups = groupPermissions(permissions); const rootNodes = Object.values(groups); return ( {showAll ? rootNodes.map((node: any, idx) => ( )) : rootNodes .slice(0, 2) .map((node: any, idx) => )} setShowAll(!showAll)}> {showAll ? "View less" : "View more"} ); }