UNPKG

@dbs-portal/module-identity

Version:

Identity management module for user and role management

41 lines 1.97 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; /** * Role Create Page */ import React from 'react'; import { Button, Space, Typography, message } from 'antd'; import { ArrowLeftOutlined } from '@ant-design/icons'; import { RoleCreate } from '../components/RoleCreate'; import { useCreateRole } from '../hooks'; const { Title } = Typography; export const RoleCreatePage = ({ onNavigate, onBack, onRoleCreated, className }) => { const createRoleMutation = useCreateRole(); const handleBack = () => { if (onBack) onBack(); else if (onNavigate) onNavigate('/identity/roles'); }; const handleSubmit = async (data) => { try { const newRole = await createRoleMutation.mutateAsync({ name: data.name, displayName: data.displayName, description: data.description, isDefault: data.isDefault ?? false, permissions: data.permissions || [] }); message.success('Role created successfully!'); if (onRoleCreated) onRoleCreated(newRole.id); else if (onNavigate) onNavigate(`/identity/roles/${newRole.id}`); } catch (error) { console.error('Failed to create role:', error); message.error('Failed to create role. Please try again.'); } }; return (_jsxs("div", { className: className, children: [_jsx("div", { style: { marginBottom: 24 }, children: _jsxs(Space, { children: [_jsx(Button, { icon: _jsx(ArrowLeftOutlined, {}), onClick: handleBack, children: "Back to Roles" }), _jsx(Title, { level: 2, style: { margin: 0 }, children: "Create New Role" })] }) }), _jsx(RoleCreate, { onSubmit: handleSubmit, loading: createRoleMutation.isPending, error: createRoleMutation.error ? createRoleMutation.error.message : undefined })] })); }; //# sourceMappingURL=RoleCreatePage.js.map