Overview
Innovaccer's platform assists healthcare organizations in managing various operational aspects, including resource and staff scheduling. A critical component for this is a robust date range selector. This problem challenges you to build a DateRangePicker component that not only allows users to select a start and end date but also enforces specific business rules, ensuring only valid date ranges can be picked. This component will be integrated into a larger shift planning module.
What you need to do / Task
- Implement
DateRangePicker Component: Create a React functional component named DateRangePicker that displays a calendar interface.
- Month Navigation: Allow users to navigate between months using 'Previous' and 'Next' buttons.
- Date Selection Logic: Enable selection of a start date and an end date. The first click should set the start date. The second click should set the end date, forming a range. If a start date is already selected and a new date is clicked, the logic should handle whether it extends the range, starts a new range, or adjusts the existing range.
- Date Constraints: Implement the following rules for selectable dates:
- Only weekdays (Monday-Friday) can be selected.
- Specific pre-defined dates (e.g., holidays, maintenance days provided in
DISABLED_DATES) must be unselectable.
- The selected date range (inclusive of start and end dates) must not exceed
MAX_RANGE_DAYS.
- Visual Feedback: Clearly indicate the current month, selected start date, selected end date, dates within the selected range, and disabled dates.
UI/UX expectations
- The component should display a clear calendar grid with 7 columns for days of the week (e.g., Sun, Mon, Tue...). The grid should correctly align the days of the month under their respective weekday headers.
- Navigation buttons for previous and next months should be present and functional.
- Visually distinguish:
- The current day.
- Selected start date (e.g., primary accent color).
- Selected end date (e.g., primary accent color).
- Dates within the selected range (e.g., a lighter accent color).
- Disabled dates (e.g., grayed out, text-decoration: line-through, and not clickable).
- When a user attempts to select an invalid range (e.g., exceeding
MAX_RANGE_DAYS), provide clear feedback (e.g., an alert or a message).
Acceptance criteria
- The
DateRangePicker component renders a calendar view for the current month upon initialization.
- Displays correct day of the week headers (e.g., Sun, Mon, Tue, ...).
- Allows navigation to previous and next months, updating the calendar view.
- Correctly implements the date selection logic for start and end dates.
- Only allows selection of weekdays (Monday-Friday); weekends are visually disabled and unclickable.
- Specific
DISABLED_DATES (provided) are visually disabled and unclickable.
- Enforces the
MAX_RANGE_DAYS constraint for the selected range, preventing selection of longer ranges and providing feedback.
- Visually highlights the selected start date, end date, and all dates within the selected range.
- The
onRangeSelect callback prop is invoked with the startDate and endDate whenever the selection changes.