diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2024-10-29 16:22:33 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2024-10-29 16:22:33 +0700 |
| commit | daaf32f9dd3af860013b70d04c89f4cca84724b1 (patch) | |
| tree | fb37b9089eebfa1dc3949117ea00211c6cfe5a50 /src/lib | |
| parent | 9054afb2c842a1177dbcf0842aadf2ad14403cde (diff) | |
<iman> updarte pengajuan tempo
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/pengajuan-tempo/api/createPengajuanTempoApi.js | 16 | ||||
| -rw-r--r-- | src/lib/pengajuan-tempo/component/PengajuanTempo.jsx | 50 | ||||
| -rw-r--r-- | src/lib/pengajuan-tempo/component/Pengiriman.jsx | 6 |
3 files changed, 66 insertions, 6 deletions
diff --git a/src/lib/pengajuan-tempo/api/createPengajuanTempoApi.js b/src/lib/pengajuan-tempo/api/createPengajuanTempoApi.js new file mode 100644 index 00000000..2d3a7357 --- /dev/null +++ b/src/lib/pengajuan-tempo/api/createPengajuanTempoApi.js @@ -0,0 +1,16 @@ +import odooApi from '@/core/api/odooApi'; +import { getAuth } from '@/core/utils/auth'; + +const createPengajuanTempoApi = async ({ data }) => { + const auth = getAuth(); + console.log('data', data); + const dataPengajuanTempo = await odooApi( + 'POST', + `/api/v1/partner/pengajuan_tempo`, + data + ); + console.log('dataPengajuanTempo', dataPengajuanTempo); + return dataPengajuanTempo; +}; + +export default createPengajuanTempoApi; diff --git a/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx b/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx index d44d44e6..0efea807 100644 --- a/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx +++ b/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx @@ -18,6 +18,7 @@ import { usePengajuanTempoStoreDokumen, } from '../../../../src-migrate/modules/register/stores/usePengajuanTempoStore'; import { ChevronRightIcon, ChevronLeftIcon } from '@heroicons/react/24/outline'; +import createPengajuanTempoApi from '../api/createPengajuanTempoApi'; const PengajuanTempo = () => { const [currentStep, setCurrentStep] = React.useState(0); const NUMBER_OF_STEPS = 6; @@ -71,7 +72,7 @@ const PengajuanTempo = () => { formPengiriman, formSupplier, formDokumen, - <div>Konfirmasi</div>, + '', ]; const stepDivsUpdateForm = [ updateForm, @@ -89,6 +90,21 @@ const PengajuanTempo = () => { 'Dokumen', 'Konfirmasi', ]; + const combineForms = () => { + return stepDivsForm.reduce((accumulator, currentForm, index) => { + if (currentForm && typeof currentForm === 'object') { + if (index === 3) { + if (!accumulator.formSupplier) { + accumulator.formSupplier = []; + } + accumulator.formSupplier.push(...currentForm); + } else { + return { ...accumulator, ...currentForm }; + } + } + return accumulator; + }, {}); + }; // const stepLabels = [ // `${auth.partnerId}_informasi_perusahaan`, @@ -148,8 +164,36 @@ const PengajuanTempo = () => { } setCurrentStep((prev) => (prev === NUMBER_OF_STEPS - 1 ? prev : prev + 1)); }; - const handleDaftarTempo = () => { - router.push('/pengajuan-tempo/finish?tempo_id=SO-2023-06480'); + const handleDaftarTempo = async () => { + for (const error of stepDivsError) { + if (error.length > 0) { + console.log('ada yang salah'); + return; // Keluar dari fungsi jika ada error + } + } + const combinedData = combineForms(); + console.log('combinedData', combinedData); + const data = { + ...combinedData, + parent_id: auth.partnerId, + }; + + const productOrder = formSupplier.map((product) => ({ + supplier: product.supplier, + pic: product.pic, + telepon: product.telepon, + quantitydurasiTempo: product.durasiTempo, + creditLimit: product.creditLimit, + })); + const data2 = { + form: JSON.stringify(productOrder), + parent_id: auth.partnerId, + }; + const address = await createPengajuanTempoApi({ combinedData }); + + console.log('Sukses Daftar'); + // router.push('/pengajuan-tempo/finish?tempo_id=SO-2023-06480'); + // if (!isFormValid) { // setNotValid(true); // setButtonSubmitClick(!buttonSubmitClick); diff --git a/src/lib/pengajuan-tempo/component/Pengiriman.jsx b/src/lib/pengajuan-tempo/component/Pengiriman.jsx index 2497fb00..89d8ed44 100644 --- a/src/lib/pengajuan-tempo/component/Pengiriman.jsx +++ b/src/lib/pengajuan-tempo/component/Pengiriman.jsx @@ -413,8 +413,8 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => { </div> <div className='w-1/3'> <input - id='zip' - name='zip' + id='zipPengiriman' + name='zipPengiriman' ref={zipRef} placeholder='Kode Pos' type='number' @@ -424,7 +424,7 @@ const Pengiriman = ({ chekValid, buttonSubmitClick, isKonfirmasi }) => { /> {chekValid && ( <div className='text-caption-2 text-danger-500 mt-1'> - {errorsPengiriman.zip} + {errorsPengiriman.zipPengiriman} </div> )} </div> |
