This page documents all custom hooks used in the HubSpot Form Builder application.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/davidmenlop/HubSpot-Form-builder/llms.txt
Use this file to discover all available pages before exploring further.
useHubSpotForms
Manages HubSpot API integration for fetching forms and form schemas. Location:main/frontend/src/hooks/useHubSpotForms.ts
Return Values
Array of available HubSpot forms
Whether forms list is currently loading
Error message if form loading failed
Whether OAuth connection to HubSpot is active
Currently loaded form schema
Whether schema is currently loading
Error message if schema loading failed
Fetches list of forms from HubSpot API
Fetches schema for a specific form by ID
Checks OAuth connection status
HubSpotForm Type
API Endpoints Used
GET /api/forms- List all formsGET /api/forms/:formId- Get form schemaGET /oauth/hubspot/status- Check connection status
Error Handling
Session Expiration
Session Expiration
When a 401 status is received, the hook:
- Sets
connectedtofalse - Throws error: “Session expired. Please reconnect to HubSpot.”
- Updates error state with the message
Usage Example
useLayoutStore
Zustand store for managing form layout state and operations. Location:main/frontend/src/hooks/useLayoutStore.ts
Store Shape
Current layout configuration
Actions
setLayout
New layout state
initializeFromSchema
Form schema to initialize from
Layout mode
- One-step mode: All fields in a single step
- Multi-step mode: Fields split evenly between two steps
setMode
New layout mode
addStep
- Switches mode to
'multi-step' - Generates unique step ID
- Names step as “Paso N” where N is step number
removeStep
ID of step to remove
renameStep
ID of step to rename
New step title
reorderSteps
Current step index
Target step index
moveFieldBetweenSteps
Field identifier
Source step index
Target step index
removeFieldFromStep
Step ID containing the field
Field to remove
addFieldToNewRow
Target step ID
Field to add
Row index to insert at (optional, defaults to end)
addFieldToRow
Target step ID
Field to add
Target row ID
Position within row (0-3)
moveFieldToNewRow
Step containing the field
Field to move
Row index to insert at (optional, defaults to end)
moveFieldWithinStep
Step containing both rows
Field to move
Source row ID
Target row ID
Position in target row
Helper Functions
createStepId
crypto.randomUUID() or fallback timestamp-based ID.
createRowId
crypto.randomUUID() or fallback timestamp-based ID.
Usage Example
useLayoutDnd
Manages drag-and-drop logic for the layout builder using@dnd-kit.
Location: main/frontend/src/hooks/useLayoutDnd.ts
Parameters
Current form schema
Return Values
Configured dnd-kit sensors (PointerSensor with 8px activation distance)
ID of currently dragged item
Type of currently dragged item
Visual indicators for where items will drop
Initiates drag operation
Tracks mouse position during drag
Calculates drop position and updates visual indicators
Executes the drop operation
Drag Types
field
field
An existing field in the layout being reordered or moved between rows/steps.
step
step
A step being reordered in multi-step mode.
palette-field
palette-field
A new field being dragged from the sidebar palette to the layout.
Drop Targets
Dropping on a field can place the dragged item before, after, or beside it (combining into same row)
Dropping on a step’s drop zone adds the field to that step
Drop Position Logic
Before
Before
When dragged item is above the target field with minimal overlap.
After
After
When dragged item is below the target field with minimal overlap.
Inside
Inside
When dragged item overlaps the target field significantly. Determines left/right placement based on horizontal position.
Constraints
- Maximum 3 fields per row
- Fields can only move within their current step (except via step-drop zones)
- Required fields cannot be removed from layout
- At least one step must exist
Usage Example
Internal Functions
findStepIndexByField
findStepIndexById
getPaletteFieldId
palette: prefix).