From 5123450a385c05762e569bc44c4cc103c11c938b Mon Sep 17 00:00:00 2001 From: SURYANSH-RAI Date: Sun, 18 Oct 2026 01:11:22 +0530 Subject: [PATCH 01/64] Share input limits between forms and server validation (R06 part 1) - New domain/shared/validation.ts: one LIMITS table plus boundedText, boundedItems/boundedList and a field-aware ValidationError, so each rejection can be shown beside the field that caused it - Over-long text is rejected with a message instead of silently cut - Profile: role, domain and about are required on the server as well as the form; interests limited to 20 items of 40 characters - Event create/update validation moves into the use cases: name 2-120, description 2000, slug 80, supported intents, up to 30 zones of 80 - Search query (300) and intro message (500) are checked server-side - Roster size and row limits read from the same table --- apps/web/app/actions/organizer.actions.ts | 14 +- apps/web/app/actions/participant.actions.ts | 9 +- .../src/application/use-cases/manage-event.ts | 35 ++++- .../application/use-cases/request-intro.ts | 4 +- .../use-cases/search-participants.ts | 4 +- .../domain/participant/participant.entity.ts | 31 ++--- apps/web/src/domain/shared/validation.ts | 77 +++++++++++ apps/web/src/lib/excel-importer.ts | 3 +- tests/unit/validation.test.ts | 123 ++++++++++++++++++ 9 files changed, 261 insertions(+), 39 deletions(-) create mode 100644 apps/web/src/domain/shared/validation.ts create mode 100644 tests/unit/validation.test.ts diff --git a/apps/web/app/actions/organizer.actions.ts b/apps/web/app/actions/organizer.actions.ts index cda4562..0d01269 100644 --- a/apps/web/app/actions/organizer.actions.ts +++ b/apps/web/app/actions/organizer.actions.ts @@ -3,7 +3,7 @@ import { redirect } from "next/navigation"; import { createEvent, importEventRoster, queueEventMatches, updateEvent } from "../../src/application/use-cases/manage-event"; import { getContainer } from "../../src/composition/container"; -import { Intent } from "../../src/domain/participant/intent"; +import { LIMITS } from "../../src/domain/shared/validation"; import { parseRosterWorkbook } from "../../src/lib/excel-importer"; import { getSession } from "../../lib/session"; @@ -26,7 +26,7 @@ export async function importEventRosterAction(organizationSlug: string, eventSlu if (!session) throw new Error("Sign in as an organizer first"); const file = formData.get("file"); if (!(file instanceof File) || !file.size) throw new Error("Choose an Excel roster file"); - if (file.size > 10 * 1024 * 1024) throw new Error("Roster files are limited to 10 MB"); + if (file.size > LIMITS.rosterBytes) throw new Error("Roster files are limited to 10 MB"); const container = getContainer(); const event = await container.events.findBySlug(organizationSlug, eventSlug); if (!event) throw new Error("Event not found"); @@ -43,16 +43,12 @@ export async function updateEventAction(organizationSlug: string, eventSlug: str if (!event) throw new Error("Event not found"); const status = String(formData.get("status") || event.status); if (!["draft", "open", "closed"].includes(status)) throw new Error("Choose a valid event status"); - const intents = String(formData.get("intents") || "NETWORKING").split(",").map((item) => item.trim().toUpperCase()).filter(Boolean); - const zones = String(formData.get("zones") || "").split(",").map((item) => item.trim()).filter(Boolean); - if (!intents.length || intents.some((intent) => !Object.values(Intent).includes(intent as Intent))) { - throw new Error("Use supported intent names separated by commas"); - } - if (zones.some((zone) => zone.length > 80)) throw new Error("Venue zone names must be 80 characters or fewer"); + const intents = String(formData.get("intents") ?? "").split(","); + const zones = String(formData.get("zones") ?? "").split(","); await updateEvent({ eventId: event.id, organizerId: session.attendeeId, - name: String(formData.get("name") || event.name), + name: String(formData.get("name") ?? ""), description: String(formData.get("description") || ""), status: status as "draft" | "open" | "closed", intents, diff --git a/apps/web/app/actions/participant.actions.ts b/apps/web/app/actions/participant.actions.ts index ce8d70d..b273810 100644 --- a/apps/web/app/actions/participant.actions.ts +++ b/apps/web/app/actions/participant.actions.ts @@ -3,6 +3,7 @@ import { upsertParticipant } from "../../src/application/use-cases/upsert-participant"; import { getContainer } from "../../src/composition/container"; import { Intent } from "../../src/domain/participant/intent"; +import { ValidationError } from "../../src/domain/shared/validation"; import { getSession } from "../../lib/session"; import { clearSession } from "../../lib/session"; import { redirect } from "next/navigation"; @@ -19,15 +20,15 @@ export async function saveParticipantProfile(eventSlug: string, formData: FormDa const intentValue = String(formData.get("intent") || Intent.NETWORKING); if (!event.intents.includes(intentValue) || !Object.values(Intent).includes(intentValue as Intent)) { - throw new Error("Choose an intent configured for this event"); + throw new ValidationError("intent", "Choose an intent configured for this event"); } const venueZone = nullable(formData.get("venueZone")); - if (venueZone && !event.zones.includes(venueZone)) throw new Error("Choose a venue zone configured for this event"); + if (venueZone && !event.zones.includes(venueZone)) throw new ValidationError("venueZone", "Choose a venue zone configured for this event"); const profile = await upsertParticipant({ eventId: event.id, attendeeId: session.attendeeId, intent: intentValue as Intent, - interests: String(formData.get("interests") || "").split(",").map((value) => value.trim()).filter(Boolean), + interests: String(formData.get("interests") || "").split(","), venueZone, aboutMe: nullable(formData.get("aboutMe")), designation: nullable(formData.get("designation")), @@ -53,6 +54,6 @@ function parseYears(value: FormDataEntryValue | null): number | null { const text = String(value ?? "").trim(); if (!text) return null; const years = Number(text); - if (!Number.isInteger(years)) throw new Error("Years of experience must be a whole number"); + if (!Number.isInteger(years)) throw new ValidationError("yearsOfExperience", "Years of experience must be a whole number"); return years; } diff --git a/apps/web/src/application/use-cases/manage-event.ts b/apps/web/src/application/use-cases/manage-event.ts index 722c5e4..81e1f13 100644 --- a/apps/web/src/application/use-cases/manage-event.ts +++ b/apps/web/src/application/use-cases/manage-event.ts @@ -1,15 +1,17 @@ import type { EventRepository, RosterAttendeeInput } from "../ports/event-repository"; import { slugify } from "../../domain/shared/value-objects"; +import { Intent } from "../../domain/participant/intent"; +import { boundedItems, boundedText, LIMITS, ValidationError } from "../../domain/shared/validation"; export async function createEvent(input: { organizationSlug: string; organizerId: string; name: string; slug?: string; description?: string }, events: EventRepository) { const organization = await events.findOrganization(input.organizationSlug); if (!organization) throw new Error("Organization not found"); if (!(await events.hasOrganizationAccess(input.organizationSlug, input.organizerId))) throw new Error("You are not an organizer for this organization"); - const name = input.name.trim(); - if (name.length < 2 || name.length > 120) throw new Error("Event name must be between 2 and 120 characters"); - const slug = slugify(input.slug || name); - if (!slug) throw new Error("Enter a valid event name or slug"); - return events.create({ organizationId: organization.id, organizerId: input.organizerId, name, slug, description: input.description?.trim() || null }); + const name = eventName(input.name)!; + const slug = slugify(boundedText(input.slug, "slug", "URL slug", LIMITS.eventSlug) || name).slice(0, LIMITS.eventSlug); + if (!slug) throw new ValidationError("slug", "Use letters or numbers in the event name or URL slug"); + const description = boundedText(input.description, "description", "Description", LIMITS.eventDescription); + return events.create({ organizationId: organization.id, organizerId: input.organizerId, name, slug, description }); } export async function updateEvent(input: { @@ -22,7 +24,15 @@ export async function updateEvent(input: { zones?: string[]; }, events: EventRepository) { if (!(await events.isOrganizer(input.eventId, input.organizerId))) throw new Error("You are not an organizer for this event"); - const updated = await events.update(input); + const updated = await events.update({ + ...input, + name: input.name === undefined ? undefined : eventName(input.name)!, + description: input.description === undefined ? undefined + : boundedText(input.description, "description", "Description", LIMITS.eventDescription), + intents: input.intents === undefined ? undefined : eventIntents(input.intents), + zones: input.zones === undefined ? undefined + : boundedItems(input.zones, "zones", "venue zones", { count: LIMITS.zoneCount, length: LIMITS.zoneLength }), + }); if (!updated) throw new Error("Event not found"); return updated; } @@ -39,3 +49,16 @@ export async function queueEventMatches(input: { eventId: string; organizerId: s for (const participantId of participants) await enqueue(input.eventId, participantId); return participants.length; } + +function eventName(value: string) { + return boundedText(value, "name", "Event name", LIMITS.eventName, { required: true, min: LIMITS.eventNameMin }); +} + +function eventIntents(values: string[]) { + const intents = boundedItems(values.map((value) => value.toUpperCase()), "intents", "intents", + { count: Object.keys(Intent).length, length: 40 }); + if (!intents.length || intents.some((intent) => !Object.values(Intent).includes(intent as Intent))) { + throw new ValidationError("intents", `Use supported intents separated by commas: ${Object.values(Intent).join(", ")}`); + } + return intents; +} diff --git a/apps/web/src/application/use-cases/request-intro.ts b/apps/web/src/application/use-cases/request-intro.ts index 16b6ee3..1dc00b1 100644 --- a/apps/web/src/application/use-cases/request-intro.ts +++ b/apps/web/src/application/use-cases/request-intro.ts @@ -1,6 +1,7 @@ import type { IntroRepository } from "../ports/intro-repository"; import type { ParticipantRepository } from "../ports/participant-repository"; import type { NotificationPort } from "../ports/notification"; +import { boundedText, LIMITS } from "../../domain/shared/validation"; export async function requestIntro( input: { eventId: string; requesterId: string; recipientId: string; message?: string | null; eventName?: string }, @@ -13,7 +14,8 @@ export async function requestIntro( dependencies.participants.findProfile(input.eventId, input.recipientId), ]); if (!requester || !recipient || !recipient.visible || !recipient.profileComplete) throw new Error("This participant is unavailable"); - const intro = await dependencies.intros.create(input); + const message = boundedText(input.message, "message", "Message", LIMITS.introMessage); + const intro = await dependencies.intros.create({ ...input, message }); if (recipient.email && dependencies.notifications) { await dependencies.notifications.introRequested({ recipientEmail: recipient.email, diff --git a/apps/web/src/application/use-cases/search-participants.ts b/apps/web/src/application/use-cases/search-participants.ts index 093df5b..bb6f1e2 100644 --- a/apps/web/src/application/use-cases/search-participants.ts +++ b/apps/web/src/application/use-cases/search-participants.ts @@ -1,5 +1,6 @@ import { MatchingPipeline } from "../../domain/matching/pipeline"; import type { RateLimiter } from "../ports/rate-limiter"; +import { boundedText, LIMITS } from "../../domain/shared/validation"; export async function searchParticipants( input: { eventId: string; participantId: string; query: string; limit?: number }, @@ -8,5 +9,6 @@ export async function searchParticipants( if (dependencies.limiter && !(await dependencies.limiter.consume(`search:${input.participantId}`, 30, 60))) { throw new Error("Too many searches. Wait a moment and try again."); } - return dependencies.pipeline.run({ ...input, mode: "search" }); + const query = boundedText(input.query, "query", "Search", LIMITS.searchQuery, { required: true })!; + return dependencies.pipeline.run({ ...input, query, mode: "search" }); } diff --git a/apps/web/src/domain/participant/participant.entity.ts b/apps/web/src/domain/participant/participant.entity.ts index 18dfa29..28a8596 100644 --- a/apps/web/src/domain/participant/participant.entity.ts +++ b/apps/web/src/domain/participant/participant.entity.ts @@ -1,4 +1,5 @@ import { Intent } from "./intent"; +import { boundedItems, boundedText, LIMITS, ValidationError } from "../shared/validation"; export interface ParticipantProfile { eventId: string; @@ -51,25 +52,21 @@ export function profileText(profile: ParticipantProfile): string { } export function validateProfile(input: ParticipantProfileInput): ParticipantProfileInput { - if (!input.eventId || !input.attendeeId) throw new Error("Participant and event are required"); - if (!Object.values(Intent).includes(input.intent)) throw new Error("Choose a valid networking intent"); - if (!Array.isArray(input.interests)) throw new Error("Interests must be a list"); - if (input.yearsOfExperience != null && (!Number.isInteger(input.yearsOfExperience) || input.yearsOfExperience < 0 || input.yearsOfExperience > 80)) { - throw new Error("Years of experience must be between 0 and 80"); + if (!input.eventId || !input.attendeeId) throw new ValidationError(null, "Participant and event are required"); + if (!Object.values(Intent).includes(input.intent)) throw new ValidationError("intent", "Choose a valid networking intent"); + if (!Array.isArray(input.interests)) throw new ValidationError("interests", "Interests must be a list"); + const years = input.yearsOfExperience; + if (years != null && (!Number.isInteger(years) || years < 0 || years > LIMITS.yearsOfExperience)) { + throw new ValidationError("yearsOfExperience", `Years of experience must be a whole number from 0 to ${LIMITS.yearsOfExperience}`); } return { ...input, - designation: clean(input.designation), - domain: clean(input.domain), - aboutMe: clean(input.aboutMe), - selfDescription: clean(input.selfDescription), - mostImpressiveBuild: clean(input.mostImpressiveBuild), - venueZone: clean(input.venueZone), - interests: [...new Set(input.interests.map((interest) => interest.trim()).filter(Boolean))].slice(0, 20), + designation: boundedText(input.designation, "designation", "Role or designation", LIMITS.designation, { required: true }), + domain: boundedText(input.domain, "domain", "Professional domain", LIMITS.domain, { required: true }), + aboutMe: boundedText(input.aboutMe, "aboutMe", "About you", LIMITS.aboutMe, { required: true }), + selfDescription: boundedText(input.selfDescription, "selfDescription", "Current focus", LIMITS.selfDescription), + mostImpressiveBuild: boundedText(input.mostImpressiveBuild, "mostImpressiveBuild", "Most impressive build", LIMITS.mostImpressiveBuild), + venueZone: boundedText(input.venueZone, "venueZone", "Venue zone", LIMITS.zoneLength), + interests: boundedItems(input.interests, "interests", "interests", { count: LIMITS.interestCount, length: LIMITS.interestLength }), }; } - -function clean(value: string | null): string | null { - const trimmed = value?.trim(); - return trimmed ? trimmed.slice(0, 2000) : null; -} diff --git a/apps/web/src/domain/shared/validation.ts b/apps/web/src/domain/shared/validation.ts new file mode 100644 index 0000000..2dc78a5 --- /dev/null +++ b/apps/web/src/domain/shared/validation.ts @@ -0,0 +1,77 @@ +/** + * Input limits shared by the forms (maxLength, min/max) and the server-side + * checks, so the browser and the server always agree on what is accepted. + */ +export const LIMITS = { + designation: 120, + domain: 120, + aboutMe: 1000, + selfDescription: 500, + mostImpressiveBuild: 1000, + yearsOfExperience: 80, + interestCount: 20, + interestLength: 40, + searchQuery: 300, + introMessage: 500, + eventNameMin: 2, + eventName: 120, + eventDescription: 2000, + eventSlug: 80, + zoneCount: 30, + zoneLength: 80, + rosterBytes: 10 * 1024 * 1024, + rosterRows: 10_000, +} as const; + +/** A rejected input. `field` names the form field so the UI can show the message beside it. */ +export class ValidationError extends Error { + constructor(readonly field: string | null, message: string) { + super(message); + this.name = "ValidationError"; + } +} + +/** Trims text; empty becomes null. Over-long text is rejected, never silently cut. */ +export function boundedText( + value: string | null | undefined, + field: string, + label: string, + max: number, + options: { required?: boolean; min?: number } = {} +): string | null { + const text = value?.trim() ?? ""; + if (!text) { + if (options.required) throw new ValidationError(field, `${label} is required`); + return null; + } + if (options.min && text.length < options.min) { + throw new ValidationError(field, `${label} must be at least ${options.min} characters`); + } + if (text.length > max) throw new ValidationError(field, `${label} must be ${max} characters or fewer`); + return text; +} + +/** Trims items, dropping blanks and duplicates, within count and per-item length limits. */ +export function boundedItems( + values: readonly string[], + field: string, + label: string, + limits: { count: number; length: number } +): string[] { + const items = [...new Set(values.map((item) => item.trim()).filter(Boolean))]; + if (items.length > limits.count) throw new ValidationError(field, `Use at most ${limits.count} ${label}`); + if (items.some((item) => item.length > limits.length)) { + throw new ValidationError(field, `Each of the ${label} must be ${limits.length} characters or fewer`); + } + return items; +} + +/** Same as boundedItems, for a comma-separated form value. */ +export function boundedList( + value: string | null | undefined, + field: string, + label: string, + limits: { count: number; length: number } +): string[] { + return boundedItems(String(value ?? "").split(","), field, label, limits); +} diff --git a/apps/web/src/lib/excel-importer.ts b/apps/web/src/lib/excel-importer.ts index c94fcb7..c672e75 100644 --- a/apps/web/src/lib/excel-importer.ts +++ b/apps/web/src/lib/excel-importer.ts @@ -1,6 +1,7 @@ import * as XLSX from "xlsx"; import { attendees } from "@match-maker/db"; import type { RosterAttendeeInput } from "../application/ports/event-repository"; +import { LIMITS } from "../domain/shared/validation"; const COLUMN_NAMES = { name: ["name", "full name"], @@ -20,7 +21,7 @@ export function parseRosterWorkbook(bytes: ArrayBuffer): RosterAttendeeInput[] { if (!firstSheet) throw new Error("The workbook has no sheets"); const sheet = workbook.Sheets[firstSheet]; const rawRows = XLSX.utils.sheet_to_json>(sheet, { defval: "" }); - if (rawRows.length > 10_000) throw new Error("Roster files are limited to 10,000 rows"); + if (rawRows.length > LIMITS.rosterRows) throw new Error("Roster files are limited to 10,000 rows"); const seenEmails = new Set(); const seenPhones = new Set(); diff --git a/tests/unit/validation.test.ts b/tests/unit/validation.test.ts new file mode 100644 index 0000000..d5b365b --- /dev/null +++ b/tests/unit/validation.test.ts @@ -0,0 +1,123 @@ +import { describe, expect, it, vi } from "vitest"; +import { boundedList, boundedText, LIMITS, ValidationError } from "@/src/domain/shared/validation"; +import { validateProfile, type ParticipantProfileInput } from "@/src/domain/participant/participant.entity"; +import { Intent } from "@/src/domain/participant/intent"; +import { createEvent, updateEvent } from "@/src/application/use-cases/manage-event"; +import { searchParticipants } from "@/src/application/use-cases/search-participants"; +import type { EventRepository } from "@/src/application/ports/event-repository"; +import type { MatchingPipeline } from "@/src/domain/matching/pipeline"; + +/** Runs `action` and returns the ValidationError it throws. */ +async function rejection(action: () => unknown): Promise { + try { + await action(); + } catch (error) { + expect(error).toBeInstanceOf(ValidationError); + return error as ValidationError; + } + throw new Error("expected a ValidationError"); +} + +describe("boundedText", () => { + it("trims text and turns blanks into null", () => { + expect(boundedText(" hello ", "f", "Field", 10)).toBe("hello"); + expect(boundedText(" ", "f", "Field", 10)).toBeNull(); + expect(boundedText(null, "f", "Field", 10)).toBeNull(); + }); + + it("rejects over-long text instead of cutting it", async () => { + const error = await rejection(() => boundedText("x".repeat(11), "about", "About", 10)); + expect(error).toMatchObject({ field: "about", message: "About must be 10 characters or fewer" }); + }); + + it("enforces required and minimum length", async () => { + expect((await rejection(() => boundedText("", "name", "Name", 10, { required: true }))).message).toBe("Name is required"); + expect((await rejection(() => boundedText("a", "name", "Name", 10, { min: 2 }))).field).toBe("name"); + }); +}); + +describe("boundedList", () => { + it("drops blanks and duplicates", () => { + expect(boundedList(" a, b ,, a ", "zones", "zones", { count: 5, length: 5 })).toEqual(["a", "b"]); + }); + + it("rejects too many or too long items", async () => { + expect((await rejection(() => boundedList("a,b,c", "zones", "zones", { count: 2, length: 5 }))).field).toBe("zones"); + expect((await rejection(() => boundedList("abcdef", "zones", "zones", { count: 2, length: 5 }))).field).toBe("zones"); + }); +}); + +describe("validateProfile", () => { + const input = (overrides: Partial = {}): ParticipantProfileInput => ({ + eventId: "event", attendeeId: "attendee", designation: "Engineer", domain: "AI", aboutMe: "I build things", + selfDescription: null, yearsOfExperience: 3, mostImpressiveBuild: null, intent: Intent.NETWORKING, + interests: ["rag", " rag ", ""], venueZone: null, ...overrides, + }); + + it("accepts a filled profile and cleans the interests", () => { + expect(validateProfile(input()).interests).toEqual(["rag"]); + }); + + it.each([ + ["designation", { designation: " " }], + ["aboutMe", { aboutMe: "x".repeat(LIMITS.aboutMe + 1) }], + ["yearsOfExperience", { yearsOfExperience: 81 }], + ["interests", { interests: Array.from({ length: LIMITS.interestCount + 1 }, (_, i) => `topic ${i}`) }], + ] as const)("names the %s field when it is invalid", async (field, overrides) => { + expect((await rejection(() => validateProfile(input(overrides)))).field).toBe(field); + }); +}); + +describe("event settings", () => { + const events = { + findOrganization: vi.fn(async () => ({ id: "org" })), + hasOrganizationAccess: vi.fn(async () => true), + isOrganizer: vi.fn(async () => true), + create: vi.fn(async (record) => record), + update: vi.fn(async (record) => record), + } as unknown as EventRepository; + const create = (overrides: Record) => + createEvent({ organizationSlug: "org", organizerId: "me", name: "AI Meetup", ...overrides }, events); + const update = (overrides: Record) => + updateEvent({ eventId: "event", organizerId: "me", ...overrides }, events); + + it("builds the slug from the name and clears a blank description", async () => { + await expect(create({ description: " " })).resolves.toMatchObject({ slug: "ai-meetup", description: null }); + }); + + it.each([ + ["name", { name: "A" }], + ["slug", { slug: "!!!", name: "??" }], + ["description", { description: "x".repeat(LIMITS.eventDescription + 1) }], + ] as const)("rejects an invalid %s on create", async (field, overrides) => { + expect((await rejection(() => create(overrides))).field).toBe(field); + }); + + it("normalises intents and zones on update", async () => { + await expect(update({ intents: ["networking", " hiring "], zones: ["Hall", "", "Hall"] })) + .resolves.toMatchObject({ intents: ["NETWORKING", "HIRING"], zones: ["Hall"] }); + }); + + it.each([ + ["intents", { intents: ["PARTYING"] }], + ["intents", { intents: [""] }], + ["zones", { zones: Array.from({ length: LIMITS.zoneCount + 1 }, (_, i) => `Zone ${i}`) }], + ] as const)("rejects invalid %s on update", async (field, overrides) => { + expect((await rejection(() => update(overrides))).field).toBe(field); + }); +}); + +describe("search query", () => { + const pipeline = { run: vi.fn(async () => []) } as unknown as MatchingPipeline; + const search = (query: string) => searchParticipants({ eventId: "event", participantId: "me", query }, { pipeline }); + + it("passes the trimmed query to the pipeline", async () => { + await search(" climate AI "); + expect(pipeline.run).toHaveBeenCalledWith(expect.objectContaining({ query: "climate AI", mode: "search" })); + }); + + it("rejects blank and over-long queries", async () => { + expect((await rejection(() => search(" "))).field).toBe("query"); + expect((await rejection(() => search("x".repeat(LIMITS.searchQuery + 1)))).field).toBe("query"); + }); +}); From d5711e8d85efc24456eb6611053bd3a2b412c5e7 Mon Sep 17 00:00:00 2001 From: SURYANSH-RAI Date: Sun, 18 Oct 2026 01:15:13 +0530 Subject: [PATCH 02/64] Keep entered data and show errors on participant forms (R06 part 2) Server actions used to throw, which showed a crash page and lost what the participant typed. They now return a form state instead. - lib/form-state.ts: FormState plus runFormAction, which passes redirects through, puts ValidationErrors on their field, returns the submitted text so fields refill, and hides database errors - components/ui/form.tsx: labelled TextField/SelectField with aria-invalid and aria-describedby, SubmitButton disabled while pending, FormAlert (role=alert), and ActionForm for one-button forms - Profile form becomes a client component using the shared limits - Request intro, accept/decline, zone sharing and refresh show their own errors inline and cannot be double-submitted - Search returns its error (production hides thrown messages), has a real label, and no longer says "no matches" before a search runs - Status notices after saving a profile, queuing a refresh, sending a request, and sharing a zone --- .../e/[eventSlug]/connections/page.tsx | 25 +++-- .../e/[eventSlug]/matches/page.tsx | 18 ++-- .../e/[eventSlug]/profile/page.tsx | 36 ++----- .../e/[eventSlug]/search/SearchForm.tsx | 29 +++--- apps/web/app/actions/intro.actions.ts | 23 ++++- apps/web/app/actions/match.actions.ts | 15 ++- apps/web/app/actions/participant.actions.ts | 16 ++- .../components/participant/ProfileForm.tsx | 51 ++++++++++ apps/web/components/ui/form.tsx | 97 +++++++++++++++++++ apps/web/lib/form-state.ts | 54 +++++++++++ tests/unit/form-state.test.ts | 51 ++++++++++ 11 files changed, 347 insertions(+), 68 deletions(-) create mode 100644 apps/web/components/participant/ProfileForm.tsx create mode 100644 apps/web/components/ui/form.tsx create mode 100644 apps/web/lib/form-state.ts create mode 100644 tests/unit/form-state.test.ts diff --git a/apps/web/app/(participant)/e/[eventSlug]/connections/page.tsx b/apps/web/app/(participant)/e/[eventSlug]/connections/page.tsx index 65aab5a..859a57c 100644 --- a/apps/web/app/(participant)/e/[eventSlug]/connections/page.tsx +++ b/apps/web/app/(participant)/e/[eventSlug]/connections/page.tsx @@ -1,15 +1,22 @@ import Link from "next/link"; import { getParticipantConnections, respondToParticipantIntro, shareVenueZoneAction } from "../../../../actions/intro.actions"; import { requireParticipantEvent } from "@/src/lib/auth"; +import { ActionForm } from "@/components/ui/form"; -export default async function ConnectionsPage({ params }: { params: Promise<{ eventSlug: string }> }) { +export default async function ConnectionsPage({ params, searchParams }: { + params: Promise<{ eventSlug: string }>; + searchParams: Promise<{ requested?: string; location?: string }>; +}) { const { eventSlug } = await params; + const notice = await searchParams; const { event } = await requireParticipantEvent(eventSlug, `/e/${eventSlug}/connections`); const connections = await getParticipantConnections(eventSlug); return
INTRODUCTIONS · {event.name}

Connections

+ {notice.requested &&

Intro request sent. You will see their contact details once they accept.

} + {notice.location &&

Your venue zone is shared with your accepted connections.

} {!connections.length ?

Your intro requests will show up here. Find someone you would like to meet from your matches or search.

:
{connections.map((connection) =>
@@ -22,15 +29,17 @@ export default async function ConnectionsPage({ params }: { params: Promise<{ ev {connection.contact.email && } {connection.contact.phone && } {connection.contact.venueZone &&
At the venue: {connection.contact.venueZone}
} - {event.zones.length > 0 &&
- - -
} + {event.zones.length > 0 && + + + }
}
{connection.incoming && connection.status === "pending" &&
-
-
+ +
} )} } @@ -40,5 +49,3 @@ export default async function ConnectionsPage({ params }: { params: Promise<{ ev const card = { display: "flex", flexWrap: "wrap", alignItems: "center", gap: 16, padding: 20, borderRadius: 12, background: "#151519", border: "1px solid #333" } as const; const muted = { color: "#a1a1aa" } as const; const contact = { background: "#111", border: "1px solid #3f3f46", borderRadius: 8, padding: 14, lineHeight: 1.8 } as const; -const button = { border: 0, borderRadius: 8, padding: "11px 16px", background: "#f59e0b", color: "#0a0a0e", fontWeight: 700, cursor: "pointer" } as const; -const secondary = { border: "1px solid #52525b", borderRadius: 8, padding: "10px 14px", background: "transparent", color: "#f4f4f5", cursor: "pointer" } as const; diff --git a/apps/web/app/(participant)/e/[eventSlug]/matches/page.tsx b/apps/web/app/(participant)/e/[eventSlug]/matches/page.tsx index f78467a..c52c374 100644 --- a/apps/web/app/(participant)/e/[eventSlug]/matches/page.tsx +++ b/apps/web/app/(participant)/e/[eventSlug]/matches/page.tsx @@ -4,9 +4,14 @@ import { getMyMatches } from "@/src/application/use-cases/get-my-matches"; import { requireParticipantEvent } from "@/src/lib/auth"; import { refreshParticipantMatches } from "../../../../actions/match.actions"; import { requestParticipantIntro } from "../../../../actions/intro.actions"; +import { ActionForm } from "@/components/ui/form"; -export default async function MatchesPage({ params }: { params: Promise<{ eventSlug: string }> }) { +export default async function MatchesPage({ params, searchParams }: { + params: Promise<{ eventSlug: string }>; + searchParams: Promise<{ saved?: string; queued?: string }>; +}) { const { eventSlug } = await params; + const notice = await searchParams; const { session, event, container } = await requireParticipantEvent(eventSlug, `/e/${eventSlug}/matches`); const viewer = await container.participants.findProfile(event.id, session.attendeeId); if (!viewer?.profileComplete) redirect(`/e/${eventSlug}/profile`); @@ -17,10 +22,12 @@ export default async function MatchesPage({ params }: { params: Promise<{ eventS YOUR EVENT MATCHES

People worth meeting.

Matches are ranked for your profile. Contact details stay private until you both accept an introduction.

+ {notice.saved &&

Profile saved. Your matches will update in the background.

} + {notice.queued &&

Refresh queued. Reload this page in a minute.

} {!matches.length ?

Your first matches are on the way.

We are embedding your profile and ranking attendees in the background.

-
+
:
{matches.map((match, index) =>
#{index + 1}
@@ -33,10 +40,8 @@ export default async function MatchesPage({ params }: { params: Promise<{ eventS

{match.mutualInterest ? "Your event goals align" : "Suggested for your profile"}

{Math.round(match.score)}%
-
- - -
+
; @@ -51,4 +56,3 @@ const score = { color: "#f59e0b", fontWeight: 800, fontSize: 20 } as const; const muted = { color: "#a1a1aa", lineHeight: 1.5 } as const; const reason = { color: "#fbbf24", lineHeight: 1.5 } as const; const empty = { marginTop: 28, padding: 24, background: "#151519", borderRadius: 12 } as const; -const button = { border: 0, borderRadius: 8, padding: "11px 15px", background: "#f59e0b", color: "#0a0a0e", fontWeight: 700, cursor: "pointer" } as const; diff --git a/apps/web/app/(participant)/e/[eventSlug]/profile/page.tsx b/apps/web/app/(participant)/e/[eventSlug]/profile/page.tsx index ff8214d..7e2497f 100644 --- a/apps/web/app/(participant)/e/[eventSlug]/profile/page.tsx +++ b/apps/web/app/(participant)/e/[eventSlug]/profile/page.tsx @@ -1,7 +1,8 @@ import Link from "next/link"; -import { notFound, redirect } from "next/navigation"; +import { notFound } from "next/navigation"; import { saveParticipantProfile } from "../../../../actions/participant.actions"; import { requireParticipantEvent } from "@/src/lib/auth"; +import ProfileForm from "@/components/participant/ProfileForm"; export default async function ProfilePage({ params }: { params: Promise<{ eventSlug: string }> }) { const { eventSlug } = await params; @@ -17,36 +18,13 @@ export default async function ProfilePage({ params }: { params: Promise<{ eventS PARTICIPANT PROFILE

Make your next introduction count.

Confirm the profile other attendees will see, then set what you want from this event.

-
{ - "use server"; - await saveParticipantProfile(eventSlug, formData); - redirect(`/e/${eventSlug}/matches`); - }} style={form}> - - - -