forked from DistinctCodes/AssetsUp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserForm.tsx
More file actions
76 lines (68 loc) · 3.96 KB
/
UserForm.tsx
File metadata and controls
76 lines (68 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import React from 'react';
import { useForm } from 'react-hook-form';
import { Role, User } from '../../../backend/src/types/admin'
interface UserFormProps {
initialData?: Partial<User>;
roles: Role[];
onSubmit: (data: Partial<User>) => void;
onCancel: () => void;
}
export const UserForm: React.FC<UserFormProps> = ({ initialData, roles, onSubmit, onCancel }) => {
const { register, handleSubmit, formState: { errors } } = useForm({ defaultValues: initialData });
return (
<div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4 z-50">
<form onSubmit={handleSubmit(onSubmit)} className="bg-white rounded-lg shadow-xl w-full max-w-md p-6">
<h3 className="text-lg font-bold mb-4">{initialData?.id ? 'Edit User' : 'Invite User'}</h3>
<div className="space-y-4">
<div>
<label className="block text-sm font-medium text-gray-700">Full Name</label>
<input
{...register('name', { required: 'Name is required' })}
className="mt-1 block w-full rounded-md border border-gray-300 px-3 py-2 shadow-sm focus:border-blue-500 focus:outline-none"
/>
{errors.name && <p className="text-red-500 text-xs mt-1">{errors.name.message as string}</p>}
</div>
<div>
<label className="block text-sm font-medium text-gray-700">Email Address</label>
<input
type="email"
{...register('email', { required: 'Email is required' })}
className="mt-1 block w-full rounded-md border border-gray-300 px-3 py-2 shadow-sm focus:border-blue-500 focus:outline-none"
/>
{errors.email && <p className="text-red-500 text-xs mt-1">{errors.email.message as string}</p>}
</div>
<div>
<label className="block text-sm font-medium text-gray-700">Role</label>
<select
{...register('role', { required: 'Role is required' })}
className="mt-1 block w-full rounded-md border border-gray-300 px-3 py-2 shadow-sm focus:border-blue-500 focus:outline-none"
>
<option value="">Select a role...</option>
{roles.map(r => <option key={r.id} value={r.name}>{r.name}</option>)}
</select>
</div>
<div>
<label className="block text-sm font-medium text-gray-700">Department</label>
<select
{...register('department')}
className="mt-1 block w-full rounded-md border border-gray-300 px-3 py-2 shadow-sm focus:border-blue-500 focus:outline-none"
>
<option value="Engineering">Engineering</option>
<option value="Marketing">Marketing</option>
<option value="Sales">Sales</option>
<option value="HR">HR</option>
</select>
</div>
</div>
<div className="mt-6 flex justify-end gap-3">
<button type="button" onClick={onCancel} className="px-4 py-2 text-sm font-medium text-gray-700 bg-gray-100 rounded-md hover:bg-gray-200">
Cancel
</button>
<button type="submit" className="px-4 py-2 text-sm font-medium text-white bg-blue-600 rounded-md hover:bg-blue-700">
{initialData?.id ? 'Save Changes' : 'Send Invitation'}
</button>
</div>
</form>
</div>
);
};