feat(documents): implement document upload functionality for companies
- Added DocumentItem component to display uploaded documents in CompanyDetailsPage. - Introduced useUploadCompanyDocuments hook for handling document uploads. - Updated CreateCompany form to include document upload capabilities and validation for file types and sizes. - Enhanced API services to support batch document uploads and retrieval of document information. - Improved response handling in the file service for better error management and user feedback.
This commit is contained in:
@@ -193,6 +193,59 @@ export const validateImageFile = ({
|
||||
return null;
|
||||
};
|
||||
|
||||
/** Company document upload limits (see company-documents API guide). */
|
||||
export const ALLOWED_DOCUMENT_FILE_TYPES = [
|
||||
// Images
|
||||
"image/jpeg",
|
||||
"image/png",
|
||||
"image/gif",
|
||||
"image/webp",
|
||||
"image/svg+xml",
|
||||
// Documents
|
||||
"application/pdf",
|
||||
"application/msword",
|
||||
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
"application/vnd.ms-excel",
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
// Text / data
|
||||
"text/plain",
|
||||
"text/csv",
|
||||
"application/json",
|
||||
// Archives
|
||||
"application/zip",
|
||||
"application/x-rar-compressed",
|
||||
"application/x-7z-compressed",
|
||||
];
|
||||
|
||||
export const MAX_DOCUMENT_FILE_SIZE = 100 * 1024 * 1024; // 100 MB
|
||||
export const MAX_DOCUMENT_FILES = 20;
|
||||
|
||||
/** `accept` attribute mirroring the allowed document MIME types. */
|
||||
export const DOCUMENT_FILE_ACCEPT =
|
||||
".pdf,.doc,.docx,.xls,.xlsx,.png,.jpg,.jpeg,.gif,.webp,.svg,.txt,.csv,.json,.zip,.rar,.7z";
|
||||
|
||||
export const validateDocumentFile = ({
|
||||
file,
|
||||
allowedTypes = ALLOWED_DOCUMENT_FILE_TYPES,
|
||||
maxSize = MAX_DOCUMENT_FILE_SIZE,
|
||||
}: {
|
||||
file: File;
|
||||
allowedTypes?: string[];
|
||||
maxSize?: number;
|
||||
}): string | null => {
|
||||
// Browsers occasionally send an empty type; the server then infers it from
|
||||
// the file extension, so only reject explicitly disallowed types.
|
||||
if (file.type && !allowedTypes.includes(file.type)) {
|
||||
return `Unsupported file type: ${file.type}`;
|
||||
}
|
||||
|
||||
if (file.size > maxSize) {
|
||||
return "File size must be 100MB or less";
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
export const formatFileSize = (bytes: number) => {
|
||||
if (bytes < 1024) return `${bytes} B`;
|
||||
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
||||
|
||||
Reference in New Issue
Block a user