docs: archive add-custom-html-block and add-lead-notifications
Sync their spec deltas into landing-pages and the new lead-notifications spec, and point the deployment SQL paths at the archive folders. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
This commit is contained in:
1 parent
d602cca2cd
commit
5b11e90303
19 files changed
+229
-7
No files matched your search
@@ -0,0 +1,2 @@
|
||||
schema: spec-driven
|
||||
created: 2026-12-02
|
||||
@@ -0,0 +1,41 @@
|
||||
# Design
|
||||
|
||||
The full design is `docs/superpowers/specs/2026-12-02-custom-html-block-design.md` (approved 2026-12-02). This file records the technical decisions.
|
||||
|
||||
## Context
|
||||
|
||||
- Pages store their blocks as JSON in `cms_page.blocks`. `CmsBlockValidator` in services-counter checks the blocks, and mobile-api passes them to the portal unchanged.
|
||||
- The portal's `middleware.ts` gives every page and API response a per-request nonce Content-Security-Policy. An `srcdoc` frame would inherit that policy and block the pasted scripts, inline styles and CDN links. So the pasted HTML needs its own response with its own policy.
|
||||
- The public page `/p/[company]/[slug]` renders on the server. `routeGuard.isPublicPath` admits only `^/p/[^/]+/[^/]+$` today.
|
||||
|
||||
## Goals / Non-Goals
|
||||
|
||||
**Goals:**
|
||||
- Pasted HTML renders as designed.
|
||||
- It runs with an opaque origin on every path, including a direct visit to the frame address.
|
||||
|
||||
**Non-Goals:**
|
||||
- SEO for the framed content.
|
||||
- Working forms inside it.
|
||||
- An HTML editor.
|
||||
|
||||
## Decisions
|
||||
|
||||
1. **Route handlers, not pages.** `app/p/[company]/[slug]/frame/[block]/route.ts` and `app/pages/[id]/preview/frame/[block]/route.ts` return `text/html` directly. They reuse the server helpers that the public page (published read) and the preview (admin read with the session token) already use.
|
||||
2. **Sandbox in two places.**
|
||||
- The response header: `Content-Security-Policy: sandbox allow-scripts allow-popups allow-popups-to-escape-sandbox; frame-ancestors 'self'`. This covers a direct visit.
|
||||
- The `<iframe sandbox="allow-scripts allow-popups allow-popups-to-escape-sandbox">` attribute. This covers embedding.
|
||||
- There is no `default-src` restriction, so the AI's CDN scripts, fonts and images load.
|
||||
3. **Middleware skips the frame routes.** It returns early, with no nonce policy, for paths ending `/frame/<n>` under `/p/` and `/pages/<id>/preview/`. The preview route still checks the session itself; the middleware's route guard still runs before the early return, so an unsigned preview request is redirected to sign in.
|
||||
4. **Height script.**
|
||||
- The handler inserts a fixed script before `</body>`, or appends it when there is no `</body>`. The script posts `{type: "colite-frame-height", height}` to `parent` on load, on resize and through a `ResizeObserver` on `document.documentElement`.
|
||||
- The parent accepts a message only when `event.source` is that iframe's `contentWindow`. It clamps the height to 100–20,000 px, starting at 600.
|
||||
5. **Not-found.** The public handler answers 404 with an empty body for every miss: unknown company or slug, a draft page, a bad index or a non-HTML block. The same rule holds on the public page.
|
||||
6. **`hideHeader`.** A `cms_page.hide_header TINYINT(1) NOT NULL DEFAULT 0` column carried through the counter DTO, the mobile-api admin request and the public page response. `LandingPage` omits the header and the `<h1>` when it is on.
|
||||
7. **Limits.** `HTML` blocks allow 200,000 characters, about 200 KB for a large AI page. The existing 30-block cap stands. The portal body limit for page saves is checked and raised if it is below the largest page: 30 × 200,000 characters.
|
||||
|
||||
## Risks / Trade-offs
|
||||
|
||||
- **Misleading content:** staff with `BO_PAGES` can publish misleading content, such as a fake form. The frame contains it, saves are audited, and the role is granted by super admins only.
|
||||
- **Cost of each frame:** each HTML block is one more request per visit. Pages have at most 30 blocks.
|
||||
- **Relative addresses:** a relative asset path in pasted HTML (such as `/logo.png`) resolves against the Co-Lite site and breaks. The editor note tells staff to use full `https://` addresses for images.
|
||||
@@ -0,0 +1,54 @@
|
||||
# Proposal
|
||||
|
||||
## Why
|
||||
|
||||
Marketing staff want to design a landing page with an AI tool and paste the result in, so a page can look like a designed site instead of only the built-in blocks. The INS page is the first case: rebuilt from blocks, it does not match the design of the INS proof of concept (`~/Projects/ins-landing-page`). On 2026-12-02 the owner chose to show pasted HTML in a sealed frame (option 1). Design approved 2026-12-02: `docs/superpowers/specs/2026-12-02-custom-html-block-design.md`.
|
||||
|
||||
## What Changes
|
||||
|
||||
- **New block type `HTML` (Custom HTML).**
|
||||
- Staff with `BO_PAGES` paste HTML, at most 200,000 characters per block.
|
||||
- Scripts are allowed in this block only. Every other block keeps refusing scripts.
|
||||
- **Sealed frame.**
|
||||
- The public page shows each HTML block in an `<iframe sandbox>` loaded from its own address: `/p/<company>/<slug>/frame/<block>`.
|
||||
- That response carries a `sandbox` Content-Security-Policy, so the pasted HTML runs with an opaque origin even when the address is opened directly. It cannot reach cookies, Co-Lite APIs, the page around it or top-level navigation, and its forms do not submit.
|
||||
- Only Co-Lite pages may frame it (`frame-ancestors 'self'`).
|
||||
- Staff preview a draft through a signed-in twin: `/pages/<id>/preview/frame/<block>`.
|
||||
- **Frame height:** a small script is added to the served HTML. It reports the document height, so the frame grows to fit.
|
||||
- **Hide page header:** a page option that hides the company header and the page title, so a page made of pasted HTML looks exactly as designed.
|
||||
- **Editor:**
|
||||
- "Add Custom HTML" with a monospace text box and a character counter;
|
||||
- a note that forms in the pasted HTML don't send;
|
||||
- the "Hide page header" switch.
|
||||
|
||||
## Capabilities
|
||||
|
||||
### New Capabilities
|
||||
|
||||
None.
|
||||
|
||||
### Modified Capabilities
|
||||
|
||||
- `landing-pages`:
|
||||
- the block types gain `HTML`, with its limit;
|
||||
- the scripts rule exempts it;
|
||||
- a new requirement covers how it is served sealed and sized;
|
||||
- the page gains the "hide header" option;
|
||||
- the editor gains the Custom HTML block and the switch.
|
||||
|
||||
## Impact
|
||||
|
||||
- **services-counter:**
|
||||
- `CmsBlockValidator` accepts `HTML` (200,000 characters, no script check);
|
||||
- `cms_page` gets a `hide_header` column and the page DTO carries it.
|
||||
- **SQL:** `sql/01-hide-header.sql` (DDL), `sql/02-html-block-labels.sql` (labels) and `sql/99-rollback.sql`. Mirror 01 into `local/seed/`.
|
||||
- **mobile-api:** the admin page request and the public page response carry `hideHeader`. Blocks already pass through unchanged.
|
||||
- **Portal:**
|
||||
- two frame route handlers;
|
||||
- `middleware.ts` leaves the frame routes without the nonce policy;
|
||||
- `routeGuard` admits the public frame path;
|
||||
- `CmsBlocks` renders the frame and honours `hideHeader`;
|
||||
- the editor;
|
||||
- labels, with Chinese.
|
||||
- **Gateway:** unchanged.
|
||||
- **Dependencies:** none.
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
## MODIFIED Requirements
|
||||
|
||||
### Requirement: A Page Is An Ordered List Of Typed Blocks
|
||||
|
||||
A page SHALL belong to one company and have a slug, a title, an optional meta description, a status (Draft or Published), a "hide header" flag that defaults to off, and an ordered list of zero to 30 blocks. The block types SHALL be HERO, RICH_TEXT, IMAGE_TEXT, FAQ, FORM and HTML. Blocks SHALL be returned in the order they were saved, and a valid save SHALL replace all of a page's blocks.
|
||||
|
||||
#### Scenario: Blocks read back in order
|
||||
|
||||
- **WHEN** staff save page `hotel-technology` with blocks HERO, RICH_TEXT, FORM
|
||||
- **THEN** reading the page returns those three blocks in that order with their fields
|
||||
|
||||
#### Scenario: A save replaces the blocks
|
||||
|
||||
- **GIVEN** a page whose blocks are HERO and FAQ
|
||||
- **WHEN** it is saved with only a RICH_TEXT block
|
||||
- **THEN** the page has only that RICH_TEXT block
|
||||
|
||||
#### Scenario: An HTML block and the header flag read back
|
||||
|
||||
- **WHEN** staff save a page with "hide header" on and blocks HTML, FORM
|
||||
- **THEN** reading the page returns "hide header" on and the HTML block with its HTML unchanged
|
||||
|
||||
### Requirement: Block Fields Are Validated Server-Side
|
||||
|
||||
A page save SHALL be refused with the offending field path, writing nothing, when a block has an unknown type, a required field is blank, or a text exceeds its limit: heading 120, text and FAQ question 300, button label 40, FAQ answer 2000, rich-text HTML 100000 characters, and an HTML block's HTML 200000 characters. An HTML block's HTML SHALL NOT be blank. A FAQ SHALL have 1 to 30 items. `imagePosition` SHALL be LEFT or RIGHT.
|
||||
|
||||
#### Scenario: Too many blocks
|
||||
|
||||
- **WHEN** a page is saved with 31 blocks
|
||||
- **THEN** the save is refused and nothing is written
|
||||
|
||||
#### Scenario: HTML block too long
|
||||
|
||||
- **WHEN** a page is saved with an HTML block of 200001 characters
|
||||
- **THEN** the save is refused on field `blocks[0].html` and nothing is written
|
||||
|
||||
### Requirement: Page Content Cannot Run Scripts
|
||||
|
||||
A button SHALL have both a label and a link or neither. The link SHALL be a same-site path starting with a single `/`, an `https://` URL, a `mailto:` link or a `tel:` link. A save SHALL be refused when the HTML of a RICH_TEXT or IMAGE_TEXT block holds a `script` element, an `on*` attribute or a `javascript:` URL. The public page SHALL also sanitise that HTML against an allow-list before rendering it. HTML blocks are exempt, because they only ever run sealed.
|
||||
|
||||
#### Scenario: Script link on a button
|
||||
|
||||
- **WHEN** a page is saved with a HERO button link `javascript:alert(1)`
|
||||
- **THEN** the save is refused on field `blocks[0].buttonUrl`
|
||||
|
||||
#### Scenario: Script in rich text
|
||||
|
||||
- **WHEN** a page is saved with rich text holding `<img src=x onerror=alert(1)>`
|
||||
- **THEN** the save is refused on that block's HTML field
|
||||
|
||||
#### Scenario: Script in an HTML block
|
||||
|
||||
- **WHEN** a page is saved with an HTML block holding `<script>document.title = "x"</script>`
|
||||
- **THEN** the save succeeds
|
||||
|
||||
## ADDED Requirements
|
||||
|
||||
### Requirement: Custom HTML Runs Sealed
|
||||
|
||||
The public page and the staff preview SHALL show each HTML block in a sandboxed frame loaded from its own address. Each frame response SHALL carry a Content-Security-Policy whose `sandbox` directive allows scripts and pop-ups only, so the HTML runs with an opaque origin even when the address is opened directly, and whose `frame-ancestors` directive allows only the Co-Lite site. The frame element SHALL NOT grant same-origin, form submission, top-level navigation or modal dialogs.
|
||||
|
||||
#### Scenario: Public frame is sealed
|
||||
|
||||
- **GIVEN** INS page `hotel-technology` is published with an HTML block at index 0
|
||||
- **WHEN** a visitor's browser loads `/p/INS/hotel-technology/frame/0`
|
||||
- **THEN** the response is the block's HTML with a `sandbox` policy that allows scripts and pop-ups and not same-origin
|
||||
- **AND** its `frame-ancestors` allows only the Co-Lite site
|
||||
|
||||
#### Scenario: Pasted HTML cannot reach the visitor's session
|
||||
|
||||
- **GIVEN** a published HTML block whose script reads `document.cookie` and calls `/api/auth/session`
|
||||
- **WHEN** the page is shown
|
||||
- **THEN** the script sees no Co-Lite cookies and its call carries no Co-Lite session
|
||||
|
||||
### Requirement: Custom HTML Frame Addresses
|
||||
|
||||
The public frame address SHALL be `/p/<company>/<slug>/frame/<block index>` and SHALL answer only for an HTML block of a published page; every other request SHALL get the same not-found response. The preview frame address SHALL be `/pages/<id>/preview/frame/<block index>` and SHALL require a signed-in user with `BO_PAGES` who may see that page.
|
||||
|
||||
#### Scenario: No frame for a draft, a missing block or a non-HTML block
|
||||
|
||||
- **WHEN** a visitor loads the frame address of a draft page, of block 7 of a page with 3 blocks, or of a FORM block
|
||||
- **THEN** each answers with the same not-found response
|
||||
|
||||
#### Scenario: Staff preview of a draft frame
|
||||
|
||||
- **GIVEN** a draft page with an HTML block
|
||||
- **WHEN** a signed-in user with `BO_PAGES` of that page's company opens the preview
|
||||
- **THEN** the frame shows the draft HTML, sealed as on the public page
|
||||
- **AND** the same address without a session sends the browser to sign in
|
||||
|
||||
### Requirement: Custom HTML Frame Height
|
||||
|
||||
The frame SHALL grow to fit its content, between 100 and 20000 pixels, using height reports sent by that frame only. Before the first report it SHALL be 600 pixels tall.
|
||||
|
||||
#### Scenario: A tall paste grows the frame
|
||||
|
||||
- **GIVEN** a published HTML block whose content is 3000 pixels tall
|
||||
- **WHEN** a visitor opens the page
|
||||
- **THEN** the frame is 3000 pixels tall and shows no inner scroll bar
|
||||
|
||||
#### Scenario: Another frame cannot resize it
|
||||
|
||||
- **WHEN** a different window posts a height report to the page
|
||||
- **THEN** the frame's height does not change
|
||||
|
||||
### Requirement: The Custom HTML Block In The Editor
|
||||
|
||||
The editor SHALL offer "Add Custom HTML", which adds an HTML block with a monospace text box, a 200000-character counter and a note that forms inside the pasted HTML do not send and the sign-up form block collects leads. The editor SHALL also offer a "hide page header" switch for the page.
|
||||
|
||||
#### Scenario: Adding a Custom HTML block
|
||||
|
||||
- **WHEN** staff add a Custom HTML block and paste HTML into it
|
||||
- **THEN** the block shows the pasted HTML, the character count and the note about forms
|
||||
|
||||
#### Scenario: Hiding the header
|
||||
|
||||
- **WHEN** staff turn on "hide page header" and save
|
||||
- **THEN** reading the page returns "hide header" on
|
||||
|
||||
### Requirement: Hide Page Header
|
||||
|
||||
When a page's "hide header" flag is on, its public page and its preview SHALL NOT show the company header or the page title, and SHALL still use the page title in the browser title and the page metadata.
|
||||
|
||||
#### Scenario: Header hidden
|
||||
|
||||
- **GIVEN** INS page `hotel-technology` has "hide header" on
|
||||
- **WHEN** a visitor opens it
|
||||
- **THEN** no company logo bar or page title heading shows above the first block
|
||||
- **AND** the browser title is still the page title
|
||||
@@ -0,0 +1,5 @@
|
||||
-- Co-Lite change add-custom-html-block: a page option that hides the company header and the page title.
|
||||
-- Target: `service-counter`. Additive only. Run once, after add-landing-pages 01.
|
||||
SET NAMES utf8mb4;
|
||||
USE `service-counter`;
|
||||
ALTER TABLE `cms_page` ADD COLUMN `hide_header` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Hide the company header and the page title on the public page' AFTER `status`;
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
-- The labels added by add-custom-html-block, cut from the output of `npm run i18n:sql`. Run it only in an environment that already ran add-zh-cn-messages/sql/03-zh-cn-messages.sql; otherwise run that 03 file, which includes these labels.
|
||||
SET NAMES utf8mb4;
|
||||
USE `service-system`;
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesBlockHtml', JSON_OBJECT('en_US', 'Custom HTML', 'zh_CN', '自定义 HTML'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesBlockHtml') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '自定义 HTML') WHERE LOWER(code) = LOWER('PagesBlockHtml') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesHtml', JSON_OBJECT('en_US', 'HTML', 'zh_CN', 'HTML'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesHtml') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', 'HTML') WHERE LOWER(code) = LOWER('PagesHtml') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesHtmlHint', JSON_OBJECT('en_US', 'Forms inside the pasted HTML don''t send. Add a Sign-up form block to collect leads.', 'zh_CN', '粘贴的 HTML 中的表单不会发送。请添加报名表单区块来收集线索。'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesHtmlHint') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '粘贴的 HTML 中的表单不会发送。请添加报名表单区块来收集线索。') WHERE LOWER(code) = LOWER('PagesHtmlHint') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesHideHeader', JSON_OBJECT('en_US', 'Hide page header', 'zh_CN', '隐藏页面顶栏'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesHideHeader') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '隐藏页面顶栏') WHERE LOWER(code) = LOWER('PagesHideHeader') AND area = 'A';
|
||||
@@ -0,0 +1,6 @@
|
||||
-- Co-Lite change add-custom-html-block: rollback. Pages with HTML blocks must be edited or deleted first,
|
||||
-- because the previous release refuses the HTML block type when such a page is saved.
|
||||
USE `service-counter`;
|
||||
ALTER TABLE `cms_page` DROP COLUMN `hide_header`;
|
||||
USE `service-system`;
|
||||
DELETE FROM message WHERE code IN ('PagesBlockHtml', 'PagesHtml', 'PagesHtmlHint', 'PagesHideHeader') AND area = 'A';
|
||||
@@ -0,0 +1,39 @@
|
||||
# Tasks: add-custom-html-block
|
||||
|
||||
Design: `design.md` and `docs/superpowers/specs/2026-12-02-custom-html-block-design.md`. Every task is TDD. Work is serial in the main session, with a self-review per task.
|
||||
|
||||
## 1. Data and services
|
||||
|
||||
- [x] 1.1 SQL: `sql/01-hide-header.sql` (`cms_page.hide_header`), `sql/99-rollback.sql`; mirror 01 into `local/seed/`.
|
||||
- [x] 1.2 services-counter:
|
||||
- the `HTML` block type: required, at most 200,000 characters, no script check;
|
||||
- `hideHeader` on the page model and DTO.
|
||||
- Verify: `mvn -T 1C -B -pl solvway-services-counter -am verify`
|
||||
- [x] 1.3 mobile-api: `hideHeader` on `AdminPageRequest` and in the public page response.
|
||||
- Verify: `mvn -T 1C -B -pl solvway-mobile-api -am verify`
|
||||
|
||||
## 2. Portal
|
||||
|
||||
- [x] 2.1 Frame routes (public and preview) with the sandbox headers, the 404 rules and the height script.
|
||||
- The middleware skips them; `routeGuard` admits the public frame path.
|
||||
- Security code: read the whole diff.
|
||||
- [x] 2.2 `CmsBlocks`:
|
||||
- the sandboxed iframe with height messages from its own frame only;
|
||||
- `hideHeader` hides the header and the title.
|
||||
- [x] 2.3 Editor:
|
||||
- "Add Custom HTML", with a monospace text box, a counter and the forms note;
|
||||
- the "Hide page header" switch;
|
||||
- field errors at the HTML field.
|
||||
- [x] 2.4 Labels in `defaultMessages.ts` with Chinese in `zh_CN.seed.json`, then `npm run i18n:sql`. `sql/02-html-block-labels.sql` holds only the new labels.
|
||||
- Verify (2.1 to 2.4): `cd solvway-admin-portal && npx vitest run; echo VITEST=$? && npx tsc --noEmit && npm run lint`
|
||||
|
||||
## 3. Release
|
||||
|
||||
- [x] 3.1 `docs/deployment.md`: the SQL rows and the frame routes. A Traefik or proxy layer must not add a CSP that overrides the frame's own policy.
|
||||
- [x] 3.2 Live Playwright check on the local stack, at 1280 and 360 px:
|
||||
- paste the INS proof-of-concept HTML into the INS page, with "hide page header" on and the sign-up form below it;
|
||||
- it looks like the PoC signed out;
|
||||
- opening the frame address directly shows no Co-Lite cookies to the frame's script;
|
||||
- a draft frame is not found for visitors and previews for staff;
|
||||
- an over-limit paste is refused at its field.
|
||||
- [x] 3.3 Whole-branch self-review (security: the sandbox headers, the middleware skip and the message handler), then the PR to main and the merge.
|
||||
@@ -0,0 +1,2 @@
|
||||
schema: spec-driven
|
||||
created: 2026-12-02
|
||||
@@ -0,0 +1,50 @@
|
||||
# Design
|
||||
|
||||
The full design is `docs/superpowers/specs/2026-12-02-lead-notifications-design.md` (approved 2026-12-02). This file records the technical decisions.
|
||||
|
||||
## Context
|
||||
|
||||
- `service-system`.`notification` exists from Tastefully (`id, receiver, message, create_date_time`, `utf8mb3`) and is empty. services-system has a thin `NotificationController` (save, find by receiver).
|
||||
- Babyboo extended the same table and built the admin inbox API and bell (`add-admin-internal-notifications`, 2026-10-07). Its files are the porting source: services-system `Notification`/`NotificationService`/`NotificationController`, mobile-api `AdminNotificationController`/`AdminNotificationService`, portal `NotificationsBell.tsx`, `app/notifications/page.tsx`, `app/api/notifications/**`, `app/lib/services/notifications.ts`.
|
||||
- services-counter already calls another service best-effort after commit: `WhatsappNotifier` (2-second timeout, never throws, `TransactionSynchronization.afterCommit`).
|
||||
- Assignment points in services-counter: `EventLeadService` capture and update (`salespersonChanged`), `RegistrationService` new capture and `alreadyCaptured` (`assign`). The event's sales team is `event_salesperson`.
|
||||
- Inbound WhatsApp: `WebhookIngestService` calls `WaConversationRepository.recordInbound`. The chat owner is `wa_conversation.owner_user_id`.
|
||||
- Leads due: `event_lead.next_follow_up_date`, `status`, `salesperson_user_id`. The lead dashboard already counts overdue follow-ups.
|
||||
- The portal has `usePolling` (babyboo used `useVisiblePolling`).
|
||||
|
||||
## Goals / Non-Goals
|
||||
|
||||
**Goals:** the bell, the four triggers, server read state, both languages, company scoping.
|
||||
|
||||
**Non-Goals:** email, WhatsApp or push alerts; per-user settings; broadcasts; purging.
|
||||
|
||||
## Decisions
|
||||
|
||||
1. **One row per recipient** in `notification`, `recipient_type = 'A'`, `receiver` = user id as text (the column is `varchar(45)`), `company_id` set. Babyboo's model; read state is a column.
|
||||
2. **Codes, not text.** `type` is `LEAD_ASSIGNED`, `WEB_SIGNUP`, `WHATSAPP_MESSAGE` or `FOLLOW_UP_DUE`. `title` and `message` hold a label code and a JSON parameter object (lead name, event name, counts). The bell renders them with `t()`. No phone numbers or emails in parameters.
|
||||
3. **Collapse key.** An optional `collapse_key` on create: when the receiver already has an unread row with that key, the create updates that row's message and time and marks nothing else; otherwise it inserts. WhatsApp uses `WA:<conversation uuid>`; the follow-up summary uses `FOLLOW_UP:<date>`, so a second run of the job on the same day before the user reads it does not duplicate.
|
||||
- ponytail: a job rerun after the user read the summary adds a second one that day. Add a run record if that happens in practice.
|
||||
4. **Delivery is a REST call after commit**, copying `WhatsappNotifier`: 2-second timeout, no retry, failures logged with ids only. Counter and WhatsApp each get one small `StaffNotifier` posting to services-system's create endpoint.
|
||||
- ponytail: no queue; a lost notification leaves the lead, chat and follow-up date in place. Move to Pub/Sub if losses show up.
|
||||
5. **Recipients are resolved by the sender**, which already has the data: counter knows the salesperson and the event's sales team; WhatsApp knows the chat owner. services-system only stores and serves rows.
|
||||
6. **Self-assignment is silent.** When the staff user making the change is the new salesperson, no "lead assigned" notification is sent. The counter compares the request's acting user with the new salesperson.
|
||||
7. **A web sign-up assigned at capture sends one notification**, of type `WEB_SIGNUP`, to the salesperson. A web sign-up without a salesperson goes to every user in `event_salesperson` for that event; none when the team is empty.
|
||||
8. **Follow-up job** in services-counter, `@Scheduled(cron = "${leads.follow-up-notice.cron:0 0 8 * * *}", zone = "Asia/Kuala_Lumpur")`. It groups open event leads with `next_follow_up_date <= today` by company and salesperson, and sends one summary each (due today count, overdue count) linking to the event leads list. Leads without a salesperson are skipped.
|
||||
9. **Admin API** in mobile-api reads the user id and company from the session, never from the request. Mark-read endpoints change only the caller's rows; another user's id returns 404.
|
||||
10. **Bell** ported from babyboo: polls the unread count every 30 seconds while visible, the drop-down shows the newest 10, opening it marks the shown items read, clicking navigates to `link`. `/notifications` lists 20 per page with "Mark all read". Every signed-in user gets it; no module permission.
|
||||
11. **Charset.** The DDL converts the table to `utf8mb4` (it is empty), so names with any characters are stored.
|
||||
|
||||
## Risks / Trade-offs
|
||||
|
||||
- [Lost notifications on a services-system outage] → the underlying data is unaffected; logs show the failures.
|
||||
- [Noisy bell for busy salespeople] → the WhatsApp collapse and the daily summary limit it; per-user settings come later if asked.
|
||||
- [Leaking another company's lead] → recipients come from the same company's data; the API filters by the session user; tests cover a second company.
|
||||
- [Links that the reader may not open] → links point to pages that still check access; a notification only names a lead its recipient is assigned to or on the team for.
|
||||
|
||||
## Migration Plan
|
||||
|
||||
Run `sql/01` (additive columns on an empty table) before deploying the services, then `sql/02` labels. Rollback: `sql/99-rollback.sql` drops the columns and labels; the old services ignore them.
|
||||
|
||||
## Open Questions
|
||||
|
||||
None.
|
||||
@@ -0,0 +1,41 @@
|
||||
# Proposal
|
||||
|
||||
## Why
|
||||
|
||||
Sales staff learn about new work only by refreshing lists. A lead assigned to them, a sign-up from a landing page, a customer's WhatsApp reply and a follow-up falling due all go unnoticed until someone looks. This is feature-list item 12, needed before go-live on 2027-01-15. On 2026-12-02 the owner chose an in-app bell only and approved the design: `docs/superpowers/specs/2026-12-02-lead-notifications-design.md`.
|
||||
|
||||
## What Changes
|
||||
|
||||
- **Bell in the portal header** for every signed-in staff user:
|
||||
- an unread badge, refreshed every 30 seconds while the tab is visible;
|
||||
- a drop-down of recent notifications, each linking to its lead or chat;
|
||||
- a full notifications page;
|
||||
- read state kept on the server.
|
||||
- **Four triggers:**
|
||||
- a lead assigned to someone notifies that salesperson;
|
||||
- a landing-page sign-up notifies the assigned salesperson, else the event's sales team;
|
||||
- an inbound WhatsApp message notifies the chat owner, at most one unread notification per chat;
|
||||
- a daily 08:00 (Malaysia) summary of follow-ups due or overdue, per salesperson.
|
||||
- **Text follows the reader's language**: notifications store message codes and parameters, not text.
|
||||
- **Best effort:** a notification that cannot be written never fails the sign-up, assignment or message behind it.
|
||||
|
||||
## Capabilities
|
||||
|
||||
### New Capabilities
|
||||
|
||||
- `lead-notifications`: the staff bell, its read state, and the four triggers with their recipients.
|
||||
|
||||
### Modified Capabilities
|
||||
|
||||
None. The triggers add a side effect to lead capture, lead assignment and WhatsApp intake without changing their specified behaviour.
|
||||
|
||||
## Impact
|
||||
|
||||
- **services-system:** the unused `notification` table gains `recipient_type`, `company_id`, `title`, `type`, `link`, `collapse_key`, `seen`, `read_at` and an index, and moves to `utf8mb4`. New endpoints: create, list mine, unread count, mark read, mark all read.
|
||||
- **SQL:** `sql/01-notification-columns.sql` (DDL), `sql/02-notification-labels.sql` (labels), `sql/99-rollback.sql`. Mirror 01 into `local/seed/`.
|
||||
- **services-counter:** a notifier called after commit on assignment and on web sign-up; a daily follow-up job.
|
||||
- **services-whatsapp:** a notifier called after an inbound message is recorded.
|
||||
- **mobile-api:** `/api/admin/notifications` (list, unread count, read, read all), always for the signed-in user.
|
||||
- **Portal:** `NotificationsBell` in the header, `/notifications` page, BFF routes, labels with Chinese. Ported from babyboo.
|
||||
- **Gateway:** unchanged; `/api/admin/**` is already routed.
|
||||
- **Dependencies:** none.
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
## Purpose
|
||||
|
||||
In-app notifications for staff: a bell with unread state, and alerts when a lead is assigned, a landing-page sign-up arrives, a customer sends a WhatsApp message, or follow-ups fall due.
|
||||
|
||||
## ADDED Requirements
|
||||
|
||||
### Requirement: Staff Notification Bell
|
||||
|
||||
The portal SHALL show every signed-in staff user a bell in the header with the count of their unread notifications, refreshed at least every 30 seconds while the page is visible. Opening the bell SHALL list their newest notifications, newest first, and mark the listed ones read. Choosing a notification SHALL open the page it links to.
|
||||
|
||||
#### Scenario: Unread count and opening the bell
|
||||
|
||||
- **GIVEN** a salesperson has 3 unread notifications
|
||||
- **WHEN** they open any portal page
|
||||
- **THEN** the bell shows 3
|
||||
- **WHEN** they open the bell
|
||||
- **THEN** the 3 notifications are listed newest first
|
||||
- **AND** after a reload the bell shows no unread count
|
||||
|
||||
#### Scenario: A notification opens its lead
|
||||
|
||||
- **GIVEN** a "lead assigned" notification for lead L
|
||||
- **WHEN** the salesperson chooses it
|
||||
- **THEN** the portal opens lead L
|
||||
|
||||
### Requirement: Notifications Page
|
||||
|
||||
The portal SHALL provide a notifications page listing the signed-in user's notifications, newest first and paged, showing which are unread, with an action to mark all of them read.
|
||||
|
||||
#### Scenario: Mark all read
|
||||
|
||||
- **GIVEN** a user with 25 notifications, 5 of them unread
|
||||
- **WHEN** they open the notifications page and choose "Mark all read"
|
||||
- **THEN** none of their notifications is unread
|
||||
- **AND** the bell shows no unread count
|
||||
|
||||
### Requirement: Notifications Are Private To Their Recipient
|
||||
|
||||
The system SHALL show and change a user's notifications only for that user, identified from their session. A request naming another user's notification SHALL be refused as not found. A notification SHALL only name a lead of the recipient's own company.
|
||||
|
||||
#### Scenario: Another user's notification
|
||||
|
||||
- **GIVEN** notification N belongs to user A
|
||||
- **WHEN** user B asks to mark N read
|
||||
- **THEN** the request is refused as not found
|
||||
- **AND** N stays unread for user A
|
||||
|
||||
#### Scenario: Two companies
|
||||
|
||||
- **GIVEN** an INS salesperson and a CV salesperson
|
||||
- **WHEN** a CV lead is assigned to the CV salesperson
|
||||
- **THEN** only the CV salesperson is notified
|
||||
|
||||
### Requirement: Notifications Follow The Reader's Language
|
||||
|
||||
A notification SHALL be stored as message codes with parameters and shown in the reader's current portal language. Its parameters SHALL NOT include phone numbers or email addresses.
|
||||
|
||||
#### Scenario: Chinese reader
|
||||
|
||||
- **GIVEN** a "lead assigned" notification
|
||||
- **WHEN** a user with the portal in Chinese opens the bell
|
||||
- **THEN** the notification text is in Chinese, with the lead's name
|
||||
|
||||
### Requirement: Lead Assigned Notification
|
||||
|
||||
When an event lead's salesperson is set or changed to a user, the system SHALL notify that user, linking to the lead. It SHALL NOT notify a user who assigned the lead to themselves, and SHALL NOT notify anyone when the salesperson is cleared.
|
||||
|
||||
#### Scenario: Manager assigns a lead
|
||||
|
||||
- **WHEN** a manager assigns event lead L to salesperson S
|
||||
- **THEN** S gets one "lead assigned" notification naming L and its event
|
||||
|
||||
#### Scenario: Self-assignment
|
||||
|
||||
- **WHEN** salesperson S assigns lead L to themselves
|
||||
- **THEN** no notification is created
|
||||
|
||||
### Requirement: Landing Page Sign-up Notification
|
||||
|
||||
When a landing-page sign-up creates or updates an event lead, the system SHALL notify the lead's salesperson if it has one, otherwise every member of the event's sales team, once each. With no salesperson and no sales team, nobody SHALL be notified.
|
||||
|
||||
#### Scenario: Unassigned sign-up
|
||||
|
||||
- **GIVEN** event E has sales team members S1 and S2
|
||||
- **WHEN** a visitor signs up on a page whose form belongs to E, and no salesperson is assigned
|
||||
- **THEN** S1 and S2 each get one "new sign-up" notification
|
||||
|
||||
#### Scenario: Assigned at capture
|
||||
|
||||
- **WHEN** a web sign-up is captured already assigned to S
|
||||
- **THEN** S gets exactly one notification, the "new sign-up" one
|
||||
|
||||
### Requirement: WhatsApp Message Notification
|
||||
|
||||
When an inbound WhatsApp message is recorded on a chat with an owner, the system SHALL notify the owner, linking to the chat. While the owner has an unread notification for that chat, a further message SHALL update it rather than add another. A chat without an owner SHALL notify nobody.
|
||||
|
||||
#### Scenario: Busy chat
|
||||
|
||||
- **GIVEN** salesperson S owns a chat
|
||||
- **WHEN** the customer sends 4 messages before S opens the bell
|
||||
- **THEN** S has one unread notification for that chat, timed at the last message
|
||||
|
||||
#### Scenario: Unowned chat
|
||||
|
||||
- **WHEN** a message arrives on a chat without an owner
|
||||
- **THEN** no notification is created
|
||||
|
||||
### Requirement: Follow-ups Due Notification
|
||||
|
||||
Every day at 08:00 Malaysia time, the system SHALL send each salesperson with open event leads whose next follow-up date is today or earlier one summary notification giving the count due today and the count overdue, linking to their event leads.
|
||||
|
||||
#### Scenario: Morning summary
|
||||
|
||||
- **GIVEN** salesperson S has 2 open leads due today and 1 open lead due yesterday
|
||||
- **WHEN** the daily run happens
|
||||
- **THEN** S gets one notification saying 2 due today and 1 overdue
|
||||
|
||||
#### Scenario: Nothing due
|
||||
|
||||
- **GIVEN** salesperson S has no open lead due today or earlier
|
||||
- **WHEN** the daily run happens
|
||||
- **THEN** S gets no notification
|
||||
|
||||
### Requirement: Notifications Never Block The Action
|
||||
|
||||
A failure to create a notification SHALL NOT fail or roll back the sign-up, assignment or inbound message that caused it. The failure SHALL be logged without names, phone numbers or email addresses.
|
||||
|
||||
#### Scenario: Notification store down
|
||||
|
||||
- **GIVEN** the notification store cannot be reached
|
||||
- **WHEN** a visitor signs up on a landing page
|
||||
- **THEN** the sign-up succeeds and the lead is saved
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
-- Co-Lite change add-lead-notifications: the staff notification bell.
|
||||
-- Target: `service-system`.`notification`, the unused table from Tastefully. Pre-check (read-only):
|
||||
-- SELECT COUNT(*) FROM `service-system`.`notification`; -- expect 0
|
||||
-- The table is converted to utf8mb4 (names in any script) and gains babyboo's bell columns plus company_id
|
||||
-- and collapse_key. Existing columns keep their meaning. Run once.
|
||||
SET NAMES utf8mb4;
|
||||
USE `service-system`;
|
||||
ALTER TABLE `notification`
|
||||
CONVERT TO CHARACTER SET utf8mb4,
|
||||
ADD COLUMN `recipient_type` char(1) NULL COMMENT 'A = staff user' AFTER `receiver`,
|
||||
ADD COLUMN `company_id` bigint NULL AFTER `recipient_type`,
|
||||
ADD COLUMN `title` varchar(255) NULL COMMENT 'Message code' AFTER `company_id`,
|
||||
ADD COLUMN `type` varchar(45) NULL COMMENT 'LEAD_ASSIGNED, WEB_SIGNUP, WHATSAPP_MESSAGE, FOLLOW_UP_DUE' AFTER `message`,
|
||||
ADD COLUMN `link` varchar(512) NULL COMMENT 'Portal path opened on click' AFTER `type`,
|
||||
ADD COLUMN `collapse_key` varchar(100) NULL COMMENT 'An unread row with the same receiver and key is updated, not duplicated' AFTER `link`,
|
||||
ADD COLUMN `seen` tinyint(1) NOT NULL DEFAULT 0 AFTER `collapse_key`,
|
||||
ADD COLUMN `read_at` datetime NULL AFTER `seen`,
|
||||
ADD INDEX `idx_notification_inbox` (`recipient_type`, `receiver`, `seen`, `create_date_time`),
|
||||
ADD INDEX `idx_notification_collapse` (`receiver`, `collapse_key`, `seen`);
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
-- The labels added by add-lead-notifications, cut from the output of `npm run i18n:sql`. Run it only in an environment that already ran add-zh-cn-messages/sql/03-zh-cn-messages.sql; otherwise run that 03 file, which includes these labels.
|
||||
SET NAMES utf8mb4;
|
||||
USE `service-system`;
|
||||
INSERT INTO message (code, content, area) SELECT 'NotificationsTitle', JSON_OBJECT('en_US', 'Notifications', 'zh_CN', '通知'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('NotificationsTitle') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '通知') WHERE LOWER(code) = LOWER('NotificationsTitle') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'NotificationsUnread', JSON_OBJECT('en_US', 'Notifications, {count} unread', 'zh_CN', '通知,{count} 条未读'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('NotificationsUnread') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '通知,{count} 条未读') WHERE LOWER(code) = LOWER('NotificationsUnread') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'NotificationsEmpty', JSON_OBJECT('en_US', 'No notifications yet.', 'zh_CN', '暂无通知。'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('NotificationsEmpty') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '暂无通知。') WHERE LOWER(code) = LOWER('NotificationsEmpty') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'NotificationsLoadFailed', JSON_OBJECT('en_US', 'Couldn''t load notifications.', 'zh_CN', '无法加载通知。'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('NotificationsLoadFailed') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '无法加载通知。') WHERE LOWER(code) = LOWER('NotificationsLoadFailed') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'NotificationsMarkAllRead', JSON_OBJECT('en_US', 'Mark all read', 'zh_CN', '全部标为已读'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('NotificationsMarkAllRead') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '全部标为已读') WHERE LOWER(code) = LOWER('NotificationsMarkAllRead') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'NotificationsSeeAll', JSON_OBJECT('en_US', 'See all', 'zh_CN', '查看全部'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('NotificationsSeeAll') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '查看全部') WHERE LOWER(code) = LOWER('NotificationsSeeAll') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'NotificationsUnreadBadge', JSON_OBJECT('en_US', 'Unread', 'zh_CN', '未读'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('NotificationsUnreadBadge') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '未读') WHERE LOWER(code) = LOWER('NotificationsUnreadBadge') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'NoticeLeadAssigned', JSON_OBJECT('en_US', 'Lead assigned to you', 'zh_CN', '有新线索分配给你'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('NoticeLeadAssigned') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '有新线索分配给你') WHERE LOWER(code) = LOWER('NoticeLeadAssigned') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'NoticeWebSignup', JSON_OBJECT('en_US', 'New sign-up', 'zh_CN', '新的报名'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('NoticeWebSignup') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '新的报名') WHERE LOWER(code) = LOWER('NoticeWebSignup') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'NoticeLeadBody', JSON_OBJECT('en_US', '{lead} · {event}', 'zh_CN', '{lead} · {event}'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('NoticeLeadBody') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '{lead} · {event}') WHERE LOWER(code) = LOWER('NoticeLeadBody') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'NoticeFollowUpDue', JSON_OBJECT('en_US', 'Follow-ups due', 'zh_CN', '待跟进'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('NoticeFollowUpDue') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '待跟进') WHERE LOWER(code) = LOWER('NoticeFollowUpDue') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'NoticeFollowUpBody', JSON_OBJECT('en_US', '{due} due today, {overdue} overdue', 'zh_CN', '今天到期 {due} 条,已逾期 {overdue} 条'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('NoticeFollowUpBody') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '今天到期 {due} 条,已逾期 {overdue} 条') WHERE LOWER(code) = LOWER('NoticeFollowUpBody') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'NoticeWhatsappMessage', JSON_OBJECT('en_US', 'New WhatsApp message', 'zh_CN', '新的 WhatsApp 消息'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('NoticeWhatsappMessage') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '新的 WhatsApp 消息') WHERE LOWER(code) = LOWER('NoticeWhatsappMessage') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'NoticeWhatsappBody', JSON_OBJECT('en_US', 'From {name}', 'zh_CN', '来自 {name}'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('NoticeWhatsappBody') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '来自 {name}') WHERE LOWER(code) = LOWER('NoticeWhatsappBody') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'NoticeWhatsappBodyNoName', JSON_OBJECT('en_US', 'From a new contact', 'zh_CN', '来自新联系人'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('NoticeWhatsappBodyNoName') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '来自新联系人') WHERE LOWER(code) = LOWER('NoticeWhatsappBodyNoName') AND area = 'A';
|
||||
@@ -0,0 +1,16 @@
|
||||
-- Co-Lite change add-lead-notifications: rollback. Drops the bell columns and labels; the previous release never
|
||||
-- reads them. The charset change is left in place (utf8mb4 holds everything utf8mb3 did).
|
||||
SET NAMES utf8mb4;
|
||||
USE `service-system`;
|
||||
ALTER TABLE `notification`
|
||||
DROP INDEX `idx_notification_inbox`,
|
||||
DROP INDEX `idx_notification_collapse`,
|
||||
DROP COLUMN `recipient_type`,
|
||||
DROP COLUMN `company_id`,
|
||||
DROP COLUMN `title`,
|
||||
DROP COLUMN `type`,
|
||||
DROP COLUMN `link`,
|
||||
DROP COLUMN `collapse_key`,
|
||||
DROP COLUMN `seen`,
|
||||
DROP COLUMN `read_at`;
|
||||
DELETE FROM message WHERE code IN ('NotificationsTitle', 'NotificationsUnread', 'NotificationsEmpty', 'NotificationsLoadFailed', 'NotificationsMarkAllRead', 'NotificationsSeeAll', 'NotificationsUnreadBadge', 'NoticeLeadAssigned', 'NoticeWebSignup', 'NoticeLeadBody', 'NoticeFollowUpDue', 'NoticeFollowUpBody', 'NoticeWhatsappMessage', 'NoticeWhatsappBody', 'NoticeWhatsappBodyNoName') AND area = 'A';
|
||||
@@ -0,0 +1,39 @@
|
||||
# Tasks: add-lead-notifications
|
||||
|
||||
Design: `design.md` and `docs/superpowers/specs/2026-12-02-lead-notifications-design.md`. Every task is TDD. Work is serial in the main session, with a self-review per task. Porting source: babyboo's `add-admin-internal-notifications`.
|
||||
|
||||
## 1. Store and API
|
||||
|
||||
- [x] 1.1 SQL: `sql/01-notification-columns.sql` (columns, index, `utf8mb4`), `sql/99-rollback.sql`; mirror 01 into `local/seed/`.
|
||||
- [x] 1.2 services-system: the extended `Notification`; create (with `collapse_key`), list mine (paged), unread count, mark one read (own rows only), mark all read.
|
||||
- Verify: `mvn -T 1C -B -pl solvway-services-system -am verify`
|
||||
- [x] 1.3 mobile-api: `/api/admin/notifications`, `/unread-count`, `/{id}/read`, `/read-all`, user and company from the session.
|
||||
- Verify: `mvn -T 1C -B -pl solvway-mobile-api -am verify`
|
||||
|
||||
## 2. Triggers
|
||||
|
||||
- [x] 2.1 services-counter `StaffNotifier` (after commit, 2 s timeout, never throws, ids-only logs).
|
||||
- Lead assigned at capture and on update, not on self-assignment or clearing.
|
||||
- Web sign-up to the salesperson, else the event's sales team; one notification when assigned at capture.
|
||||
- [x] 2.2 services-counter daily follow-up summary job (08:00 Asia/Kuala_Lumpur, cron property), one per salesperson with open leads due today or overdue.
|
||||
- Verify (2.1, 2.2): `mvn -T 1C -B -pl solvway-services-counter -am verify`
|
||||
- [x] 2.3 services-whatsapp: notify the chat owner after an inbound message is recorded, collapse key `WA:<conversation uuid>`; no owner, no notification.
|
||||
- Verify: `mvn -T 1C -B -pl solvway-services-whatsapp -am verify`
|
||||
|
||||
## 3. Portal
|
||||
|
||||
- [x] 3.1 BFF routes `app/api/notifications/**` and `app/lib/services/notifications.ts`.
|
||||
- [x] 3.2 `NotificationsBell` in the header (30 s polling while visible, newest 10, opening marks read, click opens the link) and the `/notifications` page with "Mark all read".
|
||||
- [x] 3.3 Labels in `defaultMessages.ts` with Chinese in `zh_CN.seed.json`, then `npm run i18n:sql`. `sql/02-notification-labels.sql` holds only the new labels.
|
||||
- Verify (3.1 to 3.3): `cd solvway-admin-portal && npx vitest run; echo VITEST=$? && npx tsc --noEmit && npm run lint`
|
||||
|
||||
## 4. Release
|
||||
|
||||
- [x] 4.1 `docs/deployment.md`: the SQL rows and the follow-up job's cron property.
|
||||
- [x] 4.2 Live Playwright check on the local stack, signed in as two users of different companies:
|
||||
- assigning a lead notifies the salesperson and not the other company;
|
||||
- a landing-page sign-up notifies the event's sales team;
|
||||
- a WhatsApp message (mock) on an owned chat shows one notification per chat;
|
||||
- the follow-up job (run by setting its cron for the test) gives the summary;
|
||||
- the bell, the page and "Mark all read" work in English and Chinese, at 1280 and 360 px.
|
||||
- [x] 4.3 Whole-branch self-review (security: recipient scoping, own-rows-only read endpoints, no personal data in logs or parameters), then the PR to main and the merge.
|
||||
Reference in new issue
Block a user