Frontend School

Build a Notification Center Component

Machine Coding
medium

Build a Notification Center Component

Medium
React
TypeScript
UI
State Management
Notifications

Overview

Apple's operating systems rely heavily on timely and engaging notifications to keep users informed and productive. A well-designed Notification Center is crucial for delivering critical alerts, updates, and messages without overwhelming the user. This problem challenges you to build a simplified Notification Center component, focusing on core functionalities like display, dismissal, and state management, mirroring the user experience of a real Apple product.

What you need to do / Task

Your goal is to implement a NotificationCenter React component that displays a list of notifications and allows users to manage them.

  1. Display Notifications: Render a list of notifications, each showing its title, message, timestamp, and type.
  2. Dismiss Individual Notifications: Implement a mechanism (e.g., a button or icon) to dismiss a single notification from the list.
  3. Clear All Notifications: Add a "Clear All" button that, when clicked, removes all currently displayed notifications.
  4. Notification Types: Support at least three distinct notification types (e.g., info, warning, error). Each type should have a unique visual indicator or styling.
  5. Read/Unread State: Implement a visual distinction for "read" vs. "unread" notifications. Initially, all notifications are "unread". A notification becomes "read" when it is clicked or dismissed.

UI/UX expectations

  • Layout: Notifications should be stacked vertically within a container. The "Clear All" button should be easily accessible, perhaps at the top or bottom of the list.
  • Notification Card: Each notification should be presented as a distinct card or item, clearly separating it from others.
  • Dismiss Button: An 'x' icon or similar clear button should be present on each notification for individual dismissal.
  • Visual Cues:
    • Different background colors, border styles, or icons for info, warning, and error types.
    • A subtle visual cue (e.g., a lighter background, a small dot, or a different font weight) to differentiate unread from read notifications.
  • Timestamps: Display timestamps in a human-readable format (e.g., "5 minutes ago", "Yesterday at 3:00 PM"). A helper function formatTimestamp is provided for convenience.
  • Accessibility: Ensure interactive elements (buttons) have appropriate aria-label attributes where necessary.

Acceptance criteria

  • The NotificationCenter component renders a list of notifications from the initial mock data.
  • Each notification displays its title, message, and a human-readable timestamp.
  • Clicking the "Clear All" button removes all notifications from the display.
  • Clicking an individual dismiss button removes only that specific notification.
  • Notifications of type info, warning, and error are visually distinguishable.
  • Initially, all notifications are marked as unread with a visual indicator.
  • Clicking on an unread notification or dismissing it marks it as read, updating its visual state.
  • The component gracefully handles an empty notification list (e.g., displays a "No new notifications" message).

Constraints

Constraints & assumptions

  • You should use React with TypeScript.
  • Manage all notification state within the NotificationCenter component using React hooks (e.g., useState). No external state management libraries (like Redux, Zustand) are permitted.
  • No backend integration is required; use the provided mock data as the initial set of notifications.
  • Focus on functional correctness and clean component structure.
  • Styling can be minimal but should clearly differentiate elements as per UI/UX expectations. You can use inline styles or /styles.css.
  • You do not need to implement complex animations or transitions.
  • The solution should be performant for up to ~50 notifications.

Out of scope

  • Real-time notification pushing (e.g., via WebSockets).
  • Persistent storage of notifications (e.g., local storage, IndexedDB).
  • Advanced filtering, grouping, or sorting of notifications.
  • Internationalization (i18n) for dates or messages.
  • Deep accessibility audits beyond basic ARIA attributes for interactive elements.

What interviewers evaluate

  • Component Design: How well the problem is broken down into modular, reusable React components.
  • State Management: Effective and idiomatic use of React hooks (useState, useEffect) for managing component state.
  • TypeScript Usage: Correct and consistent application of TypeScript for defining types and ensuring type safety.
  • UI/UX Implementation: Accuracy in meeting the specified UI/UX and acceptance criteria, including visual distinctions and interactive elements.
  • Code Quality: Readability, maintainability, and adherence to best practices for React development.

Loading editor...