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.
- 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).
- 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.
- 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%).
- 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.
- 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.
- 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.