Frontend School

Constrained Date Range Selector for Shift Planning

Machine Coding
medium

Constrained Date Range Selector for Shift Planning

Medium
React
Frontend
Calendar
Date Picker
UI
State Management

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

  1. Implement DateRangePicker Component: Create a React functional component named DateRangePicker that displays a calendar interface.
  2. Month Navigation: Allow users to navigate between months using 'Previous' and 'Next' buttons.
  3. 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.
  4. 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.
  5. 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.

Constraints

Constraints & assumptions

  • You must use React for building the UI.
  • Focus on core functionality; perfect pixel-perfect styling is not the primary goal, but a reasonable and functional layout is expected.
  • Date manipulation should primarily use native JavaScript Date objects. External date libraries (e.g., date-fns) are not required but can be used if you are familiar and it significantly speeds up development.
  • The calendar should display one month at a time.
  • The MAX_RANGE_DAYS constant is 7 (inclusive).
  • The DISABLED_DATES array will be provided in the starter code as an array of Date objects.

Out of scope

  • Full internationalization (i18n) for month names or day names.
  • Keyboard navigation or advanced accessibility features beyond basic click interactions.
  • Complex animations or transitions.
  • Time selection or different calendar views (e.g., week view, year view).

What interviewers evaluate

  • Component Design & State Management: How effectively state is managed within the DateRangePicker component, including separation of concerns.
  • Date Logic & Constraints: Correct and efficient implementation of date calculations, range validation, and handling of various constraints (weekdays, disabled dates, max range).
  • UI Interaction & Feedback: Responsiveness to user input, clear visual feedback for selections, invalid states, and calendar navigation.
  • Code Quality & Readability: Clean, maintainable, and well-structured code with appropriate use of React hooks and patterns.

Loading editor...