From dd8a56ad12d054e121965c41bcb077158690b208 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 17 Dec 2024 17:07:44 +0700 Subject: update code --- src/lib/pengajuan-tempo/component/Konfirmasi.jsx | 4 +- .../pengajuan-tempo/component/KontakPerusahaan.jsx | 36 ++-- .../pengajuan-tempo/component/PengajuanTempo.jsx | 9 +- src/lib/pengajuan-tempo/component/Pengiriman.jsx | 214 ++++++++++++--------- src/lib/pengajuan-tempo/component/Referensi.jsx | 2 +- .../component/informasiPerusahaan.jsx | 103 ++++++++-- 6 files changed, 236 insertions(+), 132 deletions(-) (limited to 'src') diff --git a/src/lib/pengajuan-tempo/component/Konfirmasi.jsx b/src/lib/pengajuan-tempo/component/Konfirmasi.jsx index 78591c48..0e593ac4 100644 --- a/src/lib/pengajuan-tempo/component/Konfirmasi.jsx +++ b/src/lib/pengajuan-tempo/component/Konfirmasi.jsx @@ -172,9 +172,7 @@ const Konfirmasi = ({ chekValid, buttonSubmitClick }) => { setValue('industry_id', parseInt(form.industry_id)); } }, [form]); - const handleLabelClick = () => { - setIndustriesOpen(!industriesOpen); - }; + return ( <> {isDesktop && ( diff --git a/src/lib/pengajuan-tempo/component/KontakPerusahaan.jsx b/src/lib/pengajuan-tempo/component/KontakPerusahaan.jsx index b3d5bce7..e937baec 100644 --- a/src/lib/pengajuan-tempo/component/KontakPerusahaan.jsx +++ b/src/lib/pengajuan-tempo/component/KontakPerusahaan.jsx @@ -130,9 +130,12 @@ const KontakPerusahaan = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => { /> {chekValid && ( -
- {errorsKontakPerson.direkturName} -
+ <> +
+ {errorsKontakPerson.direkturName}{' '} + {errorsKontakPerson.direkturTittle} +
+ )} @@ -230,9 +233,12 @@ const KontakPerusahaan = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => { /> {chekValid && ( -
- {errorsKontakPerson.purchasingName} -
+ <> +
+ {errorsKontakPerson.purchasingName}{' '} + {errorsKontakPerson.purchasingTittle} +
+ )} @@ -339,9 +345,12 @@ const KontakPerusahaan = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => { /> {chekValid && ( -
- {errorsKontakPerson.financeName} -
+ <> +
+ {errorsKontakPerson.financeName}{' '} + {errorsKontakPerson.financeTittle} +
+ )} @@ -454,7 +463,8 @@ const KontakPerusahaan = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => { {chekValid && (
- {errorsKontakPerson.direkturName} + {errorsKontakPerson.direkturName}{' '} + {errorsKontakPerson.direkturTittle}
)} @@ -536,7 +546,8 @@ const KontakPerusahaan = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => { {chekValid && (
- {errorsKontakPerson.purchasingName} + {errorsKontakPerson.purchasingName}{' '} + {errorsKontakPerson.purchasingTittle}
)} @@ -615,7 +626,8 @@ const KontakPerusahaan = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => { {chekValid && (
- {errorsKontakPerson.financeName} + {errorsKontakPerson.financeName}{' '} + {errorsKontakPerson.financeTittle}
)} diff --git a/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx b/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx index d7c1dfac..22227624 100644 --- a/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx +++ b/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx @@ -33,7 +33,7 @@ const PengajuanTempo = () => { const { isDesktop, isMobile } = useDevice(); const [currentStep, setCurrentStep] = React.useState(0); const NUMBER_OF_STEPS = 6; - const [isLoading, setIsLoading] = useState(true); + const [isLoading, setIsLoading] = useState(false); const [bigData, setBigData] = useState(); const [idTempo, setIdTempo] = useState(0); const { form, errors, validate, updateForm } = usePengajuanTempoStore(); @@ -547,9 +547,10 @@ const PengajuanTempo = () => { const handleCheckChange = (checked) => { setIsCheckedTNC(checked); }; - if (isLoading && !bigData) { - return; - } + // if (isLoading && !bigData) { + // return; + // } + console.log('bigData', bigData); return ( <>
diff --git a/src/lib/pengajuan-tempo/component/Pengiriman.jsx b/src/lib/pengajuan-tempo/component/Pengiriman.jsx index 068cf73c..11586267 100644 --- a/src/lib/pengajuan-tempo/component/Pengiriman.jsx +++ b/src/lib/pengajuan-tempo/component/Pengiriman.jsx @@ -34,14 +34,6 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => { const [zipsInvoice, setZipsInvoice] = useState([]); const [sameAddress, setSameAddress] = useState(false); const [sameAddressStreet, setSameAddressStreet] = useState(false); - const [everyWeekday, setEveryWeekday] = useState(false); - const [everyWeek, setEveryWeek] = useState(false); - const [tukarInvoice, setTukarInvoice] = useState(false); - const [everyWeekdayPembayaran, setEveryWeekdayPembayaran] = useState(false); - const [everyWeekPembayaran, setEveryWeekPembayaran] = useState(false); - const [tukarInvoicePembayaran, setTukarInvoicePembayaran] = useState(false); - const [selectedRadio, setSelectedRadio] = useState(''); - const [selectedRadioInvoice, setSelectedRadioInvoice] = useState(''); const [selectedIds, setSelectedIds] = useState( formPengiriman.dokumenPengiriman @@ -306,46 +298,6 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => { updateFormPengiriman(name, value); validatePengiriman(); }; - const handleRadioChange = (value) => { - setSelectedRadio(value); - if (value == 'everyWeekday') { - setEveryWeekday(!everyWeekday); - } else if (value == 'everyWeek') { - setEveryWeek(!everyWeek); - } else { - setTukarInvoice(!tukarInvoice); - } - validatePengiriman(); - }; - const handleRadioChangeInvoice = (value) => { - setSelectedRadioInvoice(value); - if (value == 'everyWeekdayPembayaran') { - setEveryWeekdayPembayaran(!everyWeekdayPembayaran); - } else if (value == 'everyWeekPembayaran') { - setEveryWeekPembayaran(!everyWeekPembayaran); - } else { - setTukarInvoicePembayaran(!tukarInvoicePembayaran); - } - validatePengiriman(); - }; - const handleEveryWeekday = () => { - setEveryWeekday(!everyWeekday); - }; - const handleEveryWeek = () => { - setEveryWeek(!everyWeek); - }; - const handleTukarInvoice = () => { - setTukarInvoice(!tukarInvoice); - }; - const handleEveryWeekdayPembayaran = () => { - setEveryWeekdayPembayaran(!everyWeekdayPembayaran); - }; - const handleEveryWeekPembayaran = () => { - setEveryWeekPembayaran(!everyWeekPembayaran); - }; - const handleTukarInvoicePembayaran = () => { - setTukarInvoicePembayaran(!tukarInvoicePembayaran); - }; const isFormValid = useMemo( () => Object.keys(errorsPengiriman).length === 0, @@ -842,7 +794,7 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => {
{chekValid && (
- {errorsPengiriman.PICName} + {errorsPengiriman.PICName} {errorsPengiriman.PICTittle}
)} @@ -968,7 +920,7 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => { /> {chekValid && (
- {errors.subDistrictPengiriman} + {errorsPengiriman.subDistrictPengiriman}
)} @@ -987,7 +939,7 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => { /> {chekValid && (
- {errors.subDistrictPengiriman} + {errorsPengiriman.subDistrictPengiriman}
)} @@ -996,19 +948,39 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => { name='zipPengiriman' control={control} render={(props) => ( - + <> + {/* Jika zips tidak kosong, tampilkan dropdown */} + {zips.length > 0 ? ( + + ) : ( + // Jika zips kosong, tampilkan input manual + + )} + )} /> {chekValid && (
- {errors.zipPengiriman} + {errorsPengiriman.zipPengiriman}
)} @@ -1054,7 +1026,8 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => { {chekValid && (
- {errorsPengiriman.invoicePic} + {errorsPengiriman.invoicePic}{' '} + {errorsPengiriman.invoicePicTittle}
)} @@ -1186,7 +1159,7 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => { /> {chekValid && (
- {errors.districtInvoice} + {errorsPengiriman.districtInvoice}
)} @@ -1205,7 +1178,7 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => { /> {chekValid && (
- {errors.subDistrictsInvoice} + {errorsPengiriman.subDistrictsInvoice}
)} @@ -1214,19 +1187,37 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => { name='zipInvoice' control={control} render={(props) => ( - + <> + {zipsInvoice.length > 0 ? ( + + ) : ( + + )} + )} /> {chekValid && (
- {errors.zipInvoice} + {errorsPengiriman.zipInvoice}
)} @@ -1486,7 +1477,7 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => { {chekValid && (
- {errorsPengiriman.PICName} + {errorsPengiriman.PICName} {errorsPengiriman.PICTittle}
)} @@ -1607,7 +1598,7 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => { /> {chekValid && (
- {errors.subDistrictPengiriman} + {errorsPengiriman.subDistrictPengiriman}
)} @@ -1626,7 +1617,7 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => { /> {chekValid && (
- {errors.subDistrictPengiriman} + {errorsPengiriman.subDistrictPengiriman}
)} @@ -1635,17 +1626,35 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => { name='zipPengiriman' control={control} render={(props) => ( - + <> + {/* Jika zips tidak kosong, tampilkan dropdown */} + {zips.length > 0 ? ( + + ) : ( + // Jika zips kosong, tampilkan input manual + + )} + )} /> {chekValid && (
- {errors.zipPengiriman} + {errorsPengiriman.zipPengiriman}
)} @@ -1685,7 +1694,8 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => { {chekValid && (
- {errorsPengiriman.invoicePic} + {errorsPengiriman.invoicePic}{' '} + {errorsPengiriman.invoicePicTittle}
)} @@ -1793,7 +1803,7 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => { /> {chekValid && (
- {errors.districtInvoice} + {errorsPengiriman.districtInvoice}
)} @@ -1812,7 +1822,7 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => { /> {chekValid && (
- {errors.subDistrictsInvoice} + {errorsPengiriman.subDistrictsInvoice}
)} @@ -1821,17 +1831,37 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => { name='zipInvoice' control={control} render={(props) => ( - + <> + {zipsInvoice.length > 0 ? ( + + ) : ( + + )} + )} /> {chekValid && (
- {errors.zipInvoice} + {errorsPengiriman.zipInvoice}
)} diff --git a/src/lib/pengajuan-tempo/component/Referensi.jsx b/src/lib/pengajuan-tempo/component/Referensi.jsx index 38693d18..8db321d1 100644 --- a/src/lib/pengajuan-tempo/component/Referensi.jsx +++ b/src/lib/pengajuan-tempo/component/Referensi.jsx @@ -415,7 +415,7 @@ const Referensi = ({ chekValid, buttonSubmitClick, data }) => {

Daftar Nama Supplier

-
+ {/*
*/}
{supplierData.map((supplier, index) => (
diff --git a/src/lib/pengajuan-tempo/component/informasiPerusahaan.jsx b/src/lib/pengajuan-tempo/component/informasiPerusahaan.jsx index 9850e927..4bc04a3f 100644 --- a/src/lib/pengajuan-tempo/component/informasiPerusahaan.jsx +++ b/src/lib/pengajuan-tempo/component/informasiPerusahaan.jsx @@ -73,9 +73,9 @@ const InformasiPerusahaan = ({ const watchState = watch('state'); useEffect(() => { - setValue('city', ''); - setValue('district', ''); - setValue('subDistrict', ''); + // setValue('city', ''); + // setValue('district', ''); + // setValue('subDistrict', ''); if (watchState) { updateForm('state', `${watchState}`); validate(); @@ -133,6 +133,15 @@ const InformasiPerusahaan = ({ useEffect(() => { let kelurahan = ''; + let kecamatan = ''; + + if (watchDistrict) { + for (const data in districts) { + if (districts[data].value == watchDistrict) { + kecamatan = districts[data].label.toLowerCase(); + } + } + } if (watchsubDistrict) { updateForm('subDistrict', `${watchsubDistrict}`); @@ -147,13 +156,30 @@ const InformasiPerusahaan = ({ `https://alamat.thecloudalert.com/api/cari/index/?keyword=${kelurahan}` ); + let dataMasuk = []; // Array untuk menyimpan kode pos yang sudah diproses + const result = await response.json(); - const dataZips = result.result.map((zip) => ({ - value: parseInt(zip.kodepos), - label: zip.kodepos, - })); - setZips(dataZips); + + // Filter dan map data + const dataZips = result.result + .filter((zip) => zip.kecamatan.toLowerCase() === kecamatan) // Filter berdasarkan kecamatan + .filter((zip) => { + // Pastikan zip.kodepos belum ada di dataMasuk + if (dataMasuk.includes(zip.kodepos)) { + return false; // Jika sudah ada, maka skip (tidak akan ditambahkan) + } else { + dataMasuk.push(zip.kodepos); // Tambahkan ke dataMasuk + return true; // Tambahkan zip ke hasil + } + }) + .map((zip) => ({ + value: parseInt(zip.kodepos), + label: zip.kodepos, + })); + + setZips(dataZips); // Set hasil ke state }; + loadZip(); } }, [watchsubDistrict, setValue, subDistricts]); @@ -744,14 +770,33 @@ const InformasiPerusahaan = ({ name='zip' control={control} render={(props) => ( - + <> + {/* Jika zips tidak kosong, tampilkan dropdown */} + {zips.length > 0 ? ( + + ) : ( + // Jika zips kosong, tampilkan input manual + + )} + )} /> + {chekValid && (
{errors.zip} @@ -1276,12 +1321,30 @@ const InformasiPerusahaan = ({ name='zip' control={control} render={(props) => ( - + <> + {/* Jika zips tidak kosong, tampilkan dropdown */} + {zips.length > 0 ? ( + + ) : ( + // Jika zips kosong, tampilkan input manual + + )} + )} /> {chekValid && ( -- cgit v1.2.3