'use client' import React, { useState } from 'react' import { ModalBase } from './ModalBase' import { apiFetch } from '../_api' export function AssignRoleModal({ onClose, onAssigned }: { onClose: () => void; onAssigned: () => void }) { const [form, setForm] = useState({ user_id: '', role_id: '', namespace_id: '', expires_at: '' }) const [saving, setSaving] = useState(false) const [error, setError] = useState(null) const handleSubmit = async () => { if (!form.user_id || !form.role_id) { setError('User-ID und Rolle sind Pflichtfelder'); return } setSaving(true) try { await apiFetch('user-roles', { method: 'POST', body: JSON.stringify({ user_id: form.user_id, role_id: form.role_id, namespace_id: form.namespace_id || null, expires_at: form.expires_at || null, }), }) onAssigned() } catch (e) { setError(e instanceof Error ? e.message : 'Fehler') } finally { setSaving(false) } } return ( {error &&
{error}
}
setForm(f => ({ ...f, user_id: e.target.value }))} placeholder="UUID" className="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm font-mono" />
setForm(f => ({ ...f, role_id: e.target.value }))} placeholder="UUID" className="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm font-mono" />
setForm(f => ({ ...f, namespace_id: e.target.value }))} placeholder="Leer = Global" className="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm font-mono" />
setForm(f => ({ ...f, expires_at: e.target.value }))} className="w-full border border-gray-300 rounded-lg px-3 py-2 text-sm" />
) }