From dc7fcad0885e4cde8ba510817a69b759607524c7 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Thu, 6 Mar 2025 11:30:26 +0700 Subject: update code --- .../pengajuan-tempo/component/PengajuanTempo.jsx | 14 +- src/lib/pengajuan-tempo/component/Pengiriman.jsx | 173 +++++++++++++++++++-- 2 files changed, 167 insertions(+), 20 deletions(-) (limited to 'src/lib') diff --git a/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx b/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx index 0db5b371..ba184057 100644 --- a/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx +++ b/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx @@ -67,11 +67,6 @@ const PengajuanTempo = () => { const [notValid, setNotValid] = useState(false); const [buttonSubmitClick, setButtonSubmitClick] = useState(false); const stepDivs = [ - , { chekValid={notValid} buttonSubmitClick={buttonSubmitClick} />, + , { useEffect(() => { const cachedData = bigData; - + console.log('cachedData', cachedData); const loadBigData = async () => { if (cachedData) { // Ambil kunci-kunci yang relevan berdasarkan currentStep dari stepDivsForm @@ -298,6 +298,7 @@ const PengajuanTempo = () => { section: label, tempo_request: tempoRequest, ...formData, + formDokumenProsedur: formData.dokumenProsedur ? JSON.stringify(formData.dokumenProsedur) : false, }); if (address.id) { setIdTempo(address.id); @@ -466,6 +467,7 @@ const PengajuanTempo = () => { user_id: address2.userId, tempo_request: false, ...formPengiriman, + formDocs: JSON.stringify(formPengiriman.dokumenProsedur), }); if (address3.id && formattedDokumen.length > 0) { // Kirim dokumen yang sudah difilter diff --git a/src/lib/pengajuan-tempo/component/Pengiriman.jsx b/src/lib/pengajuan-tempo/component/Pengiriman.jsx index c78ee69c..097f82a3 100644 --- a/src/lib/pengajuan-tempo/component/Pengiriman.jsx +++ b/src/lib/pengajuan-tempo/component/Pengiriman.jsx @@ -13,6 +13,7 @@ import { } from '../../../../src-migrate/modules/register/stores/usePengajuanTempoStore'; import { toast } from 'react-hot-toast'; import useDevice from '@/core/hooks/useDevice'; +import getFileBase64 from '@/core/utils/getFileBase64'; const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => { const { control, watch, setValue } = useForm(); const { isDesktop, isMobile } = useDevice(); @@ -21,6 +22,7 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => { errorsPengiriman, validatePengiriman, updateFormPengiriman, + updateDokumenProsedur, } = usePengajuanTempoStorePengiriman(); const { form } = usePengajuanTempoStore(); const [states, setState] = useState([]); @@ -34,6 +36,7 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => { const [zipsInvoice, setZipsInvoice] = useState([]); const [sameAddress, setSameAddress] = useState(false); const [sameAddressStreet, setSameAddressStreet] = useState(false); + const [nameFile, setNameFile] = useState(); const [selectedIds, setSelectedIds] = useState( formPengiriman.dokumenPengiriman @@ -299,6 +302,60 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => { validatePengiriman(); }; + const handleInputChangeFile = async (event) => { + let fileBase64 = ''; + const { name } = event.target; + const file = event.target.files?.[0]; + // Allowed file extensions + const allowedExtensions = ['pdf', 'png', 'jpg', 'jpeg']; + let fileExtension = ''; + if (file) { + fileExtension = file.name.split('.').pop()?.toLowerCase(); // Extract file extension + + // Check if the file extension is allowed + if (!fileExtension || !allowedExtensions.includes(fileExtension)) { + toast.error( + 'Format file yang diijinkan adalah .pdf, .png, .jpg, atau .jpeg', + { duration: 4000 } + ); + + event.target.value = ''; + return; + } + + // Check for file size + if (file.size > 2000000) { + // try { + // const toastId = toast.loading('mencoba mengompresi file...'); + // // Compress image file + // const options = { + // maxSizeMB: 0.5, // Target size in MB + // maxWidthOrHeight: 1920, // Adjust as needed + // useWebWorker: true, + // }; + // const compressedFile = await imageCompression(file, options); + // toast.success('berhasil mengompresi file', { duration: 4000 }); + // // Convert compressed file to Base64 + // fileBase64 = await getFileBase64(compressedFile); + // updateFormDokumen( + // name, + // compressedFile.name, + // fileExtension, + // fileBase64 + // ); + // } catch (error) { + // toast.error('Gagal mengompresi file', { duration: 4000 }); + // } + toast.error('Max File Upload 2MB', { duration: 4000 }); + } else { + // Convert file to Base64 + fileBase64 = await getFileBase64(file); + updateDokumenProsedur(file.name, fileExtension, fileBase64); + } + validatePengiriman(); + } + }; + console.log('formPengiriman', formPengiriman); const isFormValid = useMemo( () => Object.keys(errorsPengiriman).length === 0, [errorsPengiriman] @@ -1032,8 +1089,6 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => { - -
-
- -
+
+
+ + {!isKonfirmasi && ( + + isi nomor PIC penerimaan invoice yang bertanggung jawab di + perusahaan anda + + )} +
+
+ {chekValid && ( +
+ {errorsPengiriman.invoicePicMobile} +
+ )}
- {chekValid && ( -
- {errorsPengiriman.invoicePicMobile} -
- )}
@@ -1497,6 +1560,47 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => { )}
+
+
+ + + Format: pdf, jpeg, jpg, png. max file size 2MB + +
+
+
+ + + + {formPengiriman?.dokumenProsedur?.name} + +
+ {chekValid && ( +
+ {errorsPengiriman.dokumenProsedur} +
+ )} +
+
@@ -1753,7 +1857,6 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => { -
+ +
+
+ +
+
+
+ + + + {formPengiriman?.dokumenProsedur?.name} + +
+ {chekValid && ( +
+ {errorsPengiriman.dokumenProsedur} +
+ )} + + Format: pdf, jpeg, jpg, png. max file size 2MB + +
+
-- cgit v1.2.3