diff --git a/src/lib/pengajuan-tempo/component/Referensi.jsx b/src/lib/pengajuan-tempo/component/Referensi.jsx
index cb0bb5fe..e2a341e6 100644
--- a/src/lib/pengajuan-tempo/component/Referensi.jsx
+++ b/src/lib/pengajuan-tempo/component/Referensi.jsx
@@ -1,365 +1,326 @@
import React, { useState, useEffect, useMemo, useRef } from 'react';
-import { Controller, set, useForm } from 'react-hook-form';
-import HookFormSelect from '@/core/components/elements/Select/HookFormSelect';
-import odooApi from '~/libs/odooApi';
-import stateApi from '@/lib/address/api/stateApi.js';
-import cityApi from '@/lib/address/api/cityApi';
-import { Radio, RadioGroup, Stack, Checkbox } from '@chakra-ui/react';
-import { usePengajuanTempoStoreKontakPerson } from '../../../../src-migrate/modules/register/stores/usePengajuanTempoStore';
+import { useForm } from 'react-hook-form';
+import { usePengajuanTempoStoreSupplier } from '../../../../src-migrate/modules/register/stores/usePengajuanTempoStore';
+import * as Yup from 'yup';
+import { yupResolver } from '@hookform/resolvers/yup';
+import { PlusCircleIcon } from '@heroicons/react/24/outline';
+
+const initialData = [];
const Referensi = ({ chekValid, buttonSubmitClick }) => {
- const { control, watch } = useForm();
const {
- formKontakPerson,
- errorsKontakPerson,
- validateKontakPerson,
- updateFormKontakPerson,
- } = usePengajuanTempoStoreKontakPerson();
+ register,
+ formState: { errors },
+ handleSubmit,
+ watch,
+ setValue,
+ control,
+ } = useForm({
+ resolver: yupResolver(validationSchema),
+ defaultValues,
+ });
+ const { formSupplier, updateFormSupplier } = usePengajuanTempoStoreSupplier();
+ const [formData, setFormData] = useState([
+ {
+ supplier: '',
+ pic: '',
+ telepon: '',
+ durasiTempo: '',
+ creditLimit: '',
+ },
+ ]);
+
+ const [buttonSubmit, setButtonSubmit] = useState(false);
+ const [supplierData, setSupplierData] = useState(initialData);
+ const [newSupplier, setNewSupplier] = useState({
+ supplier: '',
+ pic: '',
+ telepon: '',
+ durasiTempo: '',
+ creditLimit: '',
+ });
+ const onChangeInput = (e, index) => {
+ const { name, value } = e.target;
+
+ let formattedValue = value;
+
+ if (name === 'durasiTempo') {
+ formattedValue = value.replace(/\s*Hari\s*/g, '');
+ } else if (name === 'creditLimit') {
+ formattedValue = value.replace(/^Rp\s*/, '');
+ }
- const handleInputChange = (event) => {
- const { name, value } = event.target;
- updateFormKontakPerson(name, value);
- validateKontakPerson();
+ const editData = supplierData.map((item, i) =>
+ i === index ? { ...item, [name]: formattedValue } : item
+ );
+
+ setSupplierData(editData);
};
- const isFormValid = useMemo(
- () => Object.keys(errorsKontakPerson).length === 0,
- [errorsKontakPerson]
- );
+ const handleNewSupplierChange = (e) => {
+ const { name, value } = e.target;
+
+ let formattedValue = value;
+
+ if (name === 'durasiTempo') {
+ formattedValue = value.replace(/\s*Hari\s*/g, '');
+ } else if (name === 'creditLimit') {
+ formattedValue = value.replace(/^Rp\s*/, '');
+ }
- const direkturNameRef = useRef(null);
- const direkturMobileRef = useRef(null);
- const direkturEmailRef = useRef(null);
- const purchasingNameRef = useRef(null);
- const purchasingEmailRef = useRef(null);
- const purchasingMobileRef = useRef(null);
- const financeNameRef = useRef(null);
- const financeMobileRef = useRef(null);
- const financeEmailRef = useRef(null);
+ const updatedSupplier = { ...newSupplier, [name]: formattedValue };
+ setNewSupplier(updatedSupplier);
+
+ // if (Object.values(updatedSupplier).every((val) => val.trim() !== '')) {
+ // setSupplierData((prevData) => {
+ // const newData = [...prevData, updatedSupplier];
+ // return newData;
+ // });
+
+ // setNewSupplier({
+ // supplier: '',
+ // pic: '',
+ // telepon: '',
+ // durasiTempo: '',
+ // creditLimit: '',
+ // });
+ // }
+ };
+
+ const handleAddNewSupplier = () => {
+ // Pastikan semua field sudah diisi sebelum menambahkan supplier baru
+ if (Object.values(newSupplier).every((val) => val.trim() !== '')) {
+ setSupplierData((prevData) => {
+ const newData = [...prevData, newSupplier];
+ return newData;
+ });
+
+ // Reset newSupplier setelah menambahkan
+ setNewSupplier({
+ supplier: '',
+ pic: '',
+ telepon: '',
+ durasiTempo: '',
+ creditLimit: '',
+ });
+ }
+ };
useEffect(() => {
- const loadIndustries = async () => {
- if (!isFormValid) {
- const options = {
- behavior: 'smooth',
- block: 'center',
- };
- if (errorsKontakPerson.direkturName && direkturNameRef.current) {
- direkturNameRef.current.scrollIntoView(options);
- return;
- }
- if (errorsKontakPerson.direkturMobile && direkturMobileRef.current) {
- direkturMobileRef.current.scrollIntoView(options);
- return;
- }
- if (errorsKontakPerson.direkturEmail && direkturEmailRef.current) {
- direkturEmailRef.current.scrollIntoView(options);
- return;
- }
- if (errorsKontakPerson.purchasingName && purchasingNameRef.current) {
- purchasingNameRef.current.scrollIntoView(options);
- return;
- }
- if (
- errorsKontakPerson.purchasingMobile &&
- purchasingMobileRef.current
- ) {
- purchasingMobileRef.current.scrollIntoView(options);
- return;
- }
- if (errorsKontakPerson.purchasingEmail && purchasingEmailRef.current) {
- purchasingEmailRef.current.scrollIntoView(options);
- return;
- }
- if (errorsKontakPerson.financeName && financeNameRef.current) {
- financeNameRef.current.scrollIntoView(options);
- return;
- }
- if (errorsKontakPerson.financeMobile && financeMobileRef.current) {
- financeMobileRef.current.scrollIntoView(options);
- return;
- }
- if (errorsKontakPerson.financeEmail && financeEmailRef.current) {
- financeEmailRef.current.scrollIntoView(options);
- return;
- }
- }
- };
- loadIndustries();
- }, [buttonSubmitClick, chekValid]);
+ handleAddNewSupplier();
+ updateFormSupplier(supplierData);
+ setButtonSubmit(!buttonSubmit);
+ }, [buttonSubmitClick]);
+ const simpanData = () => {
+ setButtonSubmit(!buttonSubmit);
+ if (Object.values(newSupplier).every((val) => val.trim() !== '')) {
+ setSupplierData((prevData) => {
+ const newData = [...prevData, newSupplier];
+ return newData;
+ });
+ // Reset newSupplier setelah menambahkan
+ setNewSupplier({
+ supplier: '',
+ pic: '',
+ telepon: '',
+ durasiTempo: '',
+ creditLimit: '',
+ });
+ }
+ };
+ const formatRupiah = (value) => {
+ if (!value) return '';
+ const numberString = value.replace(/[^0-9]/g, '');
+ return numberString
+ ? 'Rp ' + new Intl.NumberFormat('id-ID').format(numberString)
+ : '';
+ };
+ const formatHari = (value) => {
+ if (!value) return '';
+
+ const numberString = value.replace(/[^0-9]/g, '');
+
+ return numberString ? numberString.replace(/Hari/g, '') + ' Hari' : '';
+ };
+ // useEffect(() => {
+ // setSupplierData((prevData) => {
+ // const newData = [...prevData, newSupplier];
+ // return newData;
+ // });
+ // updateFormSupplier(supplierData);
+ // }, [buttonSubmitClick]);
useEffect(() => {
- validateKontakPerson();
+ updateFormSupplier(supplierData);
+ }, [buttonSubmit]);
+ useEffect(() => {
+ if (formSupplier) {
+ setSupplierData(formSupplier);
+ }
}, [buttonSubmitClick]);
return (
<>
Referensi Supplier / Rekanan Bisnis Perusahaan{' '}
- (Opsional)
+ (Opsional)
+
+
+ { }
+ {''} Tambah data baru
+
+
+ simpan data
+
+
+ {/*
+ CETAK
+ */}
>
);
};
+const validationSchema = Yup.object().shape({
+ supplier: Yup.string().required('Harus di-isi'),
+ pic: Yup.string().required('Harus di-isi'),
+ telepon: Yup.string().required('Harus di-isi'),
+ durasiTempo: Yup.string().required('Harus di-isi'),
+ creditLimit: Yup.string().required('Harus di-isi'),
+});
+
+const defaultValues = {
+ supplier: '',
+ pic: '',
+ telepon: '',
+ durasiTempo: '',
+ creditLimit: '',
+};
export default Referensi;
--
cgit v1.2.3
From d6ede238658d90315a5dc5b864f20037e8a776f6 Mon Sep 17 00:00:00 2001
From: it-fixcomart
Date: Tue, 22 Oct 2024 11:24:43 +0700
Subject: update & add section dokumen
---
src/lib/pengajuan-tempo/component/Dokumen.jsx | 441 +++++++++++++++++++++
.../pengajuan-tempo/component/PengajuanTempo.jsx | 14 +-
src/lib/pengajuan-tempo/component/Referensi.jsx | 13 +-
3 files changed, 463 insertions(+), 5 deletions(-)
create mode 100644 src/lib/pengajuan-tempo/component/Dokumen.jsx
(limited to 'src')
diff --git a/src/lib/pengajuan-tempo/component/Dokumen.jsx b/src/lib/pengajuan-tempo/component/Dokumen.jsx
new file mode 100644
index 00000000..65220b27
--- /dev/null
+++ b/src/lib/pengajuan-tempo/component/Dokumen.jsx
@@ -0,0 +1,441 @@
+import React, { useState, useEffect, useMemo, useRef } from 'react';
+import { Controller, set, useForm } from 'react-hook-form';
+import { usePengajuanTempoStoreDokumen } from '../../../../src-migrate/modules/register/stores/usePengajuanTempoStore';
+import ProgressBar from '@ramonak/react-progress-bar';
+import { UseToastOptions } from '@chakra-ui/react';
+import { toast } from 'react-hot-toast';
+import getFileBase64 from '@/core/utils/getFileBase64';
+const Dokumen = ({ chekValid, buttonSubmitClick }) => {
+ const { control, watch } = useForm();
+ const {
+ formDokumen,
+ errorsDokumen,
+ validateDokumen,
+ updateFormDokumen,
+ getJumlahDokumenDiisi,
+ } = usePengajuanTempoStoreDokumen();
+
+ // const handleInputChange = (event) => {
+ // const { name, value } = event.target;
+ // updateFormDokumen(name, value);
+ // validateDokumen();
+ // };
+ const handleInputChange = async (event) => {
+ let fileBase64 = '';
+ const { name } = event.target;
+ const file = event.target.files?.[0];
+ console.log('file', file);
+ // 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) {
+ toast.error('Maksimal ukuran file adalah 2MB', { duration: 4000 });
+
+ event.target.value = '';
+ return;
+ }
+
+ // Convert file to Base64
+ fileBase64 = await getFileBase64(file);
+ updateFormDokumen(name, file.name, fileExtension, fileBase64);
+ validateDokumen();
+ }
+ };
+
+ const isFormValid = useMemo(
+ () => Object.keys(errorsDokumen).length === 0,
+ [errorsDokumen]
+ );
+ console.log('formDokumen', formDokumen?.dokumenNib?.name);
+ const dokumenNibRef = useRef(null);
+ const dokumenNpwpRef = useRef(null);
+ const dokumenSppkpRef = useRef(null);
+ const dokumenAktaPerubahanRef = useRef(null);
+ const dokumenKtpDirutRef = useRef(null);
+ const dokumenAktaPendirianRef = useRef(null);
+ const dokumenLaporanKeuanganRef = useRef(null);
+ const dokumenFotoKantorRef = useRef(null);
+ const dokumenTempatBekerjaRef = useRef(null);
+
+ useEffect(() => {
+ const loadIndustries = async () => {
+ if (!isFormValid) {
+ const options = {
+ behavior: 'smooth',
+ block: 'center',
+ };
+ if (errorsDokumen.dokumenNib && dokumenNibRef.current) {
+ dokumenNibRef.current.scrollIntoView(options);
+ return;
+ }
+ if (errorsDokumen.dokumenNpwp && dokumenNpwpRef.current) {
+ dokumenNpwpRef.current.scrollIntoView(options);
+ return;
+ }
+ if (errorsDokumen.dokumenSppkp && dokumenSppkpRef.current) {
+ dokumenSppkpRef.current.scrollIntoView(options);
+ return;
+ }
+ if (
+ errorsDokumen.dokumenAktaPerubahan &&
+ dokumenAktaPerubahanRef.current
+ ) {
+ dokumenAktaPerubahanRef.current.scrollIntoView(options);
+ return;
+ }
+ if (errorsDokumen.dokumenKtpDirut && dokumenKtpDirutRef.current) {
+ dokumenKtpDirutRef.current.scrollIntoView(options);
+ return;
+ }
+ if (
+ errorsDokumen.dokumenAktaPendirian &&
+ dokumenAktaPendirianRef.current
+ ) {
+ dokumenAktaPendirianRef.current.scrollIntoView(options);
+ return;
+ }
+ if (
+ errorsDokumen.dokumenLaporanKeuangan &&
+ dokumenLaporanKeuanganRef.current
+ ) {
+ dokumenLaporanKeuanganRef.current.scrollIntoView(options);
+ return;
+ }
+ if (errorsDokumen.dokumenFotoKantor && dokumenFotoKantorRef.current) {
+ dokumenFotoKantorRef.current.scrollIntoView(options);
+ return;
+ }
+ if (
+ errorsDokumen.dokumenTempatBekerja &&
+ dokumenTempatBekerjaRef.current
+ ) {
+ dokumenTempatBekerjaRef.current.scrollIntoView(options);
+ return;
+ }
+ }
+ };
+ loadIndustries();
+ }, [buttonSubmitClick, chekValid]);
+
+ useEffect(() => {
+ validateDokumen();
+ }, [buttonSubmitClick]);
+ return (
+ <>
+
+
Dokumen
+
+
+
+
+
Upload Progress
+
+
+ {parseInt((getJumlahDokumenDiisi() / 9) * 100)} %
+
+
+ {getJumlahDokumenDiisi() > 5
+ ? getJumlahDokumenDiisi() == 9
+ ? 'Selesai'
+ : 'Sedikit Lagi'
+ : ''}
+
+
+
+ {/* 50 keatas baru muncul kata kata sedikit lagi */}
+
+
+ Tingkatin sedikit lagi agar pengajuan tempo kamu dapat kami proses
+ dengan cepat
+
+
+ >
+ );
+};
+
+export default Dokumen;
diff --git a/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx b/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
index 2ab7c21a..238c5e4e 100644
--- a/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
+++ b/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
@@ -5,12 +5,14 @@ import InformasiPerusahaan from './informasiPerusahaan';
import KontakPerusahaan from './KontakPerusahaan';
import Pengiriman from './Pengiriman';
import Referensi from './Referensi';
+import Dokumen from './Dokumen';
import { Controller, useForm } from 'react-hook-form';
import {
usePengajuanTempoStore,
usePengajuanTempoStoreKontakPerson,
usePengajuanTempoStorePengiriman,
usePengajuanTempoStoreSupplier,
+ usePengajuanTempoStoreDokumen,
} from '../../../../src-migrate/modules/register/stores/usePengajuanTempoStore';
import { ChevronRightIcon, ChevronLeftIcon } from '@heroicons/react/24/outline';
const PengajuanTempo = () => {
@@ -18,6 +20,8 @@ const PengajuanTempo = () => {
const NUMBER_OF_STEPS = 6;
const { form, errors, validate, updateForm } = usePengajuanTempoStore();
const { control, watch, setValue } = useForm();
+ const { formDokumen, errorsDokumen, validateDokumen, updateFormDokumen } =
+ usePengajuanTempoStoreDokumen();
const {
formKontakPerson,
errorsKontakPerson,
@@ -45,6 +49,7 @@ const PengajuanTempo = () => {
/>,
,
,
+ ,
Dokumen
,
Konfirmasi
,
];
@@ -53,7 +58,7 @@ const PengajuanTempo = () => {
errorsKontakPerson,
errorsPengiriman,
errorsSupplier,
- Dokumen
,
+ errorsDokumen,
Konfirmasi
,
];
const stepDivsForm = [
@@ -61,7 +66,7 @@ const PengajuanTempo = () => {
formKontakPerson,
formPengiriman,
formSupplier,
- Dokumen
,
+ formDokumen,
Konfirmasi
,
];
const stepDivsUpdateForm = [
@@ -69,7 +74,7 @@ const PengajuanTempo = () => {
updateFormKontakPerson,
updateFormPengiriman,
updateFormSupplier,
- Dokumen
,
+ updateFormDokumen,
Konfirmasi
,
];
const stepLabels = [
@@ -89,6 +94,7 @@ const PengajuanTempo = () => {
validate();
validateKontakPerson();
validatePengiriman();
+ validateDokumen();
window.scrollTo({
top: 0,
@@ -108,6 +114,8 @@ const PengajuanTempo = () => {
});
}
}
+ if (formSupplier) {
+ }
}, [currentStep]);
const goToNextStep = () => {
if (!isFormValid) {
diff --git a/src/lib/pengajuan-tempo/component/Referensi.jsx b/src/lib/pengajuan-tempo/component/Referensi.jsx
index e2a341e6..dd8b66ad 100644
--- a/src/lib/pengajuan-tempo/component/Referensi.jsx
+++ b/src/lib/pengajuan-tempo/component/Referensi.jsx
@@ -152,9 +152,18 @@ const Referensi = ({ chekValid, buttonSubmitClick }) => {
useEffect(() => {
updateFormSupplier(supplierData);
}, [buttonSubmit]);
+ const getFromLocalStorage = (key) => {
+ const itemStr = localStorage.getItem(key);
+ if (!itemStr) return null;
+
+ const item = JSON.parse(itemStr);
+ return item;
+ };
useEffect(() => {
- if (formSupplier) {
- setSupplierData(formSupplier);
+ const cachedData = getFromLocalStorage('Referensi');
+ if (cachedData) {
+ setSupplierData(cachedData);
+ updateFormSupplier(cachedData);
}
}, [buttonSubmitClick]);
return (
--
cgit v1.2.3
From acee071ea98505b42918f4d7cdc15252ae78f705 Mon Sep 17 00:00:00 2001
From: it-fixcomart
Date: Tue, 22 Oct 2024 15:28:40 +0700
Subject: update fix dokumen
---
src/lib/pengajuan-tempo/component/Dokumen.jsx | 311 ++++++++++++++-------
.../pengajuan-tempo/component/PengajuanTempo.jsx | 7 +-
2 files changed, 214 insertions(+), 104 deletions(-)
(limited to 'src')
diff --git a/src/lib/pengajuan-tempo/component/Dokumen.jsx b/src/lib/pengajuan-tempo/component/Dokumen.jsx
index 65220b27..42c6c47f 100644
--- a/src/lib/pengajuan-tempo/component/Dokumen.jsx
+++ b/src/lib/pengajuan-tempo/component/Dokumen.jsx
@@ -24,7 +24,6 @@ const Dokumen = ({ chekValid, buttonSubmitClick }) => {
let fileBase64 = '';
const { name } = event.target;
const file = event.target.files?.[0];
- console.log('file', file);
// Allowed file extensions
const allowedExtensions = ['pdf', 'png', 'jpg', 'jpeg'];
let fileExtension = '';
@@ -61,7 +60,6 @@ const Dokumen = ({ chekValid, buttonSubmitClick }) => {
() => Object.keys(errorsDokumen).length === 0,
[errorsDokumen]
);
- console.log('formDokumen', formDokumen?.dokumenNib?.name);
const dokumenNibRef = useRef(null);
const dokumenNpwpRef = useRef(null);
const dokumenSppkpRef = useRef(null);
@@ -142,7 +140,7 @@ const Dokumen = ({ chekValid, buttonSubmitClick }) => {