2026-07-09 11:48:54 +02:00
|
|
|
import { useEffect, useState } from 'react'
|
2026-07-05 06:41:23 +02:00
|
|
|
import { INITIATIVE_STATUSES, PRIORITIES } from '../constants/status.js'
|
|
|
|
|
import { INITIATIVE_STATUS_LABELS, PRIORITY_LABELS } from '../constants/status.js'
|
2026-07-09 11:48:54 +02:00
|
|
|
import { INITIATIVE_ARCHETYPE_LABELS } from '../constants/initiativeArchetypes.js'
|
|
|
|
|
import { listEntityArchetypes } from '../api/entityArchetypes.js'
|
2026-07-05 06:41:23 +02:00
|
|
|
|
|
|
|
|
export function InitiativeForm({
|
|
|
|
|
initial = {},
|
|
|
|
|
onSubmit,
|
|
|
|
|
onCancel,
|
|
|
|
|
busy = false,
|
|
|
|
|
submitLabel = 'Speichern',
|
|
|
|
|
}) {
|
2026-07-09 11:48:54 +02:00
|
|
|
const [archetypes, setArchetypes] = useState(null)
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
let cancelled = false
|
|
|
|
|
listEntityArchetypes('initiative')
|
|
|
|
|
.then((items) => {
|
|
|
|
|
if (!cancelled) setArchetypes(items)
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {
|
|
|
|
|
if (!cancelled) {
|
|
|
|
|
setArchetypes(
|
|
|
|
|
Object.entries(INITIATIVE_ARCHETYPE_LABELS).map(([key, label]) => ({
|
|
|
|
|
key,
|
|
|
|
|
label,
|
|
|
|
|
})),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
return () => {
|
|
|
|
|
cancelled = true
|
|
|
|
|
}
|
|
|
|
|
}, [])
|
|
|
|
|
|
2026-07-05 06:41:23 +02:00
|
|
|
async function handleSubmit(e) {
|
|
|
|
|
e.preventDefault()
|
|
|
|
|
const form = e.target
|
|
|
|
|
await onSubmit({
|
|
|
|
|
title: form.title.value.trim(),
|
2026-07-09 11:48:54 +02:00
|
|
|
archetype_key: form.archetype_key.value,
|
2026-07-05 06:41:23 +02:00
|
|
|
goal: form.goal.value,
|
2026-07-09 11:48:54 +02:00
|
|
|
vision: form.vision.value,
|
|
|
|
|
target_state_summary: form.target_state_summary.value,
|
2026-07-05 06:41:23 +02:00
|
|
|
status: form.status.value,
|
|
|
|
|
priority: form.priority.value,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<form className="form workspace-form" onSubmit={handleSubmit}>
|
|
|
|
|
<label>
|
|
|
|
|
Titel
|
|
|
|
|
<input name="title" defaultValue={initial.title || ''} required maxLength={255} />
|
|
|
|
|
</label>
|
|
|
|
|
<label>
|
2026-07-09 11:48:54 +02:00
|
|
|
Archetyp
|
|
|
|
|
<select
|
|
|
|
|
name="archetype_key"
|
|
|
|
|
defaultValue={initial.archetype_key || 'initiative.generic'}
|
|
|
|
|
disabled={!archetypes}
|
|
|
|
|
>
|
|
|
|
|
{(archetypes || []).map((item) => (
|
|
|
|
|
<option key={item.key} value={item.key}>
|
|
|
|
|
{item.label}
|
2026-07-05 06:41:23 +02:00
|
|
|
</option>
|
|
|
|
|
))}
|
|
|
|
|
</select>
|
|
|
|
|
</label>
|
|
|
|
|
<label>
|
2026-07-09 11:48:54 +02:00
|
|
|
Kurzbeschreibung (Ziel)
|
|
|
|
|
<textarea name="goal" rows={2} defaultValue={initial.goal || ''} />
|
|
|
|
|
</label>
|
|
|
|
|
<label>
|
|
|
|
|
Vision
|
|
|
|
|
<textarea name="vision" rows={4} defaultValue={initial.vision || ''} />
|
2026-07-05 06:41:23 +02:00
|
|
|
</label>
|
2026-07-09 11:48:54 +02:00
|
|
|
<label>
|
|
|
|
|
Zielzustand (Kurzfassung)
|
|
|
|
|
<textarea
|
|
|
|
|
name="target_state_summary"
|
|
|
|
|
rows={2}
|
|
|
|
|
defaultValue={initial.target_state_summary || ''}
|
|
|
|
|
/>
|
|
|
|
|
</label>
|
|
|
|
|
<div className="form-row form-row--2">
|
|
|
|
|
<label>
|
|
|
|
|
Status
|
|
|
|
|
<select name="status" defaultValue={initial.status || 'active'}>
|
|
|
|
|
{INITIATIVE_STATUSES.map((s) => (
|
|
|
|
|
<option key={s} value={s}>
|
|
|
|
|
{INITIATIVE_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>
|
|
|
|
|
</div>
|
2026-07-05 06:41:23 +02:00
|
|
|
<div className="form-actions">
|
2026-07-09 11:48:54 +02:00
|
|
|
<button type="submit" className="btn btn-primary" disabled={busy || !archetypes}>
|
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>
|
|
|
|
|
)
|
|
|
|
|
}
|