Frontend School

Multi-stage Booking Progress Tracker

Machine Coding
hard

Multi-stage Booking Progress Tracker

Hard
Progress Bar
UI Components
React
State Management
Asynchronous Operations

Overview

In high-stakes booking flows like flights or hotels on MakeMyTrip, users need clear and immediate feedback on their progress. A robust, multi-stage progress tracker is crucial for reducing user anxiety, managing expectations during asynchronous operations, and guiding them through complex sequences. This problem challenges you to build a dynamic, interactive progress bar component capable of tracking the overall and individual stage progress for a multi-step booking process, complete with simulated asynchronous updates and error handling.

What you need to do / Task

You are tasked with building a MultiStageProgressBar React component that visualizes the progress of a multi-step booking process.

  1. Stage Definition: The component should accept an array of stages, where each stage has an id, name, and an initial status (pending, active, completed, error). Each stage also needs to track its progress (0-100).
  2. Overall Progress Bar: Display a primary progress bar that visually represents the overall completion of the entire booking process. This should reflect the progression through completed stages and the current progress of the active stage.
  3. Individual Stage Indicators: Below the overall bar, display a series of indicators, one for each stage. Each indicator should clearly show:
    • The stage's name.
    • Its current status (e.g., different colors/icons for pending, active, completed, error).
    • A mini progress bar or percentage text within the active stage indicator, showing its individual progress (0-100%).
  4. Dynamic Updates:
    • Simulated Stage Progression: Implement a mechanism to simulate the progression of stages. When a stage is active, its individual progress should increment from 0% to 100% over a few seconds (e.g., using setTimeout or setInterval).
    • Stage Completion: Once an active stage reaches 100% individual progress, its status should automatically change to completed, and the next pending stage should become active.
    • Error Simulation: Randomly (e.g., 20% chance) introduce an error status for an active stage instead of completed when it reaches 100% individual progress. The final 'Confirmation' stage should not error.
  5. Error Handling & Retry:
    • When a stage enters an error status, the overall progress should halt at that stage.
    • The erroring stage indicator should visually highlight the error (e.g., red color, error icon).
    • Provide a "Retry" button within the errored stage's indicator. Clicking "Retry" should reset that stage's individual progress to 0%, set its status back to active, and restart its progression.
  6. Progress Calculation: The overall progress should be a weighted average. Assume each stage contributes equally to the overall completion. For completed stages, their contribution is 100%. For the active stage, its contribution is its current individual percentage. Pending/error stages contribute 0% until active.

UI/UX expectations

  • Layout: The overall progress bar should be prominent at the top. Below it, the individual stage indicators should be laid out horizontally, clearly separated, perhaps with connecting lines or arrows indicating flow.
  • Visual Feedback:
    • Completed Stages: Visually distinct (e.g., green, checkmark icon).
    • Active Stage: Clearly highlighted (e.g., brighter color, pulsating effect, distinct border). Its individual progress bar should be visible.
    • Pending Stages: Greyed out or muted.
    • Error Stage: Clearly indicate error (e.g., red background/border, error icon, "Retry" button).
  • Accessibility: Use appropriate ARIA attributes for progress bars (e.g., role="progressbar", aria-valuenow, aria-valuemin, aria-valuemax) for the overall progress bar. Ensure interactive elements like the "Retry" button are accessible.

Acceptance criteria

  • The MultiStageProgressBar component renders correctly with initial stage data.
  • Overall progress bar accurately reflects the combined progress of all stages.
  • Individual stage indicators correctly display name, status (pending, active, completed, error), and active stage's individual progress.
  • Stages automatically transition from active to completed upon reaching 100% individual progress.
  • The next pending stage automatically becomes active after the previous one completes.
  • Error state is randomly introduced for active stages (excluding the final stage) and is visually distinct.
  • "Retry" button for an errored stage correctly resets and restarts its progression.
  • Overall progress calculation correctly handles completed, active, and pending/error stages.
  • Basic accessibility attributes (role, aria-valuenow) are present for the main progress bar.

Constraints

Constraints & assumptions

  • The application uses React.js.
  • You should focus on functional components and hooks for state management.
  • No external UI library (e.g., Material-UI, Ant Design) is allowed for core component logic or styling, but basic CSS utility classes are fine.
  • The number of stages will be between 3 and 7.
  • Each stage contributes equally to the overall progress calculation.
  • Simulated progress updates should happen at reasonable intervals (e.g., every 100-200ms) to be visually perceivable.
  • The simulation of network requests should be done using setTimeout or setInterval, not actual fetch calls.
  • Assume the initial data for stages is provided as a prop; you don't need to fetch it.

Out of scope

  • Deep internationalization (i18n) or localization.
  • Extensive, complex animations (beyond basic transitions or color changes).
  • Server-side rendering (SSR) or advanced performance optimizations beyond standard React practices.
  • Full keyboard navigation or screen reader integration beyond basic ARIA attributes for progress bars and buttons.
  • Responsive design for extreme edge cases of screen sizes.

What interviewers evaluate

  • Component Design & Structure: How well the problem is broken down into modular, reusable components.
  • State Management: Effective use of React hooks (useState, useEffect, useRef) to manage complex, interconnected state across multiple stages.
  • Logic & Algorithms: Correct implementation of progress calculation, stage transitions, error handling, and retry mechanisms.
  • UI/UX Implementation: Adherence to visual specifications, clear feedback for different states, and basic accessibility considerations.
  • Code Quality: Readability, maintainability, error handling, and efficient use of resources (e.g., clearing intervals).

Loading editor...