diff --git a/app/email-preview/[type]/components/LiveEmailPreviewClient.tsx b/app/email-preview/[type]/components/LiveEmailPreviewClient.tsx index 7f26de2..807050d 100644 --- a/app/email-preview/[type]/components/LiveEmailPreviewClient.tsx +++ b/app/email-preview/[type]/components/LiveEmailPreviewClient.tsx @@ -1,5 +1,6 @@ "use client"; +import { useState } from "react"; import { useLivePreview } from "@payloadcms/live-preview-react"; import { renderOrderConfirmationHtml, @@ -7,6 +8,7 @@ import { renderOrderStatusHtml, ORDER_STATUS_EMAIL_ICON, SAMPLE_ORDER, + SAMPLE_ORDER_MANUAL, type EmailTemplateContent, } from "../../../lib/emailTemplates"; import type { EmailTemplateType } from "../../../lib/payload"; @@ -34,13 +36,19 @@ export function LiveEmailPreviewClient({ depth: 0, }); + // Only order-confirmation has two meaningfully different rendered + // states (isManualPayment true/false change which blocks show at all, + // not just text) — every other type has one sample and no toggle. + const [sampleVariant, setSampleVariant] = useState<"paid" | "manual">("paid"); + const orderSample = sampleVariant === "paid" ? SAMPLE_ORDER : SAMPLE_ORDER_MANUAL; + // No real company-settings fetch in this preview context — passing null // falls back to DEFAULT_LEGAL_FOOTER_LINES (placeholder Anbieterkennzeichnung) // inside buildLegalFooterLines(), same shape as the real send just with // placeholder business data. const html = type === "order-confirmation" - ? renderOrderConfirmationHtml(data, SAMPLE_ORDER, null) + ? renderOrderConfirmationHtml(data, orderSample, null) : type === "password-reset" ? renderPasswordResetHtml(data, "https://einfach-produktiv.mk360.de/konto/passwort-zuruecksetzen?token=beispiel-token", null) : renderOrderStatusHtml( @@ -53,7 +61,54 @@ export function LiveEmailPreviewClient({ return (
Status
Zahlungsstatus
+Gesamtbetrag
{formatPrice(order.total)}
diff --git a/app/lib/customerAuth.ts b/app/lib/customerAuth.ts index 4b8821c..846ec6e 100644 --- a/app/lib/customerAuth.ts +++ b/app/lib/customerAuth.ts @@ -464,6 +464,7 @@ export type CustomerOrder = { createdAt: string; total: number; status: string; + paymentStatus: "not_applicable" | "pending" | "paid" | "failed" | "refunded" | "partially_refunded"; itemCount: number; /** Raw product relationship ids, in item order — depth=0 keeps them as * plain numbers, not populated objects. Callers resolve these to image @@ -509,13 +510,21 @@ export async function getCustomerOrders(token: string, customerId: number, exclu }); if (!res.ok) return []; const data: { - docs?: { orderNumber: string; createdAt: string; total: number; status: string; items: { product: number }[] }[]; + docs?: { + orderNumber: string; + createdAt: string; + total: number; + status: string; + paymentStatus: CustomerOrder["paymentStatus"]; + items: { product: number }[]; + }[]; } = await res.json(); return (data.docs ?? []).map((doc) => ({ orderNumber: doc.orderNumber, createdAt: doc.createdAt, total: doc.total, status: doc.status, + paymentStatus: doc.paymentStatus, itemCount: doc.items.length, productIds: doc.items.map((item) => item.product), })); diff --git a/app/lib/emailTemplates.ts b/app/lib/emailTemplates.ts index bdcd6d7..c353ab3 100644 --- a/app/lib/emailTemplates.ts +++ b/app/lib/emailTemplates.ts @@ -246,6 +246,17 @@ export const SAMPLE_ORDER: OrderConfirmationData = { isManualPayment: false, }; +// Second preview fixture — demonstrates the Vorkasse/Überweisung branch +// (vorkasseNotice(), incl. the "switch to Kreditkarte/PayPal" mention) +// that SAMPLE_ORDER's own isManualPayment: false never shows. Used by +// LiveEmailPreviewClient.tsx's toggle, not by any real send — a real +// order-confirmation email always computes both flags live per order. +export const SAMPLE_ORDER_MANUAL: OrderConfirmationData = { + ...SAMPLE_ORDER, + isManualPayment: true, + hasOnlinePaymentOption: true, +}; + export function renderOrderConfirmationHtml(template: EmailTemplateContent, order: OrderConfirmationData, seller: CompanySettings | null): string { const rows = order.items .map(