@dbs-portal/module-identity
Version:
Identity management module for user and role management
79 lines • 9.86 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useState } from 'react';
import { Card, Typography, Row, Col, Statistic, Button, Space, Table, Tag, Progress, Alert, Tabs, Form, Switch, InputNumber, message } from 'antd';
import { UserOutlined, SafetyOutlined, LockOutlined, WarningOutlined, CheckCircleOutlined, ReloadOutlined, ExportOutlined } from '@ant-design/icons';
import { useUsers, useRoles } from '../hooks';
const { Title, Text } = Typography;
const { TabPane } = Tabs;
// Mock admin settings (would come from API)
const ADMIN_SETTINGS = {
passwordPolicy: {
minLength: 8,
requireUppercase: true,
requireLowercase: true,
requireNumbers: true,
requireSpecialChars: true,
maxAge: 90,
preventReuse: 5
},
lockoutPolicy: {
enabled: true,
maxAttempts: 5,
lockoutDuration: 30,
resetTime: 15
},
sessionPolicy: {
timeout: 60,
maxConcurrent: 3,
requireReauth: false
}
};
export const IdentityAdmin = () => {
const [activeTab, setActiveTab] = useState('overview');
const [settingsForm] = Form.useForm();
const { data: usersData } = useUsers({ page: 1, limit: 1000 });
const { data: rolesData } = useRoles({ page: 1, limit: 1000 });
const users = usersData?.data || [];
const roles = rolesData?.data || [];
// Calculate statistics
const activeUsers = users.filter(user => user.isActive).length;
const lockedUsers = users.filter(user => user.lockoutEnd && new Date(user.lockoutEnd) > new Date()).length;
const unverifiedUsers = users.filter(user => !user.emailConfirmed).length;
const twoFactorUsers = users.filter(user => user.twoFactorEnabled).length;
const handleExportUsers = () => {
// Mock export functionality
message.success('User data export initiated');
};
const handleExportRoles = () => {
// Mock export functionality
message.success('Role data export initiated');
};
const handleSaveSettings = (values) => {
// Mock save functionality
console.log('Saving settings:', values);
message.success('Settings saved successfully');
};
const recentUsers = users
.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime())
.slice(0, 5);
const userColumns = [
{
title: 'User',
key: 'user',
render: (_, record) => (_jsxs(Space, { children: [_jsx(UserOutlined, {}), _jsxs("div", { children: [_jsx("div", { children: record.displayName || record.userName }), _jsx(Text, { type: "secondary", children: record.email })] })] })),
},
{
title: 'Status',
key: 'status',
render: (_, record) => (_jsxs(Space, { children: [_jsx(Tag, { color: record.isActive ? 'green' : 'red', children: record.isActive ? 'Active' : 'Inactive' }), record.emailConfirmed && _jsx(Tag, { color: "blue", children: "Verified" }), record.twoFactorEnabled && _jsx(Tag, { color: "purple", children: "2FA" })] })),
},
{
title: 'Created',
dataIndex: 'createdAt',
key: 'createdAt',
render: (date) => new Date(date).toLocaleDateString(),
},
];
return (_jsxs("div", { children: [_jsx(Title, { level: 2, children: "Identity Administration" }), _jsx(Text, { type: "secondary", children: "Manage system-wide identity settings, monitor user activity, and configure security policies." }), _jsxs(Tabs, { activeKey: activeTab, onChange: setActiveTab, style: { marginTop: 24 }, children: [_jsx(TabPane, { tab: "Overview", children: _jsxs(Row, { gutter: [16, 16], children: [_jsx(Col, { xs: 24, sm: 12, lg: 6, children: _jsx(Card, { children: _jsx(Statistic, { title: "Total Users", value: users.length, prefix: _jsx(UserOutlined, {}), valueStyle: { color: '#1890ff' } }) }) }), _jsx(Col, { xs: 24, sm: 12, lg: 6, children: _jsxs(Card, { children: [_jsx(Statistic, { title: "Active Users", value: activeUsers, prefix: _jsx(CheckCircleOutlined, {}), valueStyle: { color: '#52c41a' } }), _jsx(Progress, { percent: Math.round((activeUsers / users.length) * 100), size: "small", showInfo: false, strokeColor: "#52c41a" })] }) }), _jsx(Col, { xs: 24, sm: 12, lg: 6, children: _jsxs(Card, { children: [_jsx(Statistic, { title: "Locked Users", value: lockedUsers, prefix: _jsx(LockOutlined, {}), valueStyle: { color: '#ff4d4f' } }), lockedUsers > 0 && (_jsx(Alert, { message: `${lockedUsers} users are currently locked`, type: "warning", style: { marginTop: 8 } }))] }) }), _jsx(Col, { xs: 24, sm: 12, lg: 6, children: _jsxs(Card, { children: [_jsx(Statistic, { title: "2FA Enabled", value: twoFactorUsers, prefix: _jsx(SafetyOutlined, {}), valueStyle: { color: '#722ed1' } }), _jsx(Progress, { percent: Math.round((twoFactorUsers / users.length) * 100), size: "small", showInfo: false, strokeColor: "#722ed1" })] }) }), _jsx(Col, { span: 24, children: _jsx(Card, { title: "Recent Users", extra: _jsx(Button, { icon: _jsx(ExportOutlined, {}), onClick: handleExportUsers, children: "Export Users" }), children: _jsx(Table, { columns: userColumns, dataSource: recentUsers, rowKey: "id", pagination: false, size: "small" }) }) }), _jsx(Col, { span: 24, children: _jsx(Card, { title: "System Alerts", children: _jsxs(Space, { direction: "vertical", style: { width: '100%' }, children: [unverifiedUsers > 0 && (_jsx(Alert, { message: `${unverifiedUsers} users have unverified email addresses`, type: "warning", icon: _jsx(WarningOutlined, {}), action: _jsx(Button, { size: "small", type: "text", children: "View Details" }) })), lockedUsers > 0 && (_jsx(Alert, { message: `${lockedUsers} user accounts are currently locked`, type: "error", icon: _jsx(LockOutlined, {}), action: _jsx(Button, { size: "small", type: "text", children: "Manage Locked Users" }) })), twoFactorUsers < users.length * 0.5 && (_jsx(Alert, { message: "Less than 50% of users have two-factor authentication enabled", type: "info", icon: _jsx(SafetyOutlined, {}), action: _jsx(Button, { size: "small", type: "text", children: "Promote 2FA" }) }))] }) }) })] }) }, "overview"), _jsx(TabPane, { tab: "Security Settings", children: _jsxs(Row, { gutter: [16, 16], children: [_jsx(Col, { xs: 24, lg: 12, children: _jsx(Card, { title: "Password Policy", children: _jsxs(Form, { form: settingsForm, layout: "vertical", initialValues: ADMIN_SETTINGS.passwordPolicy, onFinish: handleSaveSettings, children: [_jsx(Form.Item, { name: "minLength", label: "Minimum Length", children: _jsx(InputNumber, { min: 6, max: 32 }) }), _jsx(Form.Item, { name: "requireUppercase", label: "Require Uppercase", valuePropName: "checked", children: _jsx(Switch, {}) }), _jsx(Form.Item, { name: "requireLowercase", label: "Require Lowercase", valuePropName: "checked", children: _jsx(Switch, {}) }), _jsx(Form.Item, { name: "requireNumbers", label: "Require Numbers", valuePropName: "checked", children: _jsx(Switch, {}) }), _jsx(Form.Item, { name: "requireSpecialChars", label: "Require Special Characters", valuePropName: "checked", children: _jsx(Switch, {}) }), _jsx(Form.Item, { name: "maxAge", label: "Password Max Age (days)", children: _jsx(InputNumber, { min: 0, max: 365 }) }), _jsx(Form.Item, { children: _jsx(Button, { type: "primary", htmlType: "submit", children: "Save Password Policy" }) })] }) }) }), _jsx(Col, { xs: 24, lg: 12, children: _jsx(Card, { title: "Account Lockout Policy", children: _jsxs(Form, { layout: "vertical", initialValues: ADMIN_SETTINGS.lockoutPolicy, onFinish: handleSaveSettings, children: [_jsx(Form.Item, { name: "enabled", label: "Enable Account Lockout", valuePropName: "checked", children: _jsx(Switch, {}) }), _jsx(Form.Item, { name: "maxAttempts", label: "Max Failed Attempts", children: _jsx(InputNumber, { min: 1, max: 20 }) }), _jsx(Form.Item, { name: "lockoutDuration", label: "Lockout Duration (minutes)", children: _jsx(InputNumber, { min: 1, max: 1440 }) }), _jsx(Form.Item, { name: "resetTime", label: "Reset Counter After (minutes)", children: _jsx(InputNumber, { min: 1, max: 60 }) }), _jsx(Form.Item, { children: _jsx(Button, { type: "primary", htmlType: "submit", children: "Save Lockout Policy" }) })] }) }) })] }) }, "security"), _jsx(TabPane, { tab: "Roles Management", children: _jsx(Row, { gutter: [16, 16], children: _jsx(Col, { span: 24, children: _jsx(Card, { title: `System Roles (${roles.length})`, extra: _jsx(Button, { icon: _jsx(ExportOutlined, {}), onClick: handleExportRoles, children: "Export Roles" }), children: _jsx(Space, { wrap: true, children: roles.map(role => (_jsxs(Tag, { color: role.isStatic ? 'orange' : role.isDefault ? 'blue' : 'green', style: { marginBottom: 8 }, children: [role.displayName || role.name, role.isStatic && ' (System)', role.isDefault && ' (Default)'] }, role.id))) }) }) }) }) }, "roles"), _jsx(TabPane, { tab: "System Actions", children: _jsx(Row, { gutter: [16, 16], children: _jsx(Col, { span: 24, children: _jsx(Card, { title: "System Maintenance", children: _jsxs(Space, { direction: "vertical", style: { width: '100%' }, children: [_jsx(Alert, { message: "System Actions", description: "These actions affect all users and should be used with caution.", type: "warning", showIcon: true }), _jsxs(Space, { wrap: true, children: [_jsx(Button, { icon: _jsx(ReloadOutlined, {}), onClick: () => message.info('Cache refresh initiated'), children: "Refresh User Cache" }), _jsx(Button, { icon: _jsx(LockOutlined, {}), onClick: () => message.info('Bulk unlock initiated'), children: "Unlock All Users" }), _jsx(Button, { icon: _jsx(WarningOutlined, {}), danger: true, onClick: () => message.warning('This would force all users to re-login'), children: "Force Re-authentication" })] })] }) }) }) }) }, "actions")] })] }));
};
//# sourceMappingURL=IdentityAdmin.js.map