summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-09-11 14:01:53 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-09-11 14:01:53 +0700
commitab39764b288b4d60923cc8cc6146ccdc1b4bfbac (patch)
tree7a2a17a9627319cdb639afada3d0fa26a8b01f96 /src
parentf67560a48990dddcc820c5233a5bf3270d1d69d0 (diff)
<iman> update switch acc
Diffstat (limited to 'src')
-rw-r--r--src/lib/auth/components/SwitchAccount.jsx49
1 files changed, 46 insertions, 3 deletions
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>
</>
);
};