Add user lock/unlock functionality and remove partner management
Some checks failed
Staging Build / build (push) Failing after 26s

This commit is contained in:
DanielS
2026-06-24 23:29:16 +02:00
parent 864bb3a0c1
commit 520599986c
5 changed files with 99 additions and 253 deletions

View File

@@ -11,7 +11,7 @@ import {
TableRow,
} from '@/components/ui/table'
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
import { Key, Trash2, Mail, Loader2, Building2 } from 'lucide-react'
import { Key, Trash2, Mail, Loader2, Building2, Ban, Unlock } from 'lucide-react'
import { Button } from '@/components/ui/button'
import { deleteUser, resetPassword, updateUserRole } from '@/lib/actions/users'
import { assignCompanyToUser } from '@/lib/actions/companies'
@@ -61,6 +61,19 @@ export function UserList({ initialUsers, companies }: UserListProps) {
}
}
const handleToggleLock = async (id: string, currentRole: Role) => {
const newRole = currentRole === 'gesperrt' ? 'partner' : 'gesperrt'
setLoadingId(id + '-lock')
try {
await updateUserRole(id, newRole)
router.refresh()
} catch (e) {
console.error('Fehler beim Sperren/Entsperren:', e)
} finally {
setLoadingId(null)
}
}
const handleCompanyChange = async (userId: string, companyId: string) => {
setLoadingId(userId + '-company')
try {
@@ -160,25 +173,35 @@ export function UserList({ initialUsers, companies }: UserListProps) {
</TableCell>
<TableCell className="text-right">
<div className="flex justify-end gap-2">
<Button
variant="ghost"
size="icon"
className="h-8 w-8 text-yellow-500 hover:text-yellow-400 hover:bg-yellow-500/10"
title="Passwort zurücksetzen"
onClick={() => handleResetPassword(user.email)}
>
<Key className="h-4 w-4" />
</Button>
<Button
variant="ghost"
size="icon"
className="h-8 w-8 text-destructive hover:text-destructive hover:bg-destructive/10"
title="Löschen"
onClick={() => handleDelete(user.id)}
disabled={isLoadingDelete}
>
{isLoadingDelete ? <Loader2 className="h-4 w-4 animate-spin" /> : <Trash2 className="h-4 w-4" />}
</Button>
<Button
variant="ghost"
size="icon"
className="h-8 w-8 text-yellow-500 hover:text-yellow-400 hover:bg-yellow-500/10"
title="Passwort zurücksetzen"
onClick={() => handleResetPassword(user.email)}
>
<Key className="h-4 w-4" />
</Button>
<Button
variant="ghost"
size="icon"
className={role === 'gesperrt' ? 'h-8 w-8 text-green-500 hover:text-green-400 hover:bg-green-500/10' : 'h-8 w-8 text-red-500 hover:text-red-400 hover:bg-red-500/10'}
title={role === 'gesperrt' ? 'Entsperren' : 'Sperren'}
onClick={() => handleToggleLock(user.id, role)}
disabled={loadingId === user.id + '-lock'}
>
{loadingId === user.id + '-lock' ? <Loader2 className="h-4 w-4 animate-spin" /> : role === 'gesperrt' ? <Unlock className="h-4 w-4" /> : <Ban className="h-4 w-4" />}
</Button>
<Button
variant="ghost"
size="icon"
className="h-8 w-8 text-destructive hover:text-destructive hover:bg-destructive/10"
title="Löschen"
onClick={() => handleDelete(user.id)}
disabled={isLoadingDelete}
>
{isLoadingDelete ? <Loader2 className="h-4 w-4 animate-spin" /> : <Trash2 className="h-4 w-4" />}
</Button>
</div>
</TableCell>
</TableRow>