Modules
Customers
Customers with derived segments, at-risk detection, spend history, notes and a profile page.
Customers carry city, createdAt, tags, marketing, 12 months of monthlySpend and notes with author and date. The stored segment is only vip, regular or new; customerSegment() derives atRisk for active repeat buyers with no recent order.
Files
File | Role |
|---|---|
pages/e-commerce/customers/index.vue | The list. |
pages/e-commerce/customers/[id].vue | The profile. |
composables/useCustomers.ts | Customers and save, remove, addNote, removeNote. |
types/models/customers.ts | Customers and notes. |
config/customers.config.ts | Views, tags, the at-risk window and segment colours. |
utils/customers.ts | Pure rules, unit tested. |
components/pages/customers/ | CustomerQuickView, CustomerOrdersTable, CustomerSegmentChip, CustomerSpendCard, CustomerProfileCard, CustomerTopProducts. |
Data
useCustomers() loads its data through a CustomersProvider (types/models/customers.ts); the demo uses createCustomersMockProvider(). Write a provider that calls your API and make it the default: the pages do not change. See Connect your API.
Permissions
The list and the profile need customers.view.
Configuration
CUSTOMER_VIEWS
The views: all, VIP, new and at risk.
const CUSTOMER_VIEWS: CustomerView[]
CUSTOMER_AT_RISK_DAYS
Days without an order before a repeat buyer is at risk.
const CUSTOMER_AT_RISK_DAYS: 60
CUSTOMER_TAGS
Tag ids; labels live in customers.tags.<id>.
const CUSTOMER_TAGS: CustomerTag[]
CUSTOMER_SEGMENT_COLORS
The colour of each segment.
const CUSTOMER_SEGMENT_COLORS: Record<CustomerSegment, string>
Rules
Pure functions in utils/, unit tested in tests/unit/. Statuses and segments are derived from the stored data, never stored themselves.
customerSegment()
The derived segment.
customerSegment(customer: ActivityFields, now: Date): CustomerSegment
customerSpendTrend()
The spend trend (only with 12 months of history).
customerSpendTrend(customer: Pick<Customer, 'monthlySpend'>): number
customerOrderInterval()
Days between orders.
customerOrderInterval(customer: Pick<Customer, 'createdAt' | 'lastOrder' | 'orders'>): number | undefined
customerNextOrderIn()
Days to the next expected order.
customerNextOrderIn(customer: Pick<Customer, 'createdAt' | 'lastOrder' | 'orders' | 'status'>, now: Date): number | undefined
customerAttention()
Customers to win back.
customerAttention(customers: Customer[], now: Date): { atRisk: number; value: number; }atRiskvalueHow it works
- Operational screens have no KPI cards: analytics live in the dashboards. A warning
BaseAlertappears only when something needs attention, and its action filters the table. - Views are a
BaseToggleGroup compact fit; inactive rows are dimmed; a row click opensCustomerQuickView. - The profile shows five stats (spend and trend, orders per month, average order against the store, last order, expected next order), a monthly spend
BaseSparkline type="column",CustomerOrdersTable(reusingOrderProductStackandOrderFulfillment), the facts, top products andCustomerNotes. - Date-only fields such as
lastOrderrender throughuseDayLabel()after mount. - Table
selectfilters withmultiplealso match items whose value is an array, as tags are.