2026-07-05 06:41:23 +02:00
|
|
|
import { ACTION_STATUSES, PRIORITIES } from '../constants/status.js'
|
|
|
|
|
import { ACTION_STATUS_LABELS, PRIORITY_LABELS } from '../constants/status.js'
|
|
|
|
|
import { ActorSelect } from './ActorSelect.jsx'
|
|
|
|
|
|
2026-07-05 15:27:03 +02:00
|
|
|
function isoToLocalInput(iso) {
|
|
|
|
|
if (!iso) return ''
|
|
|
|
|
const d = new Date(iso)
|
|
|
|
|
const pad = (n) => String(n).padStart(2, '0')
|
|
|
|
|
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}T${pad(d.getHours())}:${pad(d.getMinutes())}`
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-05 06:41:23 +02:00
|
|
|
export function ActionForm({
|
|
|
|
|
initial = {},
|
2026-07-06 08:19:05 +02:00
|
|
|
projects = [],
|
2026-07-05 06:41:23 +02:00
|
|
|
actors = [],
|
2026-07-05 07:25:01 +02:00
|
|
|
actorsLoading = false,
|
|
|
|
|
actorsError = null,
|
|
|
|
|
actorsUsedFallback = false,
|
|
|
|
|
onReloadActors,
|
2026-07-05 06:41:23 +02:00
|
|
|
onSubmit,
|
|
|
|
|
onCancel,
|
|
|
|
|
busy = false,
|
|
|
|
|
submitLabel = 'Speichern',
|
|
|
|
|
}) {
|
|
|
|
|
async function handleSubmit(e) {
|
|
|
|
|
e.preventDefault()
|
|
|
|
|
const form = e.target
|
|
|
|
|
const selected = actors.filter((a) => form[`actor_${a.id}`]?.checked).map((a) => a.id)
|
|
|
|
|
await onSubmit({
|
|
|
|
|
title: form.title.value.trim(),
|
|
|
|
|
description: form.description.value,
|
|
|
|
|
status: form.status.value,
|
|
|
|
|
priority: form.priority.value,
|
2026-07-05 15:27:03 +02:00
|
|
|
due_at: form.due_at.value ? new Date(form.due_at.value).toISOString() : null,
|
2026-07-06 08:19:05 +02:00
|
|
|
project_id: form.project_id?.value || undefined,
|
2026-07-05 06:41:23 +02:00
|
|
|
assigned_actor_ids: selected,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const defaultActors = initial.assigned_actor_ids || []
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<form className="form workspace-form" onSubmit={handleSubmit}>
|
|
|
|
|
<label>
|
|
|
|
|
Titel
|
|
|
|
|
<input name="title" defaultValue={initial.title || ''} required maxLength={255} />
|
|
|
|
|
</label>
|
|
|
|
|
<label>
|
|
|
|
|
Beschreibung
|
|
|
|
|
<textarea name="description" rows={2} defaultValue={initial.description || ''} />
|
|
|
|
|
</label>
|
|
|
|
|
<label>
|
|
|
|
|
Status
|
|
|
|
|
<select name="status" defaultValue={initial.status || 'open'}>
|
|
|
|
|
{ACTION_STATUSES.map((s) => (
|
|
|
|
|
<option key={s} value={s}>
|
|
|
|
|
{ACTION_STATUS_LABELS[s]}
|
|
|
|
|
</option>
|
|
|
|
|
))}
|
|
|
|
|
</select>
|
|
|
|
|
</label>
|
|
|
|
|
<label>
|
|
|
|
|
Priorität
|
|
|
|
|
<select name="priority" defaultValue={initial.priority || 'normal'}>
|
|
|
|
|
{PRIORITIES.map((p) => (
|
|
|
|
|
<option key={p} value={p}>
|
|
|
|
|
{PRIORITY_LABELS[p]}
|
|
|
|
|
</option>
|
|
|
|
|
))}
|
|
|
|
|
</select>
|
|
|
|
|
</label>
|
2026-07-05 15:27:03 +02:00
|
|
|
<label>
|
|
|
|
|
Fällig am (optional)
|
|
|
|
|
<input
|
|
|
|
|
name="due_at"
|
|
|
|
|
type="datetime-local"
|
|
|
|
|
defaultValue={isoToLocalInput(initial.due_at)}
|
|
|
|
|
/>
|
|
|
|
|
</label>
|
2026-07-06 08:19:05 +02:00
|
|
|
{projects.length > 0 && (
|
|
|
|
|
<label>
|
|
|
|
|
Projekt (optional)
|
|
|
|
|
<select name="project_id" defaultValue={initial.project_id || ''}>
|
|
|
|
|
<option value="">— keins —</option>
|
|
|
|
|
{projects.map((p) => (
|
|
|
|
|
<option key={p.id} value={p.id}>
|
|
|
|
|
{p.title}
|
|
|
|
|
</option>
|
|
|
|
|
))}
|
|
|
|
|
</select>
|
|
|
|
|
</label>
|
|
|
|
|
)}
|
2026-07-05 07:25:01 +02:00
|
|
|
<ActorSelect
|
|
|
|
|
actors={actors}
|
|
|
|
|
defaultSelected={defaultActors}
|
|
|
|
|
loading={actorsLoading}
|
|
|
|
|
error={actorsError}
|
|
|
|
|
usedFallback={actorsUsedFallback}
|
|
|
|
|
onRetry={onReloadActors}
|
|
|
|
|
/>
|
2026-07-05 06:41:23 +02:00
|
|
|
<div className="form-actions">
|
2026-07-05 06:58:48 +02:00
|
|
|
<button type="submit" className="btn btn-primary" disabled={busy}>
|
2026-07-05 06:41:23 +02:00
|
|
|
{busy ? 'Speichern …' : submitLabel}
|
|
|
|
|
</button>
|
|
|
|
|
{onCancel && (
|
2026-07-05 06:58:48 +02:00
|
|
|
<button type="button" className="btn btn-secondary" onClick={onCancel} disabled={busy}>
|
2026-07-05 06:41:23 +02:00
|
|
|
Abbrechen
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
)
|
|
|
|
|
}
|