mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 21:41:57 +00:00
feat(FE): Enforce 2MB file limit and improve FileInput
This commit is contained in:
@@ -33,6 +33,7 @@ const FileInput = ({
|
||||
isError,
|
||||
errorMessage,
|
||||
disabled = false,
|
||||
required = false,
|
||||
onChange,
|
||||
onBlur,
|
||||
readOnly = false,
|
||||
@@ -56,6 +57,13 @@ const FileInput = ({
|
||||
)}
|
||||
>
|
||||
{label}
|
||||
{required && (
|
||||
<>
|
||||
<span className='tooltip tooltip-error' data-tip='required'>
|
||||
<span className='text-error'> *</span>
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
</label>
|
||||
)}
|
||||
|
||||
|
||||
@@ -1584,6 +1584,7 @@ const MovementForm = ({ type = 'add', initialValues }: MovementFormProps) => {
|
||||
</>
|
||||
) : (
|
||||
<FileInput
|
||||
accept='.pdf,.jpg,.jpeg,.png'
|
||||
name={`deliveries.${idx}.document`}
|
||||
onChange={(e) => {
|
||||
const file = e.target.files?.[0];
|
||||
|
||||
@@ -689,6 +689,16 @@ const PurchaseOrderAcceptApprovalForm = ({
|
||||
accept='.pdf,.jpg,.jpeg,.png'
|
||||
onChange={(e) => {
|
||||
const files = Array.from(e.target.files || []);
|
||||
const invalidFiles = files.filter(
|
||||
(file) => file.size > 2 * 1024 * 1024
|
||||
);
|
||||
|
||||
if (invalidFiles.length > 0) {
|
||||
toast.error('Ukuran dokumen maksimal 2 MB!');
|
||||
e.target.value = '';
|
||||
return;
|
||||
}
|
||||
|
||||
formik.setFieldValue('travel_documents', files);
|
||||
}}
|
||||
onBlur={formik.handleBlur}
|
||||
|
||||
@@ -392,7 +392,15 @@ export const PurchaseRequestAcceptApprovalFormSchema: Yup.ObjectSchema<PurchaseR
|
||||
.required('Item pembelian wajib diisi!')
|
||||
.typeError('Item pembelian wajib diisi!'),
|
||||
travel_documents: Yup.array()
|
||||
.of(Yup.mixed<File>().required())
|
||||
.of(
|
||||
Yup.mixed<File>()
|
||||
.required('Dokumen surat jalan wajib diupload!')
|
||||
.test('fileSize', 'Ukuran dokumen maksimal 2 MB', (value) => {
|
||||
if (!value) return true;
|
||||
if (value instanceof File) return value.size <= 2 * 1024 * 1024;
|
||||
return true;
|
||||
})
|
||||
)
|
||||
.required('Dokumen surat jalan wajib diupload!')
|
||||
.min(1, 'Minimal upload 1 dokumen surat jalan!')
|
||||
.typeError('Dokumen surat jalan wajib diupload!'),
|
||||
|
||||
Reference in New Issue
Block a user