Routing Forms
Routing forms are pre-booking questionnaires. Based on the customer’s answers, they’re automatically routed to the appropriate event type, provider, or external URL.
How it works
Section titled “How it works”- Customer visits a routing form URL
- They answer a series of questions
- Rules evaluate the responses
- Customer is redirected to the matched event type or provider’s booking page
Form structure
Section titled “Form structure”import type { RoutingFormDefinition, RoutingField, RoutingRule } from "@thebookingkit/core";
const form: RoutingFormDefinition = { name: "New Patient Intake", fields: [ { id: "visit_type", label: "What type of visit do you need?", type: "select", required: true, options: ["New patient", "Follow-up", "Emergency"], }, { id: "insurance", label: "Do you have insurance?", type: "select", required: true, options: ["Yes", "No"], }, ], rules: [ { conditions: [ { field: "visit_type", operator: "equals", value: "Emergency" }, ], action: { type: "redirect", url: "/emergency" }, }, { conditions: [ { field: "visit_type", operator: "equals", value: "New patient" }, { field: "insurance", operator: "equals", value: "Yes" }, ], action: { type: "event_type", eventTypeId: "new-patient-insured" }, }, ], fallbackAction: { type: "event_type", eventTypeId: "general-consultation" },};Evaluation
Section titled “Evaluation”import { evaluateRoutingRules, validateRoutingResponses } from "@thebookingkit/core";
// Validate responses match the form definitionvalidateRoutingResponses(form, responses);
// Find the matching ruleconst result = evaluateRoutingRules(form.rules, responses, form.fallbackAction);// Returns: RoutingResult { action, matchedRule? }Validation
Section titled “Validation”import { validateRoutingForm, RoutingFormValidationError } from "@thebookingkit/core";
validateRoutingForm(form);// Validates: field types, rule conditions reference valid fields, fallback existsAnalytics
Section titled “Analytics”import { computeRoutingAnalytics } from "@thebookingkit/core";
const analytics = computeRoutingAnalytics(submissions);// Returns: RoutingAnalytics// { totalSubmissions, ruleMatchCounts, fieldValueDistribution, completionRate }UI component
Section titled “UI component”import { RoutingForm } from "./components/routing-form";
<RoutingForm fields={form.fields} onSubmit={(responses) => { const result = evaluateRoutingRules(form.rules, responses, form.fallbackAction); router.push(result.action.url || `/book/${result.action.eventTypeId}`); }}/>