Overview
At Paytm, providing a seamless user experience for critical flows like order placement is paramount. A multi-step wizard helps users navigate complex processes by breaking them into manageable parts, reducing cognitive load and improving conversion rates. This problem challenges you to build a robust and intuitive Stepper Wizard component, crucial for guiding users through an e-commerce checkout or any sequential data entry process within our applications.
What you need to do / Task
Your primary task is to build a Stepper component in React that orchestrates a multi-step process.
- Implement the Stepper Component: Create a reusable
Stepper component that takes an array of step configurations as props.
- Manage Step State: The Stepper should maintain its own internal state to track the
currentStepIndex.
- Dynamic Content Rendering: Render the content associated with the
currentStepIndex. Each step will have its own form or display.
- Navigation Controls: Implement "Next" and "Previous" buttons to move between steps.
- The "Previous" button should be disabled when on the first step.
- The "Next" button should be disabled if the current step's content is invalid (i.e., its form is not filled out correctly).
- On the final step, the "Next" button should change its label to "Place Order" or "Submit".
- Step Validation: Each step's content should include a simple validation mechanism. The
Stepper component should prevent advancement to the next step if the current step's content is invalid.
- Completion Handling: When "Place Order" is clicked on the final step, trigger a completion callback, simulating a successful order submission.
UI/UX expectations
- Step Indicators: Display a clear visual indicator for each step (e.g., numbered circles or text labels), showing its title.
- Active Step Highlight: The currently active step indicator must be visually distinct (e.g., different color, bold text).
- Navigation Layout: Position "Previous" and "Next" buttons appropriately, typically at the bottom of the step content.
- Form Elements: Each step's content will contain basic input fields (e.g., text inputs, textareas) and display any validation errors.
- Minimal Styling: Focus on functionality, but ensure a basic, readable layout.
Acceptance criteria
- The
Stepper component renders correctly with all defined steps.
- Clicking "Next" successfully advances the user to the subsequent step.
- Clicking "Previous" successfully navigates the user to the prior step.
- The "Previous" button is disabled when the
currentStepIndex is 0 (first step).
- The "Next" button is disabled if the current step's form content is invalid.
- The "Next" button's label changes to "Place Order" on the last step.
- Clicking the "Place Order" button on the final step triggers a confirmation (e.g., an alert or console log).
- The active step indicator is clearly highlighted.
- Attempting to navigate "Next" from an invalid step displays an error and keeps the user on the current step.