Checkout Form

A Validated Checkout Form for BookNest

The practice API from Query and Zustand gained POST /orders, which allows three copies of each title and answers 409 with a message or 201 with an order number; src/api/orders.ts posts the form and the cart's items. The screen wraps the address and postcode Fields in {delivery.value === 'ship' && ...}. React Hook Form 351,018 keeps the values of fields that unmount (shouldUnregister is false by default), so switching to pickup and back loses nothing, and the schema's pickup branch simply ignores them.

With four copies of Salt and Saffron in the cart, the first tap on Place order failed on the phone (Metro logged invalid: email, address, postcode), and the second reached the server and was refused:

The checkout form after a failed submit, and after the server refused the order
The checkout form after a failed submit, and after the server refused the order

With two copies, the same form went through:

Output of 173
16:47:11 POST /orders 409
16:48:00 POST /orders 201

The screen showed "Order 1001 placed" and the cart badge dropped to zero. onValid receives the schema's output, so a name typed as " Ana " arrives trimmed.