Overview
Zerodha requires users to submit various documents (e.g., PAN card, Aadhaar card, bank statements) for KYC verification during account opening or updates. This process often involves uploading multiple files. Your task is to build a robust and user-friendly file upload component that allows users to select and manage documents before initiating an upload. This problem focuses on the client-side UI and logic for handling file selection, validation, and status updates.
What you need to do / Task
Build a React component that fulfills the following requirements:
- File Selection:
- Allow users to select files using a traditional file input dialog (triggered by a button click).
- Implement a drag-and-drop zone where users can drag files from their local system directly into the component.
- File Display & Management:
- As files are selected (via either method), display a list of these files. Each item in the list should show:
- File name
- File size (e.g., "2.5 MB")
- A status indicator (e.g., "Pending", "Uploading...", "Uploaded", "Failed")
- A button/icon to remove the file from the list before an overall upload is triggered.
- Client-side Validation:
- Before adding a file to the display list, validate it against the specified constraints (file type and size).
- If a file fails validation, provide clear feedback to the user (e.g., an error message next to the invalid file or a toast notification). Do not add invalid files to the main upload list.
- Simulated Upload Process:
- Add an "Upload All" button. When clicked, iterate through the pending files and simulate an upload for each.
- The simulation should mimic an asynchronous operation (e.g., using
setTimeout).
- Randomly simulate success or failure for each file after a short delay (e.g., 1-2 seconds).
- Update the status of each file in the display list accordingly ("Uploading...", "Uploaded", "Failed").
UI/UX expectations
- A clearly delineated drag-and-drop area, perhaps with a dashed border.
- A prominent button to "Select Files" that triggers the file input.
- The list of selected files should be easy to read and manage.
- Error messages for invalid files should be user-friendly and informative.
- The component should be responsive enough for typical desktop use.
Acceptance criteria
- User can successfully drag and drop files into the designated area.
- User can click a button to open a file selection dialog and add files.
- Only files meeting the type and size constraints are added to the list.
- Each selected file is displayed with its name, size, and current status.
- Users can remove individual files from the list before uploading.
- Clicking "Upload All" triggers a simulated asynchronous upload for all pending files.
- File statuses are updated correctly during and after the simulated upload.
- Invalid files are rejected with appropriate user feedback.