115 lines
3.3 KiB
React
115 lines
3.3 KiB
React
|
|
import { useState } from 'react'
|
||
|
|
import { REVIEW_STATUSES, REVIEW_STATUS_LABELS } from '../constants/status.js'
|
||
|
|
import { StatusBadge } from './StatusBadge.jsx'
|
||
|
|
import { EmptyState } from './EmptyState.jsx'
|
||
|
|
|
||
|
|
function formatDueAt(iso) {
|
||
|
|
if (!iso) return null
|
||
|
|
try {
|
||
|
|
return new Date(iso).toLocaleString('de-DE')
|
||
|
|
} catch {
|
||
|
|
return iso
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
export function ReviewsSection({ items, canManage, onCreate, onUpdateStatus, onDelete, busy }) {
|
||
|
|
const [title, setTitle] = useState('')
|
||
|
|
const [dueAt, setDueAt] = useState('')
|
||
|
|
const [showForm, setShowForm] = useState(false)
|
||
|
|
|
||
|
|
async function handleSubmit(e) {
|
||
|
|
e.preventDefault()
|
||
|
|
if (!title.trim()) return
|
||
|
|
await onCreate({
|
||
|
|
title: title.trim(),
|
||
|
|
due_at: dueAt ? new Date(dueAt).toISOString() : null,
|
||
|
|
})
|
||
|
|
setTitle('')
|
||
|
|
setDueAt('')
|
||
|
|
setShowForm(false)
|
||
|
|
}
|
||
|
|
|
||
|
|
return (
|
||
|
|
<section className="card">
|
||
|
|
<div className="section-header">
|
||
|
|
<h2>Reviews</h2>
|
||
|
|
{canManage && (
|
||
|
|
<button
|
||
|
|
type="button"
|
||
|
|
className="btn btn-primary btn-block-mobile"
|
||
|
|
onClick={() => setShowForm((v) => !v)}
|
||
|
|
>
|
||
|
|
{showForm ? 'Abbrechen' : 'Review planen'}
|
||
|
|
</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>
|
||
|
|
<label>
|
||
|
|
Fällig am
|
||
|
|
<input
|
||
|
|
type="datetime-local"
|
||
|
|
value={dueAt}
|
||
|
|
onChange={(e) => setDueAt(e.target.value)}
|
||
|
|
/>
|
||
|
|
</label>
|
||
|
|
<button type="submit" className="btn btn-primary" disabled={busy}>
|
||
|
|
Anlegen
|
||
|
|
</button>
|
||
|
|
</form>
|
||
|
|
)}
|
||
|
|
|
||
|
|
{items.length === 0 && <EmptyState message="Keine Reviews." />}
|
||
|
|
|
||
|
|
<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.due_at && (
|
||
|
|
<p className="muted list-item-sub">Fällig: {formatDueAt(item.due_at)}</p>
|
||
|
|
)}
|
||
|
|
</div>
|
||
|
|
<div className="list-item-meta action-controls">
|
||
|
|
<StatusBadge kind="review" status={item.status} />
|
||
|
|
{canManage && (
|
||
|
|
<>
|
||
|
|
<select
|
||
|
|
className="inline-select"
|
||
|
|
value={item.status}
|
||
|
|
onChange={(e) => onUpdateStatus(item.id, e.target.value)}
|
||
|
|
aria-label="Review-Status"
|
||
|
|
>
|
||
|
|
{REVIEW_STATUSES.map((s) => (
|
||
|
|
<option key={s} value={s}>
|
||
|
|
{REVIEW_STATUS_LABELS[s]}
|
||
|
|
</option>
|
||
|
|
))}
|
||
|
|
</select>
|
||
|
|
<button
|
||
|
|
type="button"
|
||
|
|
className="btn btn-secondary"
|
||
|
|
onClick={() => onDelete(item.id)}
|
||
|
|
>
|
||
|
|
Löschen
|
||
|
|
</button>
|
||
|
|
</>
|
||
|
|
)}
|
||
|
|
</div>
|
||
|
|
</li>
|
||
|
|
))}
|
||
|
|
</ul>
|
||
|
|
</section>
|
||
|
|
)
|
||
|
|
}
|