Add role selector to invite form and user management
This commit is contained in:
4
dist/index.html
vendored
4
dist/index.html
vendored
@@ -6,8 +6,8 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta name="description" content="Todo App - Task management made simple" />
|
||||
<title>Todo App</title>
|
||||
<script type="module" crossorigin src="/assets/index-Ce_4Zv7a.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-Cuyvk5mt.css">
|
||||
<script type="module" crossorigin src="/assets/index-CyVj0RaD.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-D509-xKq.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
|
||||
@@ -250,7 +250,7 @@ class ApiClient {
|
||||
await this.fetch(`/admin/users/${id}`, { method: 'DELETE' });
|
||||
}
|
||||
|
||||
async createInvite(data: { email: string; name: string }): Promise<Invite & { setupUrl: string }> {
|
||||
async createInvite(data: { email: string; name: string; role?: 'admin' | 'user' }): Promise<Invite & { setupUrl: string }> {
|
||||
return this.fetch('/admin/invites', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(data),
|
||||
|
||||
@@ -16,6 +16,7 @@ export function AdminPage() {
|
||||
const [showInviteForm, setShowInviteForm] = useState(false);
|
||||
const [inviteEmail, setInviteEmail] = useState('');
|
||||
const [inviteName, setInviteName] = useState('');
|
||||
const [inviteRole, setInviteRole] = useState<'admin' | 'user'>('user');
|
||||
const [inviteError, setInviteError] = useState('');
|
||||
const [inviteUrl, setInviteUrl] = useState('');
|
||||
const [copied, setCopied] = useState(false);
|
||||
@@ -45,7 +46,7 @@ export function AdminPage() {
|
||||
setInviteError('');
|
||||
|
||||
try {
|
||||
const result = await api.createInvite({ email: inviteEmail, name: inviteName });
|
||||
const result = await api.createInvite({ email: inviteEmail, name: inviteName, role: inviteRole });
|
||||
setInviteUrl(result.setupUrl);
|
||||
setInvites([result, ...invites]);
|
||||
// Keep form open to show the URL
|
||||
@@ -60,6 +61,15 @@ export function AdminPage() {
|
||||
setTimeout(() => setCopied(false), 2000);
|
||||
};
|
||||
|
||||
const handleChangeRole = async (userId: string, role: 'admin' | 'user' | 'service') => {
|
||||
try {
|
||||
await api.updateUserRole(userId, role);
|
||||
setUsers(users.map(u => u.id === userId ? { ...u, role } : u));
|
||||
} catch (error) {
|
||||
console.error('Failed to update role:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleDeleteUser = async (userId: string) => {
|
||||
if (!confirm('Are you sure you want to delete this user?')) return;
|
||||
|
||||
@@ -84,6 +94,7 @@ export function AdminPage() {
|
||||
setShowInviteForm(false);
|
||||
setInviteEmail('');
|
||||
setInviteName('');
|
||||
setInviteRole('user');
|
||||
setInviteError('');
|
||||
setInviteUrl('');
|
||||
};
|
||||
@@ -149,6 +160,7 @@ export function AdminPage() {
|
||||
<td className="px-4 py-3 text-sm font-medium text-gray-900">{user.name}</td>
|
||||
<td className="px-4 py-3 text-sm text-gray-600">{user.email}</td>
|
||||
<td className="px-4 py-3">
|
||||
{user.id === currentUser?.id || user.role === 'service' ? (
|
||||
<span className={cn(
|
||||
'px-2 py-1 text-xs rounded-full',
|
||||
user.role === 'admin' ? 'bg-purple-100 text-purple-700' :
|
||||
@@ -157,6 +169,20 @@ export function AdminPage() {
|
||||
)}>
|
||||
{user.role}
|
||||
</span>
|
||||
) : (
|
||||
<select
|
||||
value={user.role}
|
||||
onChange={(e) => handleChangeRole(user.id, e.target.value as 'admin' | 'user')}
|
||||
className={cn(
|
||||
'px-2 py-1 text-xs rounded-full border-none cursor-pointer appearance-none',
|
||||
user.role === 'admin' ? 'bg-purple-100 text-purple-700' :
|
||||
'bg-gray-100 text-gray-700'
|
||||
)}
|
||||
>
|
||||
<option value="user">user</option>
|
||||
<option value="admin">admin</option>
|
||||
</select>
|
||||
)}
|
||||
</td>
|
||||
<td className="px-4 py-3 text-sm text-gray-500">
|
||||
{new Date(user.createdAt).toLocaleDateString()}
|
||||
@@ -221,7 +247,7 @@ export function AdminPage() {
|
||||
{inviteError && (
|
||||
<p className="text-sm text-red-500">{inviteError}</p>
|
||||
)}
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div className="grid grid-cols-3 gap-4">
|
||||
<div>
|
||||
<label className="block text-sm font-medium text-gray-700 mb-1">Name</label>
|
||||
<input
|
||||
@@ -244,6 +270,17 @@ export function AdminPage() {
|
||||
placeholder="john@example.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 as 'admin' | 'user')}
|
||||
className="input"
|
||||
>
|
||||
<option value="user">User</option>
|
||||
<option value="admin">Admin</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<button type="submit" className="btn btn-primary">
|
||||
|
||||
Reference in New Issue
Block a user