summaryrefslogtreecommitdiff
path: root/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/pengajuan-tempo/component/PengajuanTempo.jsx')
-rw-r--r--src/lib/pengajuan-tempo/component/PengajuanTempo.jsx29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx b/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
index 2c10b1d6..14ea1805 100644
--- a/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
+++ b/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
@@ -9,11 +9,11 @@ import {
usePengajuanTempoStoreKontakPerson,
} from '../../../../src-migrate/modules/register/stores/usePengajuanTempoStore';
import { ChevronRightIcon, ChevronLeftIcon } from '@heroicons/react/24/outline';
-import { chakra } from '@chakra-ui/react';
const PengajuanTempo = () => {
const [currentStep, setCurrentStep] = React.useState(0);
const NUMBER_OF_STEPS = 6;
const { form, errors, validate, updateForm } = usePengajuanTempoStore();
+ const { control, watch, setValue } = useForm();
const {
formKontakPerson,
errorsKontakPerson,
@@ -55,6 +55,15 @@ const PengajuanTempo = () => {
<div>Dokumen</div>,
<div>Konfirmasi</div>,
];
+ const stepDivsUpdateForm = [
+ updateForm,
+ updateFormKontakPerson,
+ <div>Kontak Person</div>,
+ <div>Pengiriman</div>,
+ <div>Referensi</div>,
+ <div>Dokumen</div>,
+ <div>Konfirmasi</div>,
+ ];
const stepLabels = [
'informasi_perusahaan',
'kontak_person',
@@ -69,16 +78,21 @@ const PengajuanTempo = () => {
[stepDivsError[currentStep]]
);
useEffect(() => {
- validate();
validateKontakPerson();
- }, []);
+ validate();
+
+ window.scrollTo({
+ top: 0,
+ behavior: 'smooth',
+ });
+ }, [currentStep]);
+
useEffect(() => {
const cachedData = getFromLocalStorage(stepLabels[currentStep]);
- console.log('cachedData prev button', cachedData);
if (cachedData) {
// const formData = JSON.parse(cachedData);
Object.keys(cachedData).forEach((key) => {
- updateForm(key, cachedData[key]);
+ stepDivsUpdateForm[currentStep](key, cachedData[key]);
});
}
}, [currentStep]);
@@ -86,15 +100,10 @@ const PengajuanTempo = () => {
if (!isFormValid) {
setNotValid(true);
setButtonSubmitClick(!buttonSubmitClick);
- console.log('form', stepDivsForm[currentStep]);
- console.log('error', stepDivsError[currentStep]);
return;
} else {
saveToLocalStorage(stepLabels[currentStep], stepDivsForm[currentStep]);
const cachedData = getFromLocalStorage(stepLabels[currentStep]);
- console.log('cachedData', cachedData);
- console.log('form', stepDivsForm[currentStep]);
- console.log('error', stepDivsError[currentStep]);
setButtonSubmitClick(!buttonSubmitClick);
setNotValid(false);
}