fix(DocumentSlots, StaffEvidence): add file size validation for uploads to enforce 5MB limit

This commit is contained in:
estifanos
2026-08-05 07:04:13 +00:00
parent 33fe9ac55c
commit e4e93384b1
2 changed files with 17 additions and 0 deletions

View File

@@ -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 });

View 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',