Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SvuGvHpbAQ4syfuLuRvutL
43 lines
1.6 KiB
TypeScript
43 lines
1.6 KiB
TypeScript
import { redirect } from "next/navigation";
|
||
import { availableShipping } from "@/lib/checkout";
|
||
import { formatPrice } from "@/lib/money";
|
||
import { shippingPrice } from "@/lib/pricing";
|
||
import { ChoiceForm } from "@/components/shop/ChoiceForm";
|
||
import { saveShipping } from "../actions";
|
||
import { CheckoutSummary, loadCheckout } from "../shared";
|
||
|
||
export const metadata = { title: "Kasse – Versand" };
|
||
|
||
export default async function ShippingStep() {
|
||
const data = await loadCheckout();
|
||
if (!data.state.address) redirect("/kasse/adresse");
|
||
const methods = await availableShipping(data.state.address.country);
|
||
const merchandise = data.totals.subtotal - data.totals.discount;
|
||
return (
|
||
<div className="sm-checkout">
|
||
<div>
|
||
{methods.length === 0 ? (
|
||
<p className="body">In dein Land können wir gerade nicht liefern. Bitte melde dich bei uns.</p>
|
||
) : (
|
||
<ChoiceForm
|
||
action={saveShipping}
|
||
name="shippingMethodId"
|
||
legend="Wie sollen wir liefern?"
|
||
submitLabel="Weiter zur Zahlung"
|
||
selected={data.state.shippingMethodId}
|
||
choices={methods.map((m) => {
|
||
const price = shippingPrice(m, merchandise);
|
||
return {
|
||
id: m.id,
|
||
title: m.name,
|
||
price: price === 0 ? "Kostenlos" : formatPrice(price),
|
||
text: [m.description, m.freeFrom > 0 && price > 0 ? `Kostenlos ab ${formatPrice(m.freeFrom)}` : ""].filter(Boolean).join(" · "),
|
||
};
|
||
})}
|
||
/>
|
||
)}
|
||
</div>
|
||
<CheckoutSummary data={data} />
|
||
</div>
|
||
);
|
||
}
|