From 34f33b1cba1e4fbb6faacc151a3b59a1ba221d60 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 10 Sep 2024 16:26:17 +0700 Subject: add feature switch account --- src/lib/auth/components/SwitchAccount.jsx | 144 ++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 src/lib/auth/components/SwitchAccount.jsx (limited to 'src/lib') diff --git a/src/lib/auth/components/SwitchAccount.jsx b/src/lib/auth/components/SwitchAccount.jsx new file mode 100644 index 00000000..e1249779 --- /dev/null +++ b/src/lib/auth/components/SwitchAccount.jsx @@ -0,0 +1,144 @@ +import useAuth from '@/core/hooks/useAuth'; +import { setAuth } from '@/core/utils/auth'; +import addressApi from '@/lib/address/api/addressApi'; +import { ChevronDownIcon, ChevronUpIcon } from '@heroicons/react/24/outline'; +import { useEffect, useState } from 'react'; +import { useForm } from 'react-hook-form'; +import { toast } from 'react-hot-toast'; +import editPersonalProfileApi from '../api/editPersonalProfileApi'; +import FormBisnis from '~/modules/register/components/FormBisnis.tsx'; +import RegistrasiBisnis from '~/modules/register/components/RegistrasiBisnis.tsx'; +import { Radio, RadioGroup, Stack, Divider, Button } from '@chakra-ui/react'; +import { useRegisterStore } from '~/modules/register/stores/useRegisterStore.ts'; +const SwitchAccount = () => { + const auth = useAuth(); + const [isOpen, setIsOpen] = useState(true); + const toggle = () => setIsOpen(!isOpen); + const [isPKP, setIsPKP] = useState(true); + const [isTerdaftar, setIsTerdaftar] = useState(false); + const [isChecked, setIsChecked] = useState(false); + const [selectedValueBisnis, setSelectedValueBisnis] = useState('false'); + const [selectedValue, setSelectedValue] = useState('PKP'); + const { register, setValue, handleSubmit } = useForm({ + defaultValues: { + email: '', + name: '', + phone: '', + password: '', + }, + }); + + const { form, isCheckedTNC, isValidCaptcha, errors, validate, updateForm } = + useRegisterStore(); + console.log('form', form); + useEffect(() => { + const loadProfile = async () => { + const dataProfile = await addressApi({ id: auth.partnerId }); + setValue('email', dataProfile?.email); + setValue('name', dataProfile?.name); + setValue('phone', dataProfile?.phone); + }; + if (auth) loadProfile(); + }, [auth, setValue]); + + useEffect(() => { + if (selectedValue === 'PKP') { + updateForm('is_pkp', 'true'); + validate(); + } else { + updateForm('is_pkp', 'false'); + validate(); + } + }, [selectedValue]); + + useEffect(() => { + if (isTerdaftar) { + updateForm('is_terdaftar', 'true'); + validate(); + } else { + updateForm('is_terdaftar', 'false'); + validate(); + } + }, [isTerdaftar]); + + const handleChangeBisnis = (value) => { + setSelectedValueBisnis(value); + if (value === 'true') { + validate(); + setIsTerdaftar(true); + } else { + validate(); + setIsTerdaftar(false); + } + }; + const handleChange = (value) => { + setSelectedValue(value); + if (value === 'PKP') { + validate(); + setIsPKP(true); + } else { + validate(); + setIsPKP(false); + setIsPKP(false); + } + }; + return ( + <> + + + {isOpen && ( +
+
+

+ Bisnis Terdaftar di Indoteknik? +

+ + + + Sudah Terdaftar + + + Belum Terdaftar + + + +
+
+

Tipe Bisnis

+ + + + PKP + + + Non-PKP + + + +
+ +
+ )} + + ); +}; + +export default SwitchAccount; -- cgit v1.2.3 From b89d57916ec9d2be3db786a8481a0acc5fd74e2f Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Wed, 11 Sep 2024 11:11:38 +0700 Subject: update tampilan desktop switcj account --- src/lib/auth/components/SwitchAccount.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/lib') diff --git a/src/lib/auth/components/SwitchAccount.jsx b/src/lib/auth/components/SwitchAccount.jsx index e1249779..da0ff068 100644 --- a/src/lib/auth/components/SwitchAccount.jsx +++ b/src/lib/auth/components/SwitchAccount.jsx @@ -134,7 +134,7 @@ const SwitchAccount = () => { - + )} -- cgit v1.2.3 From ab39764b288b4d60923cc8cc6146ccdc1b4bfbac Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Wed, 11 Sep 2024 14:01:53 +0700 Subject: update switch acc --- src/lib/auth/components/SwitchAccount.jsx | 49 +++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) (limited to 'src/lib') diff --git a/src/lib/auth/components/SwitchAccount.jsx b/src/lib/auth/components/SwitchAccount.jsx index da0ff068..71571bd7 100644 --- a/src/lib/auth/components/SwitchAccount.jsx +++ b/src/lib/auth/components/SwitchAccount.jsx @@ -2,7 +2,7 @@ import useAuth from '@/core/hooks/useAuth'; import { setAuth } from '@/core/utils/auth'; import addressApi from '@/lib/address/api/addressApi'; import { ChevronDownIcon, ChevronUpIcon } from '@heroicons/react/24/outline'; -import { useEffect, useState } from 'react'; +import { useEffect, useState, useMemo } from 'react'; import { useForm } from 'react-hook-form'; import { toast } from 'react-hot-toast'; import editPersonalProfileApi from '../api/editPersonalProfileApi'; @@ -10,6 +10,9 @@ import FormBisnis from '~/modules/register/components/FormBisnis.tsx'; import RegistrasiBisnis from '~/modules/register/components/RegistrasiBisnis.tsx'; import { Radio, RadioGroup, Stack, Divider, Button } from '@chakra-ui/react'; import { useRegisterStore } from '~/modules/register/stores/useRegisterStore.ts'; +import { registerUser } from '~/services/auth'; +import { useMutation } from 'react-query'; +import { isValid } from 'zod'; const SwitchAccount = () => { const auth = useAuth(); const [isOpen, setIsOpen] = useState(true); @@ -27,10 +30,14 @@ const SwitchAccount = () => { password: '', }, }); - + const mutation = useMutation({ + mutationFn: (data) => registerUser(data), + }); + const [notValid, setNotValid] = useState(false); const { form, isCheckedTNC, isValidCaptcha, errors, validate, updateForm } = useRegisterStore(); console.log('form', form); + const isFormValid = useMemo(() => Object.keys(errors).length === 0, [errors]); useEffect(() => { const loadProfile = async () => { const dataProfile = await addressApi({ id: auth.partnerId }); @@ -82,6 +89,28 @@ const SwitchAccount = () => { setIsPKP(false); } }; + + const onSubmitHandler = async (values) => { + let data = values; + console.log('data', data); + if (!isFormValid) { + setNotValid(true); + return; + } else { + setNotValid(false); + } + // if (!values.password) delete data.password; + // const isUpdated = await editPersonalProfileApi({ data }); + + // if (isUpdated?.user) { + // setAuth(isUpdated.user); + // setValue('password', ''); + // toast.success('Berhasil mengubah profil', { duration: 1500 }); + // return; + // } + // toast.error('Terjadi kesalahan internal'); + }; + return ( <> + ); }; -- cgit v1.2.3 From 752e55686dfee0d536f9e4e128336e91681ba794 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Wed, 11 Sep 2024 17:07:49 +0700 Subject: update switch account --- src/lib/auth/api/switchAccountApi.js | 14 ++++ src/lib/auth/api/switchAccountProgresApi.js | 15 ++++ src/lib/auth/components/PersonalProfile.jsx | 104 +++++++++++++++++----------- src/lib/auth/components/SwitchAccount.jsx | 37 ++++++---- 4 files changed, 118 insertions(+), 52 deletions(-) create mode 100644 src/lib/auth/api/switchAccountApi.js create mode 100644 src/lib/auth/api/switchAccountProgresApi.js (limited to 'src/lib') diff --git a/src/lib/auth/api/switchAccountApi.js b/src/lib/auth/api/switchAccountApi.js new file mode 100644 index 00000000..9b772d20 --- /dev/null +++ b/src/lib/auth/api/switchAccountApi.js @@ -0,0 +1,14 @@ +import odooApi from '@/core/api/odooApi'; +import { getAuth } from '@/core/utils/auth'; + +const switchAccountApi = async ({ data }) => { + const auth = getAuth(); + const switchAccount = await odooApi( + 'PUT', + `/api/v1/user/${auth.partner_id}/switch`, + data + ); + return switchAccount; +}; + +export default switchAccountApi; diff --git a/src/lib/auth/api/switchAccountProgresApi.js b/src/lib/auth/api/switchAccountProgresApi.js new file mode 100644 index 00000000..4005ce3c --- /dev/null +++ b/src/lib/auth/api/switchAccountProgresApi.js @@ -0,0 +1,15 @@ +import odooApi from '@/core/api/odooApi'; +import { getAuth } from '@/core/utils/auth'; + +const switchAccountProgresApi = async () => { + const auth = getAuth(); + console.log('auth', auth); + const switchAccount = await odooApi( + 'PUT', + `/api/v1/user/${auth.partner_id}/switch_progres` + ); + console.log('switchAccount', switchAccount); + return switchAccount; +}; + +export default switchAccountProgresApi; diff --git a/src/lib/auth/components/PersonalProfile.jsx b/src/lib/auth/components/PersonalProfile.jsx index b9fb3f5f..7ef3af2d 100644 --- a/src/lib/auth/components/PersonalProfile.jsx +++ b/src/lib/auth/components/PersonalProfile.jsx @@ -1,56 +1,61 @@ -import useAuth from '@/core/hooks/useAuth' -import { setAuth } from '@/core/utils/auth' -import addressApi from '@/lib/address/api/addressApi' -import { ChevronDownIcon, ChevronUpIcon } from '@heroicons/react/24/outline' -import { useEffect, useState } from 'react' -import { useForm } from 'react-hook-form' -import { toast } from 'react-hot-toast' -import editPersonalProfileApi from '../api/editPersonalProfileApi' +import useAuth from '@/core/hooks/useAuth'; +import { setAuth } from '@/core/utils/auth'; +import addressApi from '@/lib/address/api/addressApi'; +import { ChevronDownIcon, ChevronUpIcon } from '@heroicons/react/24/outline'; +import { useEffect, useState } from 'react'; +import { useForm } from 'react-hook-form'; +import { toast } from 'react-hot-toast'; +import editPersonalProfileApi from '../api/editPersonalProfileApi'; const PersonalProfile = () => { - const auth = useAuth() - const [isOpen, setIsOpen] = useState(true) - const toggle = () => setIsOpen(!isOpen) + const auth = useAuth(); + const [isOpen, setIsOpen] = useState(true); + const toggle = () => setIsOpen(!isOpen); const { register, setValue, handleSubmit } = useForm({ defaultValues: { email: '', name: '', mobile: '', - password: '' - } - }) + password: '', + }, + }); useEffect(() => { const loadProfile = async () => { - const dataProfile = await addressApi({ id: auth.partnerId }) - setValue('email', dataProfile?.email) - setValue('name', dataProfile?.name) - setValue('mobile', dataProfile?.mobile) - } - if (auth) loadProfile() - }, [auth, setValue]) + const dataProfile = await addressApi({ id: auth.partner_id }); + setValue('email', dataProfile?.email); + setValue('name', dataProfile?.name); + setValue('mobile', dataProfile?.mobile); + }; + if (auth) loadProfile(); + }, [auth, setValue]); const onSubmitHandler = async (values) => { - let data = values - if (!values.password) delete data.password - const isUpdated = await editPersonalProfileApi({ data }) + let data = values; + if (!values.password) delete data.password; + const isUpdated = await editPersonalProfileApi({ data }); if (isUpdated?.user) { - setAuth(isUpdated.user) - setValue('password', '') - toast.success('Berhasil mengubah profil', { duration: 1500 }) - return + setAuth(isUpdated.user); + setValue('password', ''); + toast.success('Berhasil mengubah profil', { duration: 1500 }); + return; } - toast.error('Terjadi kesalahan internal') - } + toast.error('Terjadi kesalahan internal'); + }; return ( <> - {isOpen && ( -
+
- +
- +
- +
@@ -84,13 +105,16 @@ const PersonalProfile = () => { />
-
)} - ) -} + ); +}; -export default PersonalProfile +export default PersonalProfile; diff --git a/src/lib/auth/components/SwitchAccount.jsx b/src/lib/auth/components/SwitchAccount.jsx index 71571bd7..3146a3da 100644 --- a/src/lib/auth/components/SwitchAccount.jsx +++ b/src/lib/auth/components/SwitchAccount.jsx @@ -5,7 +5,7 @@ import { ChevronDownIcon, ChevronUpIcon } from '@heroicons/react/24/outline'; import { useEffect, useState, useMemo } from 'react'; import { useForm } from 'react-hook-form'; import { toast } from 'react-hot-toast'; -import editPersonalProfileApi from '../api/editPersonalProfileApi'; +import switchAccountApi from '../api/switchAccountApi'; import FormBisnis from '~/modules/register/components/FormBisnis.tsx'; import RegistrasiBisnis from '~/modules/register/components/RegistrasiBisnis.tsx'; import { Radio, RadioGroup, Stack, Divider, Button } from '@chakra-ui/react'; @@ -68,6 +68,14 @@ const SwitchAccount = () => { } }, [isTerdaftar]); + useEffect(() => { + updateForm('name', '-'); + updateForm('email', 'example@mail.com'); + updateForm('password', 'example@mail.com'); + updateForm('phone', '081234567890'); + validate(); + }, []); + const handleChangeBisnis = (value) => { setSelectedValueBisnis(value); if (value === 'true') { @@ -89,26 +97,31 @@ const SwitchAccount = () => { setIsPKP(false); } }; - + console.log('auth', auth); const onSubmitHandler = async (values) => { - let data = values; + let data = form; console.log('data', data); if (!isFormValid) { + console.log('masih ada yang belum valid'); setNotValid(true); return; } else { setNotValid(false); } // if (!values.password) delete data.password; - // const isUpdated = await editPersonalProfileApi({ data }); + const isUpdated = await switchAccountApi({ data }); + console.log('isupdate', isUpdated); - // if (isUpdated?.user) { - // setAuth(isUpdated.user); - // setValue('password', ''); - // toast.success('Berhasil mengubah profil', { duration: 1500 }); - // return; - // } - // toast.error('Terjadi kesalahan internal'); + if (isUpdated.switch === 'Pending') { + // setAuth(isUpdated.user); + // setValue('password', ''); + toast.success('Berhasil mengubah akun', { duration: 1500 }); + setTimeout(() => { + window.location.reload(); + }, 1500); + return; + } + toast.error('Terjadi kesalahan internal'); }; return ( @@ -171,7 +184,7 @@ const SwitchAccount = () => { /> )} -
+
- {isOpen && ( -
{ - e.preventDefault() - setChangeConfirmation(true) - }}> + { + e.preventDefault(); + setChangeConfirmation(true); + }} + >
} + render={(props) => ( + + )} />
@@ -139,7 +162,9 @@ const CompanyProfile = () => { } + render={(props) => ( + + )} />
@@ -153,14 +178,27 @@ const CompanyProfile = () => {
- +
- -
+ +
+
- +
+
)} -
- -
); }; -- cgit v1.2.3 From f0f002ff77481db91d264069d09f580d58001a8c Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 23 Sep 2024 13:15:02 +0700 Subject: update switch account --- src/lib/auth/api/switchAccountApi.js | 2 +- src/lib/auth/api/switchAccountProgresApi.js | 2 +- src/lib/auth/components/SwitchAccount.jsx | 12 ++++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) (limited to 'src/lib') diff --git a/src/lib/auth/api/switchAccountApi.js b/src/lib/auth/api/switchAccountApi.js index 9b772d20..79ca2553 100644 --- a/src/lib/auth/api/switchAccountApi.js +++ b/src/lib/auth/api/switchAccountApi.js @@ -5,7 +5,7 @@ const switchAccountApi = async ({ data }) => { const auth = getAuth(); const switchAccount = await odooApi( 'PUT', - `/api/v1/user/${auth.partner_id}/switch`, + `/api/v1/user/${auth.partnerId}/switch`, data ); return switchAccount; diff --git a/src/lib/auth/api/switchAccountProgresApi.js b/src/lib/auth/api/switchAccountProgresApi.js index 23e06742..ba1c35fa 100644 --- a/src/lib/auth/api/switchAccountProgresApi.js +++ b/src/lib/auth/api/switchAccountProgresApi.js @@ -6,7 +6,7 @@ const switchAccountProgresApi = async () => { console.log('auth', auth); const switchAccount = await odooApi( 'GET', - `/api/v1/user/${auth.partner_id}/switch_progres` + `/api/v1/user/${auth.partnerId}/switch_progres` ); console.log('switchAccount', switchAccount); return switchAccount; diff --git a/src/lib/auth/components/SwitchAccount.jsx b/src/lib/auth/components/SwitchAccount.jsx index b7b67864..bc9dee36 100644 --- a/src/lib/auth/components/SwitchAccount.jsx +++ b/src/lib/auth/components/SwitchAccount.jsx @@ -22,6 +22,7 @@ const SwitchAccount = () => { const [isChecked, setIsChecked] = useState(false); const [selectedValueBisnis, setSelectedValueBisnis] = useState('false'); const [selectedValue, setSelectedValue] = useState('PKP'); + const [buttonSubmitClick, setButtonSubmitClick] = useState(false); const { register, setValue, handleSubmit } = useForm({ defaultValues: { email: '', @@ -99,20 +100,22 @@ const SwitchAccount = () => { }; console.log('auth', auth); const onSubmitHandler = async (values) => { - let data = form; - console.log('data', data); + // let data = { ...form, id: `${auth.partnerId}` }; + const data = form; if (!isFormValid) { - console.log('masih ada yang belum valid'); setNotValid(true); + setButtonSubmitClick(!buttonSubmitClick); return; } else { + setButtonSubmitClick(!buttonSubmitClick); setNotValid(false); } // if (!values.password) delete data.password; + console.log('data', data); const isUpdated = await switchAccountApi({ data }); console.log('isupdate', isUpdated); - if (isUpdated.switch === 'Pending') { + if (isUpdated?.switch === 'Pending') { // setAuth(isUpdated.user); // setValue('password', ''); toast.success('Berhasil mengubah akun', { duration: 1500 }); @@ -181,6 +184,7 @@ const SwitchAccount = () => { required={isTerdaftar} isPKP={isPKP} chekValid={notValid} + buttonSubmitClick={buttonSubmitClick} />
+ +
+ setChangeConfirmation(true)} @@ -126,11 +167,19 @@ const CompanyProfile = () => { - - - {isOpen && ( + {/* */} + + {!isOpen && (
{ @@ -246,6 +296,7 @@ const CompanyProfile = () => {
)} + {isOpen && } ); }; diff --git a/src/lib/auth/components/PersonalProfile.jsx b/src/lib/auth/components/PersonalProfile.jsx index 727785bf..ce27c650 100644 --- a/src/lib/auth/components/PersonalProfile.jsx +++ b/src/lib/auth/components/PersonalProfile.jsx @@ -109,7 +109,7 @@ const PersonalProfile = () => { diff --git a/src/lib/auth/components/SwitchAccount.jsx b/src/lib/auth/components/SwitchAccount.jsx index 18c6076f..ad22da0f 100644 --- a/src/lib/auth/components/SwitchAccount.jsx +++ b/src/lib/auth/components/SwitchAccount.jsx @@ -69,7 +69,26 @@ const SwitchAccount = () => { validate(); } }, [isTerdaftar]); - + useEffect(() => { + const loadProfile = async () => { + const dataProfile = await addressApi({ + id: auth.parentId ? auth.parentId : auth.parent_id, + }); + if (dataProfile.companyType === 'Non PKP') { + setSelectedValue('PKP'); + } + updateForm('email_partner', dataProfile.email_partner); + updateForm('business_name', dataProfile.name); + updateForm('industry_id', dataProfile.industryId); + updateForm('company_type_id', dataProfile.companyTypeId); + updateForm('nama_wajib_pajak', dataProfile.taxName); + updateForm('npwp', dataProfile.npwp); + updateForm('alamat_wajib_pajak', dataProfile.alamatWajibPajak); + updateForm('alamat_bisnis', dataProfile.alamatBisnis); + validate(); + }; + if (auth) loadProfile(); + }, [auth, setValue]); useEffect(() => { updateForm('name', '-'); updateForm('email', 'example@mail.com'); @@ -125,6 +144,10 @@ const SwitchAccount = () => { toast.error('Terjadi kesalahan internal'); }; + const onSubmitHandlerCancel = async (values) => { + window.location.reload(); + }; + return ( <> -- cgit v1.2.3 From 016cbe790dd698ee258f17c8218ef6fdc667ad0d Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 27 Sep 2024 17:00:00 +0700 Subject: update switch account --- src/lib/auth/components/CompanyProfile.jsx | 2 +- src/lib/auth/components/Menu.jsx | 187 ++++++++++++++++++---------- src/lib/auth/components/PersonalProfile.jsx | 106 +++++++--------- src/lib/auth/components/SwitchAccount.jsx | 114 ++++++++++------- 4 files changed, 241 insertions(+), 168 deletions(-) (limited to 'src/lib') diff --git a/src/lib/auth/components/CompanyProfile.jsx b/src/lib/auth/components/CompanyProfile.jsx index 6065efde..cd55072c 100644 --- a/src/lib/auth/components/CompanyProfile.jsx +++ b/src/lib/auth/components/CompanyProfile.jsx @@ -296,7 +296,7 @@ const CompanyProfile = () => { )} - {isOpen && } + {isOpen && } ); }; diff --git a/src/lib/auth/components/Menu.jsx b/src/lib/auth/components/Menu.jsx index f475db1f..ddbb0760 100644 --- a/src/lib/auth/components/Menu.jsx +++ b/src/lib/auth/components/Menu.jsx @@ -1,76 +1,137 @@ -import Link from '@/core/components/elements/Link/Link' -import { useRouter } from 'next/router' -import ImageNext from 'next/image' -import whatsappUrl from '@/core/utils/whatsappUrl' +import Link from '@/core/components/elements/Link/Link'; +import { useRouter } from 'next/router'; +import ImageNext from 'next/image'; +import whatsappUrl from '@/core/utils/whatsappUrl'; +import useAuth from '@/core/hooks/useAuth'; +import Divider from '@/core/components/elements/Divider/Divider'; const Menu = () => { - const router = useRouter() - - const routeStartWith = (route) => router.pathname.startsWith(route) - + const router = useRouter(); + const auth = useAuth(); + const routeStartWith = (route) => router.pathname.startsWith(route); return (
-
Menu
- -
- -

Daftar Quotation

-
-
- -
- -

Daftar Transaksi

-
-
- -
- -

Daftar Pengiriman

-
-
- -
- -

Invoice & Faktur Pajak

-
-
- -
- -

Wishlist

-
-
+
+
Akun Saya
+ {auth?.company && ( +
Akun Bisnis
+ )} + {!auth?.company && ( +
Akun Individu
+ )} +
+
Menu
+
+ +
+ +

Daftar Quotation

+
+
+ +
+ +

Daftar Transaksi

+
+
+ +
+ +

Daftar Pengiriman

+
+
+ +
+ +

Invoice & Faktur Pajak

+
+
+ +
+ +

Wishlist

+
+
+
Pusat Bantuan
- +
- +

Layanan Pelanggan

Pengaturan Akun
- -
- -

Daftar Alamat

-
-
- -
- -

Profil Saya

-
-
- +
+ +
+ +

Daftar Alamat

+
+
+ +
+ +

Profil Saya

+
+
+ +
- ) -} + ); +}; const LinkItem = ({ children, ...props }) => ( ( > {children} -) +); -export default Menu +export default Menu; diff --git a/src/lib/auth/components/PersonalProfile.jsx b/src/lib/auth/components/PersonalProfile.jsx index ce27c650..3053255d 100644 --- a/src/lib/auth/components/PersonalProfile.jsx +++ b/src/lib/auth/components/PersonalProfile.jsx @@ -48,11 +48,7 @@ const PersonalProfile = () => { return ( <> - + - {isOpen && ( -
-
-
- - -
-
- - -
-
- - -
-
- - -
+ +
+
+ + +
+
+ +
- - - )} +
+ + +
+
+ + +
+
+ + ); }; diff --git a/src/lib/auth/components/SwitchAccount.jsx b/src/lib/auth/components/SwitchAccount.jsx index fa1d3924..d76d1f0e 100644 --- a/src/lib/auth/components/SwitchAccount.jsx +++ b/src/lib/auth/components/SwitchAccount.jsx @@ -14,7 +14,8 @@ import { registerUser } from '~/services/auth'; import { useMutation } from 'react-query'; import { isValid } from 'zod'; import useDevice from '@/core/hooks/useDevice'; -const SwitchAccount = () => { +import BottomPopup from '@/core/components/elements/Popup/BottomPopup'; +const SwitchAccount = ({ company_type }) => { const { isDesktop, isMobile } = useDevice(); const auth = useAuth(); const [isOpen, setIsOpen] = useState(true); @@ -25,6 +26,7 @@ const SwitchAccount = () => { const [selectedValueBisnis, setSelectedValueBisnis] = useState('false'); const [selectedValue, setSelectedValue] = useState('PKP'); const [buttonSubmitClick, setButtonSubmitClick] = useState(false); + const [changeConfirmation, setChangeConfirmation] = useState(false); const { register, setValue, handleSubmit } = useForm({ defaultValues: { email: '', @@ -74,7 +76,6 @@ const SwitchAccount = () => { const dataProfile = await addressApi({ id: auth.parentId ? auth.parentId : auth.parent_id, }); - console.log('dataProfile', dataProfile); if (dataProfile?.companyType === 'nonpkp') { setSelectedValue('PKP'); } @@ -120,6 +121,7 @@ const SwitchAccount = () => { } }; const onSubmitHandler = async (values) => { + setChangeConfirmation(false); // let data = { ...form, id: `${auth.partnerId}` }; const data = form; if (!isFormValid) { @@ -151,11 +153,32 @@ const SwitchAccount = () => { return ( <> - + +
+ +
{ *Perubahan akun tidak dapat diubah kembali
-
- {!isOpen && } - {isOpen && } -
- + - {isOpen && ( -
-
-

- Bisnis Terdaftar di Indoteknik? -

- - - - Sudah Terdaftar - - - Belum Terdaftar - - - -
+
+
+

+ Bisnis Terdaftar di Indoteknik? +

+ + + + Sudah Terdaftar + + + Belum Terdaftar + + + +
+ {!isTerdaftar && (

Tipe Bisnis

@@ -199,37 +215,43 @@ const SwitchAccount = () => { PKP - - Non-PKP - + {!(company_type === 'nonpkp') && ( + + Non-PKP + + )}
- -
+ )} + +
+
+
+
- )} +
); }; -- cgit v1.2.3 From 6de06f74f0a004900ecc415b91eb03d1b58a872f Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Sat, 28 Sep 2024 08:57:08 +0700 Subject: add hover --- src/lib/auth/components/Menu.jsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/lib') diff --git a/src/lib/auth/components/Menu.jsx b/src/lib/auth/components/Menu.jsx index ddbb0760..979de83b 100644 --- a/src/lib/auth/components/Menu.jsx +++ b/src/lib/auth/components/Menu.jsx @@ -118,7 +118,10 @@ const Menu = () => {

Profil Saya

- -- cgit v1.2.3 From 09e45bafb7d4a0522643ee3b188ae18b82fb27bb Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 1 Oct 2024 13:31:45 +0700 Subject: update switch account --- src/lib/auth/components/SwitchAccount.jsx | 37 +++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'src/lib') diff --git a/src/lib/auth/components/SwitchAccount.jsx b/src/lib/auth/components/SwitchAccount.jsx index 12d00890..9adcc726 100644 --- a/src/lib/auth/components/SwitchAccount.jsx +++ b/src/lib/auth/components/SwitchAccount.jsx @@ -39,8 +39,15 @@ const SwitchAccount = ({ company_type }) => { mutationFn: (data) => registerUser(data), }); const [notValid, setNotValid] = useState(false); - const { form, isCheckedTNC, isValidCaptcha, errors, validate, updateForm } = - useRegisterStore(); + const { + form, + isCheckedTNC, + isValidCaptcha, + errors, + validate, + updateForm, + resetForm, + } = useRegisterStore(); const isFormValid = useMemo(() => Object.keys(errors).length === 0, [errors]); useEffect(() => { const loadProfile = async () => { @@ -79,15 +86,17 @@ const SwitchAccount = ({ company_type }) => { if (dataProfile?.companyType === 'nonpkp') { setSelectedValue('PKP'); } - updateForm('email_partner', dataProfile?.email_partner); - updateForm('business_name', dataProfile?.name); - updateForm('industry_id', `${dataProfile?.industryId}`); - updateForm('company_type_id', `${dataProfile?.companyTypeId}`); - updateForm('nama_wajib_pajak', dataProfile?.taxName); - updateForm('npwp', dataProfile?.npwp); - updateForm('alamat_wajib_pajak', dataProfile?.alamatWajibPajak); - updateForm('alamat_bisnis', dataProfile?.alamatBisnis); - validate(); + if (auth?.company) { + updateForm('email_partner', dataProfile?.email_partner); + updateForm('business_name', dataProfile?.name); + updateForm('industry_id', `${dataProfile?.industryId}`); + updateForm('company_type_id', `${dataProfile?.companyTypeId}`); + updateForm('nama_wajib_pajak', dataProfile?.taxName); + updateForm('npwp', dataProfile?.npwp); + updateForm('alamat_wajib_pajak', dataProfile?.alamatWajibPajak); + updateForm('alamat_bisnis', dataProfile?.alamatBisnis); + validate(); + } }; if (auth) loadProfile(); }, [auth, setValue]); @@ -97,9 +106,10 @@ const SwitchAccount = ({ company_type }) => { updateForm('password', 'example@mail.com'); updateForm('phone', '081234567890'); validate(); - }, []); + }, [buttonSubmitClick, changeConfirmation]); const handleChangeBisnis = (value) => { + resetForm(); setSelectedValueBisnis(value); if (value === 'true') { validate(); @@ -121,9 +131,12 @@ const SwitchAccount = ({ company_type }) => { } }; const onSubmitHandler = async (values) => { + console.log('error', errors); + console.log('form', form); setChangeConfirmation(false); // let data = { ...form, id: `${auth.partnerId}` }; const data = form; + console.log('data', data); if (!isFormValid) { setNotValid(true); setButtonSubmitClick(!buttonSubmitClick); -- cgit v1.2.3 From 8f9be149cd5134a9e03d761f3e0e06361375bac4 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 1 Oct 2024 14:29:20 +0700 Subject: update switch account --- src/lib/auth/components/SwitchAccount.jsx | 96 ++++++++++++++++++++----------- 1 file changed, 61 insertions(+), 35 deletions(-) (limited to 'src/lib') diff --git a/src/lib/auth/components/SwitchAccount.jsx b/src/lib/auth/components/SwitchAccount.jsx index 9adcc726..640d29cc 100644 --- a/src/lib/auth/components/SwitchAccount.jsx +++ b/src/lib/auth/components/SwitchAccount.jsx @@ -131,12 +131,10 @@ const SwitchAccount = ({ company_type }) => { } }; const onSubmitHandler = async (values) => { - console.log('error', errors); - console.log('form', form); + updateForm('parent_id', `${auth.parentId}`); setChangeConfirmation(false); // let data = { ...form, id: `${auth.partnerId}` }; const data = form; - console.log('data', data); if (!isFormValid) { setNotValid(true); setButtonSubmitClick(!buttonSubmitClick); @@ -192,7 +190,7 @@ const SwitchAccount = ({ company_type }) => {
-
+ {/*
{ *Perubahan akun tidak dapat diubah kembali
+
*/} +
+
-
-
-

- Bisnis Terdaftar di Indoteknik? -

- - - - Sudah Terdaftar - - - Belum Terdaftar - - - -
- {!isTerdaftar && ( -
-

Tipe Bisnis

- - - - PKP - - {!(company_type === 'nonpkp') && ( - - Non-PKP +
+ {auth?.company && !(company_type === 'nonpkp') && ( + <> +
+

+ Bisnis Terdaftar di Indoteknik? +

+ + + + Sudah Terdaftar - )} - - -
+ + Belum Terdaftar + + + +
+ {!isTerdaftar && ( +
+

Tipe Bisnis

+ + + + PKP + + {!(company_type === 'nonpkp') && ( + + Non-PKP + + )} + + +
+ )} + )} Date: Tue, 1 Oct 2024 15:01:18 +0700 Subject: update switch account --- src/lib/auth/components/SwitchAccount.jsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/lib') diff --git a/src/lib/auth/components/SwitchAccount.jsx b/src/lib/auth/components/SwitchAccount.jsx index 640d29cc..e080fc39 100644 --- a/src/lib/auth/components/SwitchAccount.jsx +++ b/src/lib/auth/components/SwitchAccount.jsx @@ -170,8 +170,7 @@ const SwitchAccount = ({ company_type }) => { title='Ubah profil Bisnis' >
- Mohon diperhatikan bahwa perubahan data akun bisnis akan mengakibatkan - perubahan pada informasi yang tertera di faktur pajak dan invoice.? + Anda akan merubah profil bisnis anda?
-
+
{auth?.company && !(company_type === 'nonpkp') && ( <>
-- cgit v1.2.3 From 082a57a5188c594556ba76ce20182472ca9d0b5e Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Wed, 2 Oct 2024 11:47:30 +0700 Subject: update field sppkp --- src/lib/auth/components/CompanyProfile.jsx | 2 ++ src/lib/auth/components/SwitchAccount.jsx | 1 + 2 files changed, 3 insertions(+) (limited to 'src/lib') diff --git a/src/lib/auth/components/CompanyProfile.jsx b/src/lib/auth/components/CompanyProfile.jsx index cd55072c..78e62abd 100644 --- a/src/lib/auth/components/CompanyProfile.jsx +++ b/src/lib/auth/components/CompanyProfile.jsx @@ -110,7 +110,9 @@ const CompanyProfile = () => { const handleChange = async () => { if (isChecked) { setIsChecked(!isChecked); + setIsOpen(!isOpen); } else { + setIsChecked(!isChecked); setChangeType(true); } }; diff --git a/src/lib/auth/components/SwitchAccount.jsx b/src/lib/auth/components/SwitchAccount.jsx index e080fc39..6c1176bf 100644 --- a/src/lib/auth/components/SwitchAccount.jsx +++ b/src/lib/auth/components/SwitchAccount.jsx @@ -93,6 +93,7 @@ const SwitchAccount = ({ company_type }) => { updateForm('company_type_id', `${dataProfile?.companyTypeId}`); updateForm('nama_wajib_pajak', dataProfile?.taxName); updateForm('npwp', dataProfile?.npwp); + updateForm('sppkp', dataProfile?.sppkp); updateForm('alamat_wajib_pajak', dataProfile?.alamatWajibPajak); updateForm('alamat_bisnis', dataProfile?.alamatBisnis); validate(); -- cgit v1.2.3 From a32fa70ab3271e94a9c2b9004f872360dcb7d1c5 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Wed, 2 Oct 2024 13:21:25 +0700 Subject: update switch account --- src/lib/auth/components/SwitchAccount.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/lib') diff --git a/src/lib/auth/components/SwitchAccount.jsx b/src/lib/auth/components/SwitchAccount.jsx index 6c1176bf..fd9f04f9 100644 --- a/src/lib/auth/components/SwitchAccount.jsx +++ b/src/lib/auth/components/SwitchAccount.jsx @@ -225,7 +225,7 @@ const SwitchAccount = ({ company_type }) => {
- {auth?.company && !(company_type === 'nonpkp') && ( + {!auth?.company && company_type === 'nonpkp' && ( <>

@@ -253,7 +253,7 @@ const SwitchAccount = ({ company_type }) => { PKP - {!(company_type === 'nonpkp') && ( + {!auth?.company && company_type === 'nonpkp' && ( Non-PKP -- cgit v1.2.3 From 5f3c071f0b18055bccb78407ada60619f43bb9c3 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Wed, 2 Oct 2024 13:28:00 +0700 Subject: update color --- src/lib/auth/components/SwitchAccount.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/lib') diff --git a/src/lib/auth/components/SwitchAccount.jsx b/src/lib/auth/components/SwitchAccount.jsx index fd9f04f9..36d1e0b6 100644 --- a/src/lib/auth/components/SwitchAccount.jsx +++ b/src/lib/auth/components/SwitchAccount.jsx @@ -204,7 +204,7 @@ const SwitchAccount = ({ company_type }) => {

*/}
-
-
+
+
handleCheckboxBersediaChange('bersedia')} value={true} size='md' > @@ -522,17 +664,19 @@ const informasiPerusahaan = ({}) => { handleCheckboxBersediaChange('tidakBersedia')} value={false} size='md' > Tidak bersedia
-
- {errors.estimasi?.message} -
+ {chekValid && ( +
+ {errors.estimasi} +
+ )}
@@ -545,80 +689,40 @@ const informasiPerusahaan = ({}) => { Pilih produk bisa lebih dari 1
-
-
- {firstColumn.map((item) => ( - handleCheckboxChange(item.id)} - > - {item.name} - - ))} -
-
- {secondColumn.map((item) => ( - handleCheckboxChange(item.id)} - > - {item.name} - - ))} +
+
+
+ {firstColumn.map((item) => ( + handleCheckboxChange(item.id)} + > + {item.name} + + ))} +
+
+ {secondColumn.map((item) => ( + handleCheckboxChange(item.id)} + > + {item.name} + + ))} +
+ {chekValid && ( +
+ {errors.categoryProduk} +
+ )}
-
- - *Pastikan data yang anda masukan sudah benar dan sesuai - - -
); }; -const validationSchema = Yup.object().shape({ - // email: Yup.string() - // .email('Format harus seperti contoh@email.com') - // .required('Harus di-isi'), - name: Yup.string().required('Harus di-isi'), - industry_id: Yup.string().required('Harus di-pilih'), - street: Yup.string().required('Harus di-isi'), - zip: Yup.string().required('Harus di-isi'), - state: Yup.string().required('Harus di-pilih'), - city: Yup.string().required('Harus di-pilih'), - mobile: Yup.string().required('Harus di-isi'), - bankName: Yup.string().required('Harus di-isi'), - accountName: Yup.string().required('Harus di-isi'), - accountNumber: Yup.string().required('Harus di-isi'), - estimasi: Yup.string().required('Harus di-isi'), - tempoDuration: Yup.string().required('Harus di-isi'), - bersedia: Yup.string().required('Harus di-pilih'), -}); - -const defaultValues = { - // email: '', - name: '', - industry_id: '', - street: '', - state: '', - city: '', - zip: '', - mobile: '', - bankName: '', - accountName: '', - accountNumber: '', - estimasi: '', - tempoDuration: '', - bersedia: '', -}; - export default informasiPerusahaan; diff --git a/src/lib/pengajuan-tempo/stores/useTempoStore.ts b/src/lib/pengajuan-tempo/stores/useTempoStore.ts deleted file mode 100644 index e69de29b..00000000 -- cgit v1.2.3 From 0908fc0075f91844ffed4002165c638d02eb91be Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Thu, 17 Oct 2024 16:01:50 +0700 Subject: update pengajuan tempo --- src/lib/pengajuan-tempo/component/PengajuanTempo.jsx | 3 +++ src/lib/pengajuan-tempo/component/informasiPerusahaan.jsx | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'src/lib') diff --git a/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx b/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx index bc7dcb69..5f250438 100644 --- a/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx +++ b/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx @@ -33,8 +33,11 @@ const PengajuanTempo = () => { setNotValid(true); setButtonSubmitClick(!buttonSubmitClick); console.log('form', form); + console.log('error', errors); return; } else { + console.log('form', form); + console.log('error', errors); setButtonSubmitClick(!buttonSubmitClick); setNotValid(false); } diff --git a/src/lib/pengajuan-tempo/component/informasiPerusahaan.jsx b/src/lib/pengajuan-tempo/component/informasiPerusahaan.jsx index 82cf4aee..d2097849 100644 --- a/src/lib/pengajuan-tempo/component/informasiPerusahaan.jsx +++ b/src/lib/pengajuan-tempo/component/informasiPerusahaan.jsx @@ -126,7 +126,7 @@ const informasiPerusahaan = ({ chekValid, buttonSubmitClick }) => { } else if (value === 'tidakBersedia') { setBersedia(false); } - updateForm('bersedia', value === 'bersedia'); + updateForm('bersedia', `${value === 'bersedia'}`); validate(); }; const [selectedIds, setSelectedIds] = useState([]); -- cgit v1.2.3 From ead46a6d760850530946926b390a8954ca64e1c2 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Thu, 17 Oct 2024 17:06:58 +0700 Subject: update pengajuan tempo --- .../pengajuan-tempo/component/KontakPerusahaan.jsx | 725 +++++++++++++++++++++ .../pengajuan-tempo/component/PengajuanTempo.jsx | 5 + .../component/informasiPerusahaan.jsx | 2 +- 3 files changed, 731 insertions(+), 1 deletion(-) (limited to 'src/lib') diff --git a/src/lib/pengajuan-tempo/component/KontakPerusahaan.jsx b/src/lib/pengajuan-tempo/component/KontakPerusahaan.jsx index e69de29b..d292449b 100644 --- a/src/lib/pengajuan-tempo/component/KontakPerusahaan.jsx +++ b/src/lib/pengajuan-tempo/component/KontakPerusahaan.jsx @@ -0,0 +1,725 @@ +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 { usePengajuanTempoStore } from '../../../../src-migrate/modules/register/stores/usePengajuanTempoStore'; +const KontakPerusahaan = ({ chekValid, buttonSubmitClick }) => { + const { control, watch } = useForm(); + const { form, errors, validate, updateForm } = usePengajuanTempoStore(); + const [industries, setIndustries] = useState([]); + const [selectedCategory, setSelectedCategory] = useState(''); + const [states, setState] = useState([]); + const [cities, setCities] = useState([]); + const [bersedia, setBersedia] = useState(null); + const category_produk = [ + { id: 1, name: 'Pengaman, Kesehatan & Keamanan' }, + { id: 2, name: 'Perkakas Tangan, Listrik & Pneumatic' }, + { id: 3, name: 'Mesin Industrial' }, + { id: 4, name: 'Mesin Pertanian & Perkebunan' }, + { id: 5, name: 'Mesin Pembersih & Janitorial' }, + { id: 6, name: 'Cairan Berbahan Kimia' }, + { id: 7, name: 'Perlengkapan Pengukuran & Pengujian' }, + { id: 8, name: 'Peralatan Listrik & Elektronik' }, + { id: 9, name: 'Perlengkapan Logistik & Gudang' }, + { id: 10, name: 'Peralatan Kantor & Stationery' }, + { id: 11, name: 'Komponen & Aksesoris' }, + { id: 12, name: 'Peralatan Horeca & Food Service' }, + ]; + + useEffect(() => { + const loadState = async () => { + let dataState = await stateApi(); + dataState = dataState.map((state) => ({ + value: state.id, + label: state.name, + })); + setState(dataState); + }; + loadState(); + }, []); + + const watchState = watch('state'); + useEffect(() => { + updateForm('city', ''); + if (watchState) { + updateForm('state', `${watchState}`); + validate(); + const loadCities = async () => { + let dataCities = await cityApi({ stateId: watchState }); + dataCities = dataCities.map((city) => ({ + value: city.id, + label: city.name, + })); + setCities(dataCities); + }; + loadCities(); + } + }, [watchState]); + + const watchCity = watch('city'); + useEffect(() => { + if (watchCity) { + updateForm('city', `${watchCity}`); + validate(); + } + }, [watchCity]); + + useEffect(() => { + const loadIndustries = async () => { + const dataIndustries = await odooApi('GET', '/api/v1/partner/industry'); + setIndustries( + dataIndustries?.map((o) => ({ + value: o.id, + label: o.name, + category: o.category, + })) + ); + }; + loadIndustries(); + }, []); + + useEffect(() => { + const selectedIndustryType = industries.find( + (industry) => industry.value === watch('industry_id') + ); + if (selectedIndustryType) { + updateForm('industry_id', `${selectedIndustryType?.value}`); + validate(); + setSelectedCategory(selectedIndustryType.category); + } + }, [watch('industry_id'), industries]); + + const estimasiValue = watch('estimasi'); + const tempoLimitValue = watch('tempoLimit'); + + // Memformat angka menjadi format rupiah + const formatRupiah = (value) => { + if (!value) return ''; + const numberString = value.replace(/[^0-9]/g, ''); // Menghapus karakter non-digit + return numberString + ? 'Rp ' + new Intl.NumberFormat('id-ID').format(numberString) + : ''; + }; + + const handleChange = (e) => { + const value = e.target.value; + const formattedValue = formatRupiah(value); + console.log('formattedValue', formattedValue); + updateForm('estimasi', formattedValue.replace(/^Rp\s*/, '')); + validate(); + }; + const onChangeTempoDuration = (e) => { + updateForm('tempoDuration', `${e}`); + validate(); + }; + + const onChangeTempoLimit = (e) => { + updateForm('tempoLimit', `${e}`); + validate(); + }; + const handleCheckboxBersediaChange = (value) => { + if (value === 'bersedia') { + setBersedia(true); + } else if (value === 'tidakBersedia') { + setBersedia(false); + } + updateForm('bersedia', `${value === 'bersedia'}`); + validate(); + }; + const [selectedIds, setSelectedIds] = useState([]); + + const handleCheckboxChange = (id) => { + setSelectedIds((prevSelected) => + prevSelected.includes(id) + ? prevSelected.filter((selectedId) => selectedId !== id) + : [...prevSelected, id] + ); + updateForm('categoryProduk', `${selectedIds}`); + validate(); + }; + + const handleInputChange = (event) => { + const { name, value } = event.target; + updateForm(name, value); + validate(); + }; + + const midIndex = Math.ceil(category_produk.length / 2); + const firstColumn = category_produk.slice(0, midIndex); + const secondColumn = category_produk.slice(midIndex); + const isFormValid = useMemo(() => Object.keys(errors).length === 0, [errors]); + + const nameRef = useRef(null); + const industry_idRef = useRef(null); + const streetRef = useRef(null); + const stateRef = useRef(null); + const cityRef = useRef(null); + const zipRef = useRef(null); + const mobileRef = useRef(null); + const bankNameRef = useRef(null); + const accountNameRef = useRef(null); + const accountNumberRef = useRef(null); + const estimasiRef = useRef(null); + const tempoDurationRef = useRef(null); + const bersediaRef = useRef(null); + const categoryProdukRef = useRef(null); + const tempoLimitRef = useRef(null); + useEffect(() => { + const loadIndustries = async () => { + if (!isFormValid) { + const options = { + behavior: 'smooth', + block: 'center', + }; + if (errors.name && nameRef.current) { + nameRef.current.scrollIntoView(options); + return; + } + if (errors.industry_id && industry_idRef.current) { + industry_idRef.current.scrollIntoView(options); + return; + } + if (errors.street && streetRef.current) { + streetRef.current.scrollIntoView(options); + return; + } + if (errors.state && stateRef.current) { + stateRef.current.scrollIntoView(options); + return; + } + if (errors.city && cityRef.current) { + cityRef.current.scrollIntoView(options); + return; + } + if (errors.zip && zipRef.current) { + zipRef.current.scrollIntoView(options); + return; + } + if (errors.mobile && mobileRef.current) { + mobileRef.current.scrollIntoView(options); + return; + } + if (errors.bankName && bankNameRef.current) { + bankNameRef.current.scrollIntoView(options); + return; + } + if (errors.accountName && accountNameRef.current) { + accountNameRef.current.scrollIntoView(options); + return; + } + if (errors.accountNumber && accountNumberRef.current) { + accountNumberRef.current.scrollIntoView(options); + return; + } + if (errors.estimasi && estimasiRef.current) { + estimasiRef.current.scrollIntoView(options); + return; + } + if (errors.tempoDuration && tempoDurationRef.current) { + tempoDurationRef.current.scrollIntoView(options); + return; + } + if (errors.bersedia && bersediaRef.current) { + bersediaRef.current.scrollIntoView(options); + return; + } + if (errors.categoryProduk && categoryProdukRef.current) { + categoryProdukRef.current.scrollIntoView(options); + return; + } + if (errors.tempoLimit && tempoLimitRef.current) { + tempoLimitRef.current.scrollIntoView(options); + return; + } + } + }; + loadIndustries(); + }, [buttonSubmitClick, chekValid]); + return ( + <> +
+

Kontak Person

+
+
+
+
+
+ +
+
+ + + Format: PT. INDOTEKNIK DOTCOM GEMILANG + + {chekValid && ( +
+ {errors.name} +
+ )} +
+
+
+
+ + + isi detail perusahaan sesuai dengan nama yang terdaftar + +
+
+ ( + + )} + /> + {selectedCategory && ( + + Kategori : {selectedCategory} + + )} + {chekValid && ( +
+ {errors.industry_id} +
+ )} +
+
+ +
+
+ + + alamat sesuai dengan alamat kantor pusat + +
+
+
+ + {chekValid && ( +
+ {errors.street} +
+ )} +
+
+
+ ( + + )} + /> + {chekValid && ( +
+ {errors.state} +
+ )} +
+
+ ( + + )} + /> + {chekValid && ( +
+ {errors.city} +
+ )} +
+
+ + {chekValid && ( +
+ {errors.zip} +
+ )} +
+
+
+
+
+
+ + + isi no telfon perusahaan yang sesuai + +
+
+ + {chekValid && ( +
+ {errors.mobile} +
+ )} +
+
+ +
+
+ + + Isi detail data bank perusahaan anda + +
+
+
+ + + Format: BCA, Mandiri, CIMB, BNI dll + + {chekValid && ( +
+ {errors.bankName} +
+ )} +
+
+ + Format: John Doe + {chekValid && ( +
+ {errors.accountName} +
+ )} +
+
+ + Format: 01234567896 + {chekValid && ( +
+ {errors.accountNumber} +
+ )} +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+ value.replace(/^Rp\s*/, ''), // Menyimpan hanya angka + // })} + placeholder='Isi estimasi pembelian produk pertahun' + type='text' + className='form-input' // padding untuk memberi ruang untuk "RP" + value={formatRupiah(form.estimasi)} + onChange={handleChange} // Mengatur perubahan input + /> +
+ {chekValid && ( +
+ {errors.estimasi} +
+ )} +
+
+ +
+
+ + + Pilih durasi tempo yang anda inginkan + +
+
+
+ + + + 7 Hari + + + 14 Hari + + + 30 Hari + + + + {chekValid && ( +
+ {errors.tempoDuration} +
+ )} +
+
+
+ + + Ajukan nilai limit yang anda mau + +
+
+ + + {/* Kolom 1 */} + + + 5.000.000 + + + 10.000.000 + + + 15.000.000 + + + 20.000.000 + + + + {/* Kolom 2 */} + + + 25.000.000 + + + 30.000.000 + + + 35.000.000 + +
+ + { + const value = e.target.value; + const formattedValue = formatRupiah(value); + updateForm('tempoLimit', formattedValue); // Mengupdate nilai di react-hook-form + }} + /> +
+
+
+
+ {chekValid && ( +
+ {errors.tempoLimit} +
+ )} +
+
+
+
+ +
+ *Durasi dan limit dapat berbeda sesuaui dengan verifikasi oleh tim + Indoteknik.com +
+ +
+
+ + + Pilih produk bisa lebih dari 1 + +
+
+
+ handleCheckboxBersediaChange('bersedia')} + value={true} + size='md' + > + Saya bersedia + + handleCheckboxBersediaChange('tidakBersedia')} + value={false} + size='md' + > + Tidak bersedia + +
+ {chekValid && ( +
+ {errors.estimasi} +
+ )} +
+
+ +
+
+ + + Pilih produk bisa lebih dari 1 + +
+
+
+
+ {firstColumn.map((item) => ( + handleCheckboxChange(item.id)} + > + {item.name} + + ))} +
+
+ {secondColumn.map((item) => ( + handleCheckboxChange(item.id)} + > + {item.name} + + ))} +
+
+ {chekValid && ( +
+ {errors.categoryProduk} +
+ )} +
+
+
+
+ + ); +}; + +export default KontakPerusahaan; diff --git a/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx b/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx index 5f250438..c15189d1 100644 --- a/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx +++ b/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx @@ -2,6 +2,7 @@ import React from 'react'; import { useMemo, useState, useEffect, useRef } from 'react'; import Stepper from './Stepper'; import InformasiPerusahaan from './informasiPerusahaan'; +import KontakPerusahaan from './KontakPerusahaan'; import { Controller, useForm } from 'react-hook-form'; import { usePengajuanTempoStore } from '../../../../src-migrate/modules/register/stores/usePengajuanTempoStore'; import { ChevronRightIcon } from '@heroicons/react/24/outline'; @@ -13,6 +14,10 @@ const PengajuanTempo = () => { const isFormValid = useMemo(() => Object.keys(errors).length === 0, [errors]); const [buttonSubmitClick, setButtonSubmitClick] = useState(false); const stepDivs = [ + , { return ( <>
-

Informasi Perusahaan

+

Informasi Perusahaan

-- cgit v1.2.3 From 661d742193b62aeb3d2a2350433bdd3714667625 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 18 Oct 2024 10:39:40 +0700 Subject: add kontak perusahaan --- .../pengajuan-tempo/component/KontakPerusahaan.jsx | 598 ++++++--------------- .../pengajuan-tempo/component/PengajuanTempo.jsx | 32 +- .../component/informasiPerusahaan.jsx | 2 +- 3 files changed, 188 insertions(+), 444 deletions(-) (limited to 'src/lib') diff --git a/src/lib/pengajuan-tempo/component/KontakPerusahaan.jsx b/src/lib/pengajuan-tempo/component/KontakPerusahaan.jsx index d292449b..a595ff13 100644 --- a/src/lib/pengajuan-tempo/component/KontakPerusahaan.jsx +++ b/src/lib/pengajuan-tempo/component/KontakPerusahaan.jsx @@ -5,10 +5,15 @@ 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 { usePengajuanTempoStore } from '../../../../src-migrate/modules/register/stores/usePengajuanTempoStore'; +import { usePengajuanTempoStoreKontakPerson } from '../../../../src-migrate/modules/register/stores/usePengajuanTempoStore'; const KontakPerusahaan = ({ chekValid, buttonSubmitClick }) => { const { control, watch } = useForm(); - const { form, errors, validate, updateForm } = usePengajuanTempoStore(); + const { + formKontakPerson, + errorsKontakPerson, + validateKontakPerson, + updateFormKontakPerson, + } = usePengajuanTempoStoreKontakPerson(); const [industries, setIndustries] = useState([]); const [selectedCategory, setSelectedCategory] = useState(''); const [states, setState] = useState([]); @@ -43,10 +48,10 @@ const KontakPerusahaan = ({ chekValid, buttonSubmitClick }) => { const watchState = watch('state'); useEffect(() => { - updateForm('city', ''); + updateFormKontakPerson('city', ''); if (watchState) { - updateForm('state', `${watchState}`); - validate(); + updateFormKontakPerson('state', `${watchState}`); + validateKontakPerson(); const loadCities = async () => { let dataCities = await cityApi({ stateId: watchState }); dataCities = dataCities.map((city) => ({ @@ -62,8 +67,8 @@ const KontakPerusahaan = ({ chekValid, buttonSubmitClick }) => { const watchCity = watch('city'); useEffect(() => { if (watchCity) { - updateForm('city', `${watchCity}`); - validate(); + updateFormKontakPerson('city', `${watchCity}`); + validateKontakPerson(); } }, [watchCity]); @@ -86,8 +91,8 @@ const KontakPerusahaan = ({ chekValid, buttonSubmitClick }) => { (industry) => industry.value === watch('industry_id') ); if (selectedIndustryType) { - updateForm('industry_id', `${selectedIndustryType?.value}`); - validate(); + updateFormKontakPerson('industry_id', `${selectedIndustryType?.value}`); + validateKontakPerson(); setSelectedCategory(selectedIndustryType.category); } }, [watch('industry_id'), industries]); @@ -108,17 +113,17 @@ const KontakPerusahaan = ({ chekValid, buttonSubmitClick }) => { const value = e.target.value; const formattedValue = formatRupiah(value); console.log('formattedValue', formattedValue); - updateForm('estimasi', formattedValue.replace(/^Rp\s*/, '')); - validate(); + updateFormKontakPerson('estimasi', formattedValue.replace(/^Rp\s*/, '')); + validateKontakPerson(); }; const onChangeTempoDuration = (e) => { - updateForm('tempoDuration', `${e}`); - validate(); + updateFormKontakPerson('tempoDuration', `${e}`); + validateKontakPerson(); }; const onChangeTempoLimit = (e) => { - updateForm('tempoLimit', `${e}`); - validate(); + updateFormKontakPerson('tempoLimit', `${e}`); + validateKontakPerson(); }; const handleCheckboxBersediaChange = (value) => { if (value === 'bersedia') { @@ -126,8 +131,8 @@ const KontakPerusahaan = ({ chekValid, buttonSubmitClick }) => { } else if (value === 'tidakBersedia') { setBersedia(false); } - updateForm('bersedia', `${value === 'bersedia'}`); - validate(); + updateFormKontakPerson('bersedia', `${value === 'bersedia'}`); + validateKontakPerson(); }; const [selectedIds, setSelectedIds] = useState([]); @@ -137,36 +142,33 @@ const KontakPerusahaan = ({ chekValid, buttonSubmitClick }) => { ? prevSelected.filter((selectedId) => selectedId !== id) : [...prevSelected, id] ); - updateForm('categoryProduk', `${selectedIds}`); - validate(); + updateFormKontakPerson('categoryProduk', `${selectedIds}`); + validateKontakPerson(); }; const handleInputChange = (event) => { const { name, value } = event.target; - updateForm(name, value); - validate(); + updateFormKontakPerson(name, value); + validateKontakPerson(); }; const midIndex = Math.ceil(category_produk.length / 2); const firstColumn = category_produk.slice(0, midIndex); const secondColumn = category_produk.slice(midIndex); - const isFormValid = useMemo(() => Object.keys(errors).length === 0, [errors]); + const isFormValid = useMemo( + () => Object.keys(errorsKontakPerson).length === 0, + [errorsKontakPerson] + ); + + const direkturNameRef = useRef(null); + const direkturMobileRef = useRef(null); + const direkturEmailRef = useRef(null); + const purchasingNameRef = useRef(null); + const purchasingEmailRef = useRef(null); + const financeNameRef = useRef(null); + const financeMobileRef = useRef(null); + const financeEmailRef = useRef(null); - const nameRef = useRef(null); - const industry_idRef = useRef(null); - const streetRef = useRef(null); - const stateRef = useRef(null); - const cityRef = useRef(null); - const zipRef = useRef(null); - const mobileRef = useRef(null); - const bankNameRef = useRef(null); - const accountNameRef = useRef(null); - const accountNumberRef = useRef(null); - const estimasiRef = useRef(null); - const tempoDurationRef = useRef(null); - const bersediaRef = useRef(null); - const categoryProdukRef = useRef(null); - const tempoLimitRef = useRef(null); useEffect(() => { const loadIndustries = async () => { if (!isFormValid) { @@ -174,64 +176,36 @@ const KontakPerusahaan = ({ chekValid, buttonSubmitClick }) => { behavior: 'smooth', block: 'center', }; - if (errors.name && nameRef.current) { - nameRef.current.scrollIntoView(options); - return; - } - if (errors.industry_id && industry_idRef.current) { - industry_idRef.current.scrollIntoView(options); - return; - } - if (errors.street && streetRef.current) { - streetRef.current.scrollIntoView(options); + if (errorsKontakPerson.direkturName && direkturNameRef.current) { + direkturNameRef.current.scrollIntoView(options); return; } - if (errors.state && stateRef.current) { - stateRef.current.scrollIntoView(options); + if (errorsKontakPerson.direkturMobile && direkturMobileRef.current) { + direkturMobileRef.current.scrollIntoView(options); return; } - if (errors.city && cityRef.current) { - cityRef.current.scrollIntoView(options); + if (errorsKontakPerson.direkturEmail && direkturEmailRef.current) { + direkturEmailRef.current.scrollIntoView(options); return; } - if (errors.zip && zipRef.current) { - zipRef.current.scrollIntoView(options); + if (errorsKontakPerson.purchasingName && purchasingNameRef.current) { + purchasingNameRef.current.scrollIntoView(options); return; } - if (errors.mobile && mobileRef.current) { - mobileRef.current.scrollIntoView(options); + if (errorsKontakPerson.purchasingEmail && purchasingEmailRef.current) { + purchasingEmailRef.current.scrollIntoView(options); return; } - if (errors.bankName && bankNameRef.current) { - bankNameRef.current.scrollIntoView(options); + if (errorsKontakPerson.financeName && financeNameRef.current) { + financeNameRef.current.scrollIntoView(options); return; } - if (errors.accountName && accountNameRef.current) { - accountNameRef.current.scrollIntoView(options); + if (errorsKontakPerson.financeMobile && financeMobileRef.current) { + financeMobileRef.current.scrollIntoView(options); return; } - if (errors.accountNumber && accountNumberRef.current) { - accountNumberRef.current.scrollIntoView(options); - return; - } - if (errors.estimasi && estimasiRef.current) { - estimasiRef.current.scrollIntoView(options); - return; - } - if (errors.tempoDuration && tempoDurationRef.current) { - tempoDurationRef.current.scrollIntoView(options); - return; - } - if (errors.bersedia && bersediaRef.current) { - bersediaRef.current.scrollIntoView(options); - return; - } - if (errors.categoryProduk && categoryProdukRef.current) { - categoryProdukRef.current.scrollIntoView(options); - return; - } - if (errors.tempoLimit && tempoLimitRef.current) { - tempoLimitRef.current.scrollIntoView(options); + if (errorsKontakPerson.financeEmail && financeEmailRef.current) { + financeEmailRef.current.scrollIntoView(options); return; } } @@ -253,52 +227,46 @@ const KontakPerusahaan = ({ chekValid, buttonSubmitClick }) => {
- - Format: PT. INDOTEKNIK DOTCOM GEMILANG - {chekValid && (
- {errors.name} + {errorsKontakPerson.direkturName}
)}
+
-
- +
+ - isi detail perusahaan sesuai dengan nama yang terdaftar + isi nomor telpon direktur di perusahaan kamu
- ( - - )} + - {selectedCategory && ( - - Kategori : {selectedCategory} - - )} {chekValid && (
- {errors.industry_id} + {errorsKontakPerson.direkturMobile}
)}
@@ -307,371 +275,137 @@ const KontakPerusahaan = ({ chekValid, buttonSubmitClick }) => {
- alamat sesuai dengan alamat kantor pusat + isi email Direktur yang sesuai
-
-
- - {chekValid && ( -
- {errors.street} -
- )} -
-
-
- ( - - )} - /> - {chekValid && ( -
- {errors.state} -
- )} -
-
- ( - - )} - /> - {chekValid && ( -
- {errors.city} -
- )} -
-
- - {chekValid && ( -
- {errors.zip} -
- )} +
+ + {chekValid && ( +
+ {errorsKontakPerson.direkturEmail}
-
+ )}
+
- isi no telfon perusahaan yang sesuai + isi nama purchasing yang bertanggung jawab di perusahaan anda
{chekValid && (
- {errors.mobile} + {errorsKontakPerson.purchasingName}
)}
-
-
- - - Isi detail data bank perusahaan anda - -
-
-
- - - Format: BCA, Mandiri, CIMB, BNI dll - - {chekValid && ( -
- {errors.bankName} -
- )} -
-
- - Format: John Doe - {chekValid && ( -
- {errors.accountName} -
- )} -
-
- - Format: 01234567896 - {chekValid && ( -
- {errors.accountNumber} -
- )} -
-
-
-
+ + isi email purchasing benar +
-
-
- -
-
- -
-
-
- value.replace(/^Rp\s*/, ''), // Menyimpan hanya angka - // })} - placeholder='Isi estimasi pembelian produk pertahun' - type='text' - className='form-input' // padding untuk memberi ruang untuk "RP" - value={formatRupiah(form.estimasi)} - onChange={handleChange} // Mengatur perubahan input - /> -
{chekValid && (
- {errors.estimasi} + {errorsKontakPerson.purchasingEmail}
)}
-
+
- Pilih durasi tempo yang anda inginkan + isi nama finance yang bertanggung jawab di perusahaan anda
-
-
- - - - 7 Hari - - - 14 Hari - - - 30 Hari - - - - {chekValid && ( -
- {errors.tempoDuration} -
- )} -
-
-
- - - Ajukan nilai limit yang anda mau - -
-
- - - {/* Kolom 1 */} - - - 5.000.000 - - - 10.000.000 - - - 15.000.000 - - - 20.000.000 - - - - {/* Kolom 2 */} - - - 25.000.000 - - - 30.000.000 - - - 35.000.000 - -
- - { - const value = e.target.value; - const formattedValue = formatRupiah(value); - updateForm('tempoLimit', formattedValue); // Mengupdate nilai di react-hook-form - }} - /> -
-
-
-
- {chekValid && ( -
- {errors.tempoLimit} -
- )} +
+ + {chekValid && ( +
+ {errorsKontakPerson.financeName}
-
+ )}
- -
- *Durasi dan limit dapat berbeda sesuaui dengan verifikasi oleh tim - Indoteknik.com -
-
- Pilih produk bisa lebih dari 1 + isi nomor finance yang bertanggung jawab di perusahaan anda
-
-
- handleCheckboxBersediaChange('bersedia')} - value={true} - size='md' - > - Saya bersedia - - handleCheckboxBersediaChange('tidakBersedia')} - value={false} - size='md' - > - Tidak bersedia - -
+
+ {chekValid && (
- {errors.estimasi} + {errorsKontakPerson.financeMobile}
)}
@@ -680,38 +414,26 @@ const KontakPerusahaan = ({ chekValid, buttonSubmitClick }) => {
- Pilih produk bisa lebih dari 1 + isi email finance dengan benar
-
-
-
- {firstColumn.map((item) => ( - handleCheckboxChange(item.id)} - > - {item.name} - - ))} -
-
- {secondColumn.map((item) => ( - handleCheckboxChange(item.id)} - > - {item.name} - - ))} -
-
+
+ {chekValid && (
- {errors.categoryProduk} + {errorsKontakPerson.financeEmail}
)}
diff --git a/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx b/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx index c15189d1..b2e9832e 100644 --- a/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx +++ b/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx @@ -4,14 +4,22 @@ import Stepper from './Stepper'; import InformasiPerusahaan from './informasiPerusahaan'; import KontakPerusahaan from './KontakPerusahaan'; import { Controller, useForm } from 'react-hook-form'; -import { usePengajuanTempoStore } from '../../../../src-migrate/modules/register/stores/usePengajuanTempoStore'; +import { + usePengajuanTempoStore, + usePengajuanTempoStoreKontakPerson, +} from '../../../../src-migrate/modules/register/stores/usePengajuanTempoStore'; import { ChevronRightIcon } from '@heroicons/react/24/outline'; const PengajuanTempo = () => { const [currentStep, setCurrentStep] = React.useState(0); const NUMBER_OF_STEPS = 6; const { form, errors, validate, updateForm } = usePengajuanTempoStore(); + const { + formKontakPerson, + errorsKontakPerson, + validateKontakPerson, + updateFormKontakPerson, + } = usePengajuanTempoStoreKontakPerson(); const [notValid, setNotValid] = useState(false); - const isFormValid = useMemo(() => Object.keys(errors).length === 0, [errors]); const [buttonSubmitClick, setButtonSubmitClick] = useState(false); const stepDivs = [ {
Dokumen
,
Konfirmasi
, ]; + const stepDivsError = [ + errorsKontakPerson, + errors, +
Kontak Person
, +
Pengiriman
, +
Referensi
, +
Dokumen
, +
Konfirmasi
, + ]; + const isFormValid = useMemo( + () => Object.keys(stepDivsError[currentStep]).length === 0, + [stepDivsError[currentStep]] + ); useEffect(() => { validate(); + validateKontakPerson(); }, []); - + console.log('isFormValid', isFormValid); const goToNextStep = () => { if (!isFormValid) { setNotValid(true); setButtonSubmitClick(!buttonSubmitClick); console.log('form', form); - console.log('error', errors); + console.log('error', stepDivsError[currentStep]); return; } else { console.log('form', form); - console.log('error', errors); + console.log('error', stepDivsError[currentStep]); setButtonSubmitClick(!buttonSubmitClick); setNotValid(false); } diff --git a/src/lib/pengajuan-tempo/component/informasiPerusahaan.jsx b/src/lib/pengajuan-tempo/component/informasiPerusahaan.jsx index 0a33f5fb..e5b2ff2c 100644 --- a/src/lib/pengajuan-tempo/component/informasiPerusahaan.jsx +++ b/src/lib/pengajuan-tempo/component/informasiPerusahaan.jsx @@ -405,7 +405,7 @@ const informasiPerusahaan = ({ chekValid, buttonSubmitClick }) => { name='mobile' ref={mobileRef} placeholder='Masukkan nomor telfon perusahaan' - type='text' + type='tel' className='form-input' aria-invalid={errors.mobile} onChange={handleInputChange} -- cgit v1.2.3 From b884ae8fb7b3d208912f75decfe941435c59d571 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 18 Oct 2024 11:25:02 +0700 Subject: save to local storage --- .../pengajuan-tempo/component/PengajuanTempo.jsx | 72 +++++++++++++++++----- .../component/informasiPerusahaan.jsx | 8 +++ 2 files changed, 65 insertions(+), 15 deletions(-) (limited to 'src/lib') diff --git a/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx b/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx index b2e9832e..bdd6e6ef 100644 --- a/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx +++ b/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx @@ -8,7 +8,8 @@ import { usePengajuanTempoStore, usePengajuanTempoStoreKontakPerson, } from '../../../../src-migrate/modules/register/stores/usePengajuanTempoStore'; -import { ChevronRightIcon } from '@heroicons/react/24/outline'; +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; @@ -22,11 +23,11 @@ const PengajuanTempo = () => { const [notValid, setNotValid] = useState(false); const [buttonSubmitClick, setButtonSubmitClick] = useState(false); const stepDivs = [ - , - , @@ -37,14 +38,31 @@ const PengajuanTempo = () => {
Konfirmasi
, ]; const stepDivsError = [ - errorsKontakPerson, errors, + errorsKontakPerson, +
Kontak Person
, +
Pengiriman
, +
Referensi
, +
Dokumen
, +
Konfirmasi
, + ]; + const stepDivsForm = [ + form, + formKontakPerson,
Kontak Person
,
Pengiriman
,
Referensi
,
Dokumen
,
Konfirmasi
, ]; + const stepLabels = [ + 'informasi_perusahaan', + 'kontak_person', + 'Pengiriman', + 'Referensi', + 'Dokumen', + 'Konfirmasi', + ]; const isFormValid = useMemo( () => Object.keys(stepDivsError[currentStep]).length === 0, @@ -54,16 +72,18 @@ const PengajuanTempo = () => { validate(); validateKontakPerson(); }, []); - console.log('isFormValid', isFormValid); const goToNextStep = () => { if (!isFormValid) { setNotValid(true); setButtonSubmitClick(!buttonSubmitClick); - console.log('form', form); + console.log('form', stepDivsForm[currentStep]); console.log('error', stepDivsError[currentStep]); return; } else { - console.log('form', form); + 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); @@ -71,8 +91,29 @@ const PengajuanTempo = () => { setCurrentStep((prev) => (prev === NUMBER_OF_STEPS - 1 ? prev : prev + 1)); }; - const goToPreviousStep = () => + const goToPreviousStep = () => { + const cachedData = getFromLocalStorage(stepLabels[currentStep - 1]); + console.log('cachedData prev button', cachedData); + if (cachedData) { + // const formData = JSON.parse(cachedData); + Object.keys(cachedData).forEach((key) => { + updateForm(key, cachedData[key]); + }); + } setCurrentStep((prev) => (prev <= 0 ? prev : prev - 1)); + }; + + const saveToLocalStorage = (key, form) => { + localStorage.setItem(key, JSON.stringify(form)); + }; + + const getFromLocalStorage = (key) => { + const itemStr = localStorage.getItem(key); + if (!itemStr) return null; + + const item = JSON.parse(itemStr); + return item; + }; return ( <> @@ -94,13 +135,6 @@ const PengajuanTempo = () => {
{stepDivs[currentStep]}
- {/* */} {/*
{ ref={direkturMobileRef} placeholder='Masukkan nomor direktur anda' type='tel' + value={formKontakPerson.direkturMobile} className='form-input' aria-invalid={errorsKontakPerson.direkturMobile} onChange={handleInputChange} @@ -288,6 +164,7 @@ const KontakPerusahaan = ({ chekValid, buttonSubmitClick }) => { ref={direkturEmailRef} placeholder='contoh@email.com' type='email' + value={formKontakPerson.direkturEmail} className='form-input' aria-invalid={errorsKontakPerson.direkturEmail} onChange={handleInputChange} @@ -315,6 +192,7 @@ const KontakPerusahaan = ({ chekValid, buttonSubmitClick }) => { name='purchasingName' ref={purchasingNameRef} placeholder='Masukkan nama purchasing anda' + value={formKontakPerson.purchasingName} type='text' className='form-input' aria-invalid={errorsKontakPerson.purchasingName} @@ -328,6 +206,35 @@ const KontakPerusahaan = ({ chekValid, buttonSubmitClick }) => {
+
+
+ + + isi nomor purchasing yang bertanggung jawab di perusahaan anda + +
+
+ + {chekValid && ( +
+ {errorsKontakPerson.purchasingMobile} +
+ )} +
+
+