Sikau

Next.js · Day 19 · about 60 min

Capstone: Order online

Dynamic pages, a client cart, a server action and an API.

Everything together

Finish the café's ordering feature. The menu, dish pages and cart button are written; you'll write the server action that places an order: validate it, save it, and redirect to the confirmation page — which reads the order from an API route.

The ordering flow

Take your time with this one: it's the closest thing in the course to a real feature ticket at a real software company in Kathmandu or anywhere else.

The capstone ties the whole course into one flow. Menu and dish pages are Server Components with metadata. A Client Component cart keeps chosen dishes and puts them into a hidden form field. Submitting calls the placeOrder server action, which validates and saves the order, then redirects to a confirmation page — and that page reads the order from a route handler, the same API a mobile app could use.

Menu (Server) → Dish page (Server, metadata)
      ↓ client cart (Client) adds slugs
<form action={placeOrder}> with phone + items
      ↓ server action: validate → save → redirect(`/orders/${id}`)
Confirmation page (Server) ← GET /api/orders/[id] (route handler)

Each piece is something you've built before. The capstone's challenge is choosing the right tool at each step — and keeping the boundaries clean.

The rest of this lesson

  • Validating an orderexplain
  • Placing an orderorder
  • Feature → Next.js toolmatch
  • Parsing itemspredict
  • Place the orderchallenge
  • Badge quizquiz
  • Next.js complete!recap

Continue this lesson free — run real code in your browser

Continue with Google

See all 19 lessons of Next.js