@dbs-portal/module-identity
Version:
Identity management module for user and role management
65 lines • 3.55 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
/**
* User Edit Page
*
* Complete page component for editing users with data fetching,
* form handling, and navigation. This is a self-contained page that can be
* directly used in any application that imports the identity module.
*/
import React from 'react';
import { Button, Space, Typography, message, Spin, Alert } from 'antd';
import { ArrowLeftOutlined } from '@ant-design/icons';
// Import from same module
import { UserEdit } from '../components/UserEdit';
import { useUser, useUpdateUser } from '../hooks';
const { Title } = Typography;
export const UserEditPage = ({ userId, onNavigate, onBack, onUserUpdated, className }) => {
// Hooks from identity module
const { data: user, isLoading, error } = useUser(userId);
const updateUserMutation = useUpdateUser();
const handleBack = () => {
if (onBack) {
onBack();
}
else if (onNavigate) {
onNavigate(`/identity/users/${userId}`);
}
};
const handleSubmit = async (data) => {
try {
await updateUserMutation.mutateAsync({
id: userId,
userName: data.userName,
email: data.email,
firstName: data.firstName,
lastName: data.lastName,
phoneNumber: data.phoneNumber,
isActive: data.isActive,
roleNames: data.roleNames
});
message.success('User updated successfully!');
// Handle post-update navigation
if (onUserUpdated) {
onUserUpdated(userId);
}
else if (onNavigate) {
onNavigate(`/identity/users/${userId}`);
}
}
catch (error) {
console.error('Failed to update user:', error);
message.error('Failed to update user. 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 user 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 User Details" }) }), _jsx(Alert, { message: "Error Loading User", description: `Failed to load user details: ${error.message}`, type: "error", showIcon: true })] }));
}
if (!user) {
return (_jsxs("div", { className: className, children: [_jsx("div", { style: { marginBottom: 24 }, children: _jsx(Button, { icon: _jsx(ArrowLeftOutlined, {}), onClick: handleBack, children: "Back to User Details" }) }), _jsx(Alert, { message: "User Not Found", description: "The requested user 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 User Details" }), _jsx(Title, { level: 2, style: { margin: 0 }, children: "Edit User" })] }) }), _jsx(UserEdit, { user: user, onSubmit: handleSubmit, loading: updateUserMutation.isPending, error: updateUserMutation.error ? updateUserMutation.error.message : undefined })] }));
};
//# sourceMappingURL=UserEditPage.js.map