UNPKG

@dbs-portal/module-identity

Version:

Identity management module for user and role management

66 lines 3.47 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; /** * Role Details Page */ import React from 'react'; import { Button, Space, Typography, message, Modal, Spin, Alert } from 'antd'; import { ArrowLeftOutlined } from '@ant-design/icons'; import { RoleDetails } from '../components/RoleDetails'; import { useRole, useDeleteRole } from '../hooks'; const { Title } = Typography; export const RoleDetailsPage = ({ roleId, onNavigate, onBack, onEdit, onRoleDeleted, className }) => { const { data: role, isLoading, error } = useRole(roleId); const deleteRoleMutation = useDeleteRole(); const handleBack = () => { if (onBack) onBack(); else if (onNavigate) onNavigate('/identity/roles'); }; const handleEdit = () => { if (onEdit) onEdit(roleId); else if (onNavigate) onNavigate(`/identity/roles/${roleId}/edit`); }; const handleDelete = () => { if (!role) return; if (role.isStatic) { message.warning('System roles cannot be deleted'); return; } Modal.confirm({ title: 'Delete Role', content: `Are you sure you want to delete role "${role.displayName || role.name}"? This action cannot be undone.`, okText: 'Delete', okType: 'danger', cancelText: 'Cancel', onOk: async () => { try { await deleteRoleMutation.mutateAsync(role.id); message.success('Role deleted successfully'); if (onRoleDeleted) onRoleDeleted(); else if (onNavigate) onNavigate('/identity/roles'); } catch (error) { message.error('Failed to delete role'); console.error('Delete role error:', error); } } }); }; if (isLoading) { return (_jsxs("div", { className: className, style: { textAlign: 'center', padding: '50px' }, children: [_jsx(Spin, { size: "large" }), _jsx("div", { style: { marginTop: 16 }, children: "Loading role details..." })] })); } if (error) { return (_jsxs("div", { className: className, children: [_jsx("div", { style: { marginBottom: 24 }, children: _jsx(Button, { icon: _jsx(ArrowLeftOutlined, {}), onClick: handleBack, children: "Back to Roles" }) }), _jsx(Alert, { message: "Error Loading Role", description: `Failed to load role details: ${error.message}`, type: "error", showIcon: true })] })); } if (!role) { return (_jsxs("div", { className: className, children: [_jsx("div", { style: { marginBottom: 24 }, children: _jsx(Button, { icon: _jsx(ArrowLeftOutlined, {}), onClick: handleBack, children: "Back to Roles" }) }), _jsx(Alert, { message: "Role Not Found", description: "The requested role could not be found.", type: "warning", showIcon: true })] })); } 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: "Role Details" })] }) }), _jsx(RoleDetails, { role: role, onEdit: handleEdit, onDelete: handleDelete })] })); }; //# sourceMappingURL=RoleDetailsPage.js.map