UNPKG

@dbs-portal/module-identity

Version:

Identity management module for user and role management

55 lines 2.49 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; /** * User Create Page * * Complete page component for creating new users with form handling, * validation, 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 } from 'antd'; import { ArrowLeftOutlined } from '@ant-design/icons'; // Import from same module import { UserCreate } from '../components/UserCreate'; import { useCreateUser } from '../hooks'; const { Title } = Typography; export const UserCreatePage = ({ onNavigate, onBack, onUserCreated, className }) => { const createUserMutation = useCreateUser(); const handleBack = () => { if (onBack) { onBack(); } else if (onNavigate) { onNavigate('/identity/users'); } }; const handleSubmit = async (data) => { try { const newUser = await createUserMutation.mutateAsync({ userName: data.userName, email: data.email, password: data.password, firstName: data.firstName, lastName: data.lastName, phoneNumber: data.phoneNumber, isActive: data.isActive ?? true, roleNames: data.roleNames, sendActivationEmail: data.sendActivationEmail ?? true }); message.success('User created successfully!'); // Handle post-creation navigation if (onUserCreated) { onUserCreated(newUser.id); } else if (onNavigate) { onNavigate(`/identity/users/${newUser.id}`); } } catch (error) { console.error('Failed to create user:', error); message.error('Failed to create user. Please try again.'); } }; 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 Users" }), _jsx(Title, { level: 2, style: { margin: 0 }, children: "Create New User" })] }) }), _jsx(UserCreate, { onSubmit: handleSubmit, loading: createUserMutation.isPending, error: createUserMutation.error ? createUserMutation.error.message : undefined })] })); }; //# sourceMappingURL=UserCreatePage.js.map