Frontend School

Building a Robust Notification System: The Intuit Toast Component

Machine Coding
hard

Building a Robust Notification System: The Intuit Toast Component

Hard
Frontend
UI
React
TypeScript
Notifications
Accessibility

Overview

In modern financial applications, real-time feedback is crucial for user experience. Whether it's confirming a successful transaction, alerting about an impending session timeout, or notifying of a data synchronization error, clear and timely communication keeps users informed and confident. This problem focuses on building a versatile and accessible toast notification system, a common UI component, to enhance user feedback within an Intuit product.

What you need to do / Task

Your task is to implement a flexible and robust Toast Notification system using React and TypeScript. This system should consist of a ToastProvider component and a useToast hook, allowing any component within the provider's scope to easily trigger notifications.

Specifically, you need to implement the following:

  1. ToastProvider Component: This component will manage the state of all active and queued toasts. It should render a container for toasts, positioned on the screen.
  2. useToast Hook: A custom React hook that provides an addToast function to trigger new notifications from any child component.
  3. Toast Types: Support at least four distinct toast types: success, error, info, and warning, each with unique visual styling.
  4. Auto-Dismissal: Toasts should automatically dismiss after a configurable duration (default: 5 seconds). This duration should be overrideable per toast.
  5. Manual Dismissal: Each toast should include a visible 'Close' button allowing users to dismiss it manually before its auto-dismissal timer expires.
  6. Concurrency & Queueing: The system should only display a maximum number of toasts simultaneously (e.g., 3-5 visible toasts). If addToast is called when the maximum is reached, new toasts should be queued and appear once space becomes available.
  7. Animations: Implement smooth entry and exit animations for toasts (e.g., slide-in/slide-out, fade-in/fade-out).
  8. Accessibility: Ensure toasts are accessible to screen readers using ARIA live regions.

UI/UX expectations

  • Position: All toasts should appear anchored to one corner of the viewport (e.g., top-right), stacking vertically.
  • Visuals: Each toast type (success, error, info, warning) must have clearly distinguishable visual cues (e.g., different border colors, icons – though icons are optional if colors are clear).
  • Interaction: The close button should be easily clickable and visually clear.
  • Responsiveness: Toasts should adapt reasonably to different screen sizes, without breaking layout, though full mobile optimization is not required within the time limit.

Acceptance criteria

  • When addToast is called, a new toast appears on the screen with the specified message and type.
  • Toasts automatically disappear after their duration or when the close button is clicked.
  • Only up to maxVisibleToasts are displayed at any given time; additional toasts are queued and appear sequentially.
  • Each toast type (success, error, info, warning) renders with distinct styling.
  • Toasts animate smoothly when entering and exiting the viewport.
  • Screen readers announce the toast content when it appears, and toasts are dismissible via keyboard (if focused).
  • The useToast hook can be consumed by multiple components, and all toasts are managed by a single ToastProvider instance.

Constraints

Constraints & assumptions

  • You must use React and TypeScript.
  • No external toast notification libraries (e.g., react-toastify, notistack). Implement the core logic from scratch.
  • You may use any standard HTML/CSS/JS features and React hooks.
  • Focus on functional components and hooks for state management.
  • Assume a modern browser environment.
  • The maximum number of visible toasts should be configurable via ToastProvider props (default to 3).

Out of scope

  • Internationalization (i18n).
  • Complex customization of toast content beyond ReactNode.
  • Persistence of toasts across page navigations or reloads.
  • Deep integration with a global state management library (Context API is sufficient).

What interviewers evaluate

  • Component Architecture: How well the ToastProvider and useToast hook are designed for reusability and separation of concerns.
  • State Management: Effectiveness in managing multiple toast lifecycles, timers, and the queueing mechanism.
  • UI/UX Implementation: Fidelity to visual requirements, smooth animations, and interactive elements.
  • Accessibility: Proper use of ARIA attributes to ensure screen reader compatibility.
  • Code Quality: Readability, maintainability, and appropriate use of TypeScript types and features.

Loading editor...