diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2024-09-11 17:07:49 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2024-09-11 17:07:49 +0700 |
| commit | 752e55686dfee0d536f9e4e128336e91681ba794 (patch) | |
| tree | 65ab321175aee5520857c9e80f44009bde356c44 /src/lib/auth/components/SwitchAccount.jsx | |
| parent | ab39764b288b4d60923cc8cc6146ccdc1b4bfbac (diff) | |
<iman> update switch account
Diffstat (limited to 'src/lib/auth/components/SwitchAccount.jsx')
| -rw-r--r-- | src/lib/auth/components/SwitchAccount.jsx | 37 |
1 files changed, 25 insertions, 12 deletions
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 = () => { /> </div> )} - <div className='flex justify-end mb-4'> + <div className='flex justify-end mb-4 mr-4'> <button type='submit' onClick={onSubmitHandler} |
