import { StringIdentifier, transformObject, ucFirstAllSnakeToPascalWithSpaces } from "core/utils"; import { useBkndAuth } from "ui/client/schema/auth/use-bknd-auth"; import { Alert } from "ui/components/display/Alert"; import { bkndModals } from "ui/modals"; import { Button } from "../../components/buttons/Button"; import { CellValue, DataTable } from "../../components/table/DataTable"; import * as AppShell from "../../layouts/AppShell/AppShell"; import { routes, useNavigate } from "../../lib/routes"; export function AuthRolesList() { const [navigate] = useNavigate(); const { config, actions } = useBkndAuth(); const data = Object.values( transformObject(config.roles ?? {}, (role, name) => ({ role: name, permissions: role.permissions, is_default: role.is_default ?? false, implicit_allow: role.implicit_allow ?? false })) ); function handleClick(row) { navigate(routes.auth.roles.edit(row.role)); } function openCreateModal() { bkndModals.open( "form", { schema: { type: "object", properties: { name: StringIdentifier }, required: ["name"] }, uiSchema: { name: { "ui:title": "Role name" } }, onSubmit: async (data) => { if (data.name.length > 0) { if (await actions.roles.add(data.name)) { navigate(routes.auth.roles.edit(data.name)); } } } }, { title: "New Role" } ); } return ( <> Create new } > Roles & Permissions
); } const renderValue = ({ value, property }) => { if (["is_default", "implicit_allow"].includes(property)) { return value ? Yes : No; } if (property === "permissions") { return (
{[...(value || [])].map((p, i) => ( {p} ))}
); } return ; };