docs(openspec): archive add-lead-dashboard
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
1 parent
a8d42a8a25
commit
61d17d5e38
12 files changed
+179
No files matched your search
@@ -0,0 +1,2 @@
|
||||
schema: spec-driven
|
||||
created: 2026-12-01
|
||||
@@ -0,0 +1,95 @@
|
||||
## Context
|
||||
|
||||
Approved product design: `docs/superpowers/specs/2026-12-01-lead-dashboard-design.md` (definitions, figures, access). This file fixes the technical contract so the services-counter, mobile-api and portal tasks can be built in parallel.
|
||||
|
||||
Facts the design relies on:
|
||||
- `event_lead.status` already holds OPEN / CONTACTED / QUALIFIED / WON / LOST (event-lead-capture). Only the current value is stored.
|
||||
- `event_lead.captured_at` and `updated_at` are `LocalDateTime.now()` in the services-counter JVM, i.e. wall time in the JVM's default zone (UTC in the containers). There is no zone column.
|
||||
- services-counter has no database tests; every existing test is a Mockito unit test.
|
||||
- Salesperson names live in services-system; mobile-api already resolves them per user id with a per-request map (`AdminLeadService.salesperson`).
|
||||
|
||||
## Decisions
|
||||
|
||||
### 1. Status history table
|
||||
|
||||
`service-counter.event_lead_status_change`:
|
||||
- columns `id` bigint PK auto, `company_id` bigint NOT NULL, `event_lead_id` bigint NOT NULL, `from_status` varchar(10) NULL, `to_status` varchar(10) NOT NULL, `changed_at` datetime NOT NULL, `changed_by` varchar(255) NULL;
|
||||
- key `idx_elsc_event_lead (event_lead_id, changed_at)` and key `idx_elsc_company_to_changed (company_id, to_status, changed_at)`.
|
||||
|
||||
`EventLeadService.capture` saves one row (null → initial status, `changed_at` = the event lead's `captured_at`, `changed_by` = doneBy) in the capture transaction. `update` saves one row when the requested status differs from the stored one (`changed_at` = the new `updated_at`). Entity `EventLeadStatusChange`, repository `EventLeadStatusChangeRepository`. Nothing deletes or updates these rows.
|
||||
|
||||
Backfill (`sql/02-status-change-backfill.sql`, idempotent: only event leads with no history rows):
|
||||
- one row null → OPEN at `captured_at`, `changed_by` = `captured_by`;
|
||||
- where `status <> 'OPEN'`, one row OPEN → status at `COALESCE(updated_at, captured_at)`, `changed_by` = `COALESCE(updated_by, captured_by)`.
|
||||
|
||||
### 2. Aggregate in Java over lean rows, not in SQL
|
||||
|
||||
services-counter runs three plain native queries with bind parameters and aggregates the rows in a pure Java class (`LeadDashboardCalculator`), which is unit-tested without a database:
|
||||
1. **Captures:** event leads with `captured_at` in [fromUtc, toUtc) and the company filter, joined to `event` for name and company: `event_lead.id, event_uuid, event name, company_id, salesperson_user_id, lead_type, status, captured_at`.
|
||||
2. **Wins:** event leads with `status = 'WON'` whose latest history row with `to_status = 'WON'` has `changed_at` in [fromUtc, toUtc): `event_lead.id, captured_at, won_at`.
|
||||
3. **Overdue:** `salesperson_user_id, COUNT(*)` for status not in (WON, LOST) and `next_follow_up_date < today`, grouped by salesperson.
|
||||
|
||||
Interests for the captures come from the existing `EventLeadInterestRepository.findByIdEventLeadIdIn`, in chunks of 1000 ids, and interest names from `InterestRepository`.
|
||||
|
||||
Rejected: one grouped SQL query per figure. Its correctness could only be checked against a live database (no DB tests here), and adding Testcontainers is a new build dependency for one screen.
|
||||
|
||||
`ponytail:` row volume is one row per capture in the period. Fine for thousands per period; move the sums into SQL when one company captures hundreds of thousands of leads a year.
|
||||
|
||||
### 3. Time zone
|
||||
|
||||
mobile-api turns the period into dates; services-counter turns `[from 00:00, to+1 00:00)` in Asia/Kuala_Lumpur into the JVM default zone's wall time for the queries, and turns each stored time back to a Malaysian date for bucketing. "Today" for overdue is today in Asia/Kuala_Lumpur.
|
||||
|
||||
### 4. services-counter contract
|
||||
|
||||
`POST /counter/dashboard/leads` (route already under `/counter/**`), body:
|
||||
|
||||
```json
|
||||
{ "companyId": 2, "from": "2026-11-01", "to": "2026-11-30", "bucket": "DAY" }
|
||||
```
|
||||
|
||||
`companyId` null = all companies. `bucket` is `DAY` or `MONTH`. `from` after `to` → 400 `INVALID_PERIOD`. Response:
|
||||
|
||||
```json
|
||||
{
|
||||
"captures": 10, "newLeads": 6, "wonInPeriod": 3, "medianDaysToWin": 5, "overdueFollowUps": 4,
|
||||
"funnel": { "OPEN": 3, "CONTACTED": 1, "QUALIFIED": 1, "WON": 3, "LOST": 2 },
|
||||
"trend": [ { "bucket": "2026-11-01", "captures": 2, "wins": 0 } ],
|
||||
"events": [ { "eventUuid": "123", "name": "KL Expo", "companyId": 2, "captures": 10, "newLeads": 6, "won": 3 } ],
|
||||
"salespeople": [ { "userId": 7, "assigned": 4, "worked": 3, "won": 1, "lost": 1, "overdue": 2 } ],
|
||||
"interests": [ { "interestId": 5, "name": "Cookware", "captures": 4, "won": 1 } ]
|
||||
}
|
||||
```
|
||||
|
||||
- `medianDaysToWin` is null when there are no wins; with an even count it is the lower middle value (whole days).
|
||||
- `trend` lists every bucket in the period, zero-filled; a month bucket is the month's first day.
|
||||
- `events` is ordered by captures descending, then name; `salespeople` by assigned descending, with `userId` null for Unassigned; `salespeople` also includes a salesperson with overdue follow-ups but no captures in the period (assigned 0). `interests` by captures descending, then name.
|
||||
- `eventUuid` is a string (JavaScript loses precision on snowflake ids).
|
||||
|
||||
Rates are not sent; the portal divides.
|
||||
|
||||
### 5. mobile-api contract
|
||||
|
||||
`GET /api/admin/dashboard/leads?from=2026-11-01&to=2026-11-30&companyId=2` under `@AdminModule("BO_DASHBOARD")`:
|
||||
- `from`/`to` optional; when absent, from = first day of the current Malaysian month, to = today (Malaysia).
|
||||
- Bad date format, from after to, or a range of more than 731 days (two years) → 400 `INVALID_PERIOD` (ProblemDetail: `code`, `detail`). The cap keeps one request from building an unbounded bucket list in services-counter, which also refuses a range over 731 days.
|
||||
- bucket = `DAY` when `to - from + 1 <= 62` days, else `MONTH`.
|
||||
- company from `AdminCompanyScope.scope(caller, companyId)`.
|
||||
- Response: the counter response plus `from`, `to`, `bucket`, and each salesperson row gains `name` (the user's name, or null for Unassigned and for a user that no longer exists). Salesperson names are resolved with the existing per-request map pattern.
|
||||
|
||||
### 6. Module
|
||||
|
||||
`service-system.module` row `(40050000, 'BO_DASHBOARD', 'Dashboard', 'BO', 'M', 40000000, '/', 'LayoutDashboard')`. No role grant: super admins grant it under Roles. Id 40050000 sorts it first in the sidebar, which orders by module id. The portal's route gate (`ROUTE_MODULES`) does not list `/`: the home page itself decides between the dashboard and the welcome, using `hasModule("BO_DASHBOARD")`.
|
||||
|
||||
### 7. Portal
|
||||
|
||||
- `recharts` added to `package.json`; `app/components/ui/chart.tsx` copied from babyboo's portal.
|
||||
- `app/lib/services/adminDashboard.ts`: types for decision 5 and `getLeadDashboard({from, to, companyId})`.
|
||||
- `app/page.tsx`: welcome for users without the module; otherwise the dashboard with a period control (This month / Last month / Custom with the existing date picker), the company picker for super admins (via `useCompanyScope`), tiles, funnel bars, a recharts line or bar chart of captures and wins, and three tables (cards below `md`). Event rows link to `/event-leads/{eventUuid}`. The Company column on the event table shows only when `showCompanyColumn`.
|
||||
- Rates show as whole percent; a null median or zero captures shows "–".
|
||||
- All labels are message keys with English defaults, as on other screens.
|
||||
|
||||
## Risks
|
||||
|
||||
- Backfilled history times are approximate (deployment notes say so).
|
||||
- A lead whose status was set by a direct DB edit has no history row for that change; the dashboard then misses that win. Nothing in the app does this.
|
||||
- `captured_at` stored in the JVM zone: if production pods ever run in a different zone from when rows were written, older rows shift. Same risk already exists for every listing.
|
||||
@@ -0,0 +1,33 @@
|
||||
## Why
|
||||
|
||||
Co-Lite exists to generate leads for INS and CV marketing. Managers need to see which events, salespeople and interests produce leads and which of those leads convert (status WON). Today the portal home page is a welcome line, and the system keeps only each event lead's current status, so it cannot say when a lead was won or how long it took. Approved design: `docs/superpowers/specs/2026-12-01-lead-dashboard-design.md`.
|
||||
|
||||
## What Changes
|
||||
|
||||
- Every event-lead status change is recorded with its time and who made it. Capture records the first status. Existing event leads are backfilled with approximate times.
|
||||
- A lead dashboard on the portal home page for a chosen period (this month, last month, or a custom range):
|
||||
- tiles: captures, new leads, won in period, conversion rate, median days to win, overdue follow-ups;
|
||||
- a status funnel;
|
||||
- a trend of captures and wins;
|
||||
- tables by event, by salesperson and by interest.
|
||||
- A new back-office module `BO_DASHBOARD` gates the dashboard. Users without it keep the welcome page.
|
||||
- Company scoping as on every other admin screen.
|
||||
- The admin portal gains the `recharts` dependency (already used by babyboo's portal) for the trend chart.
|
||||
|
||||
## Capabilities
|
||||
|
||||
### New Capabilities
|
||||
|
||||
- `lead-dashboard`: the dashboard, its definitions, period rules, access and company scope.
|
||||
|
||||
### Modified Capabilities
|
||||
|
||||
- `event-lead-capture`: adds the status change history requirement.
|
||||
|
||||
## Impact
|
||||
|
||||
- Database `service-counter`: new table `event_lead_status_change`, a backfill, and an index on `event_lead`. `service-system`: one `module` row. SQL in `sql/`, mirrored in `local/seed/03-colite.sql`.
|
||||
- `solvway-services-counter`: history writes on capture and edit; a new dashboard endpoint.
|
||||
- `solvway-mobile-api`: `GET /api/admin/dashboard/leads`.
|
||||
- `solvway-admin-portal`: home page, sidebar link, `recharts`.
|
||||
- `docs/deployment.md`: the new SQL files.
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
## ADDED Requirements
|
||||
|
||||
### Requirement: Event lead status history
|
||||
|
||||
The system SHALL record every change of an event lead's status with the previous status, the new status, the time and the user who made it. Capturing an event lead SHALL record its first status with no previous status, at the capture time. An edit that leaves the status unchanged SHALL record nothing. The history SHALL never be edited or deleted through the application.
|
||||
|
||||
#### Scenario: Capture records the first status
|
||||
|
||||
- **WHEN** staff capture a lead at an event with no status chosen
|
||||
- **THEN** the history holds one entry from no status to OPEN at the capture time, by that user
|
||||
|
||||
#### Scenario: Status change recorded
|
||||
|
||||
- **GIVEN** an OPEN event lead
|
||||
- **WHEN** staff change its status to CONTACTED and later to WON
|
||||
- **THEN** the history holds OPEN to CONTACTED and CONTACTED to WON, each with its time and user
|
||||
|
||||
#### Scenario: Edit without a status change
|
||||
|
||||
- **GIVEN** a CONTACTED event lead
|
||||
- **WHEN** staff change only its temperature and notes
|
||||
- **THEN** no history entry is added
|
||||
@@ -0,0 +1,152 @@
|
||||
## ADDED Requirements
|
||||
|
||||
### Requirement: Dashboard access
|
||||
|
||||
The system SHALL show the lead dashboard on the back-office home page to users granted the `BO_DASHBOARD` module, and SHALL show users without it the welcome message instead of a not-authorised page. The dashboard endpoint SHALL answer 403 to a user without `BO_DASHBOARD`. The sidebar SHALL show a Dashboard link to users with the module.
|
||||
|
||||
#### Scenario: Granted user
|
||||
|
||||
- **GIVEN** a role holding `BO_DASHBOARD` is assigned to `sales1`
|
||||
- **WHEN** `sales1` signs in
|
||||
- **THEN** the home page shows the lead dashboard and the sidebar shows Dashboard
|
||||
|
||||
#### Scenario: User without the module
|
||||
|
||||
- **WHEN** a user without `BO_DASHBOARD` opens the home page or calls the dashboard endpoint
|
||||
- **THEN** the page shows the welcome message and the endpoint responds 403
|
||||
|
||||
### Requirement: Dashboard period
|
||||
|
||||
The dashboard SHALL cover a period of whole days in Malaysia time (Asia/Kuala_Lumpur): this month up to today (the default), last month, or a custom range from one date to another, both included. A range whose start is after its end, or that spans more than 731 days, SHALL be refused with a message. The trend SHALL be counted by day for a period of up to 62 days and by month for a longer one, and SHALL list every day or month in the period, with zero where nothing happened.
|
||||
|
||||
#### Scenario: Default period
|
||||
|
||||
- **WHEN** a user opens the dashboard on 2026-12-10
|
||||
- **THEN** it covers 2026-12-01 to 2026-12-10, with one trend point per day
|
||||
|
||||
#### Scenario: Long range counted by month
|
||||
|
||||
- **WHEN** the user picks 2026-01-01 to 2026-12-31
|
||||
- **THEN** the trend has one point per month, January to December
|
||||
|
||||
#### Scenario: Day boundary in Malaysia time
|
||||
|
||||
- **GIVEN** a lead captured at 2026-11-30 23:30 Malaysia time
|
||||
- **WHEN** the user views 2026-11-01 to 2026-11-30
|
||||
- **THEN** the capture is counted on 30 November
|
||||
|
||||
#### Scenario: Reversed range
|
||||
|
||||
- **WHEN** the user picks a start date after the end date
|
||||
- **THEN** the dashboard shows a message and no figures, and the endpoint responds 400
|
||||
|
||||
#### Scenario: Range too long
|
||||
|
||||
- **WHEN** the user picks 2024-01-01 to 2026-12-31
|
||||
- **THEN** the dashboard shows a message and no figures, and the endpoint responds 400
|
||||
|
||||
### Requirement: Capture figures
|
||||
|
||||
For the chosen period the dashboard SHALL show the captures (event leads captured in the period, so a person captured at two events counts twice), the new leads (captures whose lead type is NEW), the conversion rate (the share of the period's captures whose current status is WON, shown as a dash when there are no captures), a funnel of the period's captures by current status (OPEN, CONTACTED, QUALIFIED, WON, LOST) and the captures in the trend.
|
||||
|
||||
#### Scenario: Conversion of the period's captures
|
||||
|
||||
- **GIVEN** 10 leads captured in November, 3 of them now WON and 2 LOST
|
||||
- **WHEN** the user views November
|
||||
- **THEN** captures show 10, conversion rate 30%, and the funnel shows WON 3 and LOST 2
|
||||
|
||||
#### Scenario: No captures
|
||||
|
||||
- **WHEN** the user views a period with no captures
|
||||
- **THEN** captures show 0 and the conversion rate shows a dash
|
||||
|
||||
### Requirement: Win figures
|
||||
|
||||
The dashboard SHALL count as won in the period every event lead whose current status is WON and whose latest change to WON falls in the period, whenever it was captured. It SHALL show that count, the wins in the trend, and the median of whole days from capture to the latest change to WON over those event leads, shown as a dash when there are none.
|
||||
|
||||
#### Scenario: Win of an older capture
|
||||
|
||||
- **GIVEN** a lead captured in October and changed to WON on 5 November
|
||||
- **WHEN** the user views November
|
||||
- **THEN** won in period counts it and the November captures do not
|
||||
|
||||
#### Scenario: Reopened lead
|
||||
|
||||
- **GIVEN** a lead changed to WON on 3 November, back to QUALIFIED on 4 November, and to WON again on 20 November
|
||||
- **WHEN** the user views 1 to 10 November
|
||||
- **THEN** won in period does not count it, because its latest change to WON is 20 November
|
||||
|
||||
#### Scenario: Median days to win
|
||||
|
||||
- **GIVEN** three leads won in November, 2, 5 and 30 days after capture
|
||||
- **WHEN** the user views November
|
||||
- **THEN** median days to win shows 5
|
||||
|
||||
### Requirement: Overdue follow-ups
|
||||
|
||||
The dashboard SHALL show the event leads that are not WON or LOST and whose next follow-up date is before today in Malaysia time, whatever the chosen period.
|
||||
|
||||
#### Scenario: Overdue counted regardless of period
|
||||
|
||||
- **GIVEN** an OPEN lead captured in August with next follow-up 2026-12-01
|
||||
- **WHEN** the user views November on 2026-12-05
|
||||
- **THEN** overdue follow-ups count it
|
||||
|
||||
### Requirement: Breakdown by event
|
||||
|
||||
The dashboard SHALL list each event with captures in the period, most captures first, with its captures, new leads, won and conversion rate, and each row SHALL open that event's leads listing.
|
||||
|
||||
#### Scenario: Event drill-down
|
||||
|
||||
- **WHEN** the user selects an event row
|
||||
- **THEN** that event's leads listing opens
|
||||
|
||||
### Requirement: Breakdown by salesperson
|
||||
|
||||
The dashboard SHALL list, for the period's captures, each salesperson's assigned, worked (status other than OPEN), won, lost and conversion rate, with their current overdue follow-ups, and SHALL show captures with no salesperson as Unassigned.
|
||||
|
||||
#### Scenario: Salesperson row
|
||||
|
||||
- **GIVEN** in November `sales1` was assigned 4 captures: 1 OPEN, 1 CONTACTED, 1 WON and 1 LOST
|
||||
- **WHEN** the user views November
|
||||
- **THEN** sales1's row shows assigned 4, worked 3, won 1, lost 1 and conversion rate 25%
|
||||
|
||||
#### Scenario: Unassigned captures
|
||||
|
||||
- **GIVEN** 2 November captures have no salesperson
|
||||
- **WHEN** the user views November
|
||||
- **THEN** an Unassigned row shows assigned 2
|
||||
|
||||
### Requirement: Breakdown by interest
|
||||
|
||||
The dashboard SHALL list each interest with the period's captures tagged with it and how many of them are now WON. A capture with two interests SHALL count under both.
|
||||
|
||||
#### Scenario: Two interests
|
||||
|
||||
- **GIVEN** a November capture tagged `Cookware` and `Kitchen appliances`, now WON
|
||||
- **WHEN** the user views November
|
||||
- **THEN** both interests count 1 capture and 1 won
|
||||
|
||||
### Requirement: Phone width
|
||||
|
||||
The dashboard SHALL be usable on a 360 px wide screen without sideways scrolling.
|
||||
|
||||
#### Scenario: Phone
|
||||
|
||||
- **WHEN** a user opens the dashboard at 360 px
|
||||
- **THEN** the tiles stack and the breakdowns show as cards
|
||||
|
||||
### Requirement: Dashboard company scope
|
||||
|
||||
The dashboard SHALL count only the records of the caller's company for company staff. A super admin SHALL see every company's records by default and SHALL be able to narrow the dashboard to one company with the company picker; while all companies are shown, the by-event list SHALL show each event's company.
|
||||
|
||||
#### Scenario: Staff see their company
|
||||
|
||||
- **GIVEN** leads captured at INS and at CV events in November
|
||||
- **WHEN** an INS user with `BO_DASHBOARD` views November
|
||||
- **THEN** every figure counts INS records only
|
||||
|
||||
#### Scenario: Super admin picks a company
|
||||
|
||||
- **WHEN** a super admin picks CV in the company picker
|
||||
- **THEN** every figure counts CV records only
|
||||
@@ -0,0 +1,19 @@
|
||||
-- Co-Lite change add-lead-dashboard: event lead status history (design decision 1).
|
||||
-- Target: `service-counter`. Additive only. Run before the new images go live (services-counter writes this table), then 02.
|
||||
USE `service-counter`;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `event_lead_status_change` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||
`company_id` bigint NOT NULL,
|
||||
`event_lead_id` bigint NOT NULL,
|
||||
`from_status` varchar(10) NULL,
|
||||
`to_status` varchar(10) NOT NULL,
|
||||
`changed_at` datetime NOT NULL,
|
||||
`changed_by` varchar(255) NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_elsc_event_lead` (`event_lead_id`, `changed_at`),
|
||||
KEY `idx_elsc_company_to_changed` (`company_id`, `to_status`, `changed_at`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
-- Dashboard capture query: captures by company and capture time.
|
||||
ALTER TABLE `event_lead` ADD KEY `idx_event_lead_company_captured` (`company_id`, `captured_at`);
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
-- Co-Lite change add-lead-dashboard: history for event leads captured before the history existed.
|
||||
-- Target: `service-counter`. Idempotent: touches only event leads with no history row. Times are approximate:
|
||||
-- the first status at capture, the current status (if not OPEN) at the last update.
|
||||
USE `service-counter`;
|
||||
|
||||
INSERT INTO `event_lead_status_change` (`company_id`, `event_lead_id`, `from_status`, `to_status`, `changed_at`, `changed_by`)
|
||||
SELECT el.company_id, el.id, NULL, 'OPEN', el.captured_at, el.captured_by
|
||||
FROM `event_lead` el
|
||||
WHERE NOT EXISTS (SELECT 1 FROM `event_lead_status_change` s WHERE s.event_lead_id = el.id);
|
||||
|
||||
INSERT INTO `event_lead_status_change` (`company_id`, `event_lead_id`, `from_status`, `to_status`, `changed_at`, `changed_by`)
|
||||
SELECT el.company_id, el.id, 'OPEN', el.status, COALESCE(el.updated_at, el.captured_at), COALESCE(el.updated_by, el.captured_by)
|
||||
FROM `event_lead` el
|
||||
WHERE el.status <> 'OPEN'
|
||||
AND NOT EXISTS (SELECT 1 FROM `event_lead_status_change` s WHERE s.event_lead_id = el.id AND s.to_status = el.status);
|
||||
@@ -0,0 +1,7 @@
|
||||
-- Co-Lite change add-lead-dashboard: the Dashboard back-office module (area BO).
|
||||
-- Target: `service-system`.`module`. Additive only. Run once, after the release package.
|
||||
-- No role grant: super admins see every module; they grant BO_DASHBOARD to other roles under Roles.
|
||||
USE `service-system`;
|
||||
|
||||
INSERT INTO `module` (`id`, `name`, `desc`, `area`, `type`, `parent`, `url`, `icon_name`) VALUES
|
||||
(40050000, 'BO_DASHBOARD', 'Dashboard', 'BO', 'M', 40000000, '/', 'LayoutDashboard');
|
||||
@@ -0,0 +1,8 @@
|
||||
-- Co-Lite change add-lead-dashboard: rollback. Drops the status history (its data is lost).
|
||||
USE `service-system`;
|
||||
DELETE FROM `modules_roles` WHERE `module_id` = 40050000;
|
||||
DELETE FROM `module` WHERE `id` = 40050000;
|
||||
|
||||
USE `service-counter`;
|
||||
ALTER TABLE `event_lead` DROP KEY `idx_event_lead_company_captured`;
|
||||
DROP TABLE IF EXISTS `event_lead_status_change`;
|
||||
@@ -0,0 +1,63 @@
|
||||
# Tasks
|
||||
|
||||
Design: `design.md` (technical contract) and `docs/superpowers/specs/2026-12-01-lead-dashboard-design.md` (product).
|
||||
|
||||
Waves:
|
||||
- Wave 0 (serial, controller): 1.1 and 1.2 touch hotspots (SQL, seed, `package.json`).
|
||||
- Wave 1 (parallel, 3 implementers): 2.1, 3.1 and 4.1 build against the fixed contracts in design decisions 4 and 5. Scopes do not overlap: each touches one module.
|
||||
- Wave 2 (serial, controller): 5.1.
|
||||
|
||||
## 1. Data, module and chart dependency
|
||||
|
||||
- [x] 1.1 SQL `sql/01..03` and `99-rollback.sql`; mirror 01 and 03 in `local/seed/03-colite.sql` (02 has nothing to backfill on an empty volume); apply 01, 02 and 03 to the local database.
|
||||
- Depends on: none
|
||||
- Scope: `local/seed/**`, `openspec/changes/add-lead-dashboard/sql/**`
|
||||
- Verify: `SELECT` shows the table, the index, the backfilled rows and the module row.
|
||||
- [x] 1.2 Portal: add `recharts` (same major as babyboo's portal) with `npm install`, and copy babyboo's `app/components/ui/chart.tsx`.
|
||||
- Depends on: none
|
||||
- Scope: `solvway-admin-portal/package.json`, `solvway-admin-portal/package-lock.json`, `solvway-admin-portal/app/components/ui/chart.tsx`
|
||||
- Verify: `cd solvway-admin-portal && npm run lint && npx tsc --noEmit && npx vitest run`
|
||||
|
||||
## 2. services-counter
|
||||
|
||||
- [x] 2.1 Status history writes (decision 1) and the dashboard endpoint (decisions 2 to 4).
|
||||
- Tests first:
|
||||
- capture saves one history row null → initial status at the capture time, by doneBy;
|
||||
- update saves one row when the status changes and none when it stays;
|
||||
- the calculator, from in-memory rows: captures, new leads, funnel, won in period (latest WON only), median days (odd, even, none), overdue per salesperson, Unassigned, salesperson with overdue only, interest double-count, event ordering, zero-filled day and month trend, Malaysia day boundary from JVM-zone times;
|
||||
- the endpoint rejects from after to with 400 `INVALID_PERIOD` and passes a null company as all companies.
|
||||
- Scope: `solvway-services-counter/src/**`
|
||||
- Verify: `mvn -T 1C -q -pl solvway-services-counter verify`
|
||||
|
||||
## 3. mobile-api
|
||||
|
||||
- [x] 3.1 `GET /api/admin/dashboard/leads` (decision 5).
|
||||
- Tests first:
|
||||
- default period is this Malaysian month to today; DAY bucket up to 62 days, MONTH above;
|
||||
- bad date and from after to → 400 `INVALID_PERIOD`;
|
||||
- staff are scoped to their company, a super admin's `companyId` is passed through, null for all;
|
||||
- salesperson names resolved, null for Unassigned and for a missing user;
|
||||
- the endpoint is gated by `BO_DASHBOARD` (aspect test with the annotation).
|
||||
- Scope: `solvway-mobile-api/src/**`
|
||||
- Verify: `mvn -T 1C -q -pl solvway-mobile-api verify`
|
||||
|
||||
## 4. Portal
|
||||
|
||||
- [x] 4.1 Home page dashboard (decision 7).
|
||||
- Tests first:
|
||||
- without `BO_DASHBOARD` the welcome shows and the dashboard API is not called;
|
||||
- with it: tiles, funnel, chart container, the three tables with Unassigned, whole-percent rates and "–" for null median and zero captures;
|
||||
- period presets send the right `from`/`to`; a reversed custom range shows the error message;
|
||||
- a super admin's picker sends `companyId` and shows the Company column only for all companies;
|
||||
- an event row links to `/event-leads/{eventUuid}`;
|
||||
- the hard-coded copy sweep stays green (labels as message keys).
|
||||
- Includes the Next proxy route `app/api/dashboard/leads/route.ts` (added after review: the first plan left it out).
|
||||
- Scope: `solvway-admin-portal/app/api/dashboard/**`, `solvway-admin-portal/app/page.tsx`, `solvway-admin-portal/app/page*.test.tsx`, `solvway-admin-portal/app/components/dashboard/**`, `solvway-admin-portal/app/lib/services/adminDashboard*.ts`, `solvway-admin-portal/app/lib/i18n/defaultMessages.ts`
|
||||
- Verify: `cd solvway-admin-portal && npm run lint && npx tsc --noEmit && npx vitest run`
|
||||
|
||||
## 5. Release
|
||||
|
||||
- [x] 5.1 `docs/deployment.md` lists the SQL; live check against the local stack (seeded INS and CV event leads with status changes), and Playwright at 1280 and 360 px for a granted user, a user without the module, and a super admin switching company.
|
||||
- Depends on: 1.1 to 4.1
|
||||
- Scope: `docs/deployment.md`, `openspec/changes/add-lead-dashboard/tasks.md`
|
||||
- Verify: full `mvn -T 1C -q verify` of the three touched Maven modules and the portal verify.
|
||||
Reference in new issue
Block a user