UNPKG

@dbs-portal/module-identity

Version:

Identity management module for user and role management

98 lines 5.09 kB
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime"; /** * Role List Page * * Complete page component for role management with data fetching, filtering, * and navigation. This is a self-contained page that can be directly used * in any application that imports the identity module. */ import React, { useState } from 'react'; import { Card, Button, Space, Input, Select, Row, Col, Typography, message, Modal } from 'antd'; import { PlusOutlined, SearchOutlined, FilterOutlined, ExportOutlined } from '@ant-design/icons'; // Import from same module import { RoleList } from '../components/RoleList'; import { useRoles, useDeleteRole } from '../hooks'; const { Title } = Typography; const { Option } = Select; export const RoleListPage = ({ onNavigate, onCreateRole, onEditRole, onViewRole, className }) => { const [filters, setFilters] = useState({}); const [searchText, setSearchText] = useState(''); const [selectedType, setSelectedType] = useState(''); // Hooks from identity module const { data: rolesData, isLoading, error } = useRoles(filters); const deleteRoleMutation = useDeleteRole(); const roles = rolesData?.data || []; const handleSearch = () => { const newFilters = { ...filters, keyword: searchText }; if (selectedType === 'default') { newFilters.isDefault = true; } else if (selectedType === 'static') { newFilters.isStatic = true; } else if (selectedType === 'custom') { newFilters.isDefault = false; newFilters.isStatic = false; } setFilters(newFilters); }; const handleCreateRole = () => { if (onCreateRole) { onCreateRole(); } else if (onNavigate) { onNavigate('/identity/roles/create'); } }; const handleEditRole = (role) => { if (onEditRole) { onEditRole(role); } else if (onNavigate) { onNavigate(`/identity/roles/${role.id}/edit`); } }; const handleViewRole = (role) => { if (onViewRole) { onViewRole(role); } else if (onNavigate) { onNavigate(`/identity/roles/${role.id}`); } }; const handleDeleteRole = (role) => { 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'); } catch (error) { message.error('Failed to delete role'); console.error('Delete role error:', error); } } }); }; const handleExport = () => { // Mock export functionality message.info('Export functionality will be implemented'); }; if (error) { return (_jsx(Card, { className: className, children: _jsxs(Typography.Text, { type: "danger", children: ["Failed to load roles: ", error.message] }) })); } return (_jsxs("div", { className: className, children: [_jsx("div", { style: { marginBottom: 24 }, children: _jsxs(Row, { justify: "space-between", align: "middle", children: [_jsx(Col, { children: _jsx(Title, { level: 2, style: { margin: 0 }, children: "Role Management" }) }), _jsx(Col, { children: _jsxs(Space, { children: [_jsx(Button, { type: "primary", icon: _jsx(PlusOutlined, {}), onClick: handleCreateRole, children: "Create Role" }), _jsx(Button, { icon: _jsx(ExportOutlined, {}), onClick: handleExport, children: "Export" })] }) })] }) }), _jsx(Card, { style: { marginBottom: 16 }, children: _jsxs(Row, { gutter: 16, align: "middle", children: [_jsx(Col, { xs: 24, sm: 8, children: _jsx(Input, { placeholder: "Search roles...", prefix: _jsx(SearchOutlined, {}), value: searchText, onChange: (e) => setSearchText(e.target.value), onPressEnter: handleSearch }) }), _jsx(Col, { xs: 24, sm: 6, children: _jsxs(Select, { placeholder: "Role Type", style: { width: '100%' }, value: selectedType, onChange: setSelectedType, allowClear: true, children: [_jsx(Option, { value: "default", children: "Default Roles" }), _jsx(Option, { value: "static", children: "System Roles" }), _jsx(Option, { value: "custom", children: "Custom Roles" })] }) }), _jsx(Col, { xs: 24, sm: 4, children: _jsx(Button, { type: "primary", icon: _jsx(FilterOutlined, {}), onClick: handleSearch, style: { width: '100%' }, children: "Filter" }) })] }) }), _jsx(Card, { children: _jsx(RoleList, { roles: roles, loading: isLoading, onEdit: handleEditRole, onDelete: handleDeleteRole }) })] })); }; //# sourceMappingURL=RoleListPage.js.map