feat(pages): a hero section can carry the sign-up form beside its text

A HERO block may name an event. services-counter checks it belongs to the
page's company; mobile-api serves and accepts the form for it like a FORM
block; the portal shows the form in a card beside the hero text (below it on
phones), with the hero's own event picker, "No form" by default.

OpenSpec change: add-hero-signup-form.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
This commit is contained in:
ngqileandClaude Opus 5.5 committed 2026-12-03 19:36:16 +08:00
1 parent 55ae666f01
commit 417af36227
20 files changed
+294 -22

No files matched your search

@@ -48,7 +48,7 @@ public class PublicPageService {
List<Map<String, Object>> blocks = new ArrayList<>();
for (Object b : blocks(f.page())) {
Map<String, Object> block = new LinkedHashMap<>((Map<String, Object>) b);
if ("FORM".equals(block.get("type"))) {
if (hasForm(block)) {
PublicRegistrationService.Open o = open(f.companyId(), block);
if (o == null) block.put("closed", true);
else block.put("form", registration.eventView(o));
@@ -64,11 +64,16 @@ public class PublicPageService {
return Map.of("company", f.company(), "page", page);
}
/** A FORM block, or a HERO with an event: its sign-up form sits beside the hero text (add-hero-signup-form). */
private static boolean hasForm(Map<?, ?> block) {
return "FORM".equals(block.get("type")) || ("HERO".equals(block.get("type")) && block.get("eventUuid") != null);
}
public Map<String, Object> submit(String companyCode, String slug, int blockIndex, PublicPageFormRequest r) {
registration.limit("page:load:" + PublicRegistrationService.ip(), LOAD_LIMIT, "Too many requests from this device. Try again later.");
Found f = find(companyCode, slug);
List<?> blocks = blocks(f.page());
if (blockIndex < 0 || blockIndex >= blocks.size() || !"FORM".equals(((Map<?, ?>) blocks.get(blockIndex)).get("type"))) {
if (blockIndex < 0 || blockIndex >= blocks.size() || !hasForm((Map<?, ?>) blocks.get(blockIndex))) {
throw notFound();
}
PublicRegistrationService.Open o = open(f.companyId(), (Map<String, Object>) blocks.get(blockIndex));
@@ -180,6 +180,42 @@ class PublicPageServiceTest {
verify(rest, never()).postForEntity(eq(REGISTER), any(ParameterizedTypeReference.class), any());
}
@Test
void aHeroWithAnEventCarriesTheSignUpFormAndTakesSubmits() {
// add-hero-signup-form: block 0 is a hero with the form beside its text, block 1 a hero without one.
Map<String, Object> heroes = page();
heroes.put("blocks", List.of(
new HashMap<>(Map.of("type", "HERO", "heading", "One partner", "eventUuid", String.valueOf(EV))),
Map.of("type", "HERO", "heading", "No form here")));
when(rest.getForEntity(eq(PUBLISHED), any(ParameterizedTypeReference.class), eq(COMPANY), eq("hotel-technology")))
.thenReturn(ResponseEntity.ok(heroes));
List<Map<String, Object>> blocks = (List<Map<String, Object>>) ((Map<String, Object>) service.page("INS", "hotel-technology").get("page")).get("blocks");
assertThat((Map<String, Object>) blocks.get(0).get("form")).containsEntry("eventName", "INS website enquiries");
assertThat(blocks.get(1)).doesNotContainKeys("form", "closed");
service.submit("INS", "hotel-technology", 0, visitor(null));
ArgumentCaptor<Object> body = ArgumentCaptor.forClass(Object.class);
verify(rest).postForEntity(eq(REGISTER), any(ParameterizedTypeReference.class), body.capture());
assertThat((Map<String, Object>) body.getValue()).containsEntry("eventUuid", EV).containsEntry("source", "WEB");
assertThatThrownBy(() -> service.submit("INS", "hotel-technology", 1, visitor(null)))
.isInstanceOfSatisfying(CodedResponseStatusException.class, e -> assertThat(e.getCode()).isEqualTo("PAGE_NOT_FOUND"));
}
@Test
void aHeroFormWhoseEventEndedIsClosed() {
Map<String, Object> hero = page();
hero.put("blocks", List.of(new HashMap<>(Map.of("type", "HERO", "heading", "One partner", "eventUuid", String.valueOf(EV)))));
when(rest.getForEntity(eq(PUBLISHED), any(ParameterizedTypeReference.class), eq(COMPANY), eq("hotel-technology")))
.thenReturn(ResponseEntity.ok(hero));
stubEvent(LocalDateTime.of(2027, 1, 15, 23, 59));
List<Map<String, Object>> blocks = (List<Map<String, Object>>) ((Map<String, Object>) service.page("INS", "hotel-technology").get("page")).get("blocks");
assertThat(blocks.get(0)).containsEntry("closed", true).containsEntry("heading", "One partner").doesNotContainKey("form");
assertThatThrownBy(() -> service.submit("INS", "hotel-technology", 0, visitor(null)))
.isInstanceOfSatisfying(CodedResponseStatusException.class, e -> assertThat(e.getCode()).isEqualTo("FORM_CLOSED"));
}
@Test
void theHoneypotLooksLikeSuccessAndStoresNothing() {
assertThat(service.submit("INS", "hotel-technology", 1, visitor("http://spam"))).containsKey("eventName");