99 lines
4.1 KiB
JavaScript
99 lines
4.1 KiB
JavaScript
import "./booking-confirmation.css";
|
|
import { orderSummaryRows } from "../../shared/order-summary.js";
|
|
import { paymentNotice } from "../../shared/booking-copy.js";
|
|
|
|
const mailMessages = {
|
|
accepted:
|
|
"Die Bestätigung wurde vom Mailserver zum Versand angenommen. Die Zustellung ist noch nicht bestätigt. Bitte prüfe auch deinen Spam-Ordner.",
|
|
pending:
|
|
"Deine Buchung ist gespeichert. Der Bestätigungsversand steht noch aus. Du kannst den Versand mit derselben Buchung erneut versuchen.",
|
|
failed: "Deine Buchung ist gespeichert, aber der Bestätigungsversand ist fehlgeschlagen. Bitte buche nicht erneut. Wende dich mit deiner Buchungsnummer an Tri-Hub.",
|
|
unknown:
|
|
"Deine Buchung ist gespeichert. Der Versandstatus ist unklar. Bitte buche nicht erneut. Wende dich mit deiner Buchungsnummer an Tri-Hub.",
|
|
};
|
|
const select = (id) => document.getElementById(id);
|
|
function rows(id, values) {
|
|
const list = select(id);
|
|
for (const [label, value] of values) {
|
|
const term = document.createElement("dt");
|
|
const description = document.createElement("dd");
|
|
term.textContent = label;
|
|
description.textContent = value || "Nicht verfügbar";
|
|
list.append(term, description);
|
|
}
|
|
}
|
|
|
|
// Nur die Antwort der gespeicherten Buchung anzeigen, keine aktuellen
|
|
// Katalogpreise nachladen und keine erneute Buchungsanfrage auslösen.
|
|
let body;
|
|
try {
|
|
body = JSON.parse(sessionStorage.getItem("trihub.booking.confirmation"));
|
|
} catch {
|
|
// Ohne lesbaren Sitzungsspeicher bleibt der Hinweis sichtbar.
|
|
}
|
|
if (
|
|
body?.saved === true &&
|
|
typeof body.bookingId === "string" &&
|
|
body.bookingId
|
|
) {
|
|
const order = body.bookedPackage;
|
|
select("confirmation-payment").textContent = paymentNotice;
|
|
select("summary-title").textContent =
|
|
body.packageName || order?.title || "Dein Paket";
|
|
select("confirmation-summary").textContent = order?.summaryForBooking || "";
|
|
const date = new Date(body.createdAt);
|
|
rows("confirmation-receipt", [
|
|
["Buchungsnummer", body.bookingId],
|
|
[
|
|
"Buchungsdatum",
|
|
Number.isNaN(date.getTime())
|
|
? "Nicht verfügbar"
|
|
: new Intl.DateTimeFormat("de-DE", {
|
|
dateStyle: "long",
|
|
timeStyle: "short",
|
|
}).format(date),
|
|
],
|
|
["E-Mail-Adresse", body.customerEmail],
|
|
[
|
|
"Buchungsstatus",
|
|
body.status === "CONFIRMED"
|
|
? "Bestätigt (Simulation)"
|
|
: "Gespeichert (Simulation)",
|
|
],
|
|
]);
|
|
select("confirmation-mail-status").textContent =
|
|
mailMessages[body.emailStatus] || mailMessages.unknown;
|
|
if (order) {
|
|
rows("confirmation-totals", orderSummaryRows(order));
|
|
for (const feature of order.includedFeatures || []) {
|
|
const item = document.createElement("li");
|
|
item.textContent = feature;
|
|
select("confirmation-features").append(item);
|
|
}
|
|
select("confirmation-features-section").hidden =
|
|
!order.includedFeatures?.length;
|
|
for (const step of order.processSteps || []) {
|
|
const item = document.createElement("li");
|
|
const title = document.createElement("h3");
|
|
const text = document.createElement("p");
|
|
title.textContent = step.step;
|
|
text.textContent = step.text;
|
|
item.append(title, text);
|
|
select("confirmation-steps").append(item);
|
|
}
|
|
select("confirmation-steps-section").hidden =
|
|
!order.processSteps?.length;
|
|
} else {
|
|
select("confirmation-no-snapshot").hidden = false;
|
|
rows("confirmation-totals", [["Paket-ID", body.packageId]]);
|
|
}
|
|
if (body.emailStatus === "pending" && body.packageId) {
|
|
const params = new URLSearchParams({ id: body.packageId });
|
|
if (order?.variantId) params.set("variant", order.variantId);
|
|
select("confirmation-retry").href = `/paket-details.html?${params}`;
|
|
select("confirmation-retry").hidden = false;
|
|
}
|
|
select("confirmation-empty").hidden = true;
|
|
select("confirmation-content").hidden = false;
|
|
}
|