mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
feat(FE-65): add file type validation for dokumen in MovementForm
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user