@dbs-portal/module-identity
Version:
Identity management module for user and role management
50 lines • 3.03 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
/**
* Role Edit Page
*/
import React from 'react';
import { Button, Space, Typography, message, Spin, Alert } from 'antd';
import { ArrowLeftOutlined } from '@ant-design/icons';
import { RoleEdit } from '../components/RoleEdit';
import { useRole, useUpdateRole } from '../hooks';
const { Title } = Typography;
export const RoleEditPage = ({ roleId, onNavigate, onBack, onRoleUpdated, className }) => {
const { data: role, isLoading, error } = useRole(roleId);
const updateRoleMutation = useUpdateRole();
const handleBack = () => {
if (onBack)
onBack();
else if (onNavigate)
onNavigate(`/identity/roles/${roleId}`);
};
const handleSubmit = async (data) => {
try {
await updateRoleMutation.mutateAsync({
id: roleId,
displayName: data.displayName,
description: data.description,
permissions: data.permissions || []
});
message.success('Role updated successfully!');
if (onRoleUpdated)
onRoleUpdated(roleId);
else if (onNavigate)
onNavigate(`/identity/roles/${roleId}`);
}
catch (error) {
console.error('Failed to update role:', error);
message.error('Failed to update role. Please try again.');
}
};
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 Role Details" }) }), _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 Role Details" }) }), _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 Role Details" }), _jsx(Title, { level: 2, style: { margin: 0 }, children: "Edit Role" })] }) }), _jsx(RoleEdit, { role: role, onSubmit: handleSubmit, loading: updateRoleMutation.isPending, error: updateRoleMutation.error ? updateRoleMutation.error.message : undefined })] }));
};
//# sourceMappingURL=RoleEditPage.js.map