268 lines
8.1 KiB
TypeScript
268 lines
8.1 KiB
TypeScript
import type { Metadata } from "next";
|
|
import Link from "next/link";
|
|
import { EstimateActions } from "@/components/status/EstimateActions";
|
|
import {
|
|
fetchOlympusRepairStatus,
|
|
type OlympusEstimate,
|
|
type OlympusRepairStatus,
|
|
} from "@/lib/olympus/status";
|
|
|
|
type PageProps = {
|
|
params: Promise<{
|
|
token: string;
|
|
}>;
|
|
};
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
export const metadata: Metadata = {
|
|
title: "Reparaturstatus | Funktechnik Schubert",
|
|
description: "Öffentlicher Reparaturstatus für Kunden von Funktechnik Schubert.",
|
|
robots: {
|
|
index: false,
|
|
follow: false,
|
|
},
|
|
};
|
|
|
|
function formatDate(value: string) {
|
|
return new Intl.DateTimeFormat("de-DE", {
|
|
dateStyle: "medium",
|
|
timeStyle: "short",
|
|
}).format(new Date(value));
|
|
}
|
|
|
|
function formatDateOnly(value: string | null) {
|
|
if (!value) {
|
|
return "Nicht angegeben";
|
|
}
|
|
|
|
return new Intl.DateTimeFormat("de-DE", {
|
|
dateStyle: "medium",
|
|
}).format(new Date(value));
|
|
}
|
|
|
|
function formatMoney(cents: number, currency: string) {
|
|
return new Intl.NumberFormat("de-DE", {
|
|
style: "currency",
|
|
currency: currency || "EUR",
|
|
}).format(cents / 100);
|
|
}
|
|
|
|
function estimateStatusLabel(status: string) {
|
|
const labels: Record<string, string> = {
|
|
draft: "In Vorbereitung",
|
|
sent: "Zur Freigabe",
|
|
approved: "Freigegeben",
|
|
declined: "Abgelehnt",
|
|
expired: "Abgelaufen",
|
|
cancelled: "Storniert",
|
|
};
|
|
|
|
return labels[status] ?? status;
|
|
}
|
|
|
|
function estimateStatusText(status: string) {
|
|
const texts: Record<string, string> = {
|
|
sent: "Bitte prüfen Sie den Kostenvoranschlag. Sie können ihn freigeben, ablehnen oder eine Rückfrage senden.",
|
|
approved: "Dieser Kostenvoranschlag wurde freigegeben.",
|
|
declined: "Dieser Kostenvoranschlag wurde abgelehnt.",
|
|
expired: "Dieser Kostenvoranschlag ist nicht mehr gültig.",
|
|
cancelled: "Dieser Kostenvoranschlag wurde storniert.",
|
|
};
|
|
|
|
return texts[status] ?? "Der Kostenvoranschlag ist aktuell nicht zur Bearbeitung freigegeben.";
|
|
}
|
|
|
|
function estimateItemTypeLabel(type: string) {
|
|
const labels: Record<string, string> = {
|
|
labor: "Arbeitszeit",
|
|
part: "Ersatzteil",
|
|
material: "Material",
|
|
service: "Service",
|
|
shipping: "Versand",
|
|
other: "Sonstiges",
|
|
};
|
|
|
|
return labels[type] ?? "Position";
|
|
}
|
|
|
|
function EstimateCard({ estimate, token }: { estimate: OlympusEstimate | null | undefined; token: string }) {
|
|
if (!estimate) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<section className="estimate-card" aria-labelledby="estimate-title">
|
|
<div className="estimate-header">
|
|
<div>
|
|
<p className="eyebrow">Kostenvoranschlag</p>
|
|
<h2 id="estimate-title">{estimate.title || "Kostenvoranschlag"}</h2>
|
|
<p className="status-muted">Nummer {estimate.estimate_number}</p>
|
|
</div>
|
|
<span className="estimate-status">{estimateStatusLabel(estimate.status)}</span>
|
|
</div>
|
|
|
|
{estimate.customer_message && <p className="estimate-message">{estimate.customer_message}</p>}
|
|
|
|
<dl className="estimate-meta">
|
|
<div>
|
|
<dt>Gültig bis</dt>
|
|
<dd>{formatDateOnly(estimate.valid_until)}</dd>
|
|
</div>
|
|
<div>
|
|
<dt>Status</dt>
|
|
<dd>{estimateStatusLabel(estimate.status)}</dd>
|
|
</div>
|
|
</dl>
|
|
|
|
<div className="estimate-items" aria-label="Positionen des Kostenvoranschlags">
|
|
{estimate.items.map((item, index) => (
|
|
<div className="estimate-item" key={`${item.title}-${index}`}>
|
|
<div>
|
|
<span className="estimate-item-type">{estimateItemTypeLabel(item.item_type)}</span>
|
|
<h3>{item.title}</h3>
|
|
{item.description && <p>{item.description}</p>}
|
|
</div>
|
|
<div className="estimate-item-price">
|
|
<span>
|
|
{item.quantity} {item.unit}
|
|
</span>
|
|
<strong>{formatMoney(item.total_cents, estimate.currency)}</strong>
|
|
</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
|
|
<dl className="estimate-totals">
|
|
<div>
|
|
<dt>Zwischensumme</dt>
|
|
<dd>{formatMoney(estimate.subtotal_cents, estimate.currency)}</dd>
|
|
</div>
|
|
<div>
|
|
<dt>Mehrwertsteuer</dt>
|
|
<dd>{formatMoney(estimate.tax_cents, estimate.currency)}</dd>
|
|
</div>
|
|
<div className="estimate-total-highlight">
|
|
<dt>Gesamt</dt>
|
|
<dd>{formatMoney(estimate.total_cents, estimate.currency)}</dd>
|
|
</div>
|
|
</dl>
|
|
|
|
<p className="estimate-status-text">{estimateStatusText(estimate.status)}</p>
|
|
|
|
{estimate.status === "sent" && <EstimateActions token={token} />}
|
|
</section>
|
|
);
|
|
}
|
|
|
|
function StatusError({ title, text }: { title: string; text: string }) {
|
|
return (
|
|
<section className="status-page">
|
|
<div className="container status-page-inner">
|
|
<div className="status-card status-card-narrow">
|
|
<p className="eyebrow">Reparaturstatus</p>
|
|
<h1>{title}</h1>
|
|
<p className="lead">{text}</p>
|
|
<div className="actions">
|
|
<Link className="button" href="/reparatur">Reparatur anfragen</Link>
|
|
<Link className="button light" href="/kontakt">Kontakt aufnehmen</Link>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
);
|
|
}
|
|
|
|
function StatusTimeline({ status }: { status: OlympusRepairStatus }) {
|
|
if (status.status_history_public.length === 0) {
|
|
return <p className="status-muted">Noch keine Statushistorie vorhanden.</p>;
|
|
}
|
|
|
|
const latestIndex = status.status_history_public.length - 1;
|
|
|
|
return (
|
|
<ol className="public-status-timeline">
|
|
{status.status_history_public.map((item, index) => (
|
|
<li key={`${item.status}-${item.created_at}-${index}`} className={index === latestIndex ? "is-current" : ""}>
|
|
<span className="timeline-dot" aria-hidden="true" />
|
|
<div className="timeline-content">
|
|
<div>
|
|
<p className="timeline-title">{item.status_label}</p>
|
|
{index === latestIndex && <span className="status-pill">Aktueller Status</span>}
|
|
</div>
|
|
<time dateTime={item.created_at}>{formatDate(item.created_at)}</time>
|
|
</div>
|
|
</li>
|
|
))}
|
|
</ol>
|
|
);
|
|
}
|
|
|
|
export default async function RepairStatusPage({ params }: PageProps) {
|
|
const { token } = await params;
|
|
const result = await fetchOlympusRepairStatus(token);
|
|
|
|
if (!result.ok && result.reason === "invalid") {
|
|
return (
|
|
<StatusError
|
|
title="Statuslink nicht aktiv"
|
|
text="Dieser Statuslink ist ungültig oder nicht mehr aktiv."
|
|
/>
|
|
);
|
|
}
|
|
|
|
if (!result.ok) {
|
|
return (
|
|
<StatusError
|
|
title="Status momentan nicht abrufbar"
|
|
text="Der Reparaturstatus ist momentan nicht abrufbar. Bitte versuchen Sie es später erneut oder kontaktieren Sie uns direkt."
|
|
/>
|
|
);
|
|
}
|
|
|
|
const status = result.status;
|
|
const device = `${status.device_manufacturer} ${status.device_model}`.trim();
|
|
|
|
return (
|
|
<section className="status-page">
|
|
<div className="container status-page-inner">
|
|
<div className="status-card">
|
|
<p className="eyebrow">Reparaturstatus</p>
|
|
<div className="status-title-row">
|
|
<div>
|
|
<h1>Reparaturstatus</h1>
|
|
<p className="lead">Hier sehen Sie den aktuellen Stand Ihrer Reparatur.</p>
|
|
</div>
|
|
<span className="status-badge">{status.public_status_label}</span>
|
|
</div>
|
|
|
|
<dl className="status-summary">
|
|
<div>
|
|
<dt>Reparaturnummer</dt>
|
|
<dd>{status.repair_number}</dd>
|
|
</div>
|
|
<div>
|
|
<dt>Gerät</dt>
|
|
<dd>{device || "Nicht angegeben"}</dd>
|
|
</div>
|
|
<div>
|
|
<dt>Aktueller Status</dt>
|
|
<dd>{status.public_status_label}</dd>
|
|
</div>
|
|
<div>
|
|
<dt>Letzte Aktualisierung</dt>
|
|
<dd>{formatDate(status.updated_at)}</dd>
|
|
</div>
|
|
</dl>
|
|
|
|
<EstimateCard estimate={status.estimate} token={token} />
|
|
|
|
<div className="status-timeline-section">
|
|
<h2>Statusverlauf</h2>
|
|
<StatusTimeline status={status} />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
);
|
|
}
|