@c1m-public/dash-site-kit 0.14.1 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -267,7 +267,15 @@ before relying on it.
267
267
 
268
268
  ## Peer dependencies
269
269
 
270
- `@c1m-public/channel-client` (>=0.31.0), `next` 16, `react` 19.
270
+ `@c1m-public/channel-client` (>=0.35.0), `next` 16, `react` 19.
271
+
272
+ The moving quote form, validation, server data layer and customer lead portal
273
+ are shared across Dash sites. A site supplies its own channel client and
274
+ server actions, then renders `DashMovingQuoteForm` and `DashLeadPortalPage` from
275
+ `/ui`. Quote submission uses one attempt ID as an idempotency key; address
276
+ lookup and distance calls go through the site's server route so the channel
277
+ credential stays server-side. Other industries can add a typed intake model
278
+ without changing the broker's delivery and portal infrastructure.
271
279
 
272
280
  ## Admin host links
273
281
 
package/dist/index.d.ts CHANGED
@@ -19,6 +19,8 @@ export { FIRST_TOUCH_COOKIE, FIRST_TOUCH_MAX_AGE_SECONDS, decodeFirstTouch, enco
19
19
  export type * from "./models/directory.js";
20
20
  export type * from "./models/leads.js";
21
21
  export type * from "./models/lead-portal.js";
22
+ export type * from "./models/moving-quotes.js";
23
+ export { validateMovingQuoteForm } from "./validation/moving-quotes.js";
22
24
  export type * from "./models/plans.js";
23
25
  export type * from "./models/profile.js";
24
26
  export type { BootstrapProvider } from "./ports/bootstrap.js";
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export { GATE_EXEMPT_PATHS, gateAction } from "./models/bootstrap.js";
2
2
  export { cookieNotice, privacyNotice, termsOfUse } from "./models/legal.js";
3
3
  export { FIRST_TOUCH_COOKIE, FIRST_TOUCH_MAX_AGE_SECONDS, decodeFirstTouch, encodeFirstTouch, firstTouchFrom } from "./models/attribution.js";
4
+ export { validateMovingQuoteForm } from "./validation/moving-quotes.js";
4
5
  export { selectDirectoryRegion, validateDirectoryKey, validateRegionFilter, } from "./validation/directory.js";
5
6
  export { LEAD_LIMITS, validateLeadForm } from "./validation/leads.js";
6
7
  export { formatMoney } from "./format.js";
@@ -0,0 +1,14 @@
1
+ import type { DashMovingQuoteInput, DashMovingQuoteReceipt, DashMovingAddressList, DashMovingAddress, DashMovingDistance } from "@c1m-public/channel-client";
2
+ export type MovingQuoteInput = DashMovingQuoteInput;
3
+ export type MovingQuoteReceipt = DashMovingQuoteReceipt;
4
+ export type MovingAddressList = DashMovingAddressList;
5
+ export type MovingAddressResult = DashMovingAddress;
6
+ export type MovingDistanceResult = DashMovingDistance;
7
+ export type MovingQuoteOutcome = {
8
+ state: "created";
9
+ receipt: MovingQuoteReceipt;
10
+ } | {
11
+ state: "invalid";
12
+ } | {
13
+ state: "error";
14
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -3,6 +3,7 @@ import type { DashBootstrap } from "../models/bootstrap.js";
3
3
  import type { DirectoryEntry, DirectoryFilter, DirectoryProfileResult, DirectoryRegion } from "../models/directory.js";
4
4
  import type { LeadInput, LeadOutcome } from "../models/leads.js";
5
5
  import type { RequestLinkOutcome, ViewOutcome } from "../models/lead-portal.js";
6
+ import type { MovingQuoteInput, MovingQuoteOutcome, MovingAddressList, MovingAddressResult, MovingDistanceResult } from "../models/moving-quotes.js";
6
7
  import type { PlanCatalog } from "../models/plans.js";
7
8
  import type { DashProfile } from "../models/profile.js";
8
9
  import type { DashWaitlistForm, DashWaitlistReceipt, DashWaitlistSubmission } from "../models/waitlist.js";
@@ -33,6 +34,10 @@ export interface DashDataLayer {
33
34
  submitLead(input: LeadInput, attemptId: string): Promise<LeadOutcome>;
34
35
  requestPortalLink(email: string): Promise<RequestLinkOutcome>;
35
36
  viewPortal(token: string): Promise<ViewOutcome>;
37
+ submitMovingQuote(input: MovingQuoteInput, attemptId: string): Promise<MovingQuoteOutcome>;
38
+ lookupMovingAddresses(query: string): Promise<MovingAddressList>;
39
+ resolveMovingAddress(udprn: number): Promise<MovingAddressResult>;
40
+ getMovingDistance(fromLat: number, fromLng: number, toLat: number, toLng: number): Promise<MovingDistanceResult>;
36
41
  loadDashWaitlistForm(): Promise<DashWaitlistForm>;
37
42
  submitDashWaitlist(input: DashWaitlistSubmission, attemptId: string): Promise<DashWaitlistReceipt>;
38
43
  verifyWaitlistEmail(token: string): Promise<boolean>;
@@ -1,5 +1,6 @@
1
1
  import "server-only";
2
2
  import { cache } from "react";
3
+ import { submitMovingQuote, lookupMovingAddresses, resolveMovingAddress, getMovingDistance } from "./providers/moving-quotes.js";
3
4
  import { selectDirectoryRegion, validateDirectoryKey } from "../validation/directory.js";
4
5
  import { createC1MBootstrapProvider } from "./providers/bootstrap.js";
5
6
  import { createC1MDirectoryProvider } from "./providers/directory.js";
@@ -51,6 +52,10 @@ export function createDashDataLayer(options) {
51
52
  submitLead: (input, attemptId) => leadsProvider.create(input, attemptId),
52
53
  requestPortalLink: (email) => leadPortalProvider.requestLink(email),
53
54
  viewPortal: (token) => leadPortalProvider.view(token),
55
+ submitMovingQuote,
56
+ lookupMovingAddresses,
57
+ resolveMovingAddress,
58
+ getMovingDistance,
54
59
  loadDashWaitlistForm: cache(() => waitlistProvider.loadForm()),
55
60
  submitDashWaitlist: (input, attemptId) => waitlistProvider.submit(input, attemptId),
56
61
  verifyWaitlistEmail: (token) => waitlistProvider.verify(token),
@@ -7,6 +7,8 @@ export interface ChannelEnvironment {
7
7
  apiUrl?: string;
8
8
  }
9
9
  type ChannelProcessEnvironment = Readonly<Record<string, string | undefined>>;
10
+ /** Test seam: forget which legacy names have already warned. */
11
+ export declare function resetLegacyEnvWarningsForTests(): void;
10
12
  export declare function resolveChannelEnvironment(environment?: ChannelProcessEnvironment): ChannelEnvironment;
11
13
  /**
12
14
  * The signing secret for the site's channel webhook receiver. Preferred name
package/dist/next/env.js CHANGED
@@ -1,6 +1,29 @@
1
1
  import "server-only";
2
2
  import { ChannelConfigurationError } from "@c1m-public/channel-client";
3
3
  export { ChannelConfigurationError };
4
+ /**
5
+ * Legacy `C1M_*` names are still read, but only until the dash sites' Vercel
6
+ * env is renamed; each one in use warns once per process so the build log
7
+ * names what to rename.
8
+ */
9
+ const LEGACY_ENV_NAMES = {
10
+ C1M_CHANNEL_TOKEN: "SAASDASH_CHANNEL_TOKEN",
11
+ C1M_API_URL: "SAASDASH_API_URL",
12
+ C1M_CHANNEL_WEBHOOK_SECRET: "SAASDASH_CHANNEL_WEBHOOK_SECRET",
13
+ };
14
+ const warnedLegacyNames = new Set();
15
+ function readLegacy(environment, name) {
16
+ const value = environment[name]?.trim();
17
+ if (value && !warnedLegacyNames.has(name)) {
18
+ warnedLegacyNames.add(name);
19
+ console.warn(`[dash-site-kit] ${name} is deprecated and will stop being read in a future release; rename it to ${LEGACY_ENV_NAMES[name]}.`);
20
+ }
21
+ return value;
22
+ }
23
+ /** Test seam: forget which legacy names have already warned. */
24
+ export function resetLegacyEnvWarningsForTests() {
25
+ warnedLegacyNames.clear();
26
+ }
4
27
  export function resolveChannelEnvironment(environment = process.env) {
5
28
  if (environment.NEXT_PUBLIC_SAASDASH_CHANNEL_TOKEN || environment.NEXT_PUBLIC_C1M_CHANNEL_TOKEN) {
6
29
  throw new ChannelConfigurationError("SAASDASH_CHANNEL_TOKEN must not use a NEXT_PUBLIC_* variable");
@@ -9,7 +32,7 @@ export function resolveChannelEnvironment(environment = process.env) {
9
32
  throw new ChannelConfigurationError("SAASDASH_API_URL must not use a NEXT_PUBLIC_* variable");
10
33
  }
11
34
  const preferredToken = environment.SAASDASH_CHANNEL_TOKEN?.trim();
12
- const legacyToken = environment.C1M_CHANNEL_TOKEN?.trim();
35
+ const legacyToken = readLegacy(environment, "C1M_CHANNEL_TOKEN");
13
36
  if (preferredToken && legacyToken && preferredToken !== legacyToken) {
14
37
  throw new ChannelConfigurationError("SAASDASH_CHANNEL_TOKEN and legacy C1M_CHANNEL_TOKEN must match during migration");
15
38
  }
@@ -22,7 +45,7 @@ export function resolveChannelEnvironment(environment = process.env) {
22
45
  // The token is the only REQUIRED setting — the client knows the managed API
23
46
  // endpoint. The override exists for local smoke tests and self-hosting.
24
47
  const preferredApiUrl = environment.SAASDASH_API_URL?.trim();
25
- const legacyApiUrl = environment.C1M_API_URL?.trim();
48
+ const legacyApiUrl = readLegacy(environment, "C1M_API_URL");
26
49
  if (preferredApiUrl && legacyApiUrl && preferredApiUrl !== legacyApiUrl) {
27
50
  throw new ChannelConfigurationError("SAASDASH_API_URL and legacy C1M_API_URL must match during migration");
28
51
  }
@@ -45,7 +68,7 @@ export function resolveChannelWebhookSecret(environment = process.env) {
45
68
  throw new ChannelConfigurationError("SAASDASH_CHANNEL_WEBHOOK_SECRET must not use a NEXT_PUBLIC_* variable");
46
69
  }
47
70
  const preferred = environment.SAASDASH_CHANNEL_WEBHOOK_SECRET?.trim();
48
- const legacy = environment.C1M_CHANNEL_WEBHOOK_SECRET?.trim();
71
+ const legacy = readLegacy(environment, "C1M_CHANNEL_WEBHOOK_SECRET");
49
72
  if (preferred && legacy && preferred !== legacy) {
50
73
  throw new ChannelConfigurationError("SAASDASH_CHANNEL_WEBHOOK_SECRET and legacy C1M_CHANNEL_WEBHOOK_SECRET must match during migration");
51
74
  }
@@ -0,0 +1,6 @@
1
+ import "server-only";
2
+ import type { MovingQuoteInput, MovingQuoteOutcome, MovingAddressList, MovingAddressResult, MovingDistanceResult } from "../../models/moving-quotes.js";
3
+ export declare function submitMovingQuote(input: MovingQuoteInput, attemptId: string): Promise<MovingQuoteOutcome>;
4
+ export declare function lookupMovingAddresses(query: string): Promise<MovingAddressList>;
5
+ export declare function resolveMovingAddress(udprn: number): Promise<MovingAddressResult>;
6
+ export declare function getMovingDistance(fromLat: number, fromLng: number, toLat: number, toLng: number): Promise<MovingDistanceResult>;
@@ -0,0 +1,23 @@
1
+ import "server-only";
2
+ import { isChannelAPIError } from "@c1m-public/channel-client";
3
+ import { getVisitorDashChannelClient } from "../client.js";
4
+ export async function submitMovingQuote(input, attemptId) {
5
+ try {
6
+ const client = await getVisitorDashChannelClient();
7
+ return { state: "created", receipt: await client.dash.movingQuotes.create(input, { idempotencyKey: attemptId }) };
8
+ }
9
+ catch (error) {
10
+ if (isChannelAPIError(error) && error.status >= 400 && error.status < 500)
11
+ return { state: "invalid" };
12
+ return { state: "error" };
13
+ }
14
+ }
15
+ export async function lookupMovingAddresses(query) {
16
+ return (await getVisitorDashChannelClient()).dash.movingAddresses.lookup(query);
17
+ }
18
+ export async function resolveMovingAddress(udprn) {
19
+ return (await getVisitorDashChannelClient()).dash.movingAddresses.resolve(udprn);
20
+ }
21
+ export async function getMovingDistance(fromLat, fromLng, toLat, toLng) {
22
+ return (await getVisitorDashChannelClient()).dash.movingAddresses.distance(fromLat, fromLng, toLat, toLng);
23
+ }
@@ -0,0 +1,6 @@
1
+ export type PortalFormState = {
2
+ status: "idle" | "requested" | "invalid" | "error";
3
+ };
4
+ export declare function DashPortalLinkForm({ action }: {
5
+ action: (state: PortalFormState, form: FormData) => Promise<PortalFormState>;
6
+ }): import("react").JSX.Element;
@@ -0,0 +1,7 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useActionState } from "react";
4
+ export function DashPortalLinkForm({ action }) {
5
+ const [state, formAction, pending] = useActionState(action, { status: "idle" });
6
+ return _jsxs("form", { action: formAction, className: "rounded-3xl border border-border bg-white p-6 shadow-xl shadow-slate-900/5 sm:p-9", children: [_jsx("label", { className: "block text-sm font-semibold text-ink", htmlFor: "portal-email", children: "Your email address" }), _jsx("input", { className: "mt-3 min-h-12 w-full rounded-xl border border-border px-4", id: "portal-email", name: "email", type: "email", autoComplete: "email", maxLength: 254, required: true }), _jsx("button", { className: "mt-5 min-h-12 rounded-full bg-accent px-6 font-semibold text-accent-foreground disabled:opacity-50", disabled: pending, children: pending ? "Sending…" : "Email my link" }), state.status === "requested" && _jsx("p", { className: "mt-4 text-sm text-ink", role: "status", children: "If we found requests for that address, a secure link is on its way." }), state.status === "invalid" && _jsx("p", { className: "mt-4 text-sm text-amber-950", role: "alert", children: "Enter a valid email address." }), state.status === "error" && _jsx("p", { className: "mt-4 text-sm text-amber-950", role: "alert", children: "We could not send a link right now. Try again shortly." })] });
7
+ }
@@ -0,0 +1,6 @@
1
+ import type { ViewOutcome } from "../models/lead-portal.js";
2
+ import { type PortalFormState } from "./lead-portal-form.js";
3
+ export declare function DashLeadPortalPage({ outcome, action }: {
4
+ outcome?: ViewOutcome;
5
+ action: (state: PortalFormState, form: FormData) => Promise<PortalFormState>;
6
+ }): import("react").JSX.Element;
@@ -0,0 +1,6 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { DashPortalLinkForm } from "./lead-portal-form.js";
3
+ const labels = { received: "Received", matching: "Finding providers", matched: "Providers matched", closed: "Closed" };
4
+ export function DashLeadPortalPage({ outcome, action }) {
5
+ return _jsxs("main", { className: "mx-auto max-w-4xl px-5 py-14 sm:py-20", children: [_jsx("p", { className: "text-sm font-semibold uppercase tracking-widest text-muted", children: "My requests" }), _jsx("h1", { className: "mt-3 text-4xl font-semibold text-ink", children: "Your moving requests" }), outcome?.state === "ok" ? _jsxs(_Fragment, { children: [_jsxs("p", { className: "mt-4 text-muted", children: ["Requests for ", outcome.view.email] }), outcome.view.requests.length ? _jsx("div", { className: "mt-8 space-y-5", children: outcome.view.requests.map((request) => _jsxs("article", { className: "rounded-3xl border border-border bg-white p-6", children: [_jsxs("div", { className: "flex flex-wrap items-start justify-between gap-3", children: [_jsxs("div", { children: [_jsxs("p", { className: "text-sm text-muted", children: ["Request ", request.reference] }), _jsx("h2", { className: "mt-1 text-xl font-semibold text-ink", children: [request.summary.from, request.summary.to].filter(Boolean).join(" → ") || "Moving request" })] }), _jsx("span", { className: "rounded-full bg-subtle px-3 py-1 text-sm text-ink", children: labels[request.status] })] }), _jsxs("p", { className: "mt-3 text-sm text-muted", children: ["Submitted ", new Date(request.submittedAt).toLocaleDateString("en-GB"), request.summary.moveDate ? ` · Preferred move ${request.summary.moveDate}` : "", request.summary.size ? ` · ${request.summary.size}` : ""] }), request.matches.length ? _jsx("ul", { className: "mt-5 divide-y divide-border", children: request.matches.map((match) => _jsxs("li", { className: "flex flex-wrap justify-between gap-2 py-3", children: [_jsxs("span", { className: "font-medium text-ink", children: [match.name, match.verified ? " · Verified" : ""] }), _jsxs("span", { className: "text-sm text-muted", children: [match.coverageArea ? `${match.coverageArea} · ` : "", match.responded ? "Request accepted" : "Request delivered"] })] }, match.workspaceId)) }) : _jsx("p", { className: "mt-5 text-sm text-muted", children: "No provider matches to show yet. Check back as your request progresses." })] }, request.reference)) }) : _jsx("p", { className: "mt-8 rounded-2xl bg-subtle p-6 text-muted", children: "No requests found for this email yet." })] }) : _jsxs("div", { className: "mt-8 grid gap-8 lg:grid-cols-2", children: [_jsxs("div", { children: [_jsx("p", { className: "text-lg leading-8 text-muted", children: "Enter the email you used for your request. We will send you a secure link, with no password needed." }), outcome?.state === "invalid_link" && _jsx("p", { className: "mt-5 rounded-xl bg-amber-50 p-4 text-amber-950", role: "status", children: "That link is invalid or expired. Request a new one." }), outcome?.state === "unavailable" && _jsx("p", { className: "mt-5 rounded-xl bg-amber-50 p-4 text-amber-950", role: "status", children: "Your requests are temporarily unavailable. Try again shortly." })] }), _jsx(DashPortalLinkForm, { action: action })] })] });
6
+ }
@@ -0,0 +1,14 @@
1
+ export type MovingQuoteFormState = {
2
+ status: "idle";
3
+ } | {
4
+ status: "invalid";
5
+ } | {
6
+ status: "error";
7
+ } | {
8
+ status: "created";
9
+ reference: string;
10
+ };
11
+ export declare function DashMovingQuoteForm({ action, initialPickup, }: {
12
+ action: (state: MovingQuoteFormState, form: FormData) => Promise<MovingQuoteFormState>;
13
+ initialPickup?: string;
14
+ }): import("react").JSX.Element;
@@ -0,0 +1,79 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useActionState, useEffect, useState } from "react";
4
+ export function DashMovingQuoteForm({ action, initialPickup = "", }) {
5
+ const [state, formAction, pending] = useActionState(action, { status: "idle" });
6
+ const [attemptId, setAttemptId] = useState("");
7
+ useEffect(() => { setAttemptId(crypto.randomUUID()); }, []);
8
+ const [reviewing, setReviewing] = useState(false);
9
+ const [addresses, setAddresses] = useState({ from: [], to: [] });
10
+ const [searchState, setSearchState] = useState({ from: "", to: "" });
11
+ const [selected, setSelected] = useState({ from: null, to: null });
12
+ const [distance, setDistance] = useState(null);
13
+ const [distanceUnavailable, setDistanceUnavailable] = useState(false);
14
+ if (state.status === "created") {
15
+ return _jsxs("div", { className: "rounded-3xl border border-border bg-white p-8", role: "status", children: [_jsx("h2", { className: "text-2xl font-semibold text-ink", children: "Request received" }), _jsxs("p", { className: "mt-3 text-muted", children: ["Your reference is ", _jsx("strong", { children: state.reference }), ". Keep it for your records."] }), _jsx("p", { className: "mt-3 text-muted", children: "We will email you as the request progresses. You can also retrieve it with an email link." }), _jsx("a", { className: "mt-6 inline-flex rounded-full bg-accent px-6 py-3 font-semibold text-accent-foreground", href: "/my-quotes", children: "View my requests" })] });
16
+ }
17
+ async function lookup(side, form) {
18
+ const field = form.elements.namedItem(`${side}_postcode`);
19
+ const query = field?.value.trim() ?? "";
20
+ if (!query)
21
+ return;
22
+ setSearchState((current) => ({ ...current, [side]: "Searching addresses…" }));
23
+ try {
24
+ const response = await fetch(`/api/moving-addresses/lookup?q=${encodeURIComponent(query)}`, { cache: "no-store" });
25
+ if (!response.ok)
26
+ throw new Error("lookup failed");
27
+ const data = await response.json();
28
+ setAddresses((current) => ({ ...current, [side]: data.results }));
29
+ setSearchState((current) => ({ ...current, [side]: data.results.length ? "Choose your address below." : "No addresses found. Enter it manually." }));
30
+ }
31
+ catch {
32
+ setSearchState((current) => ({ ...current, [side]: "Address search is unavailable. Enter the address manually." }));
33
+ }
34
+ }
35
+ async function selectAddress(side, result, form) {
36
+ let resolved = result;
37
+ if (result._udprn && !result.normalized) {
38
+ try {
39
+ const response = await fetch(`/api/moving-addresses/resolve?udprn=${result._udprn}`, { cache: "no-store" });
40
+ if (!response.ok)
41
+ throw new Error("resolve failed");
42
+ resolved = await response.json();
43
+ }
44
+ catch {
45
+ setSearchState((current) => ({ ...current, [side]: "Could not confirm that address. Enter it manually." }));
46
+ return;
47
+ }
48
+ }
49
+ const addressField = form.elements.namedItem(`${side}_address`);
50
+ const postcodeField = form.elements.namedItem(`${side}_postcode`);
51
+ if (addressField)
52
+ addressField.value = resolved.display;
53
+ if (postcodeField && resolved.normalized?.postal_code)
54
+ postcodeField.value = resolved.normalized.postal_code;
55
+ setSelected((current) => ({ ...current, [side]: resolved }));
56
+ setAddresses((current) => ({ ...current, [side]: [] }));
57
+ setSearchState((current) => ({ ...current, [side]: "Address selected." }));
58
+ setDistance(null);
59
+ const counterpart = selected[side === "from" ? "to" : "from"];
60
+ const a = side === "from" ? resolved : counterpart;
61
+ const b = side === "to" ? resolved : counterpart;
62
+ if (a?.normalized && b?.normalized && Number.isFinite(a.normalized.latitude) && Number.isFinite(b.normalized.latitude)) {
63
+ try {
64
+ const params = new URLSearchParams({ fromLat: String(a.normalized.latitude), fromLng: String(a.normalized.longitude), toLat: String(b.normalized.latitude), toLng: String(b.normalized.longitude) });
65
+ const response = await fetch(`/api/moving-addresses/distance?${params}`, { cache: "no-store" });
66
+ if (!response.ok)
67
+ throw new Error("distance failed");
68
+ setDistance(await response.json());
69
+ setDistanceUnavailable(false);
70
+ }
71
+ catch {
72
+ setDistanceUnavailable(true);
73
+ }
74
+ }
75
+ }
76
+ return _jsxs("form", { action: formAction, className: "space-y-8 rounded-3xl border border-border bg-white p-6 shadow-xl shadow-slate-900/5 sm:p-9", children: [_jsx("input", { type: "hidden", name: "attempt_id", value: attemptId }), _jsx("input", { type: "hidden", name: "distance_miles", value: distance?.distanceMiles ?? "" }), _jsx("input", { type: "hidden", name: "duration_minutes", value: distance?.durationMinutes ?? "" }), ["from", "to"].map((side) => _jsxs("fieldset", { className: "space-y-3", children: [_jsx("legend", { className: "text-lg font-semibold text-ink", children: side === "from" ? "Collection" : "Delivery" }), _jsx("label", { className: "block text-sm font-medium text-ink", htmlFor: `${side}_postcode`, children: "Postcode" }), _jsxs("div", { className: "flex gap-2", children: [_jsx("input", { className: "min-h-12 min-w-0 flex-1 rounded-xl border border-border px-4", defaultValue: side === "from" ? initialPickup : "", id: `${side}_postcode`, name: `${side}_postcode`, autoComplete: "postal-code", required: true, maxLength: 16 }), _jsx("button", { className: "rounded-xl border border-border px-4 font-medium text-ink", type: "button", onClick: (event) => lookup(side, event.currentTarget.form), children: "Find address" })] }), searchState[side] && _jsx("p", { className: "text-sm text-muted", role: "status", children: searchState[side] }), addresses[side].length > 0 && _jsx("ul", { className: "max-h-48 overflow-auto rounded-xl border border-border", "aria-label": `${side} address suggestions`, children: addresses[side].map((result) => _jsx("li", { children: _jsx("button", { className: "w-full px-4 py-2 text-left text-sm hover:bg-subtle", type: "button", onClick: (event) => selectAddress(side, result, event.currentTarget.form), children: result.display }) }, `${result._udprn ?? result.display}`)) }), _jsx("label", { className: "block text-sm font-medium text-ink", htmlFor: `${side}_address`, children: "Address" }), _jsx("input", { className: "min-h-12 w-full rounded-xl border border-border px-4", id: `${side}_address`, name: `${side}_address`, required: true, maxLength: 500, placeholder: "Select an address or enter it manually" })] }, side)), distance && _jsxs("p", { className: "text-sm text-muted", children: ["Approximate driving distance: ", distance.distanceMiles, " miles."] }), distanceUnavailable && _jsx("p", { className: "text-sm text-muted", children: "Distance is unavailable. You can still submit your request." }), _jsxs("fieldset", { className: "grid gap-4 sm:grid-cols-2", children: [_jsx("legend", { className: "mb-3 text-lg font-semibold text-ink", children: "Move details" }), _jsxs("label", { className: "grid gap-2 text-sm font-medium text-ink", children: ["Preferred date", _jsx("input", { className: "min-h-12 rounded-xl border border-border px-4", type: "date", name: "move_date" })] }), _jsxs("label", { className: "grid gap-2 text-sm font-medium text-ink", children: ["Property size", _jsxs("select", { className: "min-h-12 rounded-xl border border-border px-4", name: "property_size", defaultValue: "2-bed", children: [_jsx("option", { value: "studio", children: "Studio" }), _jsx("option", { value: "1-bed", children: "1 bedroom" }), _jsx("option", { value: "2-bed", children: "2 bedrooms" }), _jsx("option", { value: "3-bed", children: "3 bedrooms" }), _jsx("option", { value: "4+-bed", children: "4 or more bedrooms" }), _jsx("option", { value: "other", children: "Other" })] })] }), _jsxs("label", { className: "grid gap-2 text-sm font-medium text-ink", children: ["Collection floor", _jsx("input", { className: "min-h-12 rounded-xl border border-border px-4", type: "number", name: "floor_from", min: "0", max: "99", defaultValue: "0" })] }), _jsxs("label", { className: "grid gap-2 text-sm font-medium text-ink", children: ["Delivery floor", _jsx("input", { className: "min-h-12 rounded-xl border border-border px-4", type: "number", name: "floor_to", min: "0", max: "99", defaultValue: "0" })] }), [["flexible_date", "My date is flexible"], ["has_lift_from", "Collection has a lift"], ["has_lift_to", "Delivery has a lift"], ["packing_required", "I need packing"], ["storage_required", "I need storage"], ["dismantling_required", "I need dismantling"]].map(([key, label]) => _jsxs("label", { className: "flex items-center gap-2 text-sm text-ink", children: [_jsx("input", { type: "checkbox", name: key }), label] }, key)), _jsxs("label", { className: "grid gap-2 text-sm font-medium text-ink sm:col-span-2", children: ["Special items, separated by commas", _jsx("input", { className: "min-h-12 rounded-xl border border-border px-4", name: "special_items", maxLength: 1000 })] }), _jsxs("label", { className: "grid gap-2 text-sm font-medium text-ink sm:col-span-2", children: ["Other details", _jsx("textarea", { className: "min-h-28 rounded-xl border border-border p-4", name: "additional_notes", maxLength: 4000 })] })] }), _jsxs("fieldset", { className: "grid gap-4 sm:grid-cols-2", children: [_jsx("legend", { className: "mb-3 text-lg font-semibold text-ink", children: "Your contact details" }), _jsxs("label", { className: "grid gap-2 text-sm font-medium text-ink", children: ["Name", _jsx("input", { className: "min-h-12 rounded-xl border border-border px-4", name: "name", required: true, maxLength: 255, autoComplete: "name" })] }), _jsxs("label", { className: "grid gap-2 text-sm font-medium text-ink", children: ["Email", _jsx("input", { className: "min-h-12 rounded-xl border border-border px-4", name: "email", type: "email", required: true, maxLength: 320, autoComplete: "email" })] }), _jsxs("label", { className: "grid gap-2 text-sm font-medium text-ink sm:col-span-2", children: ["Phone (optional)", _jsx("input", { className: "min-h-12 rounded-xl border border-border px-4", name: "phone", type: "tel", maxLength: 64, autoComplete: "tel" })] })] }), state.status === "invalid" && _jsx("p", { className: "rounded-xl bg-amber-50 p-4 text-sm text-amber-950", role: "alert", children: "Check your details and try again." }), state.status === "error" && _jsx("p", { className: "rounded-xl bg-amber-50 p-4 text-sm text-amber-950", role: "alert", children: "We could not submit your request. Please try again." }), reviewing && _jsx("p", { className: "rounded-xl bg-subtle p-4 text-sm text-ink", role: "status", children: "Review your addresses, move details, and contact email above. Submit when everything looks right." }), reviewing ? _jsx("button", { className: "min-h-12 rounded-full bg-accent px-7 font-semibold text-accent-foreground disabled:opacity-50", type: "submit", disabled: pending, children: pending ? "Submitting…" : "Submit request" })
77
+ : _jsx("button", { className: "min-h-12 rounded-full bg-accent px-7 font-semibold text-accent-foreground", type: "button", disabled: !attemptId, onClick: (event) => { if (event.currentTarget.form?.reportValidity())
78
+ setReviewing(true); }, children: "Review request" })] });
79
+ }
package/dist/ui.d.ts CHANGED
@@ -17,3 +17,6 @@ export { SiteErrorFallback } from "./ui/error-fallback.js";
17
17
  export { DashLegalPage } from "./ui/legal-page.js";
18
18
  export { DashAdminLink } from "./ui/admin-link.js";
19
19
  export { DashPlanCards } from "./ui/plan-cards.js";
20
+ export { DashMovingQuoteForm, type MovingQuoteFormState } from "./ui/moving-quote-form.js";
21
+ export { DashLeadPortalPage } from "./ui/lead-portal-page.js";
22
+ export { DashPortalLinkForm, type PortalFormState } from "./ui/lead-portal-form.js";
package/dist/ui.js CHANGED
@@ -17,3 +17,6 @@ export { SiteErrorFallback } from "./ui/error-fallback.js";
17
17
  export { DashLegalPage } from "./ui/legal-page.js";
18
18
  export { DashAdminLink } from "./ui/admin-link.js";
19
19
  export { DashPlanCards } from "./ui/plan-cards.js";
20
+ export { DashMovingQuoteForm } from "./ui/moving-quote-form.js";
21
+ export { DashLeadPortalPage } from "./ui/lead-portal-page.js";
22
+ export { DashPortalLinkForm } from "./ui/lead-portal-form.js";
@@ -0,0 +1,5 @@
1
+ import type { MovingQuoteInput } from "../models/moving-quotes.js";
2
+ export declare function validateMovingQuoteForm(form: FormData): {
3
+ input: MovingQuoteInput;
4
+ attemptId: string;
5
+ } | null;
@@ -0,0 +1,41 @@
1
+ const postcode = /^[a-z]{1,2}\d[a-z\d]?\s*\d[a-z]{2}$/i;
2
+ const email = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
3
+ export function validateMovingQuoteForm(form) {
4
+ const string = (key, limit) => {
5
+ const value = form.get(key);
6
+ return typeof value === "string" && value.length <= limit ? value.trim() : "";
7
+ };
8
+ const number = (key, min, max) => {
9
+ const value = Number(string(key, 20));
10
+ return Number.isInteger(value) && value >= min && value <= max ? value : NaN;
11
+ };
12
+ const name = string("name", 255);
13
+ const mail = string("email", 320).toLowerCase();
14
+ const from = string("from_address", 500);
15
+ const to = string("to_address", 500);
16
+ const fromPostcode = string("from_postcode", 16).toUpperCase();
17
+ const toPostcode = string("to_postcode", 16).toUpperCase();
18
+ const attemptId = string("attempt_id", 100);
19
+ const floorFrom = number("floor_from", 0, 99);
20
+ const floorTo = number("floor_to", 0, 99);
21
+ if (!name || !email.test(mail) || !from || !to || !postcode.test(fromPostcode) || !postcode.test(toPostcode) || !attemptId || !Number.isFinite(floorFrom) || !Number.isFinite(floorTo))
22
+ return null;
23
+ const distance = Number(string("distance_miles", 30));
24
+ const duration = Number(string("duration_minutes", 30));
25
+ const specialItems = string("special_items", 1000).split(",").map((item) => item.trim()).filter(Boolean).slice(0, 30);
26
+ return {
27
+ attemptId,
28
+ input: {
29
+ name, email: mail, phone: string("phone", 64), from_address: from, to_address: to,
30
+ from_postcode: fromPostcode, to_postcode: toPostcode, move_date: string("move_date", 20),
31
+ flexible_date: form.get("flexible_date") === "on", property_size: string("property_size", 80) || "unspecified",
32
+ floor_from: floorFrom, floor_to: floorTo,
33
+ has_lift_from: form.get("has_lift_from") === "on", has_lift_to: form.get("has_lift_to") === "on",
34
+ packing_required: form.get("packing_required") === "on", storage_required: form.get("storage_required") === "on",
35
+ dismantling_required: form.get("dismantling_required") === "on", special_items: specialItems,
36
+ additional_notes: string("additional_notes", 4000),
37
+ ...(Number.isFinite(distance) && distance > 0 ? { distance_miles: distance } : {}),
38
+ ...(Number.isFinite(duration) && duration > 0 ? { duration_minutes: duration } : {}),
39
+ },
40
+ };
41
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@c1m-public/dash-site-kit",
3
- "version": "0.14.1",
3
+ "version": "0.15.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Shared transport, domain and UI layer for MML dash-scoped public sites",
@@ -43,7 +43,7 @@
43
43
  "server-only": "0.0.1"
44
44
  },
45
45
  "peerDependencies": {
46
- "@c1m-public/channel-client": ">=0.31.0 <1",
46
+ "@c1m-public/channel-client": ">=0.35.0 <1",
47
47
  "@c1m-public/platform-auth": ">=0.22.0 <1",
48
48
  "next": "^16",
49
49
  "react": "^19"
@@ -57,8 +57,8 @@
57
57
  "react-dom": "19.2.8",
58
58
  "typescript": "5.9.3",
59
59
  "vitest": "^4.1.4",
60
- "@c1m-public/channel-client": "0.33.0",
61
- "@c1m-public/platform-auth": "0.22.0"
60
+ "@c1m-public/channel-client": "0.35.0",
61
+ "@c1m-public/platform-auth": "0.23.0"
62
62
  },
63
63
  "peerDependenciesMeta": {
64
64
  "next": {