feat: add role selection to user creation and UI updates
All checks were successful
Staging Build / build (push) Successful in 2m16s

This commit is contained in:
DanielS
2026-06-24 01:58:01 +02:00
parent 934879e5cf
commit e1f47ddcd0
3 changed files with 63 additions and 5 deletions

View File

@@ -29,7 +29,8 @@ import { Plus } from 'lucide-react'
const userSchema = z.object({
email: z.string().email('Ungültige E-Mail-Adresse'),
password: z.string().min(6, 'Passwort muss mindestens 6 Zeichen lang sein').optional(),
password: z.string().min(6, 'Passwort muss mindestens 6 Zeichen lang sein').optional().or(z.literal('')),
role: z.enum(['admin', 'partner']),
})
type UserFormValues = z.infer<typeof userSchema>
@@ -43,12 +44,19 @@ export function UserDialog() {
defaultValues: {
email: '',
password: '',
role: 'partner',
},
})
async function onSubmit(values: UserFormValues) {
try {
await createUser(values)
// If password is empty string, omit it
const payload = {
email: values.email,
role: values.role,
...(values.password ? { password: values.password } : {})
}
await createUser(payload)
setOpen(false)
form.reset()
router.refresh()
@@ -68,7 +76,7 @@ export function UserDialog() {
<DialogHeader>
<DialogTitle>Neuen Benutzer anlegen</DialogTitle>
<DialogDescription className="text-slate-300">
Geben Sie die E-Mail und optional ein Passwort für den neuen Benutzer ein.
Geben Sie die E-Mail, die Rolle und optional ein Passwort für den neuen Benutzer ein.
</DialogDescription>
</DialogHeader>
@@ -87,6 +95,25 @@ export function UserDialog() {
</FormItem>
)}
/>
<FormField
control={form.control}
name="role"
render={({ field }) => (
<FormItem>
<FormLabel className="text-white">Rolle</FormLabel>
<FormControl>
<select
className="flex h-10 w-full rounded-md border border-white/10 bg-slate-950/80 px-3 py-2 text-sm text-white focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2"
{...field}
>
<option value="partner">Partner</option>
<option value="admin">Admin</option>
</select>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="password"