Frontend School

Multi-Step Onboarding Form

Machine Coding
hard

Multi-Step Onboarding Form

Hard
multi-step form
React
TypeScript
State Management
Validation
UI/UX
Forms

Overview

Modern web applications often require users to input complex information through a series of guided steps, rather than a single monolithic form. This approach, known as a multi-step form, significantly enhances user experience by breaking down complexity, reducing cognitive load, and providing clear progress indicators. For a STAFF-level candidate, demonstrating proficiency in building such a system from scratch, including robust state management and validation, is crucial.

In this problem, you will build a multi-step onboarding form for a hypothetical service. This form will collect personal details, address information, and provide a final review step before submission. The core challenge lies in managing form state across steps, implementing per-step validation, and ensuring a smooth user flow without relying on external form libraries.

What you need to do / Task

Your task is to implement a responsive, multi-step form component in React/TypeScript with the following steps:

  1. Step 1: Personal Details

    • Collect Full Name (text input, required)
    • Collect Email (email input, required, must be a valid email format)
  2. Step 2: Address Details

    • Collect Street Address (text input, required)
    • Collect City (text input, required)
    • Collect Zip Code (text input, required, must be 5 digits)
  3. Step 3: Review & Submit

    • Display all collected data from Step 1 and Step 2 for user review.
    • Provide a final 'Submit' button.

For all steps, you must:

  • Implement clear navigation controls (Next and Previous buttons).
  • Disable the Next button if the current step's fields are invalid.
  • Persist data as the user navigates between steps.
  • Display clear, inline error messages for invalid fields.
  • On final submission, log the complete form data to the console.

UI/UX expectations

  • Layout: The form should be centrally aligned, with clear visual separation for each step. A basic step indicator (e.g., numbered circles or text) should show the current progress.
  • Interactions: Buttons should clearly indicate their action. Input fields should provide immediate feedback on validation errors (e.g., red border, error text).
  • Accessibility: Use appropriate HTML form elements (<label>, type attributes for inputs) to ensure basic accessibility. Focus management is out of scope beyond standard browser behavior.

Acceptance criteria

  • The form renders correctly, starting at 'Personal Details'.
  • Users can navigate between steps using 'Next' and 'Previous' buttons.
  • Data entered in previous steps is preserved when navigating back and forth.
  • The 'Next' button is disabled if required fields in the current step are empty or invalid.
  • Validation errors are displayed next to the respective fields when a field is invalid or on attempting to proceed to the next step with invalid data.
  • Email field validates for a basic email format.
  • Zip Code field validates for exactly 5 digits.
  • The 'Review & Submit' step accurately displays all collected data.
  • Clicking 'Submit' on the final step logs the complete form data object to the console.
  • The 'Previous' button is disabled on the first step.
  • The 'Next' button is disabled on the last step.

Constraints

Constraints & assumptions

  • No external form libraries: You are expected to implement form state management, validation, and navigation logic from scratch using React's built-in hooks (e.g., useState, useReducer, useCallback).
  • Client-side validation: All validation should happen client-side in JavaScript/TypeScript.
  • Data persistence: Form data needs to be persisted within the component's state as the user progresses through steps. No external storage (e.g., localStorage, backend) is required.
  • Environment: Use functional React components and TypeScript.
  • Styling: Basic CSS is sufficient; focus on functionality over elaborate design.

Out of scope

  • Backend integration or API calls.
  • Complex routing logic (the entire form should reside within a single component).
  • Advanced animations or transitions between steps.
  • Deep accessibility considerations beyond semantic HTML (e.g., ARIA live regions, keyboard traps).
  • Internationalization (i18n).

What interviewers evaluate

  • Robust State Management: How effectively multi-step form data and validation errors are managed across component renders and step changes.
  • Validation Logic: The correctness, clarity, and extensibility of per-step validation rules and error display.
  • Component Structure: Clean separation of concerns, modularity, and effective use of React hooks.
  • User Experience: Smooth navigation, clear feedback for validation, and a logical user flow.
  • TypeScript Proficiency: Correct and idiomatic use of TypeScript for defining form data, errors, and component props.

Loading editor...