'use client'; import { useCartStore } from '@/lib/cart-store'; import { useActionState, useEffect, startTransition } from 'react'; import Link from 'next/link'; import { submitOrderForm } from './actions'; import { ArrowLeft, CheckCircle2 } from 'lucide-react'; import { buttonClasses } from '@/components/ui/Button'; import { getRecaptchaToken } from '@/lib/getRecaptchaToken'; const initialState = { success: false, message: '' }; export default function ZamowieniePage() { const { items, getTotal, clearCart } = useCartStore(); const [state, formAction, pending] = useActionState(submitOrderForm, initialState); const total = getTotal(); useEffect(() => { if (state.success) clearCart(); }, [state.success, clearCart]); if (items.length === 0 && !state.success) { return (

Koszyk jest pusty.

Wróć do sklepu
); } if (state.success) { return (

Zamówienie przyjęte!

{state.message}

Wróć do sklepu
); } return (
Wróć do koszyka

Złóż zamówienie

{/* Podsumowanie produktów */}

Zamawiane produkty

{items.map((item) => (
{item.name} × {item.quantity} {(item.price * item.quantity).toLocaleString('pl-PL')} zł
))}
Łącznie (urządzenia) {total.toLocaleString('pl-PL')} zł
{/* Formularz */}
{ e.preventDefault(); const formData = new FormData(e.currentTarget); const token = await getRecaptchaToken('submit'); if (token) { formData.append('recaptchaToken', token); } startTransition(() => { formAction(formData); }); }} className="bg-white rounded-xl border border-border p-6 flex flex-col gap-4">

Twoje dane

{/* Hidden: produkty jako JSON */}