Kairo-Jinkendo/frontend/src/components/BacklogSection.jsx

116 lines
3.4 KiB
React
Raw Normal View History

import { useState } from 'react'
import {
BACKLOG_STATUSES,
BACKLOG_STATUS_LABELS,
} from '../constants/status.js'
import { StatusBadge } from './StatusBadge.jsx'
import { PriorityBadge } from './PriorityBadge.jsx'
import { EmptyState } from './EmptyState.jsx'
export function BacklogSection({
items,
canManage,
onCreate,
onUpdateStatus,
onConvert,
onDelete,
busy,
}) {
const [title, setTitle] = useState('')
const [showForm, setShowForm] = useState(false)
async function handleSubmit(e) {
e.preventDefault()
if (!title.trim()) return
await onCreate({ title: title.trim() })
setTitle('')
setShowForm(false)
}
return (
<section className="card">
<div className="section-header">
<h2>Backlog</h2>
{canManage && (
<button
type="button"
className="btn btn-primary btn-block-mobile"
onClick={() => setShowForm((v) => !v)}
>
{showForm ? 'Abbrechen' : 'Backlog-Item'}
</button>
)}
</div>
{showForm && canManage && (
<form className="inline-form-block" onSubmit={handleSubmit}>
<label>
Titel
<input
value={title}
onChange={(e) => setTitle(e.target.value)}
maxLength={255}
required
/>
</label>
<button type="submit" className="btn btn-primary" disabled={busy}>
Anlegen
</button>
</form>
)}
{items.length === 0 && <EmptyState message="Backlog ist leer." />}
<ul className="item-list">
{items.map((item) => (
<li key={item.id} className="list-item card-list-item">
<div className="list-item-main">
<strong>{item.title}</strong>
{item.description && (
<p className="list-item-desc">{item.description}</p>
)}
</div>
<div className="list-item-meta action-controls">
<StatusBadge kind="backlog" status={item.status} />
<PriorityBadge priority={item.priority} />
{canManage && item.status !== 'converted' && (
<>
<select
className="inline-select"
value={item.status}
onChange={(e) => onUpdateStatus(item.id, e.target.value)}
aria-label="Backlog-Status"
>
{BACKLOG_STATUSES.filter((s) => s !== 'converted').map((s) => (
<option key={s} value={s}>
{BACKLOG_STATUS_LABELS[s]}
</option>
))}
</select>
{item.status === 'accepted' && (
<button
type="button"
className="btn btn-primary"
onClick={() => onConvert(item.id)}
disabled={busy}
>
In Maßnahme umwandeln
</button>
)}
<button
type="button"
className="btn btn-secondary"
onClick={() => onDelete(item.id)}
>
Löschen
</button>
</>
)}
</div>
</li>
))}
</ul>
</section>
)
}