Frontend School

Document Uploader for Service Partners

Machine Coding
medium

Document Uploader for Service Partners

Medium
React
Frontend
File Upload
UI/UX
State Management

Overview

Urban Company's success relies heavily on its network of skilled service partners. Often, these partners need to upload various documents or media—such as identity proofs, before-and-after service photos, or completion certificates—to comply with service guidelines or update their profiles. This problem focuses on building a robust and user-friendly frontend component that allows partners to efficiently upload multiple files, providing clear visual feedback and management capabilities before final submission. This component is crucial for streamlining operational workflows and ensuring data accuracy.

What you need to do / Task

Your task is to build a FileUploader React component with the following features:

  1. File Input: Implement a mechanism for users to select files, supporting both clicking to open a file dialog and drag-and-drop functionality into a designated area.
  2. Multiple File Support: Allow users to select and add multiple files simultaneously.
  3. File List Display: Display a clear list of all selected files. Each item in the list should show:
    • The file name.
    • The file size (formatted for readability, e.g., "1.2 MB").
    • For image files (image/*), a small thumbnail preview.
  4. File Removal: Provide an option to remove individual files from the list before they are uploaded.
  5. Simulated Upload Progress: When an "Upload All" button is clicked, simulate an upload process for each file. Display a progress bar or percentage for each file, updating it over a short duration (e.g., 2-3 seconds).
  6. Constraints Handling: Implement basic client-side validation for file type and size as specified in the constraints.

UI/UX expectations

  • Drag-and-Drop Zone: A clearly visible area indicating where files can be dropped, with visual feedback (e.g., border change) when files are dragged over it.
  • File List: A vertically stacked list of selected files, each with its details and actions arranged logically.
  • Thumbnails: Image thumbnails should be small and not distort the layout.
  • Progress Indicators: Progress bars should be intuitive and update smoothly.
  • Action Buttons: Clear "Select Files" and "Upload All" buttons.

Acceptance criteria

  • The component allows files to be added via both drag-and-drop and click-to-select methods.
  • Multiple files can be selected and displayed in the list.
  • Each listed file correctly shows its name and formatted size.
  • Image files (image/*) display a visual thumbnail preview.
  • Individual files can be removed from the list before upload.
  • Clicking "Upload All" triggers a simulated upload for each file, with a visible progress indicator updating for each.
  • Files exceeding size or type constraints are rejected with a user-friendly message (e.g., console log or simple alert).

Constraints

Constraints & assumptions

  • Max file size: Each individual file must not exceed 5 MB.
  • Max files: A maximum of 5 files can be selected for upload at any given time.
  • Accepted file types: Only image/* (e.g., JPEG, PNG) and .pdf files are allowed.
  • No backend: You are not required to implement any backend API calls. Simulate the upload process using setTimeout or similar frontend mechanisms.
  • Frontend Focus: The problem strictly focuses on frontend implementation, state management, and UI/UX.

Out of scope

  • Full accessibility implementation (beyond basic semantic elements).
  • Advanced image editing features (cropping, resizing).
  • Persistent storage of uploaded files or their states.
  • Complex error handling for network failures (simulated success is sufficient).

What interviewers evaluate

  • React Proficiency: Demonstrating strong command over React hooks (useState, useRef, useEffect) for managing component state and lifecycle.
  • Component Design: Ability to structure the component logically, potentially breaking it down into smaller, reusable parts.
  • File API Usage: Correct and efficient use of browser's File API for handling file selection, preview generation, and validation.
  • UI/UX Implementation: Creating an intuitive and responsive user interface for file management, including drag-and-drop feedback and progress indicators.
  • Code Quality: Writing clean, readable, and maintainable code with appropriate type definitions (TypeScript).

Loading editor...