Skip to content

feat(orders): show customer delivery history badge on order detail - #153

Open
soufiweb wants to merge 1 commit into
bighadj22:mainfrom
soufiweb:feat/customer-history-badge
Open

soufiweb wants to merge 1 commit into
bighadj22:mainfrom
soufiweb:feat/customer-history-badge

Conversation

@soufiweb

@soufiweb soufiweb commented Oct 5, 2026

Copy link
Copy Markdown

What does this PR do?

Adds a customer delivery history badge to the order detail page (customer card). When the confirmation team opens an order, they see how the same customer's other orders ended, so repeat door-refusers (and loyal buyers) are visible before calling or dispatching.

  • Badge: New customer / Previous orders in progress / Reliable customer / Frequent returns
  • Summary line: Previous orders: 5 · delivered: 4 · returned: 1 · cancelled: 0

Badge rule: only carrier outcomes judge the customer. Cancellations are shown but never colour the badge, since a cancellation may be the merchant's own decision.

Tone Condition
new no other orders
pending other orders, none delivered or returned yet
reliable delivered > returned
frequent returns returned ≥ delivered

Implementation: getOrderById batches one extra grouped COUNT(*) over the customer's other orders. Customers are unique per phone (idx_customers_phone_unique) and the lookup rides the existing idx_orders_customer index. No schema change, no migration. The new customerHistory field on Order is optional and additive.

Related issues

None yet. Happy to open one if you prefer to discuss first.

How to test

  1. Open an order whose customer has other orders: the badge and summary line appear under the phone number.
  2. Open an order from a first-time customer: "New customer" badge, no summary line.
  3. Switch the dashboard to AR / FR to check translations and RTL.
  • I ran npm run typecheck and npm test in the affected package(s)
    • cod-server: 3078 tests passed (6 new), typecheck clean
    • cod-client-astro: 258 tests passed, typecheck 0 errors

Checklist

  • No secrets, API keys, or live credentials are introduced
  • Tests cover the change (or an existing test covers it)
  • README/docs claims match the implemented behavior (no unbuilt features claimed)
  • Conventional commit message (feat:, fix:, chore:, docs:, ...)

Areas affected

cod-shared / cod-server / cod-client-astro

When the confirmation team opens an order, they now see how the same
customer's other orders ended: total, delivered, returned and cancelled,
with a badge (new / pending / reliable / frequent returns).

- cod-shared: getOrderById batches one grouped count over the customer's
  other orders (customers are unique per phone, rides idx_orders_customer;
  no schema change, no migration)
- cod-server: CustomerHistory added to the Order OpenAPI schema
- cod-client-astro: CustomerHistoryBadge in the customer card, AR/FR/EN
  strings, pure customerHistoryTone() in the orders model
- Cancellations are shown but never colour the badge (they may be the
  merchant's own call); only carrier outcomes judge the customer
- Tests: real-D1 E2E for the counts + unit tests for the summarizer and tone

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D74yU9itwyFXKSvjwYfVGC
@vercel

vercel Bot commented Oct 5, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
codflow-theme01 Skipped Skipped Oct 5, 2026 11:29pm UTC

This branch was previously deployed

1 inactive deployment
Preview — 64d57eea Deployed Oct 5, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant