feat(web): cart (add to cart, cart page, header link) (#40) #123

Merged
amiryahaya merged 10 commits from feat/40-cart into main 2026-10-29 07:10:27 +01:00
Owner

Slice 3 of the ticket storefront (#40): a server-side cart for signed-in customers. Design docs/superpowers/specs/2026-10-29-storefront-cart-design.md, plan docs/superpowers/plans/2026-10-29-storefront-cart.md. No change under api/, no OpenAPI change, no migration. No checkout, promo code or payment (#41).

What it does

  • Add to cart on the park page (quantity 1-100 + Add) for park_entry and vehicle tickets that are priced and available in the page currency; never master. States: signed out (Sign in, returns to the same URL), auth off (nothing), cart in another currency (fixed note), past visit date (fixed message, no request), write in flight (disabled), too many lines / over 100 / invalid cart lines / error (fixed messages).
  • /cart: lines with name, park, visit date, quantity (Update), unit price in the cart's currency, Remove, Empty cart, the fixed note that the final price is confirmed at checkout, empty/loading/error/signed-out/auth-off states. A line that is unavailable, past or failed shows a fixed note and can still be removed. No total and no arithmetic on money anywhere.
  • Header Cart link with the item count (signed in, count > 0).
  • Data layer (src/cart): one serialised write queue (two quick Adds both land), add reads the fresh server cart before merging, the last line removed is a DELETE, a failed write refetches, sign-out mid-write cannot refill the cache.
  • Client-wide 401 handling: any 401 on a request that carried a token, or while signed in (an expired token sends no header), ends the session; a 401 during sign-in does not.
  • Local journey pnpm --filter @kws/ticket e2e:idp (+ deploy/dev-idp/seed-cart.sql, idempotent, dev only): sign in, add two, see the count, edit, remove, empty, no cart data in storage, Authorization only on /v1, 320 px, a 401 signs out.

Verification

  • pnpm typecheck, pnpm test (231), pnpm build green; standard Playwright e2e in Playwright's image: 114 passed / 46 skipped by design (new auth-off cart spec at five viewports, axe, no overflow).
  • Real-IdP journey against the real mock IdP and API: 6/6.
  • make cover: 91.3% (minimum 80%; Go code unchanged).
  • Reviews: task review after every task, whole-branch dual pass (complexity, then correctness) and a scoped re-check of the fixes. Whole-branch findings fixed: token expiry not signing out, a past/inactive line blocking every write, a silent cap at 100, a stale cached cart on Add, a request storm on the cart page.

Author calls (owner to check)

  • Names and prices come from the products endpoint per park and date (the cart line has only ids): requests = parks x distinct dates, cached 5 minutes, no refetch on focus. Marked with a shortcut: comment; the real fix is an API change returning park, product and unit price on cart lines, before checkout builds on it. [verify]
  • Single-day visits only (checkout_date = visit_date); one currency per cart; two tabs: last write wins (the API's design); seats are not shown (409 at checkout).
  • The Cart link is hidden at count 0, so an empty cart has no header route (the add confirmation links to /cart).
  • A page reload shows signed-out until Sign in is clicked (no silent renew).
  • Declined review suggestions on purpose: replacing the write queue with useMutation({scope}) (concurrency rewrite risk), the currencyId prop chain, test-overlap cleanup.

Not verified

  • Real phones, Safari and Firefox; production CORS / Zitadel.
  • The signed-in cart in CI (CI runs with auth off): covered by unit tests and the local journey only.
  • Real load against the per-IP default rate limit (#61); the real number of parks in production.

Refs #40 (does not close it).

🤖 Generated with Claude Code

Slice 3 of the ticket storefront (#40): a server-side cart for signed-in customers. Design `docs/superpowers/specs/2026-10-29-storefront-cart-design.md`, plan `docs/superpowers/plans/2026-10-29-storefront-cart.md`. No change under `api/`, no OpenAPI change, no migration. No checkout, promo code or payment (#41). ## What it does - **Add to cart** on the park page (quantity 1-100 + Add) for `park_entry` and `vehicle` tickets that are priced and available in the page currency; never `master`. States: signed out (Sign in, returns to the same URL), auth off (nothing), cart in another currency (fixed note), past visit date (fixed message, no request), write in flight (disabled), too many lines / over 100 / invalid cart lines / error (fixed messages). - **`/cart`:** lines with name, park, visit date, quantity (Update), unit price in the cart's currency, Remove, Empty cart, the fixed note that the final price is confirmed at checkout, empty/loading/error/signed-out/auth-off states. A line that is unavailable, past or failed shows a fixed note and can still be removed. **No total and no arithmetic on money anywhere.** - **Header Cart link** with the item count (signed in, count > 0). - **Data layer** (`src/cart`): one serialised write queue (two quick Adds both land), `add` reads the fresh server cart before merging, the last line removed is a `DELETE`, a failed write refetches, sign-out mid-write cannot refill the cache. - **Client-wide 401 handling:** any 401 on a request that carried a token, or while signed in (an expired token sends no header), ends the session; a 401 during sign-in does not. - **Local journey** `pnpm --filter @kws/ticket e2e:idp` (+ `deploy/dev-idp/seed-cart.sql`, idempotent, dev only): sign in, add two, see the count, edit, remove, empty, no cart data in storage, `Authorization` only on `/v1`, 320 px, a 401 signs out. ## Verification - `pnpm typecheck`, `pnpm test` (231), `pnpm build` green; standard Playwright e2e in Playwright's image: 114 passed / 46 skipped by design (new auth-off cart spec at five viewports, axe, no overflow). - Real-IdP journey against the real mock IdP and API: 6/6. - `make cover`: **91.3%** (minimum 80%; Go code unchanged). - Reviews: task review after every task, whole-branch dual pass (complexity, then correctness) and a scoped re-check of the fixes. Whole-branch findings fixed: token expiry not signing out, a past/inactive line blocking every write, a silent cap at 100, a stale cached cart on Add, a request storm on the cart page. ## Author calls (owner to check) - Names and prices come from the products endpoint per park and date (the cart line has only ids): **requests = parks x distinct dates**, cached 5 minutes, no refetch on focus. Marked with a `shortcut:` comment; the real fix is an API change returning park, product and unit price on cart lines, before checkout builds on it. **[verify]** - Single-day visits only (`checkout_date = visit_date`); one currency per cart; two tabs: last write wins (the API's design); seats are not shown (409 at checkout). - The Cart link is hidden at count 0, so an empty cart has no header route (the add confirmation links to `/cart`). - A page reload shows signed-out until Sign in is clicked (no silent renew). - Declined review suggestions on purpose: replacing the write queue with `useMutation({scope})` (concurrency rewrite risk), the `currencyId` prop chain, test-overlap cleanup. ## Not verified - Real phones, Safari and Firefox; production CORS / Zitadel. - The signed-in cart in CI (CI runs with auth off): covered by unit tests and the local journey only. - Real load against the per-IP default rate limit (#61); the real number of parks in production. Refs #40 (does not close it). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
fix(web): cart whole-branch review fixes (#40)
All checks were successful
ci / changes (pull_request) Successful in 9s
ci / api (pull_request) Has been skipped
ci / clients (pull_request) Has been skipped
ci / web (pull_request) Successful in 2m28s
ci / ci-gate (pull_request) Successful in 2s
b947b9671d
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
primatekuntech/kws!123
No description provided.