1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-20 22:09:41 +02:00
portainer/app/react/components/form-components/yup-file-validation.ts

24 lines
490 B
TypeScript

import { mixed } from 'yup';
import { MixedSchema } from 'yup/lib/mixed';
type FileSchema = MixedSchema<File | undefined>;
export function file(): FileSchema {
return mixed();
}
export function withFileSize(fileValidation: FileSchema, maxSize: number) {
return fileValidation.test(
'fileSize',
'Selected file is too big.',
validateFileSize
);
function validateFileSize(file?: File) {
if (!file) {
return true;
}
return file.size <= maxSize;
}
}