Modules

Customers

Customers with derived segments, at-risk detection, spend history, notes and a profile page.

composables/useCustomers.ts
View in the demo

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.vueThe list.
pages/e-commerce/customers/[id].vueThe profile.
composables/useCustomers.tsCustomers and save, remove, addNote, removeNote.
types/models/customers.tsCustomers and notes.
config/customers.config.tsViews, tags, the at-risk window and segment colours.
utils/customers.tsPure 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.

config/customers.config.ts
const CUSTOMER_VIEWS: CustomerView[]

CUSTOMER_AT_RISK_DAYS

Days without an order before a repeat buyer is at risk.

config/customers.config.ts
const CUSTOMER_AT_RISK_DAYS: 60

CUSTOMER_TAGS

Tag ids; labels live in customers.tags.<id>.

config/customers.config.ts
const CUSTOMER_TAGS: CustomerTag[]

CUSTOMER_SEGMENT_COLORS

The colour of each segment.

config/customers.config.ts
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.

utils/customers.ts
customerSegment(customer: ActivityFields, now: Date): CustomerSegment

customerSpendTrend()

The spend trend (only with 12 months of history).

utils/customers.ts
customerSpendTrend(customer: Pick<Customer, 'monthlySpend'>): number

customerOrderInterval()

Days between orders.

utils/customers.ts
customerOrderInterval(customer: Pick<Customer, 'createdAt' | 'lastOrder' | 'orders'>): number | undefined

customerNextOrderIn()

Days to the next expected order.

utils/customers.ts
customerNextOrderIn(customer: Pick<Customer, 'createdAt' | 'lastOrder' | 'orders' | 'status'>, now: Date): number | undefined

customerAttention()

Customers to win back.

utils/customers.ts
customerAttention(customers: Customer[], now: Date): { atRisk: number; value: number; }
ReturnsatRiskvalue

How it works

  • Operational screens have no KPI cards: analytics live in the dashboards. A warning BaseAlert appears only when something needs attention, and its action filters the table.
  • Views are a BaseToggleGroup compact fit; inactive rows are dimmed; a row click opens CustomerQuickView.
  • 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 (reusing OrderProductStack and OrderFulfillment), the facts, top products and CustomerNotes.
  • Date-only fields such as lastOrder render through useDayLabel() after mount.
  • Table select filters with multiple also match items whose value is an array, as tags are.
© 2026 melsami UI.
Developer documentation for melsami UI.