feat(FE-65): add file type validation for dokumen in MovementForm

This commit is contained in:
rstubryan
2025-10-14 10:31:34 +07:00
parent e7085ab4ff
commit b2f0bd6698
2 changed files with 19 additions and 0 deletions
@@ -61,6 +61,14 @@ const EkspedisiObjectSchema: Yup.ObjectSchema<EkspedisiSchema> = Yup.object({
no_surat_jalan: Yup.string().required('No surat jalan wajib diisi!'), no_surat_jalan: Yup.string().required('No surat jalan wajib diisi!'),
dokumen: Yup.mixed<string | File>() dokumen: Yup.mixed<string | File>()
.required('Dokumen wajib diisi!') .required('Dokumen wajib diisi!')
.test(
'fileType',
'Mohon upload file berformat PDF atau JPEG/JPG.',
(value) =>
typeof value === 'string' ||
(value instanceof File &&
['application/pdf', 'image/jpeg', 'image/jpg'].includes(value.type))
)
.test( .test(
'fileSize', 'fileSize',
'Ukuran dokumen maksimal 2 MB!', 'Ukuran dokumen maksimal 2 MB!',
@@ -817,6 +817,17 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
onChange={(e) => { onChange={(e) => {
const file = e.target.files?.[0]; const file = e.target.files?.[0];
if (file) { if (file) {
const allowedTypes = [
'application/pdf',
'image/jpeg',
'image/jpg',
];
if (!allowedTypes.includes(file.type)) {
toast.error(
'Mohon upload file berformat PDF atau JPEG/JPG.'
);
return;
}
if (file.size > 2 * 1024 * 1024) { if (file.size > 2 * 1024 * 1024) {
toast.error('Ukuran dokumen maksimal 2 MB!'); toast.error('Ukuran dokumen maksimal 2 MB!');
return; return;