feat(pages): a top bar section, section labels and serif headings
Landing pages gain a Top bar section (the company logo and an optional button, kept at the top of the window, first section only), a short label above the headings of five section types, and serif section headings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
This commit is contained in:
1 parent
2a69826e66
commit
e4ad18a8a3
18 files changed
+428
-22
No files matched your search
@@ -474,4 +474,6 @@ A form stops taking sign-ups when its event is disabled, its end date has passed
|
||||
|
||||
**Release add-landing-thanks-and-footer (SQL, in its OpenSpec change folder):** deploy services-counter and the portal together, then run `sql/01-thanks-footer-labels.sql` (labels only). Landing pages gain a Footer section (1 to 4 columns, a legal line, contact links) and a thank-you text on the Form block and on a hero with a form. Full-width heroes get a lighter shade. Deploy the counter first: an older counter refuses pages that use the new fields. Rollback: the previous images; pages saved with a Footer or thank-you text then fail to save until the release is back.
|
||||
|
||||
**Release add-landing-page-polish (SQL, in its OpenSpec change folder):** deploy services-counter first, then the portal, then run `sql/01-polish-labels.sql` (labels only). Landing pages gain a Top bar section (the company logo and an optional button, kept at the top of the window, first section only) and an optional small label above the headings of Feature cards, Steps, Image with text, FAQ and Call to action. Section headings on every landing page, CV included, now use the serif typeface. Rollback: the previous images; pages saved with a top bar or labels then fail to save until the release is back.
|
||||
|
||||
**New portal dependencies:** `@tiptap/react`, `@tiptap/pm`, `@tiptap/starter-kit` and `@tiptap/extension-text-align` (the editor, loaded only on the editor screens), and `sanitize-html` (cleans page text on the server before it reaches a visitor). The image build installs them from `package-lock.json`; nothing to do by hand.
|
||||
@@ -1743,6 +1743,12 @@ INSERT INTO message (code, content, area) SELECT 'PagesAddColumn', JSON_OBJECT('
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '添加栏') WHERE LOWER(code) = LOWER('PagesAddColumn') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesFooterLegal', JSON_OBJECT('en_US', 'Legal line', 'zh_CN', '版权声明'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesFooterLegal') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '版权声明') WHERE LOWER(code) = LOWER('PagesFooterLegal') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesBlockTopBar', JSON_OBJECT('en_US', 'Top bar', 'zh_CN', '顶栏'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesBlockTopBar') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '顶栏') WHERE LOWER(code) = LOWER('PagesBlockTopBar') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesEyebrow', JSON_OBJECT('en_US', 'Label', 'zh_CN', '小标签'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesEyebrow') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '小标签') WHERE LOWER(code) = LOWER('PagesEyebrow') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesTopBarFirst', JSON_OBJECT('en_US', 'The top bar must be the first section.', 'zh_CN', '顶栏必须是第一个区块。'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesTopBarFirst') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '顶栏必须是第一个区块。') WHERE LOWER(code) = LOWER('PagesTopBarFirst') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesUploadImage', JSON_OBJECT('en_US', 'Upload image', 'zh_CN', '上传图片'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesUploadImage') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '上传图片') WHERE LOWER(code) = LOWER('PagesUploadImage') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesUploadImageHint', JSON_OBJECT('en_US', 'PNG, JPEG or WebP up to 2 MB. Paste the link into your HTML, for example in an img tag''s src.', 'zh_CN', 'PNG、JPEG 或 WebP,最大 2 MB。将链接粘贴到您的 HTML 中,例如 img 标签的 src。'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesUploadImageHint') AND area = 'A');
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
schema: spec-driven
|
||||
created: 2026-12-04
|
||||
@@ -0,0 +1,24 @@
|
||||
# Design
|
||||
|
||||
## Context
|
||||
|
||||
The company header and the page title are drawn by `LandingPage`, and "hide page header" (`hideHeader`) removes both. Page settings are database columns threaded through services-counter, mobile-api and the portal. Blocks are JSON validated by `CmsBlockValidator`, so a new block or block field needs no schema change.
|
||||
|
||||
## Approaches
|
||||
|
||||
1. **A Top bar block, used with "hide page header" (chosen).** It is JSON only: no migration, and no changes to the page records in three services. The INS page already uses "hide page header" with a Custom HTML top bar, so this is a native swap for the same layout.
|
||||
2. **New page settings** ("hide title", header button label and link, heading font). This is the natural model, but it means four new columns and changes to every page DTO, the draft record, the admin and public APIs, and the settings panel. That is about ten times the work for the same result.
|
||||
3. **Keep the top bar in Custom HTML.** This is what the original page does; the native page exists to avoid it.
|
||||
|
||||
## Decisions
|
||||
|
||||
- **The top bar is the first block only.** The server refuses it anywhere else (`PagesTopBarFirst`), because a sticky bar in the middle of a page would cover the content as the visitor scrolls past it. The bar is `sticky top-0` with a card background and a bottom border. It runs full width (it counts as bleed), so it joins a full-width hero below it with no gap.
|
||||
- **Top bar fields.** Only `buttonLabel` and `buttonUrl` (the pair rule, at most 40 characters, a safe link) plus the usual `anchor`. A heading, text, image, cards or look are refused (`PagesUnusedField`). The logo comes from the company's branding, as the default header's does.
|
||||
- **The label (`eyebrow`).** At most 40 characters, allowed on FEATURES, STEPS, IMAGE_TEXT, FAQ and CTA, and refused on other types. It renders as a `p` above the h2, not as part of the heading, so screen readers read the heading on its own. It can be edited in place on the canvas.
|
||||
- **Label colour.** On the DARK band it uses `text-primary`, the accent colour. On light backgrounds the accent can be too pale (INS gold on white is about 2:1), so it uses the accent mixed with the foreground colour, `color-mix(in srgb, var(--primary) 60%, var(--foreground))`. On the ACCENT band it uses the band's own text colour.
|
||||
- **Serif headings.** Section h2s get `font-serif`, Tailwind's system serif, as the full-width hero does. No web font is added. This changes every landing page, CV's included. It is a small change, and it matches the hero.
|
||||
|
||||
## Risks
|
||||
|
||||
- **CV pages change font.** CV's section headings become serif. If CV wants sans-serif, a later change can make the font a company setting.
|
||||
- **Sticky bar and same-page links.** A `#name` jump lands with the heading under the bar. `scroll-margin-top` on the named blocks keeps them clear when a top bar exists.
|
||||
@@ -0,0 +1,42 @@
|
||||
# Proposal
|
||||
|
||||
## Why
|
||||
|
||||
The native INS page (`/p/INS/hotel-technology-native`) now matches INS's standalone page in content, but it still looks different at the top and in its section headings:
|
||||
|
||||
- INS has a white top bar with the logo on the left and a "Get My Free Consultation" button on the right. The bar stays at the top while the visitor scrolls. Our page has two choices: show the company header and the page title, which INS does not have, or hide both, which also hides the logo.
|
||||
- INS puts a small gold uppercase label above each section heading ("Services", "How we work", "Why Infinity", "FAQ"). We have no such label.
|
||||
- INS's section headings are serif. Ours are sans-serif, except for the full-width hero.
|
||||
|
||||
## What Changes
|
||||
|
||||
- **Top bar block** (`TOPBAR`). It shows the company logo on the left (the company name when there is no logo) and an optional button on the right (`buttonLabel` and `buttonUrl`, with the same link rules as other buttons). It stays at the top of the window while the page scrolls. It may only be the first block. Together with "hide page header", it gives INS's layout: the logo and button stay, and the title and the default header go.
|
||||
- **Section labels** (`eyebrow`, at most 40 characters). Feature cards, Steps, Image with text, FAQ and Call to action may carry a short label. It shows above the heading in small uppercase letters in the accent colour, darkened on light backgrounds so it stays readable.
|
||||
- **Serif section headings.** Section headings (h2) on landing pages use the same serif as the full-width hero.
|
||||
- New editor labels in English and Chinese, with an SQL label file.
|
||||
|
||||
Not changing:
|
||||
- The page settings and the database. "Hide page header" already exists, and the new fields live in the block JSON.
|
||||
- Card and step layout, and the bullet style in rich text.
|
||||
- The default company header on pages without a top bar.
|
||||
|
||||
## Capabilities
|
||||
|
||||
### New Capabilities
|
||||
|
||||
None.
|
||||
|
||||
### Modified Capabilities
|
||||
|
||||
- `landing-pages`: adds "Top Bar Block", "Section Labels" and "Serif Section Headings".
|
||||
|
||||
## Impact
|
||||
|
||||
- services-counter: `CmsBlock` gains `eyebrow`. `CmsBlockValidator` validates TOPBAR and `eyebrow`.
|
||||
- mobile-api: none. Public blocks pass through as maps.
|
||||
- Portal:
|
||||
- `cmsPages.ts`: the TOPBAR type, its label and empty block, and `eyebrow`;
|
||||
- `CmsBlocks.tsx`: renders the top bar, the labels and the serif headings;
|
||||
- `BlockFields.tsx`: the top bar's button and the label field;
|
||||
- labels in `defaultMessages.ts` and `zh_CN.seed.json`.
|
||||
- Data: no schema change. The new labels need a SQL label file in this change folder.
|
||||
@@ -0,0 +1,42 @@
|
||||
## ADDED Requirements
|
||||
|
||||
### Requirement: Top Bar Block
|
||||
|
||||
A page's first block MAY be a top bar. The top bar SHALL show the company logo, or the company name when there is no logo, and an optional button, and SHALL stay at the top of the window while the page scrolls. The server SHALL refuse a top bar that is not the first block, or one that carries fields other than its button and link name.
|
||||
|
||||
#### Scenario: Logo and button without the page title
|
||||
|
||||
- **GIVEN** page `/p/INS/hotel-technology-native` with "hide page header" on, a top bar with the button "Get My Free Consultation" linking to `#consult`, and a full-width hero
|
||||
- **WHEN** a visitor opens the page and scrolls down
|
||||
- **THEN** the INS logo and the button stay at the top of the window
|
||||
- **AND** no page title heading shows, and the hero starts directly under the bar
|
||||
|
||||
#### Scenario: Top bar further down is refused
|
||||
|
||||
- **WHEN** staff save a page whose top bar is the second block
|
||||
- **THEN** the save is refused with the reason naming that block
|
||||
|
||||
### Requirement: Section Labels
|
||||
|
||||
Feature cards, Steps, Image with text, FAQ and Call to action blocks MAY carry a label of at most 40 characters. The page SHALL show the label above the block's heading, in small uppercase letters in the accent colour. The server SHALL refuse a longer label, or a label on any other block type.
|
||||
|
||||
#### Scenario: Label above a heading
|
||||
|
||||
- **GIVEN** a Feature cards block with the label "Services" and the heading "Everything your guests touch, handled by one team"
|
||||
- **WHEN** a visitor opens the page
|
||||
- **THEN** "Services" shows in small uppercase letters directly above the heading
|
||||
|
||||
#### Scenario: Type a label in the editor
|
||||
|
||||
- **GIVEN** staff editing a Steps block
|
||||
- **WHEN** they type "How we work" in its label field and save
|
||||
- **THEN** the page keeps the label
|
||||
|
||||
### Requirement: Serif Section Headings
|
||||
|
||||
Section headings on landing pages SHALL use the serif typeface that the full-width hero uses.
|
||||
|
||||
#### Scenario: Feature heading in serif
|
||||
|
||||
- **WHEN** a visitor opens a page with a Feature cards block
|
||||
- **THEN** its heading uses the serif typeface
|
||||
@@ -0,0 +1,9 @@
|
||||
-- The labels added by add-landing-page-polish, 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 'PagesBlockTopBar', JSON_OBJECT('en_US', 'Top bar', 'zh_CN', '顶栏'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesBlockTopBar') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '顶栏') WHERE LOWER(code) = LOWER('PagesBlockTopBar') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesEyebrow', JSON_OBJECT('en_US', 'Label', 'zh_CN', '小标签'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesEyebrow') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '小标签') WHERE LOWER(code) = LOWER('PagesEyebrow') AND area = 'A';
|
||||
INSERT INTO message (code, content, area) SELECT 'PagesTopBarFirst', JSON_OBJECT('en_US', 'The top bar must be the first section.', 'zh_CN', '顶栏必须是第一个区块。'), 'A' FROM DUAL WHERE NOT EXISTS (SELECT 1 FROM message WHERE LOWER(code) = LOWER('PagesTopBarFirst') AND area = 'A');
|
||||
UPDATE message SET content = JSON_SET(COALESCE(content, JSON_OBJECT()), '$.zh_CN', '顶栏必须是第一个区块。') WHERE LOWER(code) = LOWER('PagesTopBarFirst') AND area = 'A';
|
||||
@@ -0,0 +1,55 @@
|
||||
# Tasks
|
||||
|
||||
## 1. Server
|
||||
|
||||
- [x] 1.1 services-counter `CmsBlock`: add `eyebrow`. `CmsBlockValidator`:
|
||||
- TOPBAR is allowed only at index 0 (`PagesTopBarFirst`); it takes the button pair and `anchor` only, and any other field is refused (`PagesUnusedField`);
|
||||
- `eyebrow` at most 40 characters on FEATURES, STEPS, IMAGE_TEXT, FAQ and CTA, and refused elsewhere (`PagesUnusedField`).
|
||||
|
||||
Verify: new validator tests fail first, then pass; `mvn -T 1C -pl solvway-services-counter verify`.
|
||||
|
||||
## 2. Portal
|
||||
|
||||
- [x] 2.1 `CmsBlocks.tsx`:
|
||||
- renders TOPBAR (logo or name, optional button, sticky, full width, joins a full-width hero);
|
||||
- renders the label above section headings, in the accent colour, darkened on light backgrounds;
|
||||
- renders section h2s in serif;
|
||||
- named blocks keep clear of a sticky bar when jumped to.
|
||||
|
||||
Verify: render tests fail first, then pass; vitest exit 0.
|
||||
- [x] 2.2 Editor:
|
||||
- `cmsPages.ts`: TOPBAR type, label and empty block; `eyebrow`;
|
||||
- `BlockFields.tsx`: the top bar's button fields, and the label field on the five types; the label is editable in place on the canvas;
|
||||
- labels in `defaultMessages.ts`, `zh_CN.seed.json` and `sql/01-polish-labels.sql`; regenerate `local/seed/04-zh-cn-messages.sql`.
|
||||
|
||||
Verify: editor tests fail first, then pass; tsc and lint clean.
|
||||
|
||||
## 3. Verification
|
||||
|
||||
- [x] 3.1 Rebuild services-counter. Use Playwright on port 3001 to edit `/p/INS/hotel-technology-native` through the editor:
|
||||
- turn on "hide page header";
|
||||
- add a top bar first, with "Get My Free Consultation" linking to `#consult`;
|
||||
- add the labels "Services", "How we work", "Why Infinity" and "FAQ";
|
||||
- publish.
|
||||
|
||||
Check the published page at 1280 px and 390 px against the INS page, including the bar staying put on scroll.
|
||||
- [x] 3.2 Run the full portal vitest (exit 0), tsc, lint, Maven verify for services-counter, and `openspec validate add-landing-page-polish --strict`.
|
||||
- [x] 3.3 Add a release note to `docs/deployment.md` (label SQL).
|
||||
|
||||
## Notes (2026-12-04)
|
||||
|
||||
- **Red first:**
|
||||
- the validator tests failed on the top bar and the labels;
|
||||
- the render tests failed on the top bar, the scroll margin, the labels and the serif headings;
|
||||
- the editor test failed on the label field and the top bar.
|
||||
- **Changed existing tests:** none. One of my own new render tests changed before going green: the sticky class sits on the top bar's row, not on the header. A sticky element only sticks inside its parent, and the header's parent is just as tall as the header.
|
||||
- **Live check** (port 3001, rebuilt counter), on `/p/INS/hotel-technology-native` through the editor:
|
||||
- "hide page header" was already on;
|
||||
- added a Top bar section, moved it first, and set "Get My Free Consultation" linking to `#consult`;
|
||||
- typed the labels "Services", "How we work", "Why Infinity" and "FAQ" on the canvas;
|
||||
- saved and published.
|
||||
- **Published result:**
|
||||
- at 1280 px the logo and button sit in a white bar above the full-width hero, with no title, and the bar stays at the top while scrolling;
|
||||
- the labels show in darkened gold uppercase above serif headings;
|
||||
- at 390 px the bar keeps the logo and button, and the hero stacks.
|
||||
- **Not reachable in the UI, covered by the validator tests:** a top bar that is not first is refused (the server rule; the editor's Move up and Move down allow it, and the refusal shows on the canvas).
|
||||
@@ -18,15 +18,16 @@ import { CopyAddress } from "./CopyAddress";
|
||||
const INLINE: Record<string, string[]> = {
|
||||
HERO: ["imageId", "heading", "text", "buttonLabel", "buttonUrl", "eventUuid", "fullWidth", "formHeading", "formText", "thanksText", "cards"],
|
||||
RICH_TEXT: ["html"],
|
||||
IMAGE_TEXT: ["imageId", "imagePosition", "heading", "html", "buttonLabel", "buttonUrl"],
|
||||
FAQ: ["heading", "items"],
|
||||
IMAGE_TEXT: ["imageId", "imagePosition", "eyebrow", "heading", "html", "buttonLabel", "buttonUrl"],
|
||||
FAQ: ["eyebrow", "heading", "items"],
|
||||
FORM: ["heading", "eventUuid", "thanksText"],
|
||||
HTML: ["html"],
|
||||
FEATURES: ["heading", "text", "cards"],
|
||||
STEPS: ["heading", "cards"],
|
||||
FEATURES: ["eyebrow", "heading", "text", "cards"],
|
||||
STEPS: ["eyebrow", "heading", "cards"],
|
||||
TRUST: ["cards"],
|
||||
CTA: ["heading", "text", "buttonLabel", "buttonUrl"],
|
||||
CTA: ["eyebrow", "heading", "text", "buttonLabel", "buttonUrl"],
|
||||
FOOTER: ["cards", "text"],
|
||||
TOPBAR: ["buttonLabel", "buttonUrl"],
|
||||
};
|
||||
const LISTED = /^(items\[\d+\]\.(question|answer)|cards\[\d+\]\.(icon|title|text))$/;
|
||||
|
||||
@@ -92,7 +93,7 @@ export function BlockFields(props: {
|
||||
const fid = (name: string) => `block-${id}-${name}`;
|
||||
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" | "formHeading" | "formText" | "thanksText", labelCode: string) => (
|
||||
const text = (name: "heading" | "text" | "buttonLabel" | "buttonUrl" | "anchor" | "formHeading" | "formText" | "thanksText" | "eyebrow", labelCode: string) => (
|
||||
<Field id={fid(name)} label={t(labelCode)} error={errors[name]}>
|
||||
<Input id={fid(name)} value={block[name] ?? ""} disabled={saving} aria-invalid={!!errors[name]} onChange={(e) => set({ [name]: e.target.value })} />
|
||||
</Field>
|
||||
@@ -258,6 +259,7 @@ export function BlockFields(props: {
|
||||
<option value="RIGHT">{t("PagesImageRight")}</option>
|
||||
</select>
|
||||
</Field>
|
||||
{text("eyebrow", "PagesEyebrow")}
|
||||
{text("heading", "PagesHeading")}
|
||||
{richText("PagesText")}
|
||||
{text("buttonLabel", "PagesButtonLabel")}
|
||||
@@ -267,6 +269,7 @@ export function BlockFields(props: {
|
||||
|
||||
{block.type === "FAQ" && (
|
||||
<>
|
||||
{text("eyebrow", "PagesEyebrow")}
|
||||
{text("heading", "PagesHeading")}
|
||||
{items.map((item, i) => (
|
||||
<div key={i} className="space-y-2 rounded-md border p-3">
|
||||
@@ -328,6 +331,7 @@ export function BlockFields(props: {
|
||||
|
||||
{block.type === "FEATURES" && (
|
||||
<>
|
||||
{text("eyebrow", "PagesEyebrow")}
|
||||
{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 })} />
|
||||
@@ -338,6 +342,7 @@ export function BlockFields(props: {
|
||||
|
||||
{block.type === "STEPS" && (
|
||||
<>
|
||||
{text("eyebrow", "PagesEyebrow")}
|
||||
{text("heading", "PagesHeading")}
|
||||
{cardList}
|
||||
</>
|
||||
@@ -345,6 +350,14 @@ export function BlockFields(props: {
|
||||
|
||||
{block.type === "TRUST" && cardList}
|
||||
|
||||
{/* add-landing-page-polish: the top bar's button; its logo comes from the company. */}
|
||||
{block.type === "TOPBAR" && (
|
||||
<>
|
||||
{text("buttonLabel", "PagesButtonLabel")}
|
||||
{text("buttonUrl", "PagesButtonLink")}
|
||||
</>
|
||||
)}
|
||||
|
||||
{block.type === "FOOTER" && (
|
||||
<>
|
||||
{cardList}
|
||||
@@ -354,6 +367,7 @@ export function BlockFields(props: {
|
||||
|
||||
{block.type === "CTA" && (
|
||||
<>
|
||||
{text("eyebrow", "PagesEyebrow")}
|
||||
{text("heading", "PagesHeading")}
|
||||
{text("text", "PagesText")}
|
||||
{text("buttonLabel", "PagesButtonLabel")}
|
||||
@@ -361,7 +375,7 @@ export function BlockFields(props: {
|
||||
</>
|
||||
)}
|
||||
|
||||
{block.type !== "HTML" && (
|
||||
{block.type !== "HTML" && block.type !== "TOPBAR" && (
|
||||
<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 })}>
|
||||
|
||||
@@ -230,3 +230,48 @@ describe("LandingPage thank-you text and footer", () => {
|
||||
expect(within(foot).getByRole("link", { name: "+60 12-833 2775" })).toHaveAttribute("href", "tel:+60128332775");
|
||||
});
|
||||
});
|
||||
|
||||
// add-landing-page-polish: the top bar, section labels and serif headings.
|
||||
describe("LandingPage polish", () => {
|
||||
const bar: PublicBlock = { type: "TOPBAR", buttonLabel: "Get My Free Consultation", buttonUrl: "#consult" };
|
||||
const hero: PublicBlock = { type: "HERO", heading: "One partner", fullWidth: true };
|
||||
|
||||
it("a top bar shows the logo and its button, stays at the top, and joins the hero", () => {
|
||||
render(<LandingPage company={company} page={{ ...page([bar, hero]), hideHeader: true }} />);
|
||||
const top = screen.getByRole("banner");
|
||||
expect(within(top).getByRole("img", { name: "INS Sdn Bhd" })).toHaveAttribute("src", "/api/public/page-images/4");
|
||||
expect(within(top).getByRole("link", { name: "Get My Free Consultation" })).toHaveAttribute("href", "#consult");
|
||||
// The row sticks, not the header: a sticky element only sticks inside its parent.
|
||||
expect(top.closest("main > div > div")).toHaveClass("sticky", "top-0");
|
||||
expect(top.closest(".max-w-5xl")).toBeNull();
|
||||
expect(screen.getAllByRole("banner")).toHaveLength(1);
|
||||
const rows = Array.from(document.querySelector("main > div")!.children);
|
||||
expect(rows.map((r) => r.classList.contains("mt-10"))).toEqual([false, false]);
|
||||
});
|
||||
|
||||
it("a top bar without a logo shows the company name, and no button without one", () => {
|
||||
render(<LandingPage company={{ ...company, logoImageId: null }} page={{ ...page([{ type: "TOPBAR" }]), hideHeader: true }} />);
|
||||
const top = screen.getByRole("banner");
|
||||
expect(top).toHaveTextContent("INS Sdn Bhd");
|
||||
expect(within(top).queryByRole("link")).toBeNull();
|
||||
});
|
||||
|
||||
it("named blocks keep clear of a sticky bar when jumped to", () => {
|
||||
render(<LandingPage company={company} page={page([bar, { type: "FORM", heading: "Join", closed: true, anchor: "consult" }])} />);
|
||||
expect(document.getElementById("consult")).toHaveClass("scroll-mt-24");
|
||||
});
|
||||
|
||||
it("shows a section's label above its heading, and section headings in serif", () => {
|
||||
render(<LandingPage company={company} page={page([
|
||||
{ type: "FEATURES", eyebrow: "Services", heading: "Everything your guests touch", cards: [{ icon: "wifi", title: "WiFi", text: "Fast." }] },
|
||||
{ type: "FAQ", eyebrow: "FAQ", heading: "Questions hotels ask us", items: [{ question: "Q", answer: "A" }], look: "DARK" },
|
||||
])} />);
|
||||
const heading = screen.getByRole("heading", { level: 2, name: "Everything your guests touch" });
|
||||
expect(heading).toHaveClass("font-serif");
|
||||
const label = heading.previousElementSibling!;
|
||||
expect(label).toHaveTextContent("Services");
|
||||
expect(label).toHaveClass("uppercase");
|
||||
expect(screen.getByRole("heading", { level: 2, name: "Questions hotels ask us" })).toHaveClass("font-serif");
|
||||
expect(screen.getByRole("heading", { level: 2, name: "Questions hotels ask us" }).previousElementSibling).toHaveClass("text-primary");
|
||||
});
|
||||
});
|
||||
@@ -42,6 +42,27 @@ function ButtonLink({ block, index, edit }: { block: CmsBlock; index: number; ed
|
||||
);
|
||||
}
|
||||
|
||||
// add-landing-page-polish: a section's serif heading, with its optional label above. The label is the accent colour,
|
||||
// darkened toward the text colour on light backgrounds, where a pale accent would be hard to read.
|
||||
const LABEL_COLOUR: Record<string, string> = {
|
||||
DARK: "text-primary",
|
||||
ACCENT: "opacity-80",
|
||||
LIGHT: "text-[color-mix(in_srgb,var(--primary)_60%,var(--foreground))]",
|
||||
};
|
||||
|
||||
const LABELLED = ["FEATURES", "STEPS", "IMAGE_TEXT", "FAQ", "CTA"];
|
||||
|
||||
function SectionHeading({ block, index, className }: { block: CmsBlock; index: number; className: string }) {
|
||||
const band = bandOf(block.look);
|
||||
return (
|
||||
<>
|
||||
{LABELLED.includes(block.type) && <Text as="p" index={index} path="eyebrow" value={block.eyebrow} max={40} code="PagesEyebrow"
|
||||
className={`mb-2 text-xs font-semibold tracking-widest uppercase ${LABEL_COLOUR[band === "DARK" || band === "ACCENT" ? band : "LIGHT"]}`} />}
|
||||
<Text as="h2" index={index} path="heading" value={block.heading} max={120} code="PagesHeading" className={`font-serif font-semibold ${className}`} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function Block({ block, index, company, slug, preview, edit }: { block: PublicBlock; index: number; company: string; slug: string; preview?: boolean; edit?: boolean }) {
|
||||
const image = block.imageId ? imageSrc(block.imageId) : undefined;
|
||||
const button = <ButtonLink block={block} index={index} edit={edit} />;
|
||||
@@ -133,7 +154,7 @@ function Block({ block, index, company, slug, preview, edit }: { block: PublicBl
|
||||
</div>
|
||||
) : null}
|
||||
<div className="space-y-3">
|
||||
<Text as="h2" index={index} path="heading" value={block.heading} max={120} code="PagesHeading" className="text-2xl font-semibold" />
|
||||
<SectionHeading block={block} index={index} className="text-2xl" />
|
||||
<RichSpot index={index} html={block.html} className={PROSE}>{block.html ? <SafeHtml html={block.html} className={PROSE} /> : null}</RichSpot>
|
||||
{button}
|
||||
</div>
|
||||
@@ -142,7 +163,7 @@ function Block({ block, index, company, slug, preview, edit }: { block: PublicBl
|
||||
case "FAQ":
|
||||
return block.items?.length ? (
|
||||
<section className="space-y-3">
|
||||
<Text as="h2" index={index} path="heading" value={block.heading} max={120} code="PagesHeading" className="text-2xl font-semibold" />
|
||||
<SectionHeading block={block} index={index} className="text-2xl" />
|
||||
<div className="divide-y rounded-lg border">
|
||||
{block.items.map((item, i) => {
|
||||
const question = <Text as="span" index={index} path={`items.${i}.question`} value={item.question} max={300} code="PagesQuestionN" n={i + 1} />;
|
||||
@@ -163,7 +184,7 @@ function Block({ block, index, company, slug, preview, edit }: { block: PublicBl
|
||||
case "FORM":
|
||||
return (
|
||||
<section className="mx-auto w-full max-w-md space-y-4 rounded-lg border bg-card p-6 shadow-card">
|
||||
<Text as="h2" index={index} path="heading" value={block.heading} max={120} code="PagesHeading" className="text-2xl font-semibold" />
|
||||
<SectionHeading block={block} index={index} className="text-2xl" />
|
||||
<LandingForm companyCode={company} slug={slug} index={index} info={block.closed ? undefined : block.form} preview={preview} thanks={block.thanksText} />
|
||||
</section>
|
||||
);
|
||||
@@ -171,7 +192,7 @@ function Block({ block, index, company, slug, preview, edit }: { block: PublicBl
|
||||
return (
|
||||
<section className="space-y-6">
|
||||
<div className="max-w-2xl space-y-2">
|
||||
<Text as="h2" index={index} path="heading" value={block.heading} max={120} code="PagesHeading" className="text-2xl font-semibold sm:text-3xl" />
|
||||
<SectionHeading block={block} index={index} className="text-2xl sm:text-3xl" />
|
||||
<Text as="p" index={index} path="text" value={block.text} max={300} code="PagesText" className="text-lg opacity-80" />
|
||||
</div>
|
||||
<ul className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
||||
@@ -191,7 +212,7 @@ function Block({ block, index, company, slug, preview, edit }: { block: PublicBl
|
||||
case "STEPS":
|
||||
return (
|
||||
<section className="space-y-6">
|
||||
<Text as="h2" index={index} path="heading" value={block.heading} max={120} code="PagesHeading" className="text-2xl font-semibold sm:text-3xl" />
|
||||
<SectionHeading block={block} index={index} className="text-2xl sm:text-3xl" />
|
||||
<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">
|
||||
@@ -216,7 +237,7 @@ function Block({ block, index, company, slug, preview, edit }: { block: PublicBl
|
||||
case "CTA":
|
||||
return (
|
||||
<section className="flex flex-col items-center gap-4 py-4 text-center">
|
||||
<Text as="h2" index={index} path="heading" value={block.heading} max={120} code="PagesHeading" className="text-2xl font-semibold sm:text-3xl" />
|
||||
<SectionHeading block={block} index={index} className="text-2xl sm:text-3xl" />
|
||||
<Text as="p" index={index} path="text" value={block.text} max={300} code="PagesText" className="max-w-2xl text-lg opacity-80" />
|
||||
{button}
|
||||
</section>
|
||||
@@ -243,21 +264,39 @@ function Block({ block, index, company, slug, preview, edit }: { block: PublicBl
|
||||
|
||||
const WIDTH = "mx-auto w-full max-w-5xl px-4";
|
||||
|
||||
/** add-landing-page-polish: the company logo (or name) and an optional button, kept at the top of the window. */
|
||||
function TopBar({ block, index, company, edit }: { block: CmsBlock; index: number; company: Branding; edit: boolean }) {
|
||||
return (
|
||||
<header role="banner" id={anchorId(block.anchor)} className="border-b bg-card/95 backdrop-blur">
|
||||
<div className="mx-auto flex max-w-6xl items-center justify-between gap-3 px-4 py-3">
|
||||
{company.logoImageId ? (
|
||||
// eslint-disable-next-line @next/next/no-img-element -- the company's uploaded logo
|
||||
<img src={imageSrc(company.logoImageId)} alt={company.name} className="h-10 w-auto" />
|
||||
) : (
|
||||
<span className="text-lg font-semibold">{company.name}</span>
|
||||
)}
|
||||
<ButtonLink block={block} index={index} edit={edit} />
|
||||
</div>
|
||||
</header>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Blocks that run the full window width: Custom HTML, a full-width hero, and a coloured band (add-compact-landing-form).
|
||||
* Two of them in a row join with no gap.
|
||||
*/
|
||||
const bleeds = (block: PublicBlock) => block.type === "HTML" || (block.type === "HERO" && !!block.fullWidth) || !!bandOf(block.look);
|
||||
const bleeds = (block: PublicBlock) => block.type === "HTML" || block.type === "TOPBAR" || (block.type === "HERO" && !!block.fullWidth) || !!bandOf(block.look);
|
||||
|
||||
/** A block in the page width; with a non-default look, inside a full-width band of that colour. */
|
||||
function Section({ block, index, children }: { block: PublicBlock; index: number; children: ReactNode }) {
|
||||
const band = bandOf(block.look);
|
||||
// add-hero-full-width: a full-width hero sets its own width.
|
||||
if (block.type === "HERO" && block.fullWidth) return <EditSection index={index}><div id={anchorId(block.anchor)}>{children}</div></EditSection>;
|
||||
if (!band) return <EditSection index={index}><div id={anchorId(block.anchor)} className={WIDTH}>{children}</div></EditSection>;
|
||||
// add-landing-page-polish: a #name jump lands clear of a sticky top bar.
|
||||
if (!band) return <EditSection index={index}><div id={anchorId(block.anchor)} className={`scroll-mt-24 ${WIDTH}`}>{children}</div></EditSection>;
|
||||
return (
|
||||
<EditSection index={index}>
|
||||
<div id={anchorId(block.anchor)} data-look={band} className={`py-12 ${BANDS[band]}`}>
|
||||
<div id={anchorId(block.anchor)} data-look={band} className={`scroll-mt-16 py-12 ${BANDS[band]}`}>
|
||||
<div className={WIDTH}>{children}</div>
|
||||
</div>
|
||||
</EditSection>
|
||||
@@ -299,8 +338,11 @@ export function LandingPage({ company, page, banner, preview, frameBase, edit }:
|
||||
<h1 className={page.hideHeader ? "sr-only" : `${WIDTH} mb-10 text-3xl font-semibold sm:text-4xl`}>{page.title}</h1>
|
||||
<div>
|
||||
{page.blocks.map((block, i) => (
|
||||
<div key={i} className={i > 0 && !(bleeds(block) && bleeds(page.blocks[i - 1])) ? "mt-10" : undefined}>
|
||||
{block.type === "HTML"
|
||||
// A top bar's row is what sticks: a sticky element only sticks inside its parent, and the rows share the page's.
|
||||
<div key={i} className={block.type === "TOPBAR" ? "sticky top-0 z-20" : i > 0 && !(bleeds(block) && bleeds(page.blocks[i - 1])) ? "mt-10" : undefined}>
|
||||
{block.type === "TOPBAR"
|
||||
? <EditSection index={i}><TopBar block={block} index={i} company={company} edit={!!edit} /></EditSection>
|
||||
: block.type === "HTML"
|
||||
? <HtmlSpot index={i}><HtmlFrame id={anchorId(block.anchor)} src={`${frames}/${i}${edit ? `?v=${edit.frameVersion}` : ""}`} title={page.title} /></HtmlSpot>
|
||||
: <Section block={block} index={i}><Block block={block} index={i} company={company.code} slug={page.slug} preview={preview} edit={!!edit} /></Section>}
|
||||
</div>
|
||||
|
||||
@@ -101,6 +101,25 @@ describe("PageEditor: sections", () => {
|
||||
});
|
||||
});
|
||||
|
||||
// add-landing-page-polish: the top bar's button, and a label above a section's heading.
|
||||
it("adds a top bar with a button and no look, and saves a section label", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<PageEditor pageId={5} />);
|
||||
await screen.findByDisplayValue("How it works");
|
||||
await user.type(within(group("Block 1: Steps")).getByLabelText("Label"), "How we work");
|
||||
await user.click(screen.getByRole("button", { name: "Add Top bar" }));
|
||||
const block = group("Block 3: Top bar");
|
||||
expect(within(block).queryByLabelText("Look")).not.toBeInTheDocument();
|
||||
expect(within(block).queryByLabelText("Label")).not.toBeInTheDocument();
|
||||
await user.type(within(block).getByLabelText("Button label"), "Get My Free Consultation");
|
||||
await user.type(within(block).getByLabelText("Button link"), "#consult");
|
||||
await user.click(screen.getByRole("button", { name: "Save" }));
|
||||
await waitFor(() => expect(mocks.savePage).toHaveBeenCalled());
|
||||
const blocks = mocks.savePage.mock.calls[0][1].blocks;
|
||||
expect(blocks[0]).toMatchObject({ type: "STEPS", eyebrow: "How we work" });
|
||||
expect(blocks[2]).toEqual({ type: "TOPBAR", buttonLabel: "Get My Free Consultation", buttonUrl: "#consult" });
|
||||
});
|
||||
|
||||
it("offers no look for a Custom HTML block", async () => {
|
||||
render(<PageEditor pageId={5} />);
|
||||
await screen.findByDisplayValue("How it works");
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
import { Calendar, Cloud, Headset, Lock, Monitor, Phone, ShieldCheck, Star, Tv, Users, Wifi, Wrench, type LucideIcon } from "lucide-react";
|
||||
|
||||
export type BlockType = "HERO" | "RICH_TEXT" | "IMAGE_TEXT" | "FAQ" | "FORM" | "HTML" | "FEATURES" | "STEPS" | "TRUST" | "CTA" | "FOOTER";
|
||||
export type BlockType = "HERO" | "RICH_TEXT" | "IMAGE_TEXT" | "FAQ" | "FORM" | "HTML" | "FEATURES" | "STEPS" | "TRUST" | "CTA" | "FOOTER" | "TOPBAR";
|
||||
|
||||
export const BLOCK_TYPES: BlockType[] = ["HERO", "RICH_TEXT", "IMAGE_TEXT", "FEATURES", "STEPS", "TRUST", "CTA", "FAQ", "FORM", "HTML", "FOOTER"];
|
||||
export const BLOCK_TYPES: BlockType[] = ["HERO", "RICH_TEXT", "IMAGE_TEXT", "FEATURES", "STEPS", "TRUST", "CTA", "FAQ", "FORM", "HTML", "FOOTER", "TOPBAR"];
|
||||
|
||||
/** Feature-card icons by the name services-counter accepts (add-page-sections). */
|
||||
export const ICONS: Record<string, LucideIcon> = {
|
||||
@@ -29,6 +29,7 @@ export const BLOCK_LABELS: Record<BlockType, string> = {
|
||||
TRUST: "PagesBlockTrust",
|
||||
CTA: "PagesBlockCta",
|
||||
FOOTER: "PagesBlockFooter",
|
||||
TOPBAR: "PagesBlockTopBar",
|
||||
};
|
||||
|
||||
/** A FEATURES (icon, title, text), STEPS (title, text) or TRUST (title) card; a HERO's points are title-only cards; a FOOTER's columns are title-and-text cards. */
|
||||
@@ -65,6 +66,8 @@ export interface CmsBlock {
|
||||
formText?: string;
|
||||
/** add-landing-thanks-and-footer: text (200) under the thank-you after a sign-up; FORM, or HERO with an event. */
|
||||
thanksText?: string;
|
||||
/** add-landing-page-polish: a short label (40) above the heading of FEATURES, STEPS, IMAGE_TEXT, FAQ and CTA. */
|
||||
eyebrow?: string;
|
||||
}
|
||||
|
||||
export type PageStatus = "DRAFT" | "PUBLISHED";
|
||||
@@ -135,6 +138,8 @@ export function emptyBlock(type: BlockType): CmsBlock {
|
||||
return { type, cards: [{ title: "" }, { title: "" }] };
|
||||
case "CTA":
|
||||
return { type, heading: "", text: "", buttonLabel: "", buttonUrl: "" };
|
||||
case "TOPBAR":
|
||||
return { type, buttonLabel: "", buttonUrl: "" };
|
||||
case "FOOTER":
|
||||
return { type, look: "DARK", text: "", cards: [{ title: "", text: "" }, { title: "", text: "" }] };
|
||||
default:
|
||||
|
||||
@@ -883,6 +883,9 @@ export const DEFAULT_MESSAGES: Record<string, string> = {
|
||||
PagesColumnN: "Column {number}",
|
||||
PagesAddColumn: "Add column",
|
||||
PagesFooterLegal: "Legal line",
|
||||
PagesBlockTopBar: "Top bar",
|
||||
PagesEyebrow: "Label",
|
||||
PagesTopBarFirst: "The top bar must be the first section.",
|
||||
PagesUploadImage: "Upload image",
|
||||
PagesUploadImageHint: "PNG, JPEG or WebP up to 2 MB. Paste the link into your HTML, for example in an img tag's src.",
|
||||
PagesToolbar: "Formatting",
|
||||
|
||||
@@ -868,6 +868,9 @@
|
||||
"PagesColumnN": "第 {number} 栏",
|
||||
"PagesAddColumn": "添加栏",
|
||||
"PagesFooterLegal": "版权声明",
|
||||
"PagesBlockTopBar": "顶栏",
|
||||
"PagesEyebrow": "小标签",
|
||||
"PagesTopBarFirst": "顶栏必须是第一个区块。",
|
||||
"PagesUploadImage": "上传图片",
|
||||
"PagesUploadImageHint": "PNG、JPEG 或 WebP,最大 2 MB。将链接粘贴到您的 HTML 中,例如 img 标签的 src。",
|
||||
"PagesToolbar": "格式",
|
||||
|
||||
+4
-1
@@ -12,7 +12,8 @@ import java.util.List;
|
||||
* One landing-page block. Which fields apply depends on {@code type}:
|
||||
* HERO (imageId, heading, text, button, optional eventUuid for a sign-up form beside the text, fullWidth, formHeading and formText, cards as title-only points), RICH_TEXT (html), IMAGE_TEXT (imageId, imagePosition, heading, html, button),
|
||||
* FAQ (heading, items), FORM (heading, eventUuid), HTML (html), FEATURES (heading, text, cards), STEPS (heading, cards),
|
||||
* TRUST (cards), CTA (heading, text, button), FOOTER (cards as title-and-text columns, text as the legal line). Any block may carry anchor and look.
|
||||
* TRUST (cards), CTA (heading, text, button), FOOTER (cards as title-and-text columns, text as the legal line),
|
||||
* TOPBAR (button only; the first block). Any block may carry anchor and look.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@@ -42,4 +43,6 @@ public class CmsBlock {
|
||||
private String formText;
|
||||
/** add-landing-thanks-and-footer: text (200) under the thank-you after a sign-up; FORM, or HERO with an event. */
|
||||
private String thanksText;
|
||||
/** add-landing-page-polish: a short label (40) above the heading of FEATURES, STEPS, IMAGE_TEXT, FAQ and CTA. */
|
||||
private String eyebrow;
|
||||
}
|
||||
+33
-1
@@ -17,7 +17,7 @@ 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-landing-thanks-and-footer adds FOOTER and the thank-you text. add-page-sections adds FEATURES, STEPS, TRUST and CTA, a look on any block, and makes the HERO image optional.
|
||||
* add-landing-page-polish adds TOPBAR and section labels. add-landing-thanks-and-footer adds FOOTER and the thank-you text. 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 {
|
||||
@@ -28,6 +28,8 @@ public final class CmsBlockValidator {
|
||||
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", "HERO", "FOOTER");
|
||||
/** add-landing-page-polish: blocks that may carry a short label above their heading. */
|
||||
private static final Set<String> EYEBROW_TYPES = Set.of("FEATURES", "STEPS", "IMAGE_TEXT", "FAQ", "CTA");
|
||||
private static final Pattern SCRIPT = Pattern.compile("(?i)<\\s*script|\\son[a-z]+\\s*=|javascript\\s*:");
|
||||
|
||||
private CmsBlockValidator() {
|
||||
@@ -66,6 +68,12 @@ public final class CmsBlockValidator {
|
||||
if (b.getThanksText() != null && !"FORM".equals(b.getType()) && !"HERO".equals(b.getType())) {
|
||||
throw refuse(path + ".thanksText", "PagesUnusedField");
|
||||
}
|
||||
if (b.getEyebrow() != null) {
|
||||
if (!EYEBROW_TYPES.contains(b.getType())) {
|
||||
throw refuse(path + ".eyebrow", "PagesUnusedField");
|
||||
}
|
||||
max(b.getEyebrow(), path + ".eyebrow", 40);
|
||||
}
|
||||
switch (b.getType()) {
|
||||
case "HERO" -> {
|
||||
if (b.getImageId() != null) {
|
||||
@@ -150,6 +158,24 @@ public final class CmsBlockValidator {
|
||||
required(b.getButtonLabel(), path + ".buttonLabel");
|
||||
button(b, path);
|
||||
}
|
||||
case "TOPBAR" -> {
|
||||
// add-landing-page-polish: the company logo and an optional button, sticky, so only at the top.
|
||||
if (i > 0) {
|
||||
throw refuse(path + ".type", "PagesTopBarFirst");
|
||||
}
|
||||
unused(path, "heading", b.getHeading());
|
||||
unused(path, "text", b.getText());
|
||||
unused(path, "html", b.getHtml());
|
||||
unused(path, "imageId", b.getImageId());
|
||||
unused(path, "imagePosition", b.getImagePosition());
|
||||
unused(path, "items", b.getItems());
|
||||
unused(path, "eventUuid", b.getEventUuid());
|
||||
unused(path, "fullWidth", b.getFullWidth());
|
||||
unused(path, "formHeading", b.getFormHeading());
|
||||
unused(path, "formText", b.getFormText());
|
||||
unused(path, "look", b.getLook());
|
||||
button(b, path);
|
||||
}
|
||||
default -> throw refuse(path + ".type", "PagesUnknownType");
|
||||
}
|
||||
}
|
||||
@@ -159,6 +185,12 @@ public final class CmsBlockValidator {
|
||||
return new ResponseStatusException(HttpStatus.UNPROCESSABLE_ENTITY, path + "|" + code);
|
||||
}
|
||||
|
||||
private static void unused(String path, String field, Object value) {
|
||||
if (value != null) {
|
||||
throw refuse(path + "." + field, "PagesUnusedField");
|
||||
}
|
||||
}
|
||||
|
||||
static void required(String value, String path) {
|
||||
if (value == null || value.isBlank()) {
|
||||
throw refuse(path, "PagesRequired");
|
||||
|
||||
+58
@@ -334,4 +334,62 @@ class CmsBlockValidatorTest {
|
||||
legal.setText("x".repeat(301));
|
||||
refused(List.of(legal), "blocks[0].text", "PagesTooLong");
|
||||
}
|
||||
|
||||
// add-landing-page-polish: the top bar block, first only, and section labels.
|
||||
private static CmsBlock topBar() {
|
||||
CmsBlock b = new CmsBlock();
|
||||
b.setType("TOPBAR");
|
||||
return b;
|
||||
}
|
||||
|
||||
@Test
|
||||
void aTopBarIsTheFirstBlockWithAnOptionalButtonOnly() {
|
||||
CmsBlock withButton = topBar();
|
||||
withButton.setButtonLabel("Get My Free Consultation");
|
||||
withButton.setButtonUrl("#consult");
|
||||
CmsBlock target = form(OWN_EVENT);
|
||||
target.setAnchor("consult");
|
||||
assertThatCode(() -> validate(List.of(withButton, target))).doesNotThrowAnyException();
|
||||
assertThatCode(() -> validate(List.of(topBar()))).doesNotThrowAnyException();
|
||||
refused(List.of(hero(), topBar()), "blocks[1].type", "PagesTopBarFirst");
|
||||
CmsBlock half = topBar();
|
||||
half.setButtonLabel("Go");
|
||||
refused(List.of(half), "blocks[0].buttonUrl", "PagesButtonPair");
|
||||
CmsBlock heading = topBar();
|
||||
heading.setHeading("Hi");
|
||||
refused(List.of(heading), "blocks[0].heading", "PagesUnusedField");
|
||||
CmsBlock text = topBar();
|
||||
text.setText("Hi");
|
||||
refused(List.of(text), "blocks[0].text", "PagesUnusedField");
|
||||
CmsBlock image = topBar();
|
||||
image.setImageId(OWN_IMAGE);
|
||||
refused(List.of(image), "blocks[0].imageId", "PagesUnusedField");
|
||||
CmsBlock html = topBar();
|
||||
html.setHtml("<p>x</p>");
|
||||
refused(List.of(html), "blocks[0].html", "PagesUnusedField");
|
||||
CmsBlock look = topBar();
|
||||
look.setLook("DARK");
|
||||
refused(List.of(look), "blocks[0].look", "PagesUnusedField");
|
||||
CmsBlock cards = topBar();
|
||||
cards.setCards(points(1));
|
||||
refused(List.of(cards), "blocks[0].cards", "PagesUnusedField");
|
||||
}
|
||||
|
||||
@Test
|
||||
void sectionLabelsOnFiveTypesUpToFortyCharacters() {
|
||||
CmsBlock steps = new CmsBlock();
|
||||
steps.setType("STEPS");
|
||||
steps.setHeading("From first survey to day-to-day care");
|
||||
steps.setCards(List.of(new CmsCard(null, "Design", "We survey."), new CmsCard(null, "Install", "We fit.")));
|
||||
steps.setEyebrow("How we work");
|
||||
CmsBlock faqBlock = faq(1);
|
||||
faqBlock.setEyebrow("x".repeat(40));
|
||||
assertThatCode(() -> validate(List.of(steps, faqBlock))).doesNotThrowAnyException();
|
||||
CmsBlock tooLong = faq(1);
|
||||
tooLong.setEyebrow("x".repeat(41));
|
||||
refused(List.of(tooLong), "blocks[0].eyebrow", "PagesTooLong");
|
||||
CmsBlock onHero = hero();
|
||||
onHero.setEyebrow("Hotels");
|
||||
refused(List.of(onHero), "blocks[0].eyebrow", "PagesUnusedField");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user