From e9cd13307f0095dc4edc5048752675d80c551564 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 6 Dec 2024 17:06:26 +0700 Subject: pengajuan tempo --- .../component/informasiPerusahaan.jsx | 359 +++++---------------- 1 file changed, 79 insertions(+), 280 deletions(-) (limited to 'src/lib/pengajuan-tempo/component/informasiPerusahaan.jsx') diff --git a/src/lib/pengajuan-tempo/component/informasiPerusahaan.jsx b/src/lib/pengajuan-tempo/component/informasiPerusahaan.jsx index f641d8fa..19f46dec 100644 --- a/src/lib/pengajuan-tempo/component/informasiPerusahaan.jsx +++ b/src/lib/pengajuan-tempo/component/informasiPerusahaan.jsx @@ -10,6 +10,7 @@ import useDevice from '@/core/hooks/useDevice'; import Divider from '@/core/components/elements/Divider/Divider'; import { getAuth } from '~/libs/auth'; import addressApi from '@/lib/address/api/addressApi'; +import { toast } from 'react-hot-toast'; const InformasiPerusahaan = ({ chekValid, buttonSubmitClick, @@ -113,10 +114,12 @@ const InformasiPerusahaan = ({ useEffect(() => { const loadPaymentTerm = async () => { - const dataPaymentTerm = await odooApi( - 'GET', - '/api/v1/partner/payment_term' - ); + const dataPaymentTerm = [ + { id: 29, name: 'Tempo 7 Hari' }, + { id: 24, name: 'Tempo 14 Hari' }, + { id: 32, name: 'Tempo 21 Hari' }, + { id: 25, name: 'Tempo 30 Hari' }, + ]; setPaymentTerm( dataPaymentTerm?.map((o) => ({ value: o.id, @@ -224,13 +227,60 @@ const InformasiPerusahaan = ({ const bersediaRef = useRef(null); const categoryProdukRef = useRef(null); const tempoLimitRef = useRef(null); + useEffect(() => { + const options = { + behavior: 'smooth', + block: 'center', + }; + const loadIndustries = async () => { - if (!isFormValid) { - const options = { - behavior: 'smooth', - block: 'center', + const watchZip = form.zip?.trim(); // Menghapus spasi berlebih + + // Validasi: hanya eksekusi jika watchZip valid (contoh: minimal 5 karakter) + if (watchZip && watchZip.length >= 5) { + const loadZip = async () => { + try { + const response = await fetch( + `https://alamat.thecloudalert.com/api/cari/index/?keyword=${watchZip}` + ); + + const result = await response.json(); + + if (!result.result.length > 0) { + toast.error('Alamat pos salah'); + updateForm('zip', ''); // Reset form.zip jika salah + validate(); // Memanggil validasi formulir + return false; + } else { + updateForm('zip', watchZip); + validate(); + return true; // Jika valid + } + } catch (error) { + toast.error('Terjadi kesalahan saat memeriksa alamat pos.'); + console.error('Error:', error); + return false; + } }; + + const isValidZip = await loadZip(); + if (!isValidZip) { + zipRef.current.scrollIntoView(options); + } + } + }; + + loadIndustries(); + }, [form.zip]); + + useEffect(() => { + const options = { + behavior: 'smooth', + block: 'center', + }; + const loadIndustries = async () => { + if (!isFormValid) { if (errors.name && nameRef.current) { nameRef.current.scrollIntoView(options); return; @@ -356,8 +406,7 @@ const InformasiPerusahaan = ({ useEffect(() => { const loadProfile = async () => { try { - const dataProfile = await addressApi({ id: auth.parentId }); - + const dataProfile = await addressApi({ id: auth.partnerId }); setValue('industryId', parseInt(dataProfile.industryId)); setValue('state', parseInt(dataProfile.stateId.id)); setValue('city', parseInt(dataProfile.city.id)); @@ -664,7 +713,8 @@ const InformasiPerusahaan = ({
@@ -738,187 +788,13 @@ const InformasiPerusahaan = ({
)}
- {!isKonfirmasi && ( -
-
- - - Ajukan nilai limit yang anda mau - -
-
- { - if (value === 'custom') { - setIsCustom(true); - updateForm('tempoLimit', tempoLimitValue); // Update dengan nilai input custom jika dipilih - } else { - setIsCustom(false); - onChangeTempoLimit(value); // Update dengan nilai radio button yang dipilih - } - }} - className='flex items-center justify-between' - value={isCustom ? 'custom' : form.tempoLimit} - > - - {/* Kolom 1 */} - - {radioOptions.slice(0, 4).map((option) => ( - - {option.label} - - ))} - - - {/* Kolom 2 */} - - {radioOptions.slice(4).map((option) => ( - - {option.label} - - ))} -
- - - { - const value = e.target.value; - const formattedValue = - formatRupiah(value); - setTempoLimitValueEx(formattedValue); - updateForm( - 'tempoLimit', - formattedValue.replace(/^Rp\s*/, '') - ); // Mengupdate nilai di react-hook-form - }} - /> -
-
-
-
- {chekValid && ( -
- {errors.tempoLimit} -
- )} -
-
- )} -
- *Durasi dan limit dapat berbeda sesuai dengan verifikasi - oleh tim Indoteknik.com +
+ **Durasi tempo dapat berbeda sesuai dengan verifikasi oleh + tim Indoteknik.com
- {isKonfirmasi && ( -
-
- - - Ajukan nilai limit yang anda mau - -
-
- { - if (value === 'custom') { - setIsCustom(true); - updateForm('tempoLimit', tempoLimitValue); // Update dengan nilai input custom jika dipilih - } else { - setIsCustom(false); - onChangeTempoLimit(value); // Update dengan nilai radio button yang dipilih - } - }} - className='flex items-center justify-between' - value={isCustom ? 'custom' : form.tempoLimit} - > - - {/* Kolom 1 */} - - {radioOptions.slice(0, 4).map((option) => ( - - {option.label} - - ))} - - - {/* Kolom 2 */} - - {radioOptions.slice(4).map((option) => ( - - {option.label} - - ))} -
- - - { - const value = e.target.value; - const formattedValue = formatRupiah(value); - setTempoLimitValueEx(formattedValue); - updateForm( - 'tempoLimit', - formattedValue.replace(/^Rp\s*/, '') - ); // Mengupdate nilai di react-hook-form - }} - /> -
-
-
-
- {chekValid && ( -
- {errors.tempoLimit} -
- )} -
-
- )}
@@ -1286,7 +1162,8 @@ const InformasiPerusahaan = ({
-
- - - - 7 Hari - - - 14 Hari - - - 30 Hari - - - +
+ ( + + )} + /> {chekValid && (
{errors.tempoDuration} @@ -1335,81 +1206,9 @@ const InformasiPerusahaan = ({ )}
-
- -
- { - if (value === 'custom') { - setIsCustom(true); - updateForm('tempoLimit', tempoLimitValue); // Update dengan nilai input custom jika dipilih - } else { - setIsCustom(false); - onChangeTempoLimit(value); // Update dengan nilai radio button yang dipilih - } - }} - className='flex items-center justify-between' - value={isCustom ? 'custom' : form.tempoLimit} - > - - {/* Kolom 1 */} - - {radioOptions.slice(0, 3).map((option) => ( - - {option.label} - - ))} - - { - const value = e.target.value; - const formattedValue = formatRupiah(value); - setTempoLimitValueEx(formattedValue); - updateForm( - 'tempoLimit', - formattedValue.replace(/^Rp\s*/, '') - ); // Mengupdate nilai di react-hook-form - }} - /> - - - {/* Kolom 2 */} - {/* - {radioOptions.slice(4).map((option) => ( - - {option.label} - - ))} -
-
*/} -
-
- {chekValid && ( -
- {errors.tempoLimit} -
- )} -
-
- **Durasi & Limit dapat berbeda dengan verifikasi oleh tim + **Durasi tempo dapat berbeda dengan verifikasi oleh tim indoteknik.com
-- cgit v1.2.3