mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-08-27 01:22:49 +00:00
fix(DocumentSlots, StaffEvidence): add file size validation for uploads to enforce 5MB limit
This commit is contained in:
@@ -25,6 +25,8 @@ import {
|
||||
type DocumentRequirement,
|
||||
} from '@ema-platform/api';
|
||||
|
||||
const MAX_FILE_SIZE_BYTES = 5 * 1024 * 1024;
|
||||
|
||||
interface Props {
|
||||
requirements: DocumentRequirement[];
|
||||
attachments: Attachment[];
|
||||
@@ -68,6 +70,11 @@ export function DocumentSlots({
|
||||
|
||||
async function handle(documentKey: string, file: File | null) {
|
||||
if (!file) return;
|
||||
if (file.size > MAX_FILE_SIZE_BYTES) {
|
||||
setError(`File exceeds 5MB limit (${(file.size / 1024 / 1024).toFixed(1)}MB).`);
|
||||
resetRefs.current[documentKey]?.();
|
||||
return;
|
||||
}
|
||||
setBusy(documentKey);
|
||||
setError(null);
|
||||
const result = await uploadDocument({ ownerType, ownerId, documentKey, file });
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Badge, Button, FileButton, Group, Loader } from '@mantine/core';
|
||||
import { notifications } from '@mantine/notifications';
|
||||
import { IconCheck } from '@tabler/icons-react';
|
||||
import {
|
||||
localized,
|
||||
@@ -8,6 +9,8 @@ import {
|
||||
type StaffEvidenceRequirement,
|
||||
} from '@ema-platform/api';
|
||||
|
||||
const MAX_FILE_SIZE_BYTES = 5 * 1024 * 1024;
|
||||
|
||||
interface Props {
|
||||
staffId: string;
|
||||
evidence: StaffEvidenceRequirement[];
|
||||
@@ -42,6 +45,13 @@ export function StaffEvidence({ staffId, evidence, readOnly, onUploaded }: Props
|
||||
accept="application/pdf,image/jpeg,image/png"
|
||||
onChange={async (file) => {
|
||||
if (!file) return;
|
||||
if (file.size > MAX_FILE_SIZE_BYTES) {
|
||||
notifications.show({
|
||||
color: 'red',
|
||||
message: `File exceeds 5MB limit (${(file.size / 1024 / 1024).toFixed(1)}MB).`,
|
||||
});
|
||||
return;
|
||||
}
|
||||
setBusy(item.docKey);
|
||||
await uploadDocument({
|
||||
ownerType: 'APPLICATION_STAFF',
|
||||
|
||||
Reference in New Issue
Block a user