Overview
In a modern document management system, users frequently need to upload multiple sensitive files simultaneously. A robust and user-friendly file upload component is crucial for ensuring a smooth experience, providing clear feedback on upload progress, and handling potential issues like invalid files or network failures.
What you need to do / Task
Your task is to build a React component that enables users to select and upload multiple files. You will need to simulate the asynchronous nature of file uploads and provide comprehensive feedback on their status.
- File Selection: Implement a mechanism for users to select one or more files from their local system.
- File List Display: Display a list of all selected files, showing their names, sizes, and initial 'Ready' status.
- File Removal: Allow users to remove individual files from the list before initiating the upload process.
- Mock Upload Functionality: Create a
mockUploadFile asynchronous function that simulates network latency (1-3 seconds) and introduces a ~20% chance of failure for any given file. This function should also report progress.
- Upload Process & Feedback: Implement an 'Upload All' button that initiates the mock upload for all 'Ready' files. During the upload, each file should display a progress indicator and its current status (e.g., 'Uploading...', 'Uploaded', 'Failed').
- Overall Status: Provide an overall status message to the user indicating whether all uploads completed successfully, some failed, or if the process is ongoing.
UI/UX expectations
- A clear button to trigger file selection.
- A list area displaying selected files. Each list item should show:
- File name and size.
- Current status (Ready, Uploading, Uploaded, Failed).
- A progress bar/indicator for files actively uploading.
- A 'Remove' button (e.g., an 'X') for files not yet uploaded or that failed.
- An 'Upload All' button to start the process for all selected files.
- Clear, concise messages for overall upload status (e.g., "Uploading files...", "All files uploaded", "Some uploads failed").
- The UI should be functional and easy to understand, even with basic styling.
Acceptance criteria
- Users can select multiple files using a standard file input.
- Selected files are displayed in a list with their name and size (in MB).
- Users can remove individual files from the list before upload.
- The 'Upload All' button becomes active only when files are selected.
- Clicking 'Upload All' initiates a mock asynchronous upload for each 'Ready' file.
- Each file displays a progress bar during its mock upload.
- Each file's status updates correctly to 'Uploaded' or 'Failed' upon completion of its mock upload.
- An overall status message is displayed, reflecting the aggregate outcome of all uploads.
- File selection adheres to specified type and size constraints, providing feedback for invalid files.