Overview
Clevertap's marketing platform empowers users to create engaging campaigns. A critical part of this process is uploading various assets like images and videos. We need a robust and user-friendly "Batch Asset Uploader" component that allows users to efficiently upload multiple files, monitor their progress, and handle potential issues. This problem challenges your ability to manage concurrent operations, handle UI updates, and provide a smooth user experience.
What you need to do / Task
Your goal is to build a React component called BatchAssetUploader that provides the following functionalities:
- File Selection:
- Allow users to select multiple files using a standard file input button.
- Implement a drag-and-drop interface for selecting files.
- File List Display:
- As files are selected (either via button or drag-and-drop), display them in a list.
- For each file, show its name, size, current status (e.g., "Pending", "Uploading", "Completed", "Failed"), and a progress bar during upload.
- Upload Simulation:
- Simulate an asynchronous file upload process. You do not need a real backend.
- Each file upload should take a random duration between 2 to 5 seconds.
- Simulate upload progress updates (e.g., update progress bar every 200ms).
- Randomly simulate failures for approximately 20% of uploads.
- Upload Cancellation:
- Provide a "Cancel" button next to each actively uploading file.
- Clicking "Cancel" should stop the ongoing simulated upload for that specific file and update its status to "Cancelled".
- Client-side Validation:
- Before starting an upload, validate each file:
- Max Size: Files must not exceed 5MB.
- Allowed Types: Only image files (JPEG, PNG, GIF) and video files (MP4, WebM) are allowed.
- Display clear error messages for invalid files (e.g., "File too large", "Unsupported file type").
- Overall Status:
- Provide a summary of the upload process (e.g., "X files uploaded successfully, Y failed, Z pending").
UI/UX expectations
- Drag-and-Drop Zone: A clearly demarcated area (e.g., a dashed border) that visually indicates when files are being dragged over it.
- File List: A scrollable list displaying each selected file. Each item should include:
- File icon (optional, but good if included).
- File name and size.
- Progress bar for active uploads.
- Status text (e.g., "Uploading (50%)", "Completed", "Failed", "Cancelled", "Pending").
- A "Cancel" button for files in "Pending" or "Uploading" state.
- Clear error messages for failed uploads or validation issues.
- Feedback: Provide immediate feedback on file selection, drag-over states, and upload progress/status.
Acceptance criteria
- Users can select multiple files via a button.
- Users can drag and drop multiple files into the designated area.
- Files exceeding 5MB are rejected with an error message.
- Files of unsupported types are rejected with an error message.
- Each valid file displays its name, size, and current status in a list.
- Uploading files show an individual progress bar that updates dynamically.
- Clicking "Cancel" on an uploading file stops its progress and marks it as "Cancelled".
- Upload failures (simulated) are clearly indicated with an error message.
- A summary displays the count of successfully uploaded, failed, and pending/active files.
- The UI remains responsive during concurrent uploads.