summaryrefslogtreecommitdiff
path: root/src/lib/pengajuan-tempo/component/Pengiriman.jsx
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2025-05-14 09:27:26 +0700
committerit-fixcomart <it@fixcomart.co.id>2025-05-14 09:27:26 +0700
commit29ecab270822500ead372d8d3e05c9281a514715 (patch)
treea32735f4b7fab774de6a2bbee9380f363c51bec2 /src/lib/pengajuan-tempo/component/Pengiriman.jsx
parentdd66804b05166ad6bb71bf54fe3374d9897fee86 (diff)
parent746a11b810ae9e8a974a76d0548297cd0faff9b5 (diff)
Merge branch 'new-release' into CR/form-merchant
Diffstat (limited to 'src/lib/pengajuan-tempo/component/Pengiriman.jsx')
-rw-r--r--src/lib/pengajuan-tempo/component/Pengiriman.jsx310
1 files changed, 294 insertions, 16 deletions
diff --git a/src/lib/pengajuan-tempo/component/Pengiriman.jsx b/src/lib/pengajuan-tempo/component/Pengiriman.jsx
index 755cf45d..a8e7fd22 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,11 +302,66 @@ 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();
+ }
+ };
const isFormValid = useMemo(
() => Object.keys(errorsPengiriman).length === 0,
[errorsPengiriman]
);
+ const tukarInvoiceInputRef = useRef(null);
+ const tukarInvoiceInputPembayaranRef = useRef(null);
const PICNameRef = useRef(null);
const streetPengirimanRef = useRef(null);
const statePengirimanRef = useRef(null);
@@ -311,7 +369,9 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
const districtPengirimanRef = useRef(null);
const subDistrictPengirimanRef = useRef(null);
const zipRef = useRef(null);
+ const PICBarangMobileRef = useRef(null);
const invoicePicRef = useRef(null);
+ const invoicePicMobileRef = useRef(null);
const streetInvoiceRef = useRef(null);
const stateInvoiceRef = useRef(null);
const cityInvoiceRef = useRef(null);
@@ -332,6 +392,14 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
behavior: 'smooth',
block: 'center',
};
+ if (errorsPengiriman.tukarInvoiceInput && tukarInvoiceInputRef.current) {
+ tukarInvoiceInputRef.current.scrollIntoView(options);
+ return;
+ }
+ if (errorsPengiriman.tukarInvoiceInputPembayaran && tukarInvoiceInputPembayaranRef.current) {
+ tukarInvoiceInputPembayaranRef.current.scrollIntoView(options);
+ return;
+ }
if (errorsPengiriman.PICName && PICNameRef.current) {
PICNameRef.current.scrollIntoView(options);
return;
@@ -366,10 +434,18 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
zipRef.current.scrollIntoView(options);
return;
}
+ if (errorsPengiriman.PICBarangMobile && PICBarangMobileRef.current) {
+ PICBarangMobileRef.current.scrollIntoView(options);
+ return;
+ }
if (errorsPengiriman.invoicePic && invoicePicRef.current) {
invoicePicRef.current.scrollIntoView(options);
return;
}
+ if (errorsPengiriman.invoicePicMobile && invoicePicMobileRef.current) {
+ invoicePicMobileRef.current.scrollIntoView(options);
+ return;
+ }
if (errorsPengiriman.streetInvoice && streetInvoiceRef.current) {
streetInvoiceRef.current.scrollIntoView(options);
return;
@@ -803,6 +879,38 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
<div className='flex flex-row justify-between items-start'>
<div className='w-2/5'>
<label className='form-label text-nowrap'>
+ No. HP PIC Penerimaan Barang
+ </label>
+ {!isKonfirmasi && (
+ <span className='text-xs opacity-60'>
+ isi nomor PIC penerimaan barang yang bertanggung jawab di
+ perusahaan anda
+ </span>
+ )}
+ </div>
+ <div className='w-3/5'>
+ <input
+ id='PICBarangMobile'
+ name='PICBarangMobile'
+ ref={PICBarangMobileRef}
+ placeholder='Masukkan nomor PIC penerimaan barang'
+ value={formPengiriman.PICBarangMobile}
+ type='tel'
+ className='form-input'
+ aria-invalid={errorsPengiriman.PICBarangMobile}
+ onChange={handleInputChange}
+ />
+ {chekValid && (
+ <div className='text-caption-2 text-danger-500 mt-1'>
+ {errorsPengiriman.PICBarangMobile}
+ </div>
+ )}
+ </div>
+ </div>
+
+ <div className='flex flex-row justify-between items-start'>
+ <div className='w-2/5'>
+ <label className='form-label text-nowrap'>
Alamat Pengiriman Barang
</label>
{!isKonfirmasi && (
@@ -954,9 +1062,7 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
<HookFormSelect
{...props}
options={zips}
- disabled={
- !watchsubDistrict || sameAddressStreet
- }
+ disabled={sameAddressStreet}
placeholder='Zip'
/>
) : (
@@ -967,9 +1073,7 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
ref={zipRef}
placeholder='Kode Pos'
type='number'
- disabled={
- !watchsubDistrict || sameAddressStreet
- }
+ disabled={sameAddressStreet}
value={formPengiriman.zipPengiriman}
className='form-input'
onChange={handleInputChange}
@@ -1035,6 +1139,38 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
<div className='flex flex-row justify-between items-start'>
<div className='w-2/5'>
+ <label className='form-label text-nowrap'>
+ No. HP PIC Penerimaan Invoice
+ </label>
+ {!isKonfirmasi && (
+ <span className='text-xs opacity-60'>
+ isi nomor PIC penerimaan invoice yang bertanggung jawab di
+ perusahaan anda
+ </span>
+ )}
+ </div>
+ <div className='w-3/5'>
+ <input
+ id='invoicePicMobile'
+ name='invoicePicMobile'
+ ref={invoicePicMobileRef}
+ placeholder='Masukkan nomor PIC Penerimaan Invoice'
+ value={formPengiriman.invoicePicMobile}
+ type='tel'
+ className='form-input'
+ aria-invalid={errorsPengiriman.invoicePicMobile}
+ onChange={handleInputChange}
+ />
+ {chekValid && (
+ <div className='text-caption-2 text-danger-500 mt-1'>
+ {errorsPengiriman.invoicePicMobile}
+ </div>
+ )}
+ </div>
+ </div>
+
+ <div className='flex flex-row justify-between items-start'>
+ <div className='w-2/5'>
<label className='form-label text-nowrap'>
Alamat Pengiriman Invoice
</label>
@@ -1192,9 +1328,7 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
<HookFormSelect
{...props}
options={zipsInvoice}
- disabled={
- !watchsubDistrictInvoice || sameAddress
- }
+ disabled={sameAddress}
placeholder='Zip'
/>
) : (
@@ -1204,9 +1338,7 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
ref={zipInvoiceRef}
placeholder='Kode Pos'
type='number'
- disabled={
- !watchsubDistrictInvoice || sameAddress
- }
+ disabled={sameAddress}
value={formPengiriman.zipInvoice}
className='form-input'
onChange={handleInputChange}
@@ -1231,11 +1363,10 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
<div className='w-2/5'>
<label className='form-label text-wrap'>
Jadwal Penukaran Invoice{' '}
- <span className=' opacity-60'>(Opsional)</span>
</label>
{!isKonfirmasi && (
<span className='text-xs opacity-60'>
- isi jika perusahaan anda memiliki jadwal penukaran invoice
+ isi jadwal penukaran invoice
</span>
)}
</div>
@@ -1248,9 +1379,17 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
value={formPengiriman.tukarInvoiceInput}
className='form-input'
rows={4}
+ aria-invalid={errorsPengiriman.tukarInvoiceInput}
+ ref={tukarInvoiceInputRef}
cols={40}
onChange={handleInputChange}
+ required
/>
+ {chekValid && (
+ <div className='text-caption-2 text-danger-500 mt-1'>
+ {errorsPengiriman.tukarInvoiceInput}
+ </div>
+ )}
</div>
</div>
@@ -1258,11 +1397,10 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
<div className='w-2/5'>
<label className='form-label text-nowrap'>
Jadwal Pembayaran{' '}
- <span className=' opacity-60'>(Opsional)</span>
</label>
{!isKonfirmasi && (
<span className='text-xs opacity-60'>
- isi jika perusahaan anda memiliki jadwal pembayaran
+ isi jadwal pembayaran
</span>
)}
</div>
@@ -1273,10 +1411,60 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
placeholder='Masukkan jadwal pembayaran'
value={formPengiriman.tukarInvoiceInputPembayaran}
className='form-input'
+ aria-invalid={errorsPengiriman.tukarInvoiceInputPembayaran}
+ ref={tukarInvoiceInputPembayaranRef}
rows={4}
cols={40}
onChange={handleInputChange}
+ required
/>
+ {chekValid && (
+ <div className='text-caption-2 text-danger-500 mt-1'>
+ {errorsPengiriman.tukarInvoiceInputPembayaran}
+ </div>
+ )}
+ </div>
+ </div>
+
+ <div className='w-full flex flex-row justify-between items-start'>
+ <div className='w-2/5'>
+ <label className='form-label text-nowrap'>
+ Prosedur Pengiriman{' '}
+ <span className=' opacity-60'>(Opsional)</span>
+ </label>
+ <span className='text-xs opacity-60 text-red-500'>
+ Format: pdf, jpeg, jpg, png. max file size 2MB
+ </span>
+ </div>
+ <div className='w-3/5'>
+ <div className='flex flex-row items-start gap-2'>
+ <label
+ htmlFor='dokumenProsedur'
+ className='cursor-pointer min-w-40 text-center bg-gray-200 hover:bg-gray-300 text-gray-700 py-2 px-4 rounded'
+ >
+ {formPengiriman?.dokumenProsedur?.name
+ ? 'Ubah Dokumen'
+ : 'Upload Dokumen'}
+ </label>
+ <input
+ id='dokumenProsedur'
+ name='dokumenProsedur'
+ type='file'
+ title=' '
+ className='hidden'
+ aria-invalid={formPengiriman.dokumenProsedur}
+ onChange={handleInputChangeFile}
+ accept='.pdf,.png,.jpg,.jpeg'
+ />
+ <span className='text-gray-600 line-clamp-2'>
+ {formPengiriman?.dokumenProsedur?.name}
+ </span>
+ </div>
+ {chekValid && (
+ <div className='text-caption-2 text-danger-500 mt-1'>
+ {errorsPengiriman.dokumenProsedur}
+ </div>
+ )}
</div>
</div>
@@ -1483,6 +1671,30 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
</div>
<div className='flex flex-col gap-2 justify-between items-start'>
+ <label className='form-label text-nowrap'>
+ No. HP PIC Penerimaan Barang
+ </label>
+ <div className='flex items-center border border-gray-300 rounded-md w-full'>
+ <input
+ id='PICBarangMobile'
+ name='PICBarangMobile'
+ ref={PICBarangMobileRef}
+ value={formPengiriman.PICBarangMobile}
+ placeholder='Masukkan nomor PIC penerimaan barang'
+ type='tel'
+ className='form-input'
+ aria-invalid={errorsPengiriman.PICBarangMobile}
+ onChange={handleInputChange}
+ />
+ </div>
+ {chekValid && (
+ <div className='text-caption-2 text-danger-500 mt-1'>
+ {errorsPengiriman.PICBarangMobile}
+ </div>
+ )}
+ </div>
+
+ <div className='flex flex-col gap-2 justify-between items-start'>
<label className='form-label text-nowrap'>
Alamat Pengiriman Barang
</label>
@@ -1701,6 +1913,30 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
</div>
<div className='flex flex-col gap-2 justify-between items-start'>
+ <label className='form-label text-nowrap'>
+ No. HP PIC Penerimaan Invoice
+ </label>
+ <div className='flex items-center border border-gray-300 rounded-md w-full'>
+ <input
+ id='invoicePicMobile'
+ name='invoicePicMobile'
+ ref={invoicePicMobileRef}
+ value={formPengiriman.invoicePicMobile}
+ placeholder='Masukkan nomor PIC Penerimaan Invoice'
+ type='tel'
+ className='form-input'
+ aria-invalid={errorsPengiriman.invoicePicMobile}
+ onChange={handleInputChange}
+ />
+ </div>
+ {chekValid && (
+ <div className='text-caption-2 text-danger-500 mt-1'>
+ {errorsPengiriman.PICBarangMobile}
+ </div>
+ )}
+ </div>
+
+ <div className='flex flex-col gap-2 justify-between items-start'>
<label className='form-label text-nowrap'>
Alamat Pengiriman Invoice
</label>
@@ -1920,6 +2156,48 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
</div>
</div>
+ <div className='w-full flex flex-col justify-between items-start gap-2'>
+ <div className=''>
+ <label className='form-label text-nowrap'>
+ Prosedur Pengiriman{' '}
+ <span className=' opacity-60'>(Opsional)</span>
+ </label>
+ </div>
+ <div className='flex flex-col gap-2'>
+ <div className='flex flex-row items-start gap-2'>
+ <label
+ htmlFor='dokumenProsedur'
+ className='cursor-pointer min-w-40 text-center bg-gray-200 hover:bg-gray-300 text-gray-700 py-2 px-4 rounded'
+ >
+ {formPengiriman?.dokumenProsedur?.name
+ ? 'Ubah Dokumen'
+ : 'Upload Dokumen'}
+ </label>
+ <input
+ id='dokumenProsedur'
+ name='dokumenProsedur'
+ type='file'
+ title=' '
+ className='hidden'
+ aria-invalid={errorsPengiriman.dokumenProsedur}
+ onChange={handleInputChangeFile}
+ accept='.pdf,.png,.jpg,.jpeg'
+ />
+ <span className='mt-2 text-gray-600 line-clamp-2'>
+ {formPengiriman?.dokumenProsedur?.name}
+ </span>
+ </div>
+ {chekValid && (
+ <div className='text-caption-2 text-danger-500 mt-1'>
+ {errorsPengiriman.dokumenProsedur}
+ </div>
+ )}
+ <span className='text-xs opacity-60 text-red-500'>
+ Format: pdf, jpeg, jpg, png. max file size 2MB
+ </span>
+ </div>
+ </div>
+
<div className='flex flex-col gap-2 justify-between items-start'>
<label className='form-label text-wrap'>
Apakah ada dokumen tanda terima yang diberikan pada saat