summaryrefslogtreecommitdiff
path: root/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-12-04 10:59:21 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-12-04 10:59:21 +0700
commit9a49b8d84761781531cb417731cb9ef802f63541 (patch)
tree140f9ca02190789d0d20f8ca13d00f20e81b6adc /src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
parent77f9843ad5072583cb1797d7ecf5ac80394bad3f (diff)
<iman> update pengajuan tempo
Diffstat (limited to 'src/lib/pengajuan-tempo/component/PengajuanTempo.jsx')
-rw-r--r--src/lib/pengajuan-tempo/component/PengajuanTempo.jsx90
1 files changed, 39 insertions, 51 deletions
diff --git a/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx b/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
index 97e64030..1704556e 100644
--- a/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
+++ b/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
@@ -176,12 +176,6 @@ const PengajuanTempo = () => {
`/api/v1/partner/detail-tempo/${auth.parentId}`
);
- console.log('Original dataPaymentTerm', dataPaymentTerm);
-
- const transformedData = transformKeysToCamelCase(dataPaymentTerm);
-
- console.log('Transformed dataPaymentTerm', transformedData);
-
setBigData(transformedData);
} catch (error) {
console.error('Error loading dataPaymentTerm:', error);
@@ -189,54 +183,50 @@ const PengajuanTempo = () => {
};
loadBigData();
- }, []);
-
- console.log('bigData', bigData);
+ }, [auth]);
useEffect(() => {
const cachedData = bigData;
- console.log('data_lama', getFromLocalStorage(stepLabels[currentStep]));
-
- if (cachedData) {
- // Ambil kunci-kunci yang relevan berdasarkan currentStep dari stepDivsForm
- const formKeys = stepDivsForm[currentStep]
- ? Object.keys(stepDivsForm[currentStep])
- : [];
- console.log('formKeys', formKeys);
- if (currentStep === 3) {
- console.log('cachedData', cachedData.supplierIds[0]);
- stepDivsUpdateForm[currentStep](cachedData.supplierIds);
- } else if (currentStep === 4) {
- formKeys.forEach((key) => {
- if (cachedData[key]) {
- // Proses hanya kunci yang ada di cachedData
- const { name, format, base64 } = cachedData[key];
- stepDivsUpdateForm[currentStep](key, name, format, base64);
- }
- });
- } else {
- formKeys.forEach((key) => {
- if (cachedData[key]) {
- // Ubah data menjadi string
- const stringData =
- typeof cachedData[key] === 'object'
- ? JSON.stringify(cachedData[key]) // Untuk objek atau array
- : String(cachedData[key]); // Untuk tipe primitif
- // Kirim data yang sudah diubah ke string ke stepDivsUpdateForm
- stepDivsUpdateForm[currentStep](key, stringData);
- }
- });
+ const loadBigData = async () => {
+ if (cachedData) {
+ // Ambil kunci-kunci yang relevan berdasarkan currentStep dari stepDivsForm
+ const formKeys = stepDivsForm[currentStep]
+ ? Object.keys(stepDivsForm[currentStep])
+ : [];
+ if (currentStep === 3) {
+ stepDivsUpdateForm[currentStep](cachedData.supplierIds);
+ } else if (currentStep === 4) {
+ formKeys.forEach((key) => {
+ if (cachedData[key]) {
+ // Proses hanya kunci yang ada di cachedData
+ const { name, format, base64 } = cachedData[key];
+ stepDivsUpdateForm[currentStep](key, name, format, base64);
+ }
+ });
+ } else {
+ formKeys.forEach((key) => {
+ if (bigData[key]) {
+ // Ubah data menjadi string
+ const stringData =
+ typeof bigData[key] === 'object'
+ ? JSON.stringify(bigData[key]) // Untuk objek atau array
+ : String(bigData[key]); // Untuk tipe primitif
+ // Kirim data yang sudah diubah ke string ke stepDivsUpdateForm
+ stepDivsUpdateForm[currentStep](key, stringData);
+ }
+ });
+ }
}
- }
-
+ };
+ loadBigData();
validate();
validateKontakPerson();
validatePengiriman();
validateDokumen();
validateSupplier();
updateHasSave(false);
- }, [currentStep, bigData]);
+ }, [currentStep, bigData, auth]);
const goToNextStep = () => {
if (!isFormValid) {
@@ -277,6 +267,7 @@ const PengajuanTempo = () => {
const address = await createPengajuanTempoApi({
id: idTempo,
user_id: auth.parentId,
+ partner_id: auth.partnerId,
section: label,
tempo_request: tempoRequest,
...formData,
@@ -297,7 +288,6 @@ const PengajuanTempo = () => {
const handleDaftarTempoDokumen = async () => {
for (const error of stepDivsError) {
if (error.length > 0) {
- console.log('iman_erro', error);
return;
}
}
@@ -315,6 +305,7 @@ const PengajuanTempo = () => {
const address = await createPengajuanTempoApi({
id: idTempo,
user_id: auth.parentId,
+ partner_id: auth.partnerId,
formDocs: JSON.stringify(formattedDokumen),
});
if (address.id) {
@@ -343,15 +334,14 @@ const PengajuanTempo = () => {
durasiTempo: product.durasiTempo,
creditLimit: product.creditLimit,
}));
- console.log('productOrder', productOrder);
const toastId = toast.loading('Mengirimkan formulir pengajuan tempo...');
setIsLoading(true);
try {
const address = await createPengajuanTempoApi({
id: idTempo,
user_id: auth.parentId,
+ partner_id: auth.partnerId,
formSupplier: JSON.stringify(productOrder),
- section,
});
if (address.id) {
setIdTempo(address.id);
@@ -402,7 +392,6 @@ const PengajuanTempo = () => {
setIsLoading(true);
try {
let address5;
- console.log('MASUK SINI');
const address = await createPengajuanTempoApi({
id: 0,
partner_id: auth.partnerId,
@@ -410,7 +399,6 @@ const PengajuanTempo = () => {
tempo_request: false,
...form,
});
- console.log('address', address);
if (address.id) {
const address2 = await createPengajuanTempoApi({
id: address.id,
@@ -447,12 +435,12 @@ const PengajuanTempo = () => {
}
}
}
- toast.dismiss(toastId);
- setIsLoading(false);
if (address5.id) {
- toast.success('Pengajuan tempo berhasil dilakukan');
const isUpdated = await editAuthTempo();
+ toast.dismiss(toastId);
+ setIsLoading(false);
+ toast.success('Pengajuan tempo berhasil dilakukan');
if (isUpdated?.user) {
setAuth(isUpdated.user);
toast.success('Berhasil mengubah status akun', { duration: 1000 });