import React from 'react';
import { useMemo, useState, useEffect, useRef } from 'react';
import Image from '~/components/ui/image';
import InformasiPerusahaan from './InformasiPerusahaan';
import InformasiVendor from './InformasiVendor';
import SyaratDagang from './SyaratDagang';
import Dokumen from './Dokumen';
import { getAuth } from '~/libs/auth';
import { setAuth } from '@/core/utils/auth';
import useAuth from '@/core/hooks/useAuth';
import { useRouter } from 'next/router';
import { Controller, useForm } from 'react-hook-form';
import { ChevronRightIcon, ChevronLeftIcon } from '@heroicons/react/24/outline';
import { Button, Checkbox, Spinner, Tooltip } from '@chakra-ui/react';
import clsxm from '~/libs/clsxm';
import { toast } from 'react-hot-toast';
import useDevice from '@/core/hooks/useDevice';
import odooApi from '~/libs/odooApi';
import BottomPopup from '@/core/components/elements/Popup/BottomPopup';
import PageContent from '@/lib/content/components/PageContent';
const Merchant = () => {
const { isDesktop, isMobile } = useDevice();
const [currentStep, setCurrentStep] = React.useState(0);
const NUMBER_OF_STEPS = 5;
const [isLoading, setIsLoading] = useState(false);
const [bigData, setBigData] = useState();
const [idTempo, setIdTempo] = useState(0);
const { control, watch, setValue } = useForm();
const auth = useAuth();
const router = useRouter();
const [BannerTempo, setBannerTempo] = useState();
const [notValid, setNotValid] = useState(false);
const [buttonSubmitClick, setButtonSubmitClick] = useState(false);
const [error, setError] = useState(false);
const handleIsError = (value) => {
console.log('value yang dihasilkan', value);
if (!value) {
goToNextStep();
}
setError(value); // Memperbarui state berdasarkan isError
};
const stepDivs = [
,
,
,
,
];
const stepLabels = [
'informasi_perusahaan',
'kontak_person',
'Pengiriman',
'Referensi',
'Dokumen',
'Konfirmasi',
];
useEffect(() => {
window.scrollTo({
top: 0,
behavior: 'smooth',
});
}, [currentStep]);
// useEffect(() => {
// const loadBigData = async () => {
// const toCamelCase = (str) =>
// str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
// const transformKeysToCamelCase = (data) => {
// if (Array.isArray(data)) {
// return data.map((item) => transformKeysToCamelCase(item));
// } else if (data && typeof data === 'object') {
// return Object.keys(data).reduce((acc, key) => {
// const camelKey = toCamelCase(key); // Ubah kunci menjadi camelCase
// acc[camelKey] = transformKeysToCamelCase(data[key]); // Rekursif untuk nested object atau array
// return acc;
// }, {});
// }
// return data; // Jika bukan object atau array, kembalikan nilai aslinya
// };
// try {
// const dataPaymentTerm = await odooApi(
// 'GET',
// `/api/v1/partner/detail-tempo/${auth.parentId}`
// );
// const transformedData = transformKeysToCamelCase(dataPaymentTerm);
// setBigData(transformedData);
// } catch (error) {
// console.error('Error loading dataPaymentTerm:', error);
// }
// };
// loadBigData();
// }, [auth]);
// useEffect(() => {
// const cachedData = bigData;
// 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(true);
// }, [currentStep, bigData, auth]);
const goToNextStep = () => {
// if (!isFormValid) {
// setNotValid(true);
// setButtonSubmitClick(!buttonSubmitClick);
// return;
// } else {
// // saveToLocalStorage(stepLabels[currentStep], stepDivsForm[currentStep]);
// if (currentStep == 3) {
// handleDaftarTempoSupplier();
// } else if (currentStep == 4) {
// handleDaftarTempoDokumen();
// } else {
// handleDaftarTempoPerPage(
// stepLabels[currentStep],
// stepDivsForm[currentStep]
// );
// }
// setButtonSubmitClick(!buttonSubmitClick);
// setNotValid(false);
// }
setCurrentStep((prev) => (prev === NUMBER_OF_STEPS - 1 ? prev : prev + 1));
};
const goPrevStep = () => {
setCurrentStep((prev) => (prev === NUMBER_OF_STEPS - 1 ? prev : prev - 1));
};
useEffect(() => {
const getBanner = async () => {
const get = await odooApi('GET', '/api/v1/banner?type=banner-form-tempo');
// setBannerTempo(get[0].image);
setBannerTempo(
'https://erp.indoteknik.com/api/image/x_banner.banner/x_banner_image/431'
);
};
getBanner();
}, []);
return (
<>
{BannerTempo && (
)}
Form Merchant
Pembayaran tempo adalah layanan pembayaran berjangka yang difasilitasi
indoteknik.com untuk konsumen akun bisnis yang terdaftar dengan waktu
pembayaran mulai dari 7, 14, 21 hingga 30 Hari.
{stepDivs[currentStep]}
{isDesktop &&
}
{isMobile && (
)}
{/*
*Pastikan data yang anda masukan sudah benar dan sesuai
0 && currentStep < 5
? 'justify-between'
: 'justify-end'
} items-center w-full ${isMobile ? 'gap-x-4 ' : ''}`}
>
{currentStep < 5 && currentStep > 0 && (
{ }
Langkah Sebelumnya
)}
{currentStep < 5 && (
<>
Langkah Selanjutnya
{ }
>
)}
{currentStep == 5 && (
Daftar Tempo { }
)}
*/}
>
);
};
export default Merchant;