Merge pull request 'feat(pages): feature cards, steps, trust strip, CTA band and section looks' (#60) from add-page-sections into main
CI / build-and-publish (push) Failing after 1s
CI / build-and-publish (push) Failing after 1s
This commit was merged in pull request #60.
This commit is contained in:
commit
d2711a5aa9
23 files changed
+1203
-14
No files matched your search
+3
-1
@@ -155,6 +155,7 @@ Run the three in order before the new services-system, gateway and mobile-api go
|
||||
| `openspec/changes/archive/2026-12-03-add-lead-notifications/sql/01-notification-columns.sql` | Turns the unused `service-system`.`notification` table into the staff bell: converts it to utf8mb4 and adds the recipient, company, type, link, collapse and read columns and two indexes. DDL. |
|
||||
| `openspec/changes/archive/2026-12-03-add-lead-notifications/sql/02-notification-labels.sql` | Adds the bell's labels in English and Chinese. Same rule as `05-page-labels.sql`: only where `add-zh-cn-messages/sql/03` already ran. |
|
||||
| `openspec/changes/archive/2026-12-03-add-page-anchor-links/sql/01-anchor-labels.sql` | Adds the "Link name" labels and updates the link hint and the bad-link message, in English and Chinese. Same rule as `05-page-labels.sql`: only where `add-zh-cn-messages/sql/03` already ran. No DDL: link names live in the page's blocks JSON. |
|
||||
| `openspec/changes/add-page-sections/sql/01-section-labels.sql` | Adds the labels for the new page sections (feature cards, steps, trust strip, call to action), section looks and icons, in English and Chinese. Same rule as `05-page-labels.sql`: only where `add-zh-cn-messages/sql/03` already ran. No DDL: sections live in the page's blocks JSON. |
|
||||
|
||||
Run them in order before the new services-counter, services-system and mobile-api go live: the new services read the new columns on every event lead and company query. `01` to `03` need a user that may alter tables. `99-rollback.sql` in the same folder removes the module and drops the two tables and the columns, which deletes every page, image, page address and campaign tag.
|
||||
|
||||
@@ -454,12 +455,13 @@ If nothing arrives: the mobile-api log says `WhatsApp webhook forward failed: <s
|
||||
|
||||
## 12. Landing pages
|
||||
|
||||
Marketing builds public pages under **Events → Pages**. Each page has blocks (hero, text, image with text, FAQ and a sign-up form) and is a draft until published. Its address is `/p/<company-code>/<slug>`.
|
||||
Marketing builds public pages under **Events → Pages**. Each page has blocks (hero, text, image with text, feature cards, steps, trust strip, call to action, FAQ, sign-up form and custom HTML) and is a draft until published. Every block except custom HTML has a look: Default, Light grey, Dark or Company colour; the last three draw the block as a full-width band. In dark mode the Dark band shows light, as the page's colours invert. Its address is `/p/<company-code>/<slug>`.
|
||||
|
||||
1. **Module.** Grant `BO_PAGES` to the roles that build pages.
|
||||
2. **Branding.** A super admin sets each company's logo and accent colour under **Companies → Branding**. Buttons on the company's pages use the accent colour, with black or white text, whichever is easier to read. Without them the page shows the company name and the default blue.
|
||||
3. **Standing enquiries event.** A sign-up form always belongs to an event. For general enquiries, each company creates one event, for example "INS website enquiries", with a far-off end date and its sales team, and picks it in the form block. Sign-ups from a landing page are never marked as attended, so this event does not inflate attendance. Name it clearly: it shows in event lists and dashboards.
|
||||
4. **The INS page.** The INS proof of concept (`ins-landing-page`, never deployed) is content, not code: rebuild it by hand in the editor after deploy. Its test leads are not imported.
|
||||
- **Rebuild it as sections.** The INS page is pasted HTML today, which only a developer can maintain. Rebuild it from sections (hero, trust strip, feature cards, steps, FAQ, sign-up form, call to action) so marketing can edit it, then delete the Custom HTML block.
|
||||
- **Jump to the form.** To make a button jump to the sign-up form, give the form block a link name, for example `signup`, and link the button to `#signup`. Links inside a Custom HTML block work the same way: on the INS page, change the HTML's `#consult` links to `#signup`. A `#name` link inside the HTML that matches an `id` in that same HTML (such as `#top`) scrolls to that spot instead.
|
||||
5. **Check.** Publish a page, open its address signed out, sign up through its form with `?utm_source=test` on the address, and check that the event lead shows source **Web page**, the page address and the campaign. Delete that test lead afterwards.
|
||||
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
# Landing-page builder for marketing staff — design
|
||||
|
||||
Status: approved by the owner on 2026-12-03, including the two calls below.
|
||||
|
||||
Owner calls, 2026-12-03:
|
||||
- **Draft and live are separate (option b).** Edits to a published page stay a draft until Publish; visitors see the published version meanwhile.
|
||||
- **Order.** The three changes ship in order. Whether go-live waits for the on-page editor is decided nearer 2027-01-15; until then the form editor stays.
|
||||
|
||||
## Why
|
||||
|
||||
Marketing staff at INS and CV build a landing page for every event. They are not technical. Today they fill in a form of blocks and open a separate preview of the last saved version, and the one real page (INS "hotel-technology") is pasted HTML that only a developer can change. The owner wants a Wix-like experience: staff edit the page itself and see the result as they work, and start from templates rather than a blank page.
|
||||
|
||||
Success: a marketing staff member, without help, creates an event page from a template, changes its text and images on the page, links its form to the event, checks it at phone size, and publishes it, in well under an hour.
|
||||
|
||||
## Goals
|
||||
|
||||
- Edit on the page: click text to change it, click a section to change its settings, add, move, duplicate and remove sections, and see the change at once.
|
||||
- Desktop and phone views in the editor, each showing the page exactly as visitors on that device see it.
|
||||
- Templates: start a page from a ready-made design, or copy an earlier event's page.
|
||||
- Enough section types to build a page like the INS one without code.
|
||||
|
||||
## Non-goals
|
||||
|
||||
- Free placement of elements anywhere on a canvas (owner chose stacking sections, 2026-12-03).
|
||||
- Per-element styling: fonts, sizes or colours chosen per text. Each section has a small set of looks instead.
|
||||
- Animations, page version history, scheduled publishing, custom domains, A/B tests.
|
||||
- Editing pages on a phone: the on-page editor is for laptop and desktop screens.
|
||||
|
||||
## Anti-goals
|
||||
|
||||
- A page that looks fine in the editor but broken on a visitor's phone.
|
||||
- An editor that saves anything the server would not accept, or shows something different from the public page.
|
||||
- Weakening the landing-page rules: block validation, HTML sanitising, the sealed Custom HTML frame, and company scoping all stay as they are.
|
||||
|
||||
## Constraints
|
||||
|
||||
- Go-live is 2027-01-15. The work ships as three changes, each usable on its own, so a late editor does not hold back the rest. The current form editor keeps working until the on-page editor replaces it.
|
||||
- Pages stay one JSON list of blocks in `cms_page.blocks`, checked by services-counter. New section types extend that list; the editor writes the same JSON.
|
||||
- Tailwind 3.4 with viewport breakpoints (`sm:`, `md:`): a block's phone layout depends on the window width, not the width of its container.
|
||||
- Owner rules apply: TDD, Playwright checks, no Tastefully customer data, and SQL only in the change folders.
|
||||
|
||||
## Approaches considered
|
||||
|
||||
**How staff place content** (owner's choice): stacking full-width sections (chosen) versus free placement on a canvas. Free placement roughly doubles the build and makes phone layouts the staff's problem.
|
||||
|
||||
**How the editor is built** (my call, the owner handed over the how):
|
||||
|
||||
1. **Our own editor on the existing blocks (chosen).** The page renders in edit mode inside a same-origin frame. Text becomes editable in place (Tiptap, already installed, for rich text), and a side panel reuses today's block fields. Pros: the data, validation, sanitising and public rendering do not change; no large dependency. Cons: drag-and-drop, selection and undo are ours to build and test.
|
||||
2. **An open-source page-builder library (Puck, MIT).** It ships drag-and-drop, a fields panel, an outline and undo. Pros: less UI to build. Cons: a large new dependency with its own look and data format (an adapter both ways), and its in-place text editing is less mature than Tiptap (unverified for the current version). Rejected: the parts it saves us are the smaller parts of the work.
|
||||
3. **An HTML builder (GrapesJS).** It produces free-form HTML and CSS. Rejected: it bypasses block validation and sanitising, it cannot hold the lead form, and it is free placement.
|
||||
|
||||
**Phone view** (my call): render the page in a frame of the chosen width, so the page's own breakpoints apply, as visitors see it. The alternative, container queries, needs a Tailwind plugin and changes to every block's and the sign-up form's classes, which the QR registration pages share.
|
||||
|
||||
**Templates** (my call): starter templates shipped with the portal, plus "Duplicate page". Templates saved by staff per company would need a new table and screens; duplicating last event's page covers the "every event" case without them.
|
||||
|
||||
## Design
|
||||
|
||||
### Change 1: `add-page-sections` (new section types and section looks)
|
||||
|
||||
New block types, each validated in services-counter, rendered by the public page and edited in today's form:
|
||||
|
||||
- `FEATURES`: heading, optional intro, 2 to 6 cards, each with an icon from a fixed list (about 12 Lucide icons), a title and a short text.
|
||||
- `STEPS`: heading, 2 to 6 numbered steps, each with a title and a short text.
|
||||
- `TRUST`: 2 to 6 short items in one strip (for example "Certified with LG · Samsung · Philips").
|
||||
- `CTA`: a full-width band with a heading, a short text and a button.
|
||||
|
||||
Every block gains a look: `DEFAULT`, `MUTED`, `DARK` or `ACCENT` (the company's accent colour). The look sets the background and the text colour, which is always readable on it. Sections become full-width bands with their content centred, so a page reads like the INS design. The HERO image becomes optional: a hero without an image uses its look's background.
|
||||
|
||||
Limits follow the existing ones: headings 120 characters, short texts 300, card and step titles 80.
|
||||
|
||||
### Change 2: `add-page-drafts-and-templates`
|
||||
|
||||
**Draft and live.**
|
||||
|
||||
- `cms_page` gains a nullable JSON column `draft` holding the editable content: slug, title, description, hide-header and blocks.
|
||||
- A page that has never been published works as today: Save writes the page itself.
|
||||
- A published page saves into `draft` instead. Visitors keep seeing the published content.
|
||||
- **Publish** copies the draft into the page and clears it.
|
||||
- **Discard changes** clears the draft.
|
||||
- Unpublishing works as today.
|
||||
- The draft passes the same checks as a save, including a unique slug among the company's pages. Publish checks it again, because an event may have ended since.
|
||||
- The editor and the staff preview show the draft when there is one. The pages list marks such pages "Unpublished changes".
|
||||
|
||||
**Templates.**
|
||||
|
||||
|
||||
- "New page" first asks for a starting point: Blank, or a starter template with a thumbnail and one line on what it is for. Starters at launch: **Event sign-up** (hero, trust strip, features, steps, FAQ, sign-up form, CTA) and **Service showcase** (hero, image with text, features, FAQ, CTA, form). Placeholder text tells staff what to write ("Your event name"). Templates hold no images; the editor marks the image spots to fill in.
|
||||
- A template's sign-up form has no event yet. Saving tells staff to pick one, as today.
|
||||
- "Duplicate" on the pages list and in the editor copies a page into a new draft of the same company, with slug `<slug>-copy` and status Draft. It runs in the portal (load, then save as new). It needs no new API.
|
||||
- Starters live in portal code as block lists, with their own tests that every starter passes the same rules as a save.
|
||||
|
||||
### Change 3: `add-page-visual-editor` (the on-page editor)
|
||||
|
||||
Layout, at 1024 px and wider:
|
||||
|
||||
```
|
||||
┌ ← Pages Hotel day ▾ Draft [Desktop|Phone] ↶ ↷ [Preview] [Save] [Publish] ┐
|
||||
├───────────────────────────────────────────────────────────────┬───────────────────────┤
|
||||
│ ┌──────── canvas (the page, at the chosen width) ────────┐ │ Section: Features │
|
||||
│ │ HERO "Hotel technology that just works" │ │ Look: [Muted ▾] │
|
||||
│ │ ┌─[⠿ ↑ ↓ ⧉ 🗑]──────────────────────────────────────┐ │ │ Link name: [ ] │
|
||||
│ │ │ FEATURES (selected) click any text to edit │ │ │ Cards: 3 [+ card] │
|
||||
│ │ └─────────────────────────────────────────────────────┘ │ │ Icon card 1: [Wifi▾] │
|
||||
│ │ [ + Add section ] │ │ │
|
||||
│ └─────────────────────────────────────────────────────────┘ │ │
|
||||
└───────────────────────────────────────────────────────────────┴───────────────────────┘
|
||||
```
|
||||
|
||||
- **Canvas.** A same-origin frame showing the page through the same `LandingPage` component the public page uses, in edit mode, at full width (Desktop) or 390 px (Phone). The editor and the canvas exchange the draft and the edit events by `postMessage`, and each accepts messages only from the other. Custom HTML blocks stay sealed frames inside the canvas, showing the unsaved HTML.
|
||||
- **Select.** Hovering a section outlines it. Clicking selects it and shows its toolbar: drag handle, up, down, duplicate, delete. The side panel shows that section's settings, which are today's block fields plus the look and the link name. With nothing selected, the panel shows the page settings: title, address, description, header, status.
|
||||
- **Edit text in place.** Clicking a heading, a short text or a button label edits it in place as plain text, with the same length limits as the server, shown when close. Rich text (Text and Image-with-text blocks) edits in place with Tiptap and a small floating toolbar (bold, italic, link, lists, alignment). Links are typed in the side panel or the toolbar's link box, and follow the existing link rule.
|
||||
- **Images.** Clicking an image, or an empty image spot, opens the file picker. The new image shows at once and uploads on save, as today.
|
||||
- **Add and move.** "+ Add section" between sections and at the end opens a picker of section types with small thumbnails. Sections move by dragging the handle (native drag-and-drop) or with the up and down buttons; the buttons are also the keyboard path.
|
||||
- **Undo and redo.** Page-level, up to 50 steps, with Ctrl+Z and Ctrl+Shift+Z.
|
||||
- **Saving.** Save keeps the draft; Publish saves with status Published. Server refusals show on the canvas (the section is outlined, and the panel shows the field's message), using today's error paths. Leaving with unsaved changes asks first, including in-app links (this closes today's gap).
|
||||
- **Below 1024 px** the editor shows today's form, with Preview, because the canvas and panel do not fit.
|
||||
|
||||
The server and the public page do not change in this change, apart from edit-mode hooks in `LandingPage` that only the canvas uses.
|
||||
|
||||
## Left to the builder
|
||||
|
||||
- The exact icon list, the starter templates' wording, the thumbnail images, and the colours of each look within the design tokens.
|
||||
- Undo grouping (one step per word or per field).
|
||||
- Whether the canvas reuses `BlockFields` sub-components for the side panel or splits them.
|
||||
|
||||
## Sequencing
|
||||
|
||||
1. `add-page-sections`: about 3 to 4 days.
|
||||
2. `add-page-drafts-and-templates`: about 4 days.
|
||||
3. `add-page-visual-editor`: about 2 to 3 weeks.
|
||||
|
||||
Each is its own OpenSpec change, approved before it is built. Once change 1 is out, the INS page can be rebuilt as sections instead of pasted HTML. Staff do this in the editor; it is content, not code.
|
||||
@@ -1491,6 +1491,78 @@ INSERT INTO message (code, content, area) SELECT 'PagesBlockForm', JSON_OBJECT('
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '报名表') WHERE LOWER(code) = LOWER('PagesBlockForm') AND area = 'A';
|
||||
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 'PagesBlockFeatures', JSON_OBJECT('en_US', 'Feature cards', 'zh_CN', '功能卡片'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesBlockFeatures') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '功能卡片') WHERE LOWER(code) = LOWER('PagesBlockFeatures') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesBlockSteps', JSON_OBJECT('en_US', 'Steps', 'zh_CN', '步骤'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesBlockSteps') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '步骤') WHERE LOWER(code) = LOWER('PagesBlockSteps') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesBlockTrust', JSON_OBJECT('en_US', 'Trust strip', 'zh_CN', '信任条'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesBlockTrust') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '信任条') WHERE LOWER(code) = LOWER('PagesBlockTrust') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesBlockCta', JSON_OBJECT('en_US', 'Call to action', 'zh_CN', '行动号召'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesBlockCta') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '行动号召') WHERE LOWER(code) = LOWER('PagesBlockCta') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesLook', JSON_OBJECT('en_US', 'Look', 'zh_CN', '外观'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesLook') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '外观') WHERE LOWER(code) = LOWER('PagesLook') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesLookDefault', JSON_OBJECT('en_US', 'Default', 'zh_CN', '默认'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesLookDefault') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '默认') WHERE LOWER(code) = LOWER('PagesLookDefault') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesLookMuted', JSON_OBJECT('en_US', 'Light grey', 'zh_CN', '浅灰'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesLookMuted') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '浅灰') WHERE LOWER(code) = LOWER('PagesLookMuted') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesLookDark', JSON_OBJECT('en_US', 'Dark', 'zh_CN', '深色'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesLookDark') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '深色') WHERE LOWER(code) = LOWER('PagesLookDark') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesLookAccent', JSON_OBJECT('en_US', 'Company colour', 'zh_CN', '公司主色'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesLookAccent') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '公司主色') WHERE LOWER(code) = LOWER('PagesLookAccent') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesIntro', JSON_OBJECT('en_US', 'Intro', 'zh_CN', '简介'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesIntro') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '简介') WHERE LOWER(code) = LOWER('PagesIntro') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesCardN', JSON_OBJECT('en_US', 'Card {number}', 'zh_CN', '卡片 {number}'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesCardN') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '卡片 {number}') WHERE LOWER(code) = LOWER('PagesCardN') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesStepN', JSON_OBJECT('en_US', 'Step {number}', 'zh_CN', '步骤 {number}'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesStepN') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '步骤 {number}') WHERE LOWER(code) = LOWER('PagesStepN') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesItemN', JSON_OBJECT('en_US', 'Item {number}', 'zh_CN', '项目 {number}'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesItemN') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '项目 {number}') WHERE LOWER(code) = LOWER('PagesItemN') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesCardIcon', JSON_OBJECT('en_US', 'Icon', 'zh_CN', '图标'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesCardIcon') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '图标') WHERE LOWER(code) = LOWER('PagesCardIcon') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesCardTitle', JSON_OBJECT('en_US', 'Title', 'zh_CN', '标题'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesCardTitle') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '标题') WHERE LOWER(code) = LOWER('PagesCardTitle') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesCardText', JSON_OBJECT('en_US', 'Text', 'zh_CN', '文字'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesCardText') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '文字') WHERE LOWER(code) = LOWER('PagesCardText') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesAddCard', JSON_OBJECT('en_US', 'Add card', 'zh_CN', '添加卡片'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesAddCard') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '添加卡片') WHERE LOWER(code) = LOWER('PagesAddCard') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesAddStep', JSON_OBJECT('en_US', 'Add step', 'zh_CN', '添加步骤'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesAddStep') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '添加步骤') WHERE LOWER(code) = LOWER('PagesAddStep') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesAddItem', JSON_OBJECT('en_US', 'Add item', 'zh_CN', '添加项目'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesAddItem') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '添加项目') WHERE LOWER(code) = LOWER('PagesAddItem') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesRemoveCard', JSON_OBJECT('en_US', 'Remove', 'zh_CN', '移除'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesRemoveCard') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '移除') WHERE LOWER(code) = LOWER('PagesRemoveCard') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesIconWifi', JSON_OBJECT('en_US', 'WiFi', 'zh_CN', 'WiFi'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesIconWifi') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', 'WiFi') WHERE LOWER(code) = LOWER('PagesIconWifi') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesIconPhone', JSON_OBJECT('en_US', 'Phone', 'zh_CN', '电话'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesIconPhone') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '电话') WHERE LOWER(code) = LOWER('PagesIconPhone') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesIconTv', JSON_OBJECT('en_US', 'TV', 'zh_CN', '电视'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesIconTv') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '电视') WHERE LOWER(code) = LOWER('PagesIconTv') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesIconMonitor', JSON_OBJECT('en_US', 'Screen', 'zh_CN', '屏幕'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesIconMonitor') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '屏幕') WHERE LOWER(code) = LOWER('PagesIconMonitor') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesIconLock', JSON_OBJECT('en_US', 'Lock', 'zh_CN', '门锁'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesIconLock') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '门锁') WHERE LOWER(code) = LOWER('PagesIconLock') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesIconShieldCheck', JSON_OBJECT('en_US', 'Security', 'zh_CN', '安全'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesIconShieldCheck') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '安全') WHERE LOWER(code) = LOWER('PagesIconShieldCheck') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesIconCloud', JSON_OBJECT('en_US', 'Cloud', 'zh_CN', '云端'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesIconCloud') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '云端') WHERE LOWER(code) = LOWER('PagesIconCloud') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesIconWrench', JSON_OBJECT('en_US', 'Service', 'zh_CN', '维修服务'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesIconWrench') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '维修服务') WHERE LOWER(code) = LOWER('PagesIconWrench') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesIconHeadset', JSON_OBJECT('en_US', 'Support', 'zh_CN', '客服支持'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesIconHeadset') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '客服支持') WHERE LOWER(code) = LOWER('PagesIconHeadset') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesIconUsers', JSON_OBJECT('en_US', 'People', 'zh_CN', '人员'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesIconUsers') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '人员') WHERE LOWER(code) = LOWER('PagesIconUsers') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesIconCalendar', JSON_OBJECT('en_US', 'Calendar', 'zh_CN', '日历'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesIconCalendar') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '日历') WHERE LOWER(code) = LOWER('PagesIconCalendar') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesIconStar', JSON_OBJECT('en_US', 'Star', 'zh_CN', '星标'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesIconStar') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '星标') WHERE LOWER(code) = LOWER('PagesIconStar') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesCardCount', JSON_OBJECT('en_US', 'Use 2 to 6 cards.', 'zh_CN', '请使用 2 至 6 张卡片。'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesCardCount') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '请使用 2 至 6 张卡片。') WHERE LOWER(code) = LOWER('PagesCardCount') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesBadIcon', JSON_OBJECT('en_US', 'Choose an icon from the list.', 'zh_CN', '请从列表中选择图标。'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesBadIcon') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '请从列表中选择图标。') WHERE LOWER(code) = LOWER('PagesBadIcon') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesBadLook', JSON_OBJECT('en_US', 'Choose a look from the list.', 'zh_CN', '请从列表中选择外观。'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesBadLook') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '请从列表中选择外观。') WHERE LOWER(code) = LOWER('PagesBadLook') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesUnusedField', JSON_OBJECT('en_US', 'This section doesn''t use this field.', 'zh_CN', '此区块不使用该字段。'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesUnusedField') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '此区块不使用该字段。') WHERE LOWER(code) = LOWER('PagesUnusedField') 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');
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
schema: spec-driven
|
||||
created: 2026-12-03
|
||||
@@ -0,0 +1,28 @@
|
||||
## Context
|
||||
|
||||
Design: `docs/superpowers/specs/2026-12-03-page-builder-design.md`, change 1. Blocks are one JSON list per page, validated by `CmsBlockValidator`, passed through mobile-api as maps, rendered by `LandingPage`/`Block` in `CmsBlocks.tsx`, and edited by `BlockFields.tsx`.
|
||||
|
||||
## Goals / Non-Goals
|
||||
|
||||
**Goals:** four new section types, a look per section, an optional hero image, form-editor support.
|
||||
|
||||
**Non-Goals:** the on-page editor and templates (changes 2 and 3); per-element colours or fonts.
|
||||
|
||||
## Decisions
|
||||
|
||||
1. **One `cards` list** for FEATURES, STEPS and TRUST: items `{icon, title, text}`. FEATURES uses all three (icon required, from a fixed list); STEPS uses title and text (numbered by position); TRUST uses title only. Fields a type does not use are refused, so stored JSON stays clean. Limits: 2 to 6 cards, title 80, text 300.
|
||||
2. **Icons** are a fixed list of Lucide names: `wifi, phone, tv, monitor, lock, shield-check, cloud, wrench, headset, users, calendar, star`. The server checks the name; the portal maps names to components, so no icon markup is stored.
|
||||
3. **CTA** is heading (required), text (optional) and a button (required: a CTA without one has no purpose). Same link rule as other buttons.
|
||||
4. **Look** is an optional block field `look`: `DEFAULT` (or absent), `MUTED`, `DARK`, `ACCENT`. Any block type may carry it. Non-default looks render the block as a full-width band (background across the window, content in the usual width, vertical padding); `ACCENT` uses the company accent with `contrastText` for the text, falling back to the default primary colour. `DEFAULT` renders as today, so existing pages are unchanged.
|
||||
5. **Hero image optional.** A hero without an image already renders as plain text in the renderer; only the validator's requirement goes. A given image must still be the company's.
|
||||
6. **Editor.** Each new type gets an "Add …" button, its fields, and a card list with add/remove/move like FAQ items. The look picker is a select on every block.
|
||||
|
||||
## Risks / Trade-offs
|
||||
|
||||
- A Dark or Accent band right after another band of the same look merges visually → acceptable; staff see it in the preview.
|
||||
- `HTML` blocks ignore a look: a Custom HTML block is a full design of its own, so the editor does not offer the picker for it and the renderer draws no band.
|
||||
- Rollback: pages saved with new types must be edited before the previous release saves them; their new sections render as nothing under it.
|
||||
|
||||
## Migration Plan
|
||||
|
||||
Deploy services-counter and the portal; run `sql/01-section-labels.sql`. Rollback: previous images and `sql/99-rollback.sql`.
|
||||
@@ -0,0 +1,28 @@
|
||||
## Why
|
||||
|
||||
Marketing staff will build a landing page for every event and are not technical. Today's blocks (hero, text, image with text, FAQ, form, custom HTML) cannot produce a page like the INS design without pasting HTML, which only a developer can maintain. This is change 1 of the page builder: `docs/superpowers/specs/2026-12-03-page-builder-design.md`.
|
||||
|
||||
## What Changes
|
||||
|
||||
- New section types: FEATURES (icon cards), STEPS (numbered steps), TRUST (a strip of short items) and CTA (a call-to-action band).
|
||||
- Every section gets a look: Default, Muted, Dark or Accent (the company colour), drawn as a full-width band with readable text. Default keeps today's appearance, so existing pages do not change.
|
||||
- A HERO image becomes optional.
|
||||
- The form editor gains the new types, their fields and the look picker; labels in English and Chinese.
|
||||
|
||||
## Capabilities
|
||||
|
||||
### New Capabilities
|
||||
|
||||
None.
|
||||
|
||||
### Modified Capabilities
|
||||
|
||||
- `landing-pages`: new section types, section looks, optional hero image.
|
||||
|
||||
## Impact
|
||||
|
||||
- services-counter: `CmsBlock` gains `look` and `cards`; `CmsBlockValidator` rules for the new types. No DDL (blocks are JSON).
|
||||
- mobile-api: none (blocks pass through).
|
||||
- Portal: `cmsPages.ts`, `CmsBlocks.tsx`, `BlockFields.tsx`, `PageEditor.tsx` (add buttons), labels.
|
||||
- SQL: `sql/01-section-labels.sql`, `sql/99-rollback.sql` (labels only).
|
||||
- Rollback: the previous release refuses the new types and fields when such a page is saved, and renders unknown types as nothing.
|
||||
@@ -0,0 +1,103 @@
|
||||
## 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, HTML, FEATURES, STEPS, TRUST and CTA. 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
|
||||
|
||||
#### Scenario: New section types read back
|
||||
|
||||
- **WHEN** staff save a page with blocks FEATURES, STEPS, TRUST and CTA
|
||||
- **THEN** reading the page returns those four blocks in that order with their cards and fields
|
||||
|
||||
## ADDED Requirements
|
||||
|
||||
### Requirement: Card Sections
|
||||
|
||||
A FEATURES, STEPS or TRUST block SHALL have 2 to 6 cards, with titles of at most 80 characters and texts of at most 300. FEATURES SHALL have a heading, an optional intro and cards with an icon from the fixed list, a title and a text. STEPS SHALL have a heading and numbered cards with a title and a text. TRUST SHALL have only card titles. A save breaking these rules, or using a card field its type lacks, SHALL be refused on that field.
|
||||
|
||||
#### Scenario: Feature cards show their icons
|
||||
|
||||
- **GIVEN** a published page with a FEATURES block of three cards with icons `wifi`, `tv` and `lock`
|
||||
- **WHEN** a visitor opens it
|
||||
- **THEN** the page shows the heading and three cards, each with its icon, title and text
|
||||
|
||||
#### Scenario: Unknown icon
|
||||
|
||||
- **WHEN** a page is saved with a FEATURES card whose icon is `rocket-launcher`
|
||||
- **THEN** the save is refused on field `blocks[0].cards[0].icon`
|
||||
|
||||
#### Scenario: Too few cards
|
||||
|
||||
- **WHEN** a page is saved with a STEPS block of one card
|
||||
- **THEN** the save is refused on field `blocks[0].cards`
|
||||
|
||||
#### Scenario: Steps are numbered
|
||||
|
||||
- **GIVEN** a published page with a STEPS block of three steps
|
||||
- **WHEN** a visitor opens it
|
||||
- **THEN** the steps show the numbers 1, 2 and 3 in order
|
||||
|
||||
### Requirement: Call-To-Action Band
|
||||
|
||||
A CTA block SHALL have a heading of at most 120 characters, an optional text of at most 300, and a button with both a label and a link following the button link rule. A save without the button SHALL be refused on the button field.
|
||||
|
||||
#### Scenario: A CTA needs its button
|
||||
|
||||
- **WHEN** a page is saved with a CTA block that has a heading and no button
|
||||
- **THEN** the save is refused on field `blocks[0].buttonLabel`
|
||||
|
||||
### Requirement: Section Looks
|
||||
|
||||
Any block MAY carry a look: Default, Muted, Dark or Accent. Default, or no look, SHALL render as before. Muted, Dark and Accent SHALL render the block as a full-width band in that colour with text readable on it; Accent SHALL use the company's accent colour, or the default primary colour when the company has none. Any other look SHALL be refused on that block's look field.
|
||||
|
||||
#### Scenario: A dark band
|
||||
|
||||
- **GIVEN** a published page whose CTA block has the Dark look
|
||||
- **WHEN** a visitor opens it
|
||||
- **THEN** the CTA shows as a dark full-width band with light text
|
||||
|
||||
#### Scenario: Existing pages unchanged
|
||||
|
||||
- **GIVEN** a page saved before this change, whose blocks have no look
|
||||
- **WHEN** a visitor opens it
|
||||
- **THEN** it renders as it did before
|
||||
|
||||
#### Scenario: Unknown look
|
||||
|
||||
- **WHEN** a page is saved with a block whose look is `NEON`
|
||||
- **THEN** the save is refused on field `blocks[0].look`
|
||||
|
||||
### Requirement: Hero Image Is Optional
|
||||
|
||||
A HERO block MAY have no image; it then shows its heading, text and button on its look's background. When it has an image, the image SHALL still belong to the page's company.
|
||||
|
||||
#### Scenario: Hero without an image
|
||||
|
||||
- **WHEN** a page is saved with a HERO block that has a heading and no image
|
||||
- **THEN** the save succeeds
|
||||
|
||||
### Requirement: New Sections In The Editor
|
||||
|
||||
The page editor SHALL offer adding FEATURES, STEPS, TRUST and CTA blocks, editing their fields, adding, removing and reordering cards, and choosing any block's look. Refusals SHALL show at the field they name, including card fields.
|
||||
|
||||
#### Scenario: A refused card title shows at its field
|
||||
|
||||
- **GIVEN** staff editing a page with a FEATURES block
|
||||
- **WHEN** the save is refused on field `blocks[0].cards[1].title`
|
||||
- **THEN** the message shows under the second card's title field
|
||||
@@ -0,0 +1,75 @@
|
||||
-- The labels added by add-page-sections, 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 'PagesBlockFeatures', JSON_OBJECT('en_US', 'Feature cards', 'zh_CN', '功能卡片'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesBlockFeatures') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '功能卡片') WHERE LOWER(code) = LOWER('PagesBlockFeatures') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesBlockSteps', JSON_OBJECT('en_US', 'Steps', 'zh_CN', '步骤'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesBlockSteps') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '步骤') WHERE LOWER(code) = LOWER('PagesBlockSteps') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesBlockTrust', JSON_OBJECT('en_US', 'Trust strip', 'zh_CN', '信任条'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesBlockTrust') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '信任条') WHERE LOWER(code) = LOWER('PagesBlockTrust') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesBlockCta', JSON_OBJECT('en_US', 'Call to action', 'zh_CN', '行动号召'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesBlockCta') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '行动号召') WHERE LOWER(code) = LOWER('PagesBlockCta') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesLook', JSON_OBJECT('en_US', 'Look', 'zh_CN', '外观'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesLook') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '外观') WHERE LOWER(code) = LOWER('PagesLook') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesLookDefault', JSON_OBJECT('en_US', 'Default', 'zh_CN', '默认'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesLookDefault') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '默认') WHERE LOWER(code) = LOWER('PagesLookDefault') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesLookMuted', JSON_OBJECT('en_US', 'Light grey', 'zh_CN', '浅灰'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesLookMuted') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '浅灰') WHERE LOWER(code) = LOWER('PagesLookMuted') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesLookDark', JSON_OBJECT('en_US', 'Dark', 'zh_CN', '深色'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesLookDark') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '深色') WHERE LOWER(code) = LOWER('PagesLookDark') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesLookAccent', JSON_OBJECT('en_US', 'Company colour', 'zh_CN', '公司主色'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesLookAccent') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '公司主色') WHERE LOWER(code) = LOWER('PagesLookAccent') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesIntro', JSON_OBJECT('en_US', 'Intro', 'zh_CN', '简介'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesIntro') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '简介') WHERE LOWER(code) = LOWER('PagesIntro') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesCardN', JSON_OBJECT('en_US', 'Card {number}', 'zh_CN', '卡片 {number}'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesCardN') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '卡片 {number}') WHERE LOWER(code) = LOWER('PagesCardN') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesStepN', JSON_OBJECT('en_US', 'Step {number}', 'zh_CN', '步骤 {number}'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesStepN') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '步骤 {number}') WHERE LOWER(code) = LOWER('PagesStepN') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesItemN', JSON_OBJECT('en_US', 'Item {number}', 'zh_CN', '项目 {number}'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesItemN') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '项目 {number}') WHERE LOWER(code) = LOWER('PagesItemN') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesCardIcon', JSON_OBJECT('en_US', 'Icon', 'zh_CN', '图标'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesCardIcon') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '图标') WHERE LOWER(code) = LOWER('PagesCardIcon') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesCardTitle', JSON_OBJECT('en_US', 'Title', 'zh_CN', '标题'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesCardTitle') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '标题') WHERE LOWER(code) = LOWER('PagesCardTitle') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesCardText', JSON_OBJECT('en_US', 'Text', 'zh_CN', '文字'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesCardText') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '文字') WHERE LOWER(code) = LOWER('PagesCardText') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesAddCard', JSON_OBJECT('en_US', 'Add card', 'zh_CN', '添加卡片'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesAddCard') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '添加卡片') WHERE LOWER(code) = LOWER('PagesAddCard') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesAddStep', JSON_OBJECT('en_US', 'Add step', 'zh_CN', '添加步骤'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesAddStep') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '添加步骤') WHERE LOWER(code) = LOWER('PagesAddStep') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesAddItem', JSON_OBJECT('en_US', 'Add item', 'zh_CN', '添加项目'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesAddItem') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '添加项目') WHERE LOWER(code) = LOWER('PagesAddItem') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesRemoveCard', JSON_OBJECT('en_US', 'Remove', 'zh_CN', '移除'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesRemoveCard') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '移除') WHERE LOWER(code) = LOWER('PagesRemoveCard') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesIconWifi', JSON_OBJECT('en_US', 'WiFi', 'zh_CN', 'WiFi'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesIconWifi') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', 'WiFi') WHERE LOWER(code) = LOWER('PagesIconWifi') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesIconPhone', JSON_OBJECT('en_US', 'Phone', 'zh_CN', '电话'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesIconPhone') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '电话') WHERE LOWER(code) = LOWER('PagesIconPhone') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesIconTv', JSON_OBJECT('en_US', 'TV', 'zh_CN', '电视'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesIconTv') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '电视') WHERE LOWER(code) = LOWER('PagesIconTv') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesIconMonitor', JSON_OBJECT('en_US', 'Screen', 'zh_CN', '屏幕'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesIconMonitor') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '屏幕') WHERE LOWER(code) = LOWER('PagesIconMonitor') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesIconLock', JSON_OBJECT('en_US', 'Lock', 'zh_CN', '门锁'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesIconLock') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '门锁') WHERE LOWER(code) = LOWER('PagesIconLock') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesIconShieldCheck', JSON_OBJECT('en_US', 'Security', 'zh_CN', '安全'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesIconShieldCheck') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '安全') WHERE LOWER(code) = LOWER('PagesIconShieldCheck') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesIconCloud', JSON_OBJECT('en_US', 'Cloud', 'zh_CN', '云端'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesIconCloud') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '云端') WHERE LOWER(code) = LOWER('PagesIconCloud') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesIconWrench', JSON_OBJECT('en_US', 'Service', 'zh_CN', '维修服务'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesIconWrench') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '维修服务') WHERE LOWER(code) = LOWER('PagesIconWrench') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesIconHeadset', JSON_OBJECT('en_US', 'Support', 'zh_CN', '客服支持'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesIconHeadset') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '客服支持') WHERE LOWER(code) = LOWER('PagesIconHeadset') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesIconUsers', JSON_OBJECT('en_US', 'People', 'zh_CN', '人员'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesIconUsers') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '人员') WHERE LOWER(code) = LOWER('PagesIconUsers') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesIconCalendar', JSON_OBJECT('en_US', 'Calendar', 'zh_CN', '日历'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesIconCalendar') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '日历') WHERE LOWER(code) = LOWER('PagesIconCalendar') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesIconStar', JSON_OBJECT('en_US', 'Star', 'zh_CN', '星标'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesIconStar') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '星标') WHERE LOWER(code) = LOWER('PagesIconStar') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesCardCount', JSON_OBJECT('en_US', 'Use 2 to 6 cards.', 'zh_CN', '请使用 2 至 6 张卡片。'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesCardCount') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '请使用 2 至 6 张卡片。') WHERE LOWER(code) = LOWER('PagesCardCount') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesBadIcon', JSON_OBJECT('en_US', 'Choose an icon from the list.', 'zh_CN', '请从列表中选择图标。'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesBadIcon') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '请从列表中选择图标。') WHERE LOWER(code) = LOWER('PagesBadIcon') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesBadLook', JSON_OBJECT('en_US', 'Choose a look from the list.', 'zh_CN', '请从列表中选择外观。'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesBadLook') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '请从列表中选择外观。') WHERE LOWER(code) = LOWER('PagesBadLook') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesUnusedField', JSON_OBJECT('en_US', 'This section doesn''t use this field.', 'zh_CN', '此区块不使用该字段。'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesUnusedField') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '此区块不使用该字段。') WHERE LOWER(code) = LOWER('PagesUnusedField') AND area = 'A';
|
||||
@@ -0,0 +1,5 @@
|
||||
-- Co-Lite change add-page-sections: rollback of the labels. Pages using FEATURES, STEPS, TRUST, CTA, a look or an
|
||||
-- image-less hero must be edited before the previous release saves them; it refuses those, and renders the new
|
||||
-- section types as nothing.
|
||||
USE `service-system`;
|
||||
DELETE FROM message WHERE code IN ('PagesBlockFeatures', 'PagesBlockSteps', 'PagesBlockTrust', 'PagesBlockCta', 'PagesLook', 'PagesLookDefault', 'PagesLookMuted', 'PagesLookDark', 'PagesLookAccent', 'PagesIntro', 'PagesCardN', 'PagesStepN', 'PagesItemN', 'PagesCardIcon', 'PagesCardTitle', 'PagesCardText', 'PagesAddCard', 'PagesAddStep', 'PagesAddItem', 'PagesRemoveCard', 'PagesIconWifi', 'PagesIconPhone', 'PagesIconTv', 'PagesIconMonitor', 'PagesIconLock', 'PagesIconShieldCheck', 'PagesIconCloud', 'PagesIconWrench', 'PagesIconHeadset', 'PagesIconUsers', 'PagesIconCalendar', 'PagesIconStar', 'PagesCardCount', 'PagesBadIcon', 'PagesBadLook', 'PagesUnusedField') AND area = 'A';
|
||||
@@ -0,0 +1,19 @@
|
||||
# Tasks: add-page-sections
|
||||
|
||||
Design: `design.md` and `docs/superpowers/specs/2026-12-03-page-builder-design.md` (change 1). Every task is TDD. Work is serial in the main session, with a self-review per task.
|
||||
|
||||
## 1. services-counter
|
||||
|
||||
- [x] 1.1 `CmsBlock.look` and `cards` (`CmsCard` record: icon, title, text); `CmsBlockValidator`: FEATURES, STEPS, TRUST, CTA rules, the icon list, the look values, HERO image optional.
|
||||
- Verify: `mvn -T 1C -B -pl solvway-services-counter -am verify`
|
||||
|
||||
## 2. Portal
|
||||
|
||||
- [x] 2.1 Model and renderer: types, `emptyBlock`, `BLOCK_LABELS`, icon map; `CmsBlocks` renders the four new types and the looks (full-width bands, readable text, Accent from the company colour); Default unchanged.
|
||||
- [x] 2.2 Editor: add buttons, fields and card lists (add, remove, move) for the new types, the look select on every block, inline card errors; labels in `defaultMessages.ts` and `zh_CN.seed.json`, `npm run i18n:sql`, `sql/01-section-labels.sql` and `sql/99-rollback.sql`.
|
||||
- Verify (2.1 to 2.2): `cd solvway-admin-portal && npx vitest run; echo VITEST=$? && npx tsc --noEmit && npm run lint`
|
||||
|
||||
## 3. Release
|
||||
|
||||
- [x] 3.1 `docs/deployment.md`: SQL row; landing-pages notes (new sections, looks, rebuilding the INS page as sections).
|
||||
- [x] 3.2 Live check (Playwright) on a local portal: build a disposable page with every new type and each look; refusals (unknown look is API-only, so check a too-few-cards and a missing CTA button); preview and public page at 1280 and 360 px.
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import type { ReactNode } from "react";
|
||||
import { ArrowDown, ArrowUp, Plus, Trash2 } from "lucide-react";
|
||||
import { BLOCK_LABELS, imageSrc, type CmsBlock } from "@/app/lib/cmsPages";
|
||||
import { BLOCK_LABELS, ICONS, LOOKS, imageSrc, type CmsBlock, type CmsCard, type Look } from "@/app/lib/cmsPages";
|
||||
import { Button } from "@/app/components/ui/button";
|
||||
import { Input } from "@/app/components/ui/input";
|
||||
import { Label } from "@/app/components/ui/label";
|
||||
@@ -20,8 +20,25 @@ const INLINE: Record<string, string[]> = {
|
||||
FAQ: ["heading", "items"],
|
||||
FORM: ["heading", "eventUuid"],
|
||||
HTML: ["html"],
|
||||
FEATURES: ["heading", "text", "cards"],
|
||||
STEPS: ["heading", "cards"],
|
||||
TRUST: ["cards"],
|
||||
CTA: ["heading", "text", "buttonLabel", "buttonUrl"],
|
||||
};
|
||||
const LISTED = /^(items\[\d+\]\.(question|answer)|cards\[\d+\]\.(icon|title|text))$/;
|
||||
|
||||
// add-page-sections: labels for looks, feature icons and each card type's wording.
|
||||
const LOOK_LABELS: Record<Look, string> = { DEFAULT: "PagesLookDefault", MUTED: "PagesLookMuted", DARK: "PagesLookDark", ACCENT: "PagesLookAccent" };
|
||||
const ICON_LABELS: Record<string, string> = {
|
||||
wifi: "PagesIconWifi", phone: "PagesIconPhone", tv: "PagesIconTv", monitor: "PagesIconMonitor", lock: "PagesIconLock",
|
||||
"shield-check": "PagesIconShieldCheck", cloud: "PagesIconCloud", wrench: "PagesIconWrench", headset: "PagesIconHeadset",
|
||||
users: "PagesIconUsers", calendar: "PagesIconCalendar", star: "PagesIconStar",
|
||||
};
|
||||
const CARD_KINDS: Record<string, { legend: string; add: string; icon: boolean; text: boolean; empty: CmsCard }> = {
|
||||
FEATURES: { legend: "PagesCardN", add: "PagesAddCard", icon: true, text: true, empty: { icon: "star", title: "", text: "" } },
|
||||
STEPS: { legend: "PagesStepN", add: "PagesAddStep", icon: false, text: true, empty: { title: "", text: "" } },
|
||||
TRUST: { legend: "PagesItemN", add: "PagesAddItem", icon: false, text: false, empty: { title: "" } },
|
||||
};
|
||||
const LISTED = /^items\[\d+\]\.(question|answer)$/;
|
||||
const SELECT = "flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm disabled:cursor-not-allowed disabled:opacity-50";
|
||||
|
||||
export interface EventOption {
|
||||
@@ -64,7 +81,7 @@ export function BlockFields(props: {
|
||||
const t = useT();
|
||||
const set = (patch: Partial<CmsBlock>) => onChange((b) => ({ ...b, ...patch }));
|
||||
const fid = (name: string) => `block-${id}-${name}`;
|
||||
const topErrors = Object.entries(errors).filter(([path]) => path !== "anchor" && !INLINE[block.type]?.includes(path) && !LISTED.test(path));
|
||||
const topErrors = Object.entries(errors).filter(([path]) => path !== "anchor" && path !== "look" && !INLINE[block.type]?.includes(path) && !LISTED.test(path));
|
||||
|
||||
const text = (name: "heading" | "text" | "buttonLabel" | "buttonUrl" | "anchor", labelCode: string) => (
|
||||
<Field id={fid(name)} label={t(labelCode)} error={errors[name]}>
|
||||
@@ -97,6 +114,56 @@ export function BlockFields(props: {
|
||||
</Field>
|
||||
);
|
||||
|
||||
const kind = CARD_KINDS[block.type];
|
||||
const cards = block.cards ?? [];
|
||||
const setCards = (next: CmsCard[]) => set({ cards: next });
|
||||
const moveCard = (i: number, delta: -1 | 1) => {
|
||||
const next = [...cards];
|
||||
[next[i], next[i + delta]] = [next[i + delta], next[i]];
|
||||
setCards(next);
|
||||
};
|
||||
const cardList = kind ? (
|
||||
<>
|
||||
{cards.map((card, i) => {
|
||||
const err = (f: string) => errors[`cards[${i}].${f}`];
|
||||
const cardField = (f: "title" | "text", labelCode: string, multiline: boolean) => (
|
||||
<Field id={fid(`c${i}${f}`)} label={t(labelCode)} error={err(f)}>
|
||||
{multiline
|
||||
? <Textarea id={fid(`c${i}${f}`)} rows={2} value={card[f] ?? ""} disabled={saving} aria-invalid={!!err(f)}
|
||||
onChange={(e) => setCards(cards.map((c, j) => (j === i ? { ...c, [f]: e.target.value } : c)))} />
|
||||
: <Input id={fid(`c${i}${f}`)} value={card[f] ?? ""} disabled={saving} aria-invalid={!!err(f)}
|
||||
onChange={(e) => setCards(cards.map((c, j) => (j === i ? { ...c, [f]: e.target.value } : c)))} />}
|
||||
</Field>
|
||||
);
|
||||
return (
|
||||
<fieldset key={i} className="space-y-2 rounded-md border p-3">
|
||||
<legend className="px-1 text-sm font-medium">{t(kind.legend, { number: i + 1 })}</legend>
|
||||
{kind.icon ? (
|
||||
<Field id={fid(`c${i}icon`)} label={t("PagesCardIcon")} error={err("icon")}>
|
||||
<select id={fid(`c${i}icon`)} className={SELECT} value={card.icon ?? "star"} disabled={saving} aria-invalid={!!err("icon")}
|
||||
onChange={(e) => setCards(cards.map((c, j) => (j === i ? { ...c, icon: e.target.value } : c)))}>
|
||||
{Object.keys(ICONS).map((name) => <option key={name} value={name}>{t(ICON_LABELS[name])}</option>)}
|
||||
</select>
|
||||
</Field>
|
||||
) : null}
|
||||
{cardField("title", "PagesCardTitle", false)}
|
||||
{kind.text ? cardField("text", "PagesCardText", true) : null}
|
||||
<div className="flex flex-wrap gap-1">
|
||||
<Button type="button" variant="ghost" size="sm" disabled={saving || i === 0} onClick={() => moveCard(i, -1)}>{t("PagesMoveUp")}</Button>
|
||||
<Button type="button" variant="ghost" size="sm" disabled={saving || i === cards.length - 1} onClick={() => moveCard(i, 1)}>{t("PagesMoveDown")}</Button>
|
||||
<Button type="button" variant="ghost" size="sm" disabled={saving || cards.length <= 2} onClick={() => setCards(cards.filter((_, j) => j !== i))}>{t("PagesRemoveCard")}</Button>
|
||||
</div>
|
||||
</fieldset>
|
||||
);
|
||||
})}
|
||||
<FieldError message={errors.cards} />
|
||||
<Button type="button" variant="outline" size="sm" disabled={saving || cards.length >= 6} onClick={() => setCards([...cards, { ...kind.empty }])}>
|
||||
<Plus aria-hidden="true" className="size-4" />
|
||||
{t(kind.add)}
|
||||
</Button>
|
||||
</>
|
||||
) : null;
|
||||
|
||||
const items = block.items ?? [];
|
||||
const setItems = (next: typeof items) => set({ items: next });
|
||||
|
||||
@@ -196,6 +263,43 @@ export function BlockFields(props: {
|
||||
</>
|
||||
)}
|
||||
|
||||
{block.type === "FEATURES" && (
|
||||
<>
|
||||
{text("heading", "PagesHeading")}
|
||||
<Field id={fid("text")} label={t("PagesIntro")} error={errors.text}>
|
||||
<Textarea id={fid("text")} rows={2} value={block.text ?? ""} disabled={saving} aria-invalid={!!errors.text} onChange={(e) => set({ text: e.target.value })} />
|
||||
</Field>
|
||||
{cardList}
|
||||
</>
|
||||
)}
|
||||
|
||||
{block.type === "STEPS" && (
|
||||
<>
|
||||
{text("heading", "PagesHeading")}
|
||||
{cardList}
|
||||
</>
|
||||
)}
|
||||
|
||||
{block.type === "TRUST" && cardList}
|
||||
|
||||
{block.type === "CTA" && (
|
||||
<>
|
||||
{text("heading", "PagesHeading")}
|
||||
{text("text", "PagesText")}
|
||||
{text("buttonLabel", "PagesButtonLabel")}
|
||||
{text("buttonUrl", "PagesButtonLink")}
|
||||
</>
|
||||
)}
|
||||
|
||||
{block.type !== "HTML" && (
|
||||
<Field id={fid("look")} label={t("PagesLook")} error={errors.look}>
|
||||
<select id={fid("look")} className={SELECT} value={block.look ?? "DEFAULT"} disabled={saving} aria-invalid={!!errors.look}
|
||||
onChange={(e) => set({ look: e.target.value as Look })}>
|
||||
{LOOKS.map((look) => <option key={look} value={look}>{t(LOOK_LABELS[look])}</option>)}
|
||||
</select>
|
||||
</Field>
|
||||
)}
|
||||
|
||||
{/* add-page-anchor-links: the block's id on the page, the target of #name links. */}
|
||||
<div className="space-y-1">
|
||||
{text("anchor", "PagesAnchor")}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
import { render, screen, within } from "@testing-library/react";
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { LandingPage, type PublicBlock } from "./CmsBlocks";
|
||||
|
||||
// add-page-sections: card sections, the CTA band, section looks and the image-less hero.
|
||||
const company = { code: "INS", name: "INS Sdn Bhd", logoImageId: null, accentColor: "#FFEE00" };
|
||||
const page = (blocks: PublicBlock[]) => ({ slug: "hotel", title: "Hotel day", blocks });
|
||||
|
||||
describe("LandingPage: sections", () => {
|
||||
it("shows feature cards with their icons, titles and texts", () => {
|
||||
render(<LandingPage company={company} page={page([{
|
||||
type: "FEATURES", heading: "What we do", text: "One partner.",
|
||||
cards: [{ icon: "wifi", title: "Managed WiFi", text: "Guests connect." }, { icon: "tv", title: "In-room TV", text: "Casting." }],
|
||||
}])} />);
|
||||
expect(screen.getByRole("heading", { name: "What we do" })).toBeInTheDocument();
|
||||
expect(screen.getByText("One partner.")).toBeInTheDocument();
|
||||
const items = screen.getAllByRole("listitem");
|
||||
expect(items).toHaveLength(2);
|
||||
expect(within(items[0]).getByRole("heading", { name: "Managed WiFi" })).toBeInTheDocument();
|
||||
expect(items[0].querySelector("svg.lucide-wifi")).not.toBeNull();
|
||||
expect(items[1].querySelector("svg.lucide-tv")).not.toBeNull();
|
||||
});
|
||||
|
||||
it("numbers steps in order", () => {
|
||||
render(<LandingPage company={company} page={page([{
|
||||
type: "STEPS", heading: "How it works",
|
||||
cards: [{ title: "Survey", text: "We visit." }, { title: "Install", text: "We fit it." }, { title: "Support", text: "We stay." }],
|
||||
}])} />);
|
||||
const list = screen.getByRole("list");
|
||||
expect(list.tagName).toBe("OL");
|
||||
const items = within(list).getAllByRole("listitem");
|
||||
expect(items.map((li) => li.textContent)).toEqual(["1SurveyWe visit.", "2InstallWe fit it.", "3SupportWe stay."]);
|
||||
});
|
||||
|
||||
it("shows a trust strip of short items", () => {
|
||||
render(<LandingPage company={company} page={page([{ type: "TRUST", cards: [{ title: "Certified with LG" }, { title: "Local support" }] }])} />);
|
||||
expect(screen.getAllByRole("listitem").map((li) => li.textContent)).toEqual(["Certified with LG", "Local support"]);
|
||||
});
|
||||
|
||||
it("shows a call-to-action band with its button, and drops an unsafe one", () => {
|
||||
render(<LandingPage company={company} page={page([
|
||||
{ type: "CTA", heading: "Ready?", text: "Talk to us.", buttonLabel: "Get a quote", buttonUrl: "#signup" },
|
||||
{ type: "CTA", heading: "Bad", buttonLabel: "Evil", buttonUrl: "javascript:alert(1)" },
|
||||
])} />);
|
||||
expect(screen.getByRole("heading", { name: "Ready?" })).toBeInTheDocument();
|
||||
expect(screen.getByRole("link", { name: "Get a quote" })).toHaveAttribute("href", "#signup");
|
||||
expect(screen.queryByRole("link", { name: "Evil" })).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("draws a non-default look as a full-width band and leaves default blocks as before", () => {
|
||||
render(<LandingPage company={company} page={page([
|
||||
{ type: "CTA", heading: "Dark", buttonLabel: "Go", buttonUrl: "/x", look: "DARK" },
|
||||
{ type: "CTA", heading: "Accent", buttonLabel: "Go", buttonUrl: "/x", look: "ACCENT" },
|
||||
{ type: "CTA", heading: "Muted", buttonLabel: "Go", buttonUrl: "/x", look: "MUTED" },
|
||||
{ type: "CTA", heading: "Plain", buttonLabel: "Go", buttonUrl: "/x" },
|
||||
{ type: "CTA", heading: "Junk", buttonLabel: "Go", buttonUrl: "/x", look: "NEON" as never },
|
||||
])} />);
|
||||
const band = (name: string) => screen.getByRole("heading", { name }).closest("[data-look]");
|
||||
expect(band("Dark")).toHaveAttribute("data-look", "DARK");
|
||||
expect(band("Dark")).toHaveClass("bg-foreground", "text-background");
|
||||
expect(band("Accent")).toHaveClass("bg-primary", "text-primary-foreground");
|
||||
expect(band("Muted")).toHaveClass("bg-muted");
|
||||
expect(band("Plain")).toBeNull();
|
||||
expect(band("Junk")).toBeNull();
|
||||
// On an accent band the button flips, so it never matches the band's colour.
|
||||
expect(within(band("Accent") as HTMLElement).getByRole("link", { name: "Go" })).toHaveClass("bg-background", "text-foreground");
|
||||
});
|
||||
|
||||
it("shows a hero without an image as text on its look's background", () => {
|
||||
render(<LandingPage company={company} page={page([{ type: "HERO", heading: "No picture", buttonLabel: "Join", buttonUrl: "#signup", look: "DARK" }])} />);
|
||||
expect(screen.getByRole("heading", { name: "No picture" })).toBeInTheDocument();
|
||||
expect(document.querySelector("main img")).toBeNull();
|
||||
expect(screen.getByRole("link", { name: "Join" })).toBeInTheDocument();
|
||||
// On a band the hero takes the band's colours; its own grey box would put light text on a light background.
|
||||
expect(screen.getByRole("heading", { name: "No picture" }).closest("section")).not.toHaveClass("bg-muted");
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { CSSProperties, ReactNode } from "react";
|
||||
import { anchorId, contrastText, imageSrc, isSafeLink, type CmsBlock } from "@/app/lib/cmsPages";
|
||||
import { ICONS, LOOKS, anchorId, contrastText, imageSrc, isSafeLink, type CmsBlock, type Look } from "@/app/lib/cmsPages";
|
||||
import type { RegistrationInfo } from "@/app/lib/services/publicRegistration";
|
||||
import { SafeHtml } from "./SafeHtml";
|
||||
import { LandingForm } from "./LandingForm";
|
||||
@@ -20,12 +20,21 @@ export interface Branding {
|
||||
|
||||
const PROSE = "space-y-3 text-base leading-relaxed [&_a]:text-primary [&_a]:underline [&_blockquote]:border-l-2 [&_blockquote]:pl-3 [&_h2]:text-2xl [&_h2]:font-semibold [&_h3]:text-xl [&_h3]:font-semibold [&_ol]:list-decimal [&_ol]:pl-5 [&_ul]:list-disc [&_ul]:pl-5";
|
||||
|
||||
// add-page-sections: non-default looks are full-width bands. On an accent band the button flips to stay visible.
|
||||
const BANDS: Record<Exclude<Look, "DEFAULT">, string> = {
|
||||
MUTED: "bg-muted text-foreground",
|
||||
DARK: "bg-foreground text-background",
|
||||
ACCENT: "bg-primary text-primary-foreground",
|
||||
};
|
||||
const bandOf = (look: unknown) => (LOOKS.includes(look as Look) && look !== "DEFAULT" ? (look as Exclude<Look, "DEFAULT">) : null);
|
||||
|
||||
function ButtonLink({ block }: { block: CmsBlock }) {
|
||||
if (!block.buttonLabel || !isSafeLink(block.buttonUrl)) return null;
|
||||
const external = /^https:/i.test(block.buttonUrl!);
|
||||
const colours = bandOf(block.look) === "ACCENT" ? "bg-background text-foreground" : "bg-primary text-primary-foreground";
|
||||
return (
|
||||
<a href={block.buttonUrl} {...(external ? { target: "_blank", rel: "noopener noreferrer" } : {})}
|
||||
className="inline-flex h-11 items-center rounded-md bg-primary px-5 text-sm font-medium text-primary-foreground hover:opacity-90 focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none">
|
||||
className={`inline-flex h-11 items-center rounded-md px-5 text-sm font-medium hover:opacity-90 focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none ${colours}`}>
|
||||
{block.buttonLabel}
|
||||
</a>
|
||||
);
|
||||
@@ -40,7 +49,7 @@ function Block({ block, index, company, slug, preview }: { block: PublicBlock; i
|
||||
switch (block.type) {
|
||||
case "HERO":
|
||||
return (
|
||||
<section className="relative overflow-hidden rounded-lg bg-muted">
|
||||
<section className={`relative overflow-hidden rounded-lg ${bandOf(block.look) ? "" : "bg-muted"}`}>
|
||||
<BlockImage id={block.imageId} className="absolute inset-0 h-full w-full object-cover" />
|
||||
<div className={block.imageId ? "relative flex min-h-72 flex-col justify-end gap-3 bg-gradient-to-t from-black/80 via-black/50 to-transparent p-6 text-white sm:min-h-96" : "flex flex-col gap-3 p-6"}>
|
||||
{block.heading ? <h2 className="text-3xl font-semibold sm:text-4xl">{block.heading}</h2> : null}
|
||||
@@ -83,6 +92,60 @@ function Block({ block, index, company, slug, preview }: { block: PublicBlock; i
|
||||
<LandingForm companyCode={company} slug={slug} index={index} info={block.closed ? undefined : block.form} preview={preview} />
|
||||
</section>
|
||||
);
|
||||
case "FEATURES":
|
||||
return (
|
||||
<section className="space-y-6">
|
||||
<div className="max-w-2xl space-y-2">
|
||||
{block.heading ? <h2 className="text-2xl font-semibold sm:text-3xl">{block.heading}</h2> : null}
|
||||
{block.text ? <p className="text-lg opacity-80">{block.text}</p> : null}
|
||||
</div>
|
||||
<ul className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{(block.cards ?? []).map((card, i) => {
|
||||
const Icon = card.icon ? ICONS[card.icon] : undefined;
|
||||
return (
|
||||
<li key={i} className="space-y-2 rounded-lg border bg-card p-5 text-card-foreground shadow-card">
|
||||
{Icon ? <Icon aria-hidden="true" className="size-7 text-primary" /> : null}
|
||||
<h3 className="text-lg font-semibold">{card.title}</h3>
|
||||
<p className="text-muted-foreground">{card.text}</p>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
</section>
|
||||
);
|
||||
case "STEPS":
|
||||
return (
|
||||
<section className="space-y-6">
|
||||
{block.heading ? <h2 className="text-2xl font-semibold sm:text-3xl">{block.heading}</h2> : null}
|
||||
<ol className="grid gap-6 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{(block.cards ?? []).map((card, i) => (
|
||||
<li key={i} className="flex gap-4">
|
||||
<span aria-hidden="true" className="flex size-10 shrink-0 items-center justify-center rounded-full border-2 border-current text-lg font-semibold">{i + 1}</span>
|
||||
<div className="space-y-1">
|
||||
<h3 className="text-lg font-semibold">{card.title}</h3>
|
||||
<p className="opacity-80">{card.text}</p>
|
||||
</div>
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
</section>
|
||||
);
|
||||
case "TRUST":
|
||||
return (
|
||||
<section>
|
||||
<ul className="flex flex-wrap items-center justify-center gap-x-8 gap-y-2 text-center font-medium">
|
||||
{(block.cards ?? []).map((card, i) => <li key={i}>{card.title}</li>)}
|
||||
</ul>
|
||||
</section>
|
||||
);
|
||||
case "CTA":
|
||||
return (
|
||||
<section className="flex flex-col items-center gap-4 py-4 text-center">
|
||||
<h2 className="text-2xl font-semibold sm:text-3xl">{block.heading}</h2>
|
||||
{block.text ? <p className="max-w-2xl text-lg opacity-80">{block.text}</p> : null}
|
||||
<ButtonLink block={block} />
|
||||
</section>
|
||||
);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
@@ -90,6 +153,17 @@ function Block({ block, index, company, slug, preview }: { block: PublicBlock; i
|
||||
|
||||
const WIDTH = "mx-auto w-full max-w-5xl px-4";
|
||||
|
||||
/** A block in the page width; with a non-default look, inside a full-width band of that colour. */
|
||||
function Section({ block, children }: { block: PublicBlock; children: ReactNode }) {
|
||||
const band = bandOf(block.look);
|
||||
if (!band) return <div id={anchorId(block.anchor)} className={WIDTH}>{children}</div>;
|
||||
return (
|
||||
<div id={anchorId(block.anchor)} data-look={band} className={`py-12 ${BANDS[band]}`}>
|
||||
<div className={WIDTH}>{children}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A whole landing page: the company header (logo, accent), the title as the only h1, then the blocks. Custom HTML
|
||||
* blocks run full width; with hideHeader the header goes and the title is for screen readers only.
|
||||
@@ -124,7 +198,7 @@ export function LandingPage({ company, page, banner, preview, frameBase }: {
|
||||
<div className="space-y-10">
|
||||
{page.blocks.map((block, i) => block.type === "HTML"
|
||||
? <HtmlFrame key={i} id={anchorId(block.anchor)} src={`${frames}/${i}`} title={page.title} />
|
||||
: <div key={i} id={anchorId(block.anchor)} className={WIDTH}><Block block={block} index={i} company={company.code} slug={page.slug} preview={preview} /></div>)}
|
||||
: <Section key={i} block={block}><Block block={block} index={i} company={company.code} slug={page.slug} preview={preview} /></Section>)}
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
import { render, screen, waitFor, within } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
import { ApiError } from "@/app/lib/clientApi";
|
||||
|
||||
// add-page-sections: the new section types, their cards and the look picker in the form editor.
|
||||
const mocks = vi.hoisted(() => ({
|
||||
getPage: vi.fn(), savePage: vi.fn(), deletePage: vi.fn(), uploadPageImage: vi.fn(),
|
||||
listAdminEvents: vi.fn(), useAdminAuth: vi.fn(), useCompanyScope: vi.fn(),
|
||||
}));
|
||||
vi.mock("@/app/lib/services/adminPages", () => ({ getPage: mocks.getPage, savePage: mocks.savePage, deletePage: mocks.deletePage, uploadPageImage: mocks.uploadPageImage }));
|
||||
vi.mock("@/app/lib/services/adminEvents", () => ({ listAdminEvents: mocks.listAdminEvents }));
|
||||
vi.mock("@/app/lib/AdminAuthContext", () => ({ useAdminAuth: mocks.useAdminAuth }));
|
||||
vi.mock("@/app/lib/CompanyScope", () => ({ useCompanyScope: mocks.useCompanyScope }));
|
||||
vi.mock("next/navigation", async () => (await import("@/test/memoryRouter")).navigationMock);
|
||||
|
||||
import { memoryRouter } from "@/test/memoryRouter";
|
||||
import { PageEditor } from "./PageEditor";
|
||||
|
||||
const stored = {
|
||||
id: 5, companyId: 2, slug: "hotel", title: "Hotel", metaDescription: null, status: "DRAFT" as const, hideHeader: false,
|
||||
blocks: [
|
||||
{ type: "STEPS" as const, heading: "How it works", cards: [{ title: "Survey", text: "We visit." }, { title: "Install", text: "We fit it." }] },
|
||||
{ type: "HTML" as const, html: "<p>x</p>" },
|
||||
],
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
memoryRouter.reset("/pages/5");
|
||||
mocks.useAdminAuth.mockReturnValue({ isSuper: false, companyCode: "INS" });
|
||||
mocks.useCompanyScope.mockReturnValue({ companyId: undefined, companies: [{ id: 2, code: "INS", name: "INS", status: "A" }], codeOf: (id?: number) => (id === 2 ? "INS" : "") });
|
||||
mocks.listAdminEvents.mockResolvedValue({ items: [], total: 0 });
|
||||
mocks.getPage.mockResolvedValue(stored);
|
||||
mocks.savePage.mockImplementation(async (id: number | undefined, body: object) => ({ ...stored, ...body, id: id ?? 7 }));
|
||||
});
|
||||
|
||||
const group = (name: string) => screen.getByRole("group", { name });
|
||||
|
||||
describe("PageEditor: sections", () => {
|
||||
it("adds feature cards with icons and a look, and saves them", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<PageEditor pageId={5} />);
|
||||
await screen.findByDisplayValue("How it works");
|
||||
await user.click(screen.getByRole("button", { name: "Add Feature cards" }));
|
||||
const block = group("Block 3: Feature cards");
|
||||
await user.type(within(block).getByLabelText("Heading"), "What we do");
|
||||
await user.type(within(block).getByLabelText("Intro"), "One partner.");
|
||||
const card1 = within(block).getByRole("group", { name: "Card 1" });
|
||||
await user.selectOptions(within(card1).getByLabelText("Icon"), "WiFi");
|
||||
await user.type(within(card1).getByLabelText("Title"), "Managed WiFi");
|
||||
await user.type(within(card1).getByLabelText("Text"), "Guests connect.");
|
||||
const card2 = within(block).getByRole("group", { name: "Card 2" });
|
||||
await user.type(within(card2).getByLabelText("Title"), "TV");
|
||||
await user.type(within(card2).getByLabelText("Text"), "Casting.");
|
||||
await user.selectOptions(within(block).getByLabelText("Look"), "Dark");
|
||||
await user.click(screen.getByRole("button", { name: "Save" }));
|
||||
await waitFor(() => expect(mocks.savePage).toHaveBeenCalled());
|
||||
expect(mocks.savePage.mock.calls[0][1].blocks[2]).toEqual({
|
||||
type: "FEATURES", heading: "What we do", text: "One partner.", look: "DARK",
|
||||
cards: [{ icon: "wifi", title: "Managed WiFi", text: "Guests connect." }, { icon: "star", title: "TV", text: "Casting." }],
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps 2 to 6 cards and moves them", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<PageEditor pageId={5} />);
|
||||
await screen.findByDisplayValue("How it works");
|
||||
const block = group("Block 1: Steps");
|
||||
expect(within(within(block).getByRole("group", { name: "Step 1" })).getByRole("button", { name: "Remove" })).toBeDisabled();
|
||||
await user.click(within(within(block).getByRole("group", { name: "Step 2" })).getByRole("button", { name: "Move up" }));
|
||||
expect(within(within(block).getByRole("group", { name: "Step 1" })).getByLabelText("Title")).toHaveValue("Install");
|
||||
const add = within(block).getByRole("button", { name: "Add step" });
|
||||
for (let i = 0; i < 4; i++) await user.click(add);
|
||||
expect(add).toBeDisabled();
|
||||
expect(within(within(block).getByRole("group", { name: "Step 6" })).getByRole("button", { name: "Remove" })).toBeEnabled();
|
||||
});
|
||||
|
||||
it("offers no look for a Custom HTML block", async () => {
|
||||
render(<PageEditor pageId={5} />);
|
||||
await screen.findByDisplayValue("How it works");
|
||||
expect(within(group("Block 1: Steps")).getByLabelText("Look")).toBeInTheDocument();
|
||||
expect(within(group("Block 2: Custom HTML")).queryByLabelText("Look")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("shows a refused card field at that card", async () => {
|
||||
mocks.savePage.mockRejectedValue(new ApiError("x", 422, { code: "PagesTooLong", details: { field: "blocks[0].cards[1].title" } }));
|
||||
const user = userEvent.setup();
|
||||
render(<PageEditor pageId={5} />);
|
||||
await screen.findByDisplayValue("How it works");
|
||||
await user.click(screen.getByRole("button", { name: "Save" }));
|
||||
const step2 = within(group("Block 1: Steps")).getByRole("group", { name: "Step 2" });
|
||||
expect(await within(step2).findByText("Too long.")).toBeInTheDocument();
|
||||
expect(within(step2).getByLabelText("Title")).toHaveAttribute("aria-invalid", "true");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,32 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { BLOCK_TYPES, ICONS, LOOKS, emptyBlock, emptyPage, pageBody } from "./cmsPages";
|
||||
|
||||
// add-page-sections: the new block types in the editor model and the save body.
|
||||
describe("cmsPages: sections", () => {
|
||||
it("offers the four new types, the server's icon list and looks", () => {
|
||||
expect(BLOCK_TYPES).toEqual(expect.arrayContaining(["FEATURES", "STEPS", "TRUST", "CTA"]));
|
||||
expect(Object.keys(ICONS).sort()).toEqual(["calendar", "cloud", "headset", "lock", "monitor", "phone", "shield-check", "star", "tv", "users", "wifi", "wrench"]);
|
||||
expect(LOOKS).toEqual(["DEFAULT", "MUTED", "DARK", "ACCENT"]);
|
||||
});
|
||||
|
||||
it("starts each card section with the minimum cards and only the fields its type uses", () => {
|
||||
expect(emptyBlock("FEATURES")).toEqual({ type: "FEATURES", heading: "", text: "", cards: [{ icon: "star", title: "", text: "" }, { icon: "star", title: "", text: "" }] });
|
||||
expect(emptyBlock("STEPS")).toEqual({ type: "STEPS", heading: "", cards: [{ title: "", text: "" }, { title: "", text: "" }] });
|
||||
expect(emptyBlock("TRUST")).toEqual({ type: "TRUST", cards: [{ title: "" }, { title: "" }] });
|
||||
expect(emptyBlock("CTA")).toEqual({ type: "CTA", heading: "", text: "", buttonLabel: "", buttonUrl: "" });
|
||||
});
|
||||
|
||||
it("trims card fields and drops a default look on save", () => {
|
||||
const body = pageBody({
|
||||
...emptyPage(), title: "T", slug: "t",
|
||||
blocks: [
|
||||
{ type: "STEPS", heading: " How ", look: "DEFAULT", cards: [{ title: " Survey ", text: " We visit. " }, { title: "Fit", text: "" }] },
|
||||
{ type: "CTA", heading: "Go", look: "DARK", buttonLabel: "Join", buttonUrl: "#signup" },
|
||||
],
|
||||
});
|
||||
expect(body.blocks).toEqual([
|
||||
{ type: "STEPS", heading: "How", cards: [{ title: "Survey", text: "We visit." }, { title: "Fit", text: "" }] },
|
||||
{ type: "CTA", heading: "Go", look: "DARK", buttonLabel: "Join", buttonUrl: "#signup" },
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -1,9 +1,21 @@
|
||||
// Landing-page blocks and the editor's pure helpers (add-landing-pages), ported from babyboo's cmsPages.ts
|
||||
// minus the product blocks. Images are page_image ids, served at /api/public/page-images/<id>.
|
||||
|
||||
export type BlockType = "HERO" | "RICH_TEXT" | "IMAGE_TEXT" | "FAQ" | "FORM" | "HTML";
|
||||
import { Calendar, Cloud, Headset, Lock, Monitor, Phone, ShieldCheck, Star, Tv, Users, Wifi, Wrench, type LucideIcon } from "lucide-react";
|
||||
|
||||
export const BLOCK_TYPES: BlockType[] = ["HERO", "RICH_TEXT", "IMAGE_TEXT", "FAQ", "FORM", "HTML"];
|
||||
export type BlockType = "HERO" | "RICH_TEXT" | "IMAGE_TEXT" | "FAQ" | "FORM" | "HTML" | "FEATURES" | "STEPS" | "TRUST" | "CTA";
|
||||
|
||||
export const BLOCK_TYPES: BlockType[] = ["HERO", "RICH_TEXT", "IMAGE_TEXT", "FEATURES", "STEPS", "TRUST", "CTA", "FAQ", "FORM", "HTML"];
|
||||
|
||||
/** Feature-card icons by the name services-counter accepts (add-page-sections). */
|
||||
export const ICONS: Record<string, LucideIcon> = {
|
||||
wifi: Wifi, phone: Phone, tv: Tv, monitor: Monitor, lock: Lock, "shield-check": ShieldCheck,
|
||||
cloud: Cloud, wrench: Wrench, headset: Headset, users: Users, calendar: Calendar, star: Star,
|
||||
};
|
||||
|
||||
/** Section looks: DEFAULT renders as before; the others are full-width bands. */
|
||||
export const LOOKS = ["DEFAULT", "MUTED", "DARK", "ACCENT"] as const;
|
||||
export type Look = (typeof LOOKS)[number];
|
||||
|
||||
export const BLOCK_LABELS: Record<BlockType, string> = {
|
||||
HERO: "PagesBlockHero",
|
||||
@@ -12,8 +24,19 @@ export const BLOCK_LABELS: Record<BlockType, string> = {
|
||||
FAQ: "PagesBlockFaq",
|
||||
FORM: "PagesBlockForm",
|
||||
HTML: "PagesBlockHtml",
|
||||
FEATURES: "PagesBlockFeatures",
|
||||
STEPS: "PagesBlockSteps",
|
||||
TRUST: "PagesBlockTrust",
|
||||
CTA: "PagesBlockCta",
|
||||
};
|
||||
|
||||
/** A FEATURES (icon, title, text), STEPS (title, text) or TRUST (title) card. */
|
||||
export interface CmsCard {
|
||||
icon?: string;
|
||||
title: string;
|
||||
text?: string;
|
||||
}
|
||||
|
||||
export interface CmsFaqItem {
|
||||
question: string;
|
||||
answer: string;
|
||||
@@ -31,6 +54,8 @@ export interface CmsBlock {
|
||||
items?: CmsFaqItem[];
|
||||
/** Optional link name: the block's id on the page, the target of a #name link (add-page-anchor-links). */
|
||||
anchor?: string;
|
||||
look?: Look;
|
||||
cards?: CmsCard[];
|
||||
/** The FORM block's event (a Snowflake uuid, kept as a string). */
|
||||
eventUuid?: string | null;
|
||||
}
|
||||
@@ -80,6 +105,14 @@ export function emptyBlock(type: BlockType): CmsBlock {
|
||||
return { type, heading: "", eventUuid: null };
|
||||
case "HTML":
|
||||
return { type, html: "" };
|
||||
case "FEATURES":
|
||||
return { type, heading: "", text: "", cards: [{ icon: "star", title: "", text: "" }, { icon: "star", title: "", text: "" }] };
|
||||
case "STEPS":
|
||||
return { type, heading: "", cards: [{ title: "", text: "" }, { title: "", text: "" }] };
|
||||
case "TRUST":
|
||||
return { type, cards: [{ title: "" }, { title: "" }] };
|
||||
case "CTA":
|
||||
return { type, heading: "", text: "", buttonLabel: "", buttonUrl: "" };
|
||||
default:
|
||||
return { type };
|
||||
}
|
||||
@@ -113,6 +146,12 @@ export function pageBody(draft: CmsPageDraft) {
|
||||
out.items = (val as CmsFaqItem[]).map((it) => ({ question: it.question.trim(), answer: it.answer.trim() }));
|
||||
continue;
|
||||
}
|
||||
if (key === "cards") {
|
||||
// Trimmed but kept, so a blank card field is refused at its own path.
|
||||
out.cards = (val as CmsCard[]).map((c) => Object.fromEntries(Object.entries(c).map(([k, x]) => [k, typeof x === "string" ? x.trim() : x])));
|
||||
continue;
|
||||
}
|
||||
if (key === "look" && val === "DEFAULT") continue;
|
||||
const v = typeof val === "string" ? val.trim() : val;
|
||||
if (!blank(v)) out[key] = v;
|
||||
}
|
||||
|
||||
@@ -757,6 +757,42 @@ export const DEFAULT_MESSAGES: Record<string, string> = {
|
||||
PagesBlockFaq: "FAQ",
|
||||
PagesBlockForm: "Sign-up form",
|
||||
PagesBlockHtml: "Custom HTML",
|
||||
PagesBlockFeatures: "Feature cards",
|
||||
PagesBlockSteps: "Steps",
|
||||
PagesBlockTrust: "Trust strip",
|
||||
PagesBlockCta: "Call to action",
|
||||
PagesLook: "Look",
|
||||
PagesLookDefault: "Default",
|
||||
PagesLookMuted: "Light grey",
|
||||
PagesLookDark: "Dark",
|
||||
PagesLookAccent: "Company colour",
|
||||
PagesIntro: "Intro",
|
||||
PagesCardN: "Card {number}",
|
||||
PagesStepN: "Step {number}",
|
||||
PagesItemN: "Item {number}",
|
||||
PagesCardIcon: "Icon",
|
||||
PagesCardTitle: "Title",
|
||||
PagesCardText: "Text",
|
||||
PagesAddCard: "Add card",
|
||||
PagesAddStep: "Add step",
|
||||
PagesAddItem: "Add item",
|
||||
PagesRemoveCard: "Remove",
|
||||
PagesIconWifi: "WiFi",
|
||||
PagesIconPhone: "Phone",
|
||||
PagesIconTv: "TV",
|
||||
PagesIconMonitor: "Screen",
|
||||
PagesIconLock: "Lock",
|
||||
PagesIconShieldCheck: "Security",
|
||||
PagesIconCloud: "Cloud",
|
||||
PagesIconWrench: "Service",
|
||||
PagesIconHeadset: "Support",
|
||||
PagesIconUsers: "People",
|
||||
PagesIconCalendar: "Calendar",
|
||||
PagesIconStar: "Star",
|
||||
PagesCardCount: "Use 2 to 6 cards.",
|
||||
PagesBadIcon: "Choose an icon from the list.",
|
||||
PagesBadLook: "Choose a look from the list.",
|
||||
PagesUnusedField: "This section doesn't use this field.",
|
||||
PagesHtml: "HTML",
|
||||
PagesHtmlHint: "Forms inside the pasted HTML don't send. Add a Sign-up form block to collect leads.",
|
||||
PagesHideHeader: "Hide page header",
|
||||
|
||||
@@ -765,6 +765,42 @@
|
||||
"PagesFormEventHint": "报名会成为此活动的线索。一般咨询请选择长期的咨询活动。",
|
||||
"PagesBlockHtml": "自定义 HTML",
|
||||
"PagesHtml": "HTML",
|
||||
"PagesBlockFeatures": "功能卡片",
|
||||
"PagesBlockSteps": "步骤",
|
||||
"PagesBlockTrust": "信任条",
|
||||
"PagesBlockCta": "行动号召",
|
||||
"PagesLook": "外观",
|
||||
"PagesLookDefault": "默认",
|
||||
"PagesLookMuted": "浅灰",
|
||||
"PagesLookDark": "深色",
|
||||
"PagesLookAccent": "公司主色",
|
||||
"PagesIntro": "简介",
|
||||
"PagesCardN": "卡片 {number}",
|
||||
"PagesStepN": "步骤 {number}",
|
||||
"PagesItemN": "项目 {number}",
|
||||
"PagesCardIcon": "图标",
|
||||
"PagesCardTitle": "标题",
|
||||
"PagesCardText": "文字",
|
||||
"PagesAddCard": "添加卡片",
|
||||
"PagesAddStep": "添加步骤",
|
||||
"PagesAddItem": "添加项目",
|
||||
"PagesRemoveCard": "移除",
|
||||
"PagesIconWifi": "WiFi",
|
||||
"PagesIconPhone": "电话",
|
||||
"PagesIconTv": "电视",
|
||||
"PagesIconMonitor": "屏幕",
|
||||
"PagesIconLock": "门锁",
|
||||
"PagesIconShieldCheck": "安全",
|
||||
"PagesIconCloud": "云端",
|
||||
"PagesIconWrench": "维修服务",
|
||||
"PagesIconHeadset": "客服支持",
|
||||
"PagesIconUsers": "人员",
|
||||
"PagesIconCalendar": "日历",
|
||||
"PagesIconStar": "星标",
|
||||
"PagesCardCount": "请使用 2 至 6 张卡片。",
|
||||
"PagesBadIcon": "请从列表中选择图标。",
|
||||
"PagesBadLook": "请从列表中选择外观。",
|
||||
"PagesUnusedField": "此区块不使用该字段。",
|
||||
"PagesHtmlHint": "粘贴的 HTML 中的表单不会发送。请添加报名表单区块来收集线索。",
|
||||
"PagesHideHeader": "隐藏页面顶栏",
|
||||
"NotificationsTitle": "通知",
|
||||
|
||||
+5
-1
@@ -11,7 +11,8 @@ import java.util.List;
|
||||
/**
|
||||
* One landing-page block. Which fields apply depends on {@code type}:
|
||||
* HERO (imageId, heading, text, button), RICH_TEXT (html), IMAGE_TEXT (imageId, imagePosition, heading, html, button),
|
||||
* FAQ (heading, items), FORM (heading, eventUuid).
|
||||
* FAQ (heading, items), FORM (heading, eventUuid), HTML (html), FEATURES (heading, text, cards), STEPS (heading, cards),
|
||||
* TRUST (cards), CTA (heading, text, button). Any block may carry anchor and look.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@@ -27,7 +28,10 @@ public class CmsBlock {
|
||||
private String buttonUrl;
|
||||
/** Optional link name: the block's id on the public page, the target of a #name link (add-page-anchor-links). */
|
||||
private String anchor;
|
||||
/** DEFAULT (or absent), MUTED, DARK or ACCENT (add-page-sections). */
|
||||
private String look;
|
||||
private List<CmsFaqItem> items;
|
||||
private List<CmsCard> cards;
|
||||
/** A Snowflake value beyond JavaScript number precision: written as a string, read from either. */
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long eventUuid;
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.solvway.services.counter.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
/** One card of a FEATURES (icon, title, text), STEPS (title, text) or TRUST (title) block (add-page-sections). */
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public record CmsCard(String icon, String title, String text) {}
|
||||
+68
-1
@@ -1,6 +1,7 @@
|
||||
package com.solvway.services.counter.service;
|
||||
|
||||
import com.solvway.services.counter.dto.CmsBlock;
|
||||
import com.solvway.services.counter.dto.CmsCard;
|
||||
import com.solvway.services.counter.dto.CmsFaqItem;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
@@ -16,12 +17,17 @@ import java.util.regex.Pattern;
|
||||
* Co-Lite changes: images are uploaded ids of the page's company, FORM points at an event of that company,
|
||||
* buttons may also use mailto: and tel:, and rich-text HTML holding scripts is refused (the public page sanitises as well).
|
||||
* The HTML block (custom HTML) is exempt from the script check: it is served only inside a sandboxed frame.
|
||||
* add-page-sections adds FEATURES, STEPS, TRUST and CTA, a look on any block, and makes the HERO image optional.
|
||||
* Throws 422 on the first violation, with the reason "path|MessageCode".
|
||||
*/
|
||||
public final class CmsBlockValidator {
|
||||
private static final int MAX_BLOCKS = 30;
|
||||
/** A block link name (add-page-anchor-links); a same-page link is "#" plus one. "reg-" is the sign-up form's own ids. */
|
||||
static final Pattern ANCHOR = Pattern.compile("(?!reg-)[a-z0-9][a-z0-9-]{0,39}");
|
||||
/** Section looks and feature icons (add-page-sections). */
|
||||
private static final Set<String> LOOKS = Set.of("DEFAULT", "MUTED", "DARK", "ACCENT");
|
||||
static final Set<String> ICONS = Set.of("wifi", "phone", "tv", "monitor", "lock", "shield-check", "cloud", "wrench", "headset", "users", "calendar", "star");
|
||||
private static final Set<String> CARD_TYPES = Set.of("FEATURES", "STEPS", "TRUST");
|
||||
private static final Pattern SCRIPT = Pattern.compile("(?i)<\\s*script|\\son[a-z]+\\s*=|javascript\\s*:");
|
||||
|
||||
private CmsBlockValidator() {
|
||||
@@ -50,9 +56,17 @@ public final class CmsBlockValidator {
|
||||
throw refuse(path + ".anchor", "PagesAnchorTaken");
|
||||
}
|
||||
}
|
||||
if (b.getLook() != null && !LOOKS.contains(b.getLook())) {
|
||||
throw refuse(path + ".look", "PagesBadLook");
|
||||
}
|
||||
if (b.getCards() != null && !CARD_TYPES.contains(b.getType())) {
|
||||
throw refuse(path + ".cards", "PagesUnusedField");
|
||||
}
|
||||
switch (b.getType()) {
|
||||
case "HERO" -> {
|
||||
image(b, path, ownImage);
|
||||
if (b.getImageId() != null) {
|
||||
image(b, path, ownImage);
|
||||
}
|
||||
required(b.getHeading(), path + ".heading");
|
||||
max(b.getHeading(), path + ".heading", 120);
|
||||
max(b.getText(), path + ".text", 300);
|
||||
@@ -80,6 +94,30 @@ public final class CmsBlockValidator {
|
||||
throw refuse(path + ".eventUuid", "PagesBadEvent");
|
||||
}
|
||||
}
|
||||
case "FEATURES" -> {
|
||||
required(b.getHeading(), path + ".heading");
|
||||
max(b.getHeading(), path + ".heading", 120);
|
||||
max(b.getText(), path + ".text", 300);
|
||||
cards(b, path, true, true);
|
||||
}
|
||||
case "STEPS" -> {
|
||||
required(b.getHeading(), path + ".heading");
|
||||
max(b.getHeading(), path + ".heading", 120);
|
||||
cards(b, path, false, true);
|
||||
}
|
||||
case "TRUST" -> {
|
||||
if (b.getHeading() != null) {
|
||||
throw refuse(path + ".heading", "PagesUnusedField");
|
||||
}
|
||||
cards(b, path, false, false);
|
||||
}
|
||||
case "CTA" -> {
|
||||
required(b.getHeading(), path + ".heading");
|
||||
max(b.getHeading(), path + ".heading", 120);
|
||||
max(b.getText(), path + ".text", 300);
|
||||
required(b.getButtonLabel(), path + ".buttonLabel");
|
||||
button(b, path);
|
||||
}
|
||||
default -> throw refuse(path + ".type", "PagesUnknownType");
|
||||
}
|
||||
}
|
||||
@@ -131,6 +169,35 @@ public final class CmsBlockValidator {
|
||||
}
|
||||
}
|
||||
|
||||
/** 2 to 6 cards; an icon from the list where the type uses one, a title (80), a text (300) where used, nothing else. */
|
||||
private static void cards(CmsBlock b, String path, boolean icon, boolean text) {
|
||||
List<CmsCard> cards = b.getCards();
|
||||
if (cards == null || cards.size() < 2 || cards.size() > 6) {
|
||||
throw refuse(path + ".cards", "PagesCardCount");
|
||||
}
|
||||
for (int i = 0; i < cards.size(); i++) {
|
||||
CmsCard card = cards.get(i);
|
||||
String cardPath = path + ".cards[" + i + "]";
|
||||
if (card == null) {
|
||||
throw refuse(cardPath + ".title", "PagesRequired");
|
||||
}
|
||||
if (icon && (card.icon() == null || !ICONS.contains(card.icon()))) {
|
||||
throw refuse(cardPath + ".icon", "PagesBadIcon");
|
||||
}
|
||||
if (!icon && card.icon() != null) {
|
||||
throw refuse(cardPath + ".icon", "PagesUnusedField");
|
||||
}
|
||||
required(card.title(), cardPath + ".title");
|
||||
max(card.title(), cardPath + ".title", 80);
|
||||
if (text) {
|
||||
required(card.text(), cardPath + ".text");
|
||||
max(card.text(), cardPath + ".text", 300);
|
||||
} else if (card.text() != null) {
|
||||
throw refuse(cardPath + ".text", "PagesUnusedField");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void button(CmsBlock b, String path) {
|
||||
boolean hasLabel = b.getButtonLabel() != null && !b.getButtonLabel().isBlank();
|
||||
boolean hasUrl = b.getButtonUrl() != null && !b.getButtonUrl().isBlank();
|
||||
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
package com.solvway.services.counter.service;
|
||||
|
||||
import com.solvway.services.counter.dto.CmsBlock;
|
||||
import com.solvway.services.counter.dto.CmsCard;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
/** add-page-sections: card sections (FEATURES, STEPS, TRUST), the CTA band, section looks and the optional hero image. */
|
||||
class CmsBlockValidatorSectionsTest {
|
||||
|
||||
private static void validate(List<CmsBlock> blocks) {
|
||||
CmsBlockValidator.validate(blocks, id -> id == 5L, uuid -> uuid == 900L);
|
||||
}
|
||||
|
||||
private static void ok(CmsBlock... blocks) {
|
||||
assertThatCode(() -> validate(List.of(blocks))).doesNotThrowAnyException();
|
||||
}
|
||||
|
||||
private static void refused(CmsBlock b, String path, String code) {
|
||||
assertThatThrownBy(() -> validate(List.of(b)))
|
||||
.isInstanceOfSatisfying(ResponseStatusException.class, e -> assertThat(e.getReason()).isEqualTo(path + "|" + code));
|
||||
}
|
||||
|
||||
private static CmsBlock block(String type, String heading, CmsCard... cards) {
|
||||
CmsBlock b = new CmsBlock();
|
||||
b.setType(type);
|
||||
b.setHeading(heading);
|
||||
if (cards.length > 0) b.setCards(new ArrayList<>(Arrays.asList(cards)));
|
||||
return b;
|
||||
}
|
||||
|
||||
private static CmsCard feature(String icon) {
|
||||
return new CmsCard(icon, "Managed WiFi", "Guests connect at once.");
|
||||
}
|
||||
|
||||
private static CmsCard step(String title) {
|
||||
return new CmsCard(null, title, "We visit your property.");
|
||||
}
|
||||
|
||||
private static CmsCard trust(String title) {
|
||||
return new CmsCard(null, title, null);
|
||||
}
|
||||
|
||||
private static CmsBlock cta() {
|
||||
CmsBlock b = block("CTA", "Ready to upgrade?");
|
||||
b.setText("Talk to our team today.");
|
||||
b.setButtonLabel("Get a quote");
|
||||
b.setButtonUrl("#signup");
|
||||
return b;
|
||||
}
|
||||
|
||||
@Test
|
||||
void validSectionsOfEveryNewTypePass() {
|
||||
CmsBlock features = block("FEATURES", "What we do", feature("wifi"), feature("tv"), feature("lock"));
|
||||
features.setText("One partner for every system.");
|
||||
ok(features,
|
||||
block("STEPS", "How it works", step("Survey"), step("Install")),
|
||||
block("TRUST", null, trust("Certified with LG"), trust("Local support")),
|
||||
cta());
|
||||
}
|
||||
|
||||
@Test
|
||||
void cardSectionsHaveTwoToSixCards() {
|
||||
refused(block("STEPS", "How", step("One")), "blocks[0].cards", "PagesCardCount");
|
||||
refused(block("TRUST", null), "blocks[0].cards", "PagesCardCount");
|
||||
CmsCard[] seven = new CmsCard[7];
|
||||
for (int i = 0; i < 7; i++) seven[i] = feature("wifi");
|
||||
refused(block("FEATURES", "Too many", seven), "blocks[0].cards", "PagesCardCount");
|
||||
CmsCard[] six = new CmsCard[6];
|
||||
for (int i = 0; i < 6; i++) six[i] = feature("star");
|
||||
ok(block("FEATURES", "Six", six));
|
||||
}
|
||||
|
||||
@Test
|
||||
void featureCardsNeedAKnownIconATitleAndAText() {
|
||||
refused(block("FEATURES", "X", feature("rocket-launcher"), feature("wifi")), "blocks[0].cards[0].icon", "PagesBadIcon");
|
||||
refused(block("FEATURES", "X", feature("wifi"), feature(null)), "blocks[0].cards[1].icon", "PagesBadIcon");
|
||||
refused(block("FEATURES", "X", feature("wifi"), new CmsCard("tv", " ", "t")), "blocks[0].cards[1].title", "PagesRequired");
|
||||
refused(block("FEATURES", "X", feature("wifi"), new CmsCard("tv", "T", "")), "blocks[0].cards[1].text", "PagesRequired");
|
||||
refused(block("FEATURES", null, feature("wifi"), feature("tv")), "blocks[0].heading", "PagesRequired");
|
||||
for (String icon : List.of("wifi", "phone", "tv", "monitor", "lock", "shield-check", "cloud", "wrench", "headset", "users", "calendar", "star")) {
|
||||
ok(block("FEATURES", "Icons", feature(icon), feature(icon)));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void cardLimitsAndFieldsATypeDoesNotUse() {
|
||||
refused(block("STEPS", "X", step("a".repeat(81)), step("b")), "blocks[0].cards[0].title", "PagesTooLong");
|
||||
refused(block("STEPS", "X", step("a"), new CmsCard(null, "b", "c".repeat(301))), "blocks[0].cards[1].text", "PagesTooLong");
|
||||
refused(block("STEPS", "X", step("a"), new CmsCard("wifi", "b", "c")), "blocks[0].cards[1].icon", "PagesUnusedField");
|
||||
refused(block("TRUST", null, trust("a"), new CmsCard(null, "b", "c")), "blocks[0].cards[1].text", "PagesUnusedField");
|
||||
refused(block("TRUST", "Heading", trust("a"), trust("b")), "blocks[0].heading", "PagesUnusedField");
|
||||
refused(block("STEPS", null, step("a"), step("b")), "blocks[0].heading", "PagesRequired");
|
||||
refused(block("STEPS", "X", step("a"), null), "blocks[0].cards[1].title", "PagesRequired");
|
||||
CmsBlock faqWithCards = block("FAQ", "Q", trust("a"), trust("b"));
|
||||
refused(faqWithCards, "blocks[0].cards", "PagesUnusedField");
|
||||
}
|
||||
|
||||
@Test
|
||||
void aCtaNeedsAHeadingAndAButton() {
|
||||
CmsBlock noButton = cta();
|
||||
noButton.setButtonLabel(null);
|
||||
noButton.setButtonUrl(null);
|
||||
refused(noButton, "blocks[0].buttonLabel", "PagesRequired");
|
||||
CmsBlock badLink = cta();
|
||||
badLink.setButtonUrl("javascript:alert(1)");
|
||||
refused(badLink, "blocks[0].buttonUrl", "PagesBadLink");
|
||||
CmsBlock noHeading = cta();
|
||||
noHeading.setHeading(" ");
|
||||
refused(noHeading, "blocks[0].heading", "PagesRequired");
|
||||
CmsBlock longText = cta();
|
||||
longText.setText("x".repeat(301));
|
||||
refused(longText, "blocks[0].text", "PagesTooLong");
|
||||
}
|
||||
|
||||
@Test
|
||||
void anyBlockMayCarryAKnownLook() {
|
||||
for (String look : List.of("DEFAULT", "MUTED", "DARK", "ACCENT")) {
|
||||
CmsBlock b = cta();
|
||||
b.setLook(look);
|
||||
ok(b);
|
||||
}
|
||||
CmsBlock neon = cta();
|
||||
neon.setLook("NEON");
|
||||
refused(neon, "blocks[0].look", "PagesBadLook");
|
||||
CmsBlock html = new CmsBlock();
|
||||
html.setType("HTML");
|
||||
html.setHtml("<p>x</p>");
|
||||
html.setLook("dark");
|
||||
refused(html, "blocks[0].look", "PagesBadLook");
|
||||
}
|
||||
|
||||
@Test
|
||||
void aHeroImageIsOptionalButMustBeTheCompanysWhenGiven() {
|
||||
CmsBlock hero = block("HERO", "Hotel technology");
|
||||
ok(hero);
|
||||
hero.setImageId(6L);
|
||||
refused(hero, "blocks[0].imageId", "PagesBadImage");
|
||||
}
|
||||
}
|
||||
+5
-2
@@ -145,8 +145,11 @@ class CmsBlockValidatorTest {
|
||||
CmsBlock foreignImage = hero();
|
||||
foreignImage.setImageId(6L);
|
||||
refused(List.of(foreignImage), "blocks[0].imageId", "PagesBadImage");
|
||||
CmsBlock noImage = hero();
|
||||
noImage.setImageId(null);
|
||||
// add-page-sections: a hero may have no image (CmsBlockValidatorSectionsTest); an image-with-text block still needs one.
|
||||
CmsBlock noImage = new CmsBlock();
|
||||
noImage.setType("IMAGE_TEXT");
|
||||
noImage.setImagePosition("LEFT");
|
||||
noImage.setHtml("<p>x</p>");
|
||||
refused(List.of(noImage), "blocks[0].imageId", "PagesBadImage");
|
||||
refused(List.of(form(901)), "blocks[0].eventUuid", "PagesBadEvent");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user