Frontend School

Nykaa Product Image Uploader

Machine Coding
medium

Nykaa Product Image Uploader

Medium
React
File Upload
UI
Frontend
Machine Coding

Overview

At Nykaa, providing a seamless experience for sellers to showcase their products is crucial. High-quality product images are a cornerstone of this experience. This problem challenges you to build a robust and user-friendly image upload component that handles multiple files, provides clear visual feedback, and ensures basic client-side data integrity before actual upload.

What you need to do / Task

Your task is to develop a React component named App that functions as a product image uploader. This component should allow users to select multiple image files, display them in a list, and manage their upload status.

  1. File Selection: Create a UI element (e.g., a button) that, when clicked, allows the user to select multiple image files (.jpg, .jpeg, .png, .gif).
  2. Display Selected Files: Once files are selected, display them in a list. Each list item should clearly show:
    • The file's name.
    • Its size, formatted for readability (e.g., "1.2 MB").
    • Its current status (e.g., "Pending", "Uploading...", "Uploaded", "Failed", "Invalid").
    • An "Upload" button.
    • A "Remove" button.
  3. Remove File Functionality: Implement the "Remove" button for each file. Clicking this button should delete the corresponding file from the selection list.
  4. Simulated Upload: Implement the "Upload" button for each file. Clicking this button should:
    • Update the file's status to "Uploading...".
    • Simulate an asynchronous upload operation (e.g., using setTimeout for 2-3 seconds).
    • After the simulated upload, update the file's status to either "Uploaded" or "Failed" (you can randomize this for demonstration purposes, e.g., 80% success rate).
    • Disable the "Upload" button once the file has been successfully uploaded.
  5. Clear All Functionality: Add a "Clear All" button that, when clicked, removes all files from the current selection list.
  6. Client-side Validation: Implement the following validation rules when files are selected:
    • File Type: Only allow image/jpeg, image/png, and image/gif files. Files of other types should be marked as "Invalid" with an appropriate error message.
    • File Size: Each file must not exceed 2 MB. Files larger than this should be marked as "Invalid" with an appropriate error message.

UI/UX expectations

  • The component should have a clear area or button for initiating file selection.
  • The list of selected files should be easy to read, with each file entry visually distinct.
  • Status indicators (e.g., text, potentially different colors) should clearly communicate the state of each file (pending, uploading, uploaded, failed, invalid).
  • Buttons should be appropriately enabled/disabled based on the file's status (e.g., "Upload" disabled during upload or after completion).
  • Validation error messages should be clearly displayed next to the invalid file.

Acceptance criteria

  • User can select multiple image files via a file input or button interaction.
  • Selected files are displayed in a list, showing name, formatted size, status, and action buttons ("Upload", "Remove").
  • Clicking "Remove" on a file correctly deletes it from the displayed list.
  • Clicking "Upload" on a file initiates a simulated asynchronous process, showing "Uploading..." then transitioning to "Uploaded" or "Failed".
  • The "Upload" button becomes disabled/hidden for files that are successfully uploaded.
  • Clicking "Clear All" effectively removes all files from the list.
  • Only image files (JPEG, PNG, GIF) are accepted; non-image files are marked "Invalid" with a message.
  • Files exceeding 2MB are marked "Invalid" with a message.
  • The UI provides clear feedback for all file statuses and validation errors.

Constraints

Constraints & assumptions

  • You should build a React functional component. No class components are required.
  • No actual backend integration is required. Simulate API calls using setTimeout.
  • Focus purely on client-side logic and UI rendering.
  • Assume a modern browser environment for file API support.
  • For simplicity, assume a maximum of 10 files can be in the selection list at any given time.

Out of scope

  • Drag-and-drop functionality for file selection.
  • Complex progress bars with percentage completion (simple text status is sufficient).
  • Advanced accessibility features beyond basic semantic HTML and button labels.
  • Server-side validation or actual file storage.

What interviewers evaluate

  • React State Management: Effective use of React hooks (useState, useRef) to manage the list of files and their individual statuses.
  • Asynchronous Operations: Correct handling and sequencing of simulated asynchronous events (file uploads) and subsequent UI updates.
  • Client-side Validation: Robust implementation of file type and size validation, providing clear user feedback.
  • Code Quality & Structure: Clean, modular, and readable component structure, demonstrating good practices for a React application.

Loading editor...