forked from jobbykingz/Verinode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserManagement.tsx
More file actions
129 lines (120 loc) · 6.24 KB
/
UserManagement.tsx
File metadata and controls
129 lines (120 loc) · 6.24 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import React, { useState, useEffect } from 'react';
interface User {
id: string;
name: string;
email: string;
role: string;
}
const UserManagement: React.FC = () => {
const [users, setUsers] = useState<User[]>([]);
const [isInviting, setIsInviting] = useState(false);
const [inviteEmail, setInviteEmail] = useState('');
const [inviteRole, setInviteRole] = useState('viewer');
// Mock data loading
useEffect(() => {
setUsers([
{ id: '1', name: 'Alice Johnson', email: 'alice@example.com', role: 'admin' },
{ id: '2', name: 'Bob Smith', email: 'bob@example.com', role: 'editor' },
]);
}, []);
const handleRoleChange = (userId: string, newRole: string) => {
setUsers(users.map(u => u.id === userId ? { ...u, role: newRole } : u));
};
const handleInvite = (e: React.FormEvent) => {
e.preventDefault();
// Mock invite logic
const newUser: User = {
id: Math.random().toString(36).substr(2, 9),
name: inviteEmail.split('@')[0], // Mock name from email
email: inviteEmail,
role: inviteRole
};
setUsers([...users, newUser]);
setIsInviting(false);
setInviteEmail('');
setInviteRole('viewer');
};
return (
<div className="bg-white shadow rounded-lg p-6">
<div className="flex justify-between items-center mb-4">
<h2 className="text-xl font-semibold text-gray-800">Team Members</h2>
<button
onClick={() => setIsInviting(!isInviting)}
className="bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700"
>
{isInviting ? 'Cancel' : 'Invite Member'}
</button>
</div>
{isInviting && (
<form onSubmit={handleInvite} className="mb-6 bg-gray-50 p-4 rounded-lg border border-gray-200">
<div className="grid grid-cols-1 md:grid-cols-3 gap-4 items-end">
<div>
<label className="block text-sm font-medium text-gray-700 mb-1">Email Address</label>
<input
type="email"
required
value={inviteEmail}
onChange={(e) => setInviteEmail(e.target.value)}
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500"
placeholder="colleague@company.com"
/>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 mb-1">Role</label>
<select
value={inviteRole}
onChange={(e) => setInviteRole(e.target.value)}
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500"
>
<option value="admin">Admin</option>
<option value="editor">Editor</option>
<option value="viewer">Viewer</option>
</select>
</div>
<button
type="submit"
className="bg-indigo-600 text-white px-4 py-2 rounded hover:bg-indigo-700"
>
Send Invitation
</button>
</div>
</form>
)}
<div className="overflow-x-auto">
<table className="min-w-full divide-y divide-gray-200">
<thead className="bg-gray-50">
<tr>
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Name</th>
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Email</th>
<th className="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Role</th>
<th className="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
</tr>
</thead>
<tbody className="bg-white divide-y divide-gray-200">
{users.map((user) => (
<tr key={user.id}>
<td className="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">{user.name}</td>
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{user.email}</td>
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
<select
value={user.role}
onChange={(e) => handleRoleChange(user.id, e.target.value)}
className="mt-1 block w-full py-2 px-3 border border-gray-300 bg-white rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm"
>
<option value="admin">Admin</option>
<option value="editor">Editor</option>
<option value="viewer">Viewer</option>
</select>
</td>
<td className="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
<button className="text-red-600 hover:text-red-900">Remove</button>
</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
);
};
export default UserManagement;