fix: harden delivery accounting and history
This commit is contained in:
1 parent
8871e4794a
commit
510fde7afa
13 files changed
+728
-88
No files matched your search
@@ -1,11 +1,8 @@
|
||||
import Link from "next/link";
|
||||
|
||||
import { formatBerlinDateTime } from "@/modules/downloads/format";
|
||||
import type { UsageHistoryAttempt, UsageHistoryPage } from "@/modules/downloads/stream";
|
||||
|
||||
const dateTimeFormatter = new Intl.DateTimeFormat("de-DE", {
|
||||
dateStyle: "medium",
|
||||
timeStyle: "short",
|
||||
});
|
||||
const priceFormatter = new Intl.NumberFormat("de-DE", {
|
||||
style: "currency",
|
||||
currency: "EUR",
|
||||
@@ -39,7 +36,7 @@ export function UsageHistoryContent({ history }: Readonly<{ history: UsageHistor
|
||||
<li key={usage.usageId}>
|
||||
<article className="usage-ledger-entry">
|
||||
<header>
|
||||
<p>{formatDateTime(usage.createdAt)}</p>
|
||||
<p>{formatBerlinDateTime(usage.createdAt)}</p>
|
||||
<h2>{usage.filename}</h2>
|
||||
</header>
|
||||
<dl className="usage-snapshot">
|
||||
@@ -51,6 +48,14 @@ export function UsageHistoryContent({ history }: Readonly<{ history: UsageHistor
|
||||
<dt>Verwendungszweck</dt>
|
||||
<dd>{usage.purpose}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>Nutzungspreis</dt>
|
||||
<dd>{priceFormatter.format(usage.priceCents / 100)}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>Abrechnungsstatus</dt>
|
||||
<dd>{billingStatusLabel(usage.billingStatus)}</dd>
|
||||
</div>
|
||||
{usage.reference ? (
|
||||
<div>
|
||||
<dt>Interne Referenz</dt>
|
||||
@@ -59,7 +64,9 @@ export function UsageHistoryContent({ history }: Readonly<{ history: UsageHistor
|
||||
) : null}
|
||||
</dl>
|
||||
{usage.attempts.length === 0 ? (
|
||||
<p className="usage-attempt-empty">Noch kein abgeschlossener Auslieferungsversuch.</p>
|
||||
<p className="usage-attempt-empty">
|
||||
Keine Auslieferungsversuche auf dieser Auslieferungsseite.
|
||||
</p>
|
||||
) : (
|
||||
<ol className="usage-attempts" aria-label={`Auslieferungen für ${usage.filename}`}>
|
||||
{usage.attempts.map((attempt) => (
|
||||
@@ -74,6 +81,7 @@ export function UsageHistoryContent({ history }: Readonly<{ history: UsageHistor
|
||||
)}
|
||||
|
||||
<HistoryPagination history={history} />
|
||||
<AttemptPagination history={history} />
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -81,7 +89,9 @@ export function UsageHistoryContent({ history }: Readonly<{ history: UsageHistor
|
||||
function AttemptRow({ attempt }: Readonly<{ attempt: UsageHistoryAttempt }>) {
|
||||
return (
|
||||
<li>
|
||||
<time dateTime={attempt.finishedAt.toISOString()}>{formatDateTime(attempt.finishedAt)}</time>
|
||||
<time dateTime={attempt.finishedAt.toISOString()}>
|
||||
{formatBerlinDateTime(attempt.finishedAt)}
|
||||
</time>
|
||||
<strong>{statusLabel(attempt.status)}</strong>
|
||||
<span>{attempt.repeat ? "Wiederholter Abruf" : "Neue Nutzung"}</span>
|
||||
<span>{byteFormatter.format(attempt.transferredBytes)}</span>
|
||||
@@ -95,12 +105,36 @@ function HistoryPagination({ history }: Readonly<{ history: UsageHistoryPage }>)
|
||||
return (
|
||||
<nav aria-label="Seiten der Nutzungshistorie" className="photo-pagination">
|
||||
{history.page > 1 ? (
|
||||
<Link href={`/redaktion/nutzungen?page=${history.page - 1}`}>Vorherige Seite</Link>
|
||||
<Link href={`/redaktion/nutzungen?page=${history.page - 1}`}>
|
||||
Vorherige Nutzungsseite
|
||||
</Link>
|
||||
) : (
|
||||
<span />
|
||||
)}
|
||||
{history.hasNext ? (
|
||||
<Link href={`/redaktion/nutzungen?page=${history.page + 1}`}>Nächste Seite</Link>
|
||||
<Link href={`/redaktion/nutzungen?page=${history.page + 1}`}>
|
||||
Nächste Nutzungsseite
|
||||
</Link>
|
||||
) : null}
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
|
||||
function AttemptPagination({ history }: Readonly<{ history: UsageHistoryPage }>) {
|
||||
if (!history.attemptCursor && !history.nextAttemptCursor) return null;
|
||||
return (
|
||||
<nav aria-label="Seiten der Auslieferungsversuche" className="photo-pagination">
|
||||
{history.attemptCursor ? (
|
||||
<Link href={`/redaktion/nutzungen?page=${history.page}`}>Neueste Auslieferungen</Link>
|
||||
) : (
|
||||
<span />
|
||||
)}
|
||||
{history.nextAttemptCursor ? (
|
||||
<Link
|
||||
href={`/redaktion/nutzungen?page=${history.page}&attemptCursor=${encodeURIComponent(history.nextAttemptCursor)}`}
|
||||
>
|
||||
Ältere Auslieferungen
|
||||
</Link>
|
||||
) : null}
|
||||
</nav>
|
||||
);
|
||||
@@ -115,6 +149,12 @@ function statusLabel(status: UsageHistoryAttempt["status"]): string {
|
||||
return labels[status];
|
||||
}
|
||||
|
||||
function formatDateTime(value: Date): string {
|
||||
return dateTimeFormatter.format(value);
|
||||
function billingStatusLabel(status: UsageHistoryPage["items"][number]["billingStatus"]): string {
|
||||
const labels: Record<UsageHistoryPage["items"][number]["billingStatus"], string> = {
|
||||
open: "Offen",
|
||||
billed: "Abgerechnet",
|
||||
reopened: "Wieder geöffnet",
|
||||
voided: "Storniert",
|
||||
};
|
||||
return labels[status];
|
||||
}
|
||||
Reference in new issue
Block a user