feat: v2.2 batch (calendar, self-service, sort, description, filename search, stats, collab, invoice) on pre-redesign base

This commit is contained in:
Leon Tonhäuser committed 2026-11-30 21:20:13 +01:00
1 parent 453bece72c
commit 7204dd6b60
108 files changed
+10400 -105

No files matched your search

@@ -162,6 +162,28 @@ export function BillingSelection({
}
}
async function handleToggleCollab(position: BillingPosition) {
setActionState({ loading: true, message: null, isError: false });
try {
const response = await fetch(`/api/usages/${encodeURIComponent(position.id)}/collab`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ collab: !position.collab }),
});
if (!response.ok) {
const body = await response.json().catch(() => ({ code: "ERROR" }));
throw new Error(body.code ?? "Collab-Kennzeichnung fehlgeschlagen");
}
window.location.reload();
} catch (error) {
setActionState({
loading: false,
message: error instanceof Error ? error.message : "Collab-Kennzeichnung fehlgeschlagen",
isError: true,
});
}
}
const quarterParam = isQuarter ? null : Math.ceil((month ?? 1) / 3);
const quarterHref = quarter
? `/admin/abrechnungen/${editorialId}?year=${year}&quarter=${quarter}`
@@ -228,7 +250,20 @@ export function BillingSelection({
<td>{position.albumName}</td>
<td>{position.purpose}</td>
<td>{position.reference ?? "—"}</td>
<td className="billing-price">{formatCents(position.priceCents)}</td>
<td className="billing-price">
{formatCents(position.priceCents)}
{position.collab && <span className="billing-collab-badge">Collab</span>}
{position.selectable && (
<button
type="button"
className="billing-collab-toggle"
onClick={() => handleToggleCollab(position)}
disabled={actionState.loading}
>
{position.collab ? "Collab entfernen" : "Als Collab markieren"}
</button>
)}
</td>
<td>
<span className="billing-status">
{STATUS_LABELS[position.status]}
@@ -334,13 +369,48 @@ export function BillingSelection({
</div>
{report.status === "final" && (
<>
<div className="billing-invoice-block">
<p className="billing-invoice-status">
Rechnung:{" "}
{report.invoiceEmailStatus === "sent" ? (
<>
versendet am{" "}
<time
dateTime={report.invoiceEmailSentAt?.toISOString()}
suppressHydrationWarning
>
{report.invoiceEmailSentAt?.toLocaleDateString("de-DE")}
</time>
</>
) : report.hasInvoicePdf ? (
"PDF hinterlegt, Versand fehlgeschlagen"
) : (
"noch keine PDF hinterlegt"
)}
</p>
<InvoiceUploadForm
reportId={report.id}
reportNumber={report.reportNumber}
hasInvoice={report.hasInvoicePdf}
emailFailed={report.hasInvoicePdf && report.invoiceEmailStatus === "failed"}
/>
{report.hasInvoicePdf && (
<a
href={`/api/billing-reports/${encodeURIComponent(report.id)}/invoice`}
className="billing-report-download"
download
>
Rechnungs-PDF herunterladen
</a>
)}
</div>
<CancelReportForm reportId={report.id} reportNumber={report.reportNumber} />
<a
<a
href={`/api/billing-reports/${encodeURIComponent(report.id)}`}
className="billing-report-download"
download
>
PDF herunterladen
Nutzungsnachweis herunterladen
</a>
</>
)}
@@ -403,6 +473,114 @@ function PeriodSelector({ year, month, quarter, isQuarter }: PeriodSelectorProps
);
}
type InvoiceUploadFormProps = {
reportId: string;
reportNumber: number;
hasInvoice: boolean;
emailFailed: boolean;
};
function InvoiceUploadForm({ reportId, reportNumber, hasInvoice, emailFailed }: InvoiceUploadFormProps) {
const [file, setFile] = useState<File | null>(null);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
async function handleUpload(event: React.FormEvent) {
event.preventDefault();
if (!file || loading) return;
setLoading(true);
setError(null);
try {
const formData = new FormData();
formData.set("invoice", file);
const response = await fetch(`/api/billing-reports/${encodeURIComponent(reportId)}/invoice`, {
method: "POST",
body: formData,
});
if (!response.ok) {
const body = await response.json().catch(() => ({ code: "ERROR" }));
throw new Error(invoiceErrorMessage(body.code));
}
window.location.reload();
} catch (err) {
setError(err instanceof Error ? err.message : "Upload fehlgeschlagen");
setLoading(false);
}
}
async function handleResend() {
if (loading) return;
setLoading(true);
setError(null);
try {
const response = await fetch(
`/api/billing-reports/${encodeURIComponent(reportId)}/invoice/resend`,
{ method: "POST" },
);
if (!response.ok) {
const body = await response.json().catch(() => ({ code: "ERROR" }));
throw new Error(invoiceErrorMessage(body.code));
}
window.location.reload();
} catch (err) {
setError(err instanceof Error ? err.message : "Versand fehlgeschlagen");
setLoading(false);
}
}
return (
<form className="billing-invoice-form" onSubmit={handleUpload}>
<label>
<span>
{hasInvoice ? "Rechnungs-PDF ersetzen" : "Rechnungs-PDF hochladen"} (Bericht Nr. {reportNumber})
</span>
<input
type="file"
accept="application/pdf,.pdf"
required
disabled={loading}
onChange={(event) => setFile(event.target.files?.[0] ?? null)}
aria-label={`Rechnungs-PDF für Bericht Nr. ${reportNumber}`}
/>
</label>
<div className="billing-invoice-controls">
<button type="submit" disabled={!file || loading}>
{loading ? "Wird gesendet…" : "Hochladen & senden"}
</button>
{hasInvoice && (
<button type="button" onClick={handleResend} disabled={loading}>
{emailFailed ? "Erneut senden" : "Nochmal senden"}
</button>
)}
</div>
<p className="form-note">
Nach dem Upload geht die Rechnung gebündelt mit dem Nutzungsnachweis automatisch per
E-Mail an die Redaktion.
</p>
{error && (
<p className="billing-status-message" role="alert">
{error}
</p>
)}
</form>
);
}
function invoiceErrorMessage(code: unknown): string {
switch (code) {
case "INVALID_PDF":
return "Die Datei ist keine gültige PDF (max. 20 MB).";
case "REPORT_NOT_FINAL":
return "Der Bericht ist nicht finalisiert.";
case "INVOICE_NOT_UPLOADED":
return "Es ist noch keine Rechnungs-PDF hinterlegt.";
case "RATE_LIMITED":
return "Zu viele Versuche. Bitte kurz warten.";
default:
return "Der Vorgang ist fehlgeschlagen. Bitte erneut versuchen.";
}
}
type CancelReportFormProps = {
reportId: string;
reportNumber: number;