diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2024-09-11 14:01:53 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2024-09-11 14:01:53 +0700 |
| commit | ab39764b288b4d60923cc8cc6146ccdc1b4bfbac (patch) | |
| tree | 7a2a17a9627319cdb639afada3d0fa26a8b01f96 | |
| parent | f67560a48990dddcc820c5233a5bf3270d1d69d0 (diff) | |
<iman> update switch acc
| -rw-r--r-- | src-migrate/modules/register/components/FormBisnis.tsx | 8 | ||||
| -rw-r--r-- | src/lib/auth/components/SwitchAccount.jsx | 49 |
2 files changed, 50 insertions, 7 deletions
diff --git a/src-migrate/modules/register/components/FormBisnis.tsx b/src-migrate/modules/register/components/FormBisnis.tsx index 6631cb3b..73de60cb 100644 --- a/src-migrate/modules/register/components/FormBisnis.tsx +++ b/src-migrate/modules/register/components/FormBisnis.tsx @@ -296,7 +296,7 @@ const form: React.FC<FormProps> = ({ type, required, isPKP, chekValid }) => { className={` ${ type === 'bisnis' ? 'mt-6 grid grid-cols-1 gap-y-4' - : 'mt-6 grid grid-cols-2 gap-x-4 gap-y-2' + : 'mt-6 grid grid-cols-2 gap-x-4 gap-y-5 auto-rows-min' }`} onSubmit={handleSubmit} > @@ -332,11 +332,11 @@ const form: React.FC<FormProps> = ({ type, required, isPKP, chekValid }) => { )} </div> - <div> + <div className='bg-red-400 h-full'> <label className='font-bold' htmlFor='company'> Nama Bisnis </label> - <div className='flex justify-between items-start gap-2 max-h-12 min-h-12 text-sm mt-3'> + <div className='flex justify-between items-start gap-2 max-h-11 min-h-11 text-sm mt-3'> <div className='w-4/5 pr-1 max-h-11'> <Controller name='companyType' @@ -380,7 +380,7 @@ const form: React.FC<FormProps> = ({ type, required, isPKP, chekValid }) => { <label className='font-bold' htmlFor='business_name'> Klasifikasi Jenis Usaha </label> - <div className='max-h-10'> + <div className='max-h-10 mt-3'> <Controller name='industry_id' control={control} 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 ( <> <button @@ -134,9 +163,23 @@ const SwitchAccount = () => { </Stack> </RadioGroup> </div> - <FormBisnis type='profil' required={isTerdaftar} isPKP={isPKP} /> + <FormBisnis + type='profil' + required={isTerdaftar} + isPKP={isPKP} + chekValid={notValid} + /> </div> )} + <div className='flex justify-end mb-4'> + <button + type='submit' + onClick={onSubmitHandler} + className='btn-yellow w-full sm:w-fit sm:ml-auto mt-6' + > + {mutation.isLoading ? 'Loading...' : 'Simpan Perubahan'} + </button> + </div> </> ); }; |
