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 | |
| parent | ab39764b288b4d60923cc8cc6146ccdc1b4bfbac (diff) | |
<iman> update switch account
| -rw-r--r-- | src-migrate/modules/register/components/FormBisnis.tsx | 4 | ||||
| -rw-r--r-- | src/lib/auth/api/switchAccountApi.js | 14 | ||||
| -rw-r--r-- | src/lib/auth/api/switchAccountProgresApi.js | 15 | ||||
| -rw-r--r-- | src/lib/auth/components/PersonalProfile.jsx | 104 | ||||
| -rw-r--r-- | src/lib/auth/components/SwitchAccount.jsx | 37 | ||||
| -rw-r--r-- | src/pages/my/profile.jsx | 17 |
6 files changed, 134 insertions, 57 deletions
diff --git a/src-migrate/modules/register/components/FormBisnis.tsx b/src-migrate/modules/register/components/FormBisnis.tsx index 73de60cb..85bb491d 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-5 auto-rows-min' + : 'mt-6 grid grid-cols-2 gap-x-4 gap-y-6 auto-rows-min' }`} onSubmit={handleSubmit} > @@ -332,7 +332,7 @@ const form: React.FC<FormProps> = ({ type, required, isPKP, chekValid }) => { )} </div> - <div className='bg-red-400 h-full'> + <div className=''> <label className='font-bold' htmlFor='company'> Nama Bisnis </label> 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 ( <> - <button type='button' onClick={toggle} className='p-4 flex items-center text-left w-full'> + <button + type='button' + onClick={toggle} + className='p-4 flex items-center text-left w-full' + > <div> <div className='font-semibold mb-2'>Informasi Akun</div> <div className='text-gray_r-11'> - Dibawah ini adalah data diri yang anda masukan, periksa kembali data diri anda + Dibawah ini adalah data diri yang anda masukan, periksa kembali data + diri anda </div> </div> <div className='ml-auto p-2 bg-gray_r-3 rounded'> @@ -60,19 +65,35 @@ const PersonalProfile = () => { </button> {isOpen && ( - <form className='p-4 border-t border-gray_r-6' onSubmit={handleSubmit(onSubmitHandler)}> + <form + className='p-4 border-t border-gray_r-6' + onSubmit={handleSubmit(onSubmitHandler)} + > <div className='grid grid-cols-1 sm:grid-cols-2 gap-4'> <div> <label>Email</label> - <input {...register('email')} type='text' disabled className='form-input mt-3' /> + <input + {...register('email')} + type='text' + disabled + className='form-input mt-3' + /> </div> <div> <label>Nama Lengkap</label> - <input {...register('name')} type='text' className='form-input mt-3' /> + <input + {...register('name')} + type='text' + className='form-input mt-3' + /> </div> <div> <label>No. Handphone</label> - <input {...register('mobile')} type='tel' className='form-input mt-3' /> + <input + {...register('mobile')} + type='tel' + className='form-input mt-3' + /> </div> <div> <label>Kata Sandi</label> @@ -84,13 +105,16 @@ const PersonalProfile = () => { /> </div> </div> - <button type='submit' className='btn-yellow w-full sm:w-fit sm:ml-auto mt-6'> + <button + type='submit' + className='btn-yellow w-full sm:w-fit sm:ml-auto mt-6' + > Simpan </button> </form> )} </> - ) -} + ); +}; -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 = () => { /> </div> )} - <div className='flex justify-end mb-4'> + <div className='flex justify-end mb-4 mr-4'> <button type='submit' onClick={onSubmitHandler} diff --git a/src/pages/my/profile.jsx b/src/pages/my/profile.jsx index ca6f4700..c9742a14 100644 --- a/src/pages/my/profile.jsx +++ b/src/pages/my/profile.jsx @@ -10,14 +10,25 @@ import IsAuth from '@/lib/auth/components/IsAuth'; import Menu from '@/lib/auth/components/Menu'; import PersonalProfile from '@/lib/auth/components/PersonalProfile'; import { Button, Checkbox, Spinner, Tooltip } from '@chakra-ui/react'; -import { useState } from 'react'; - +import { useState, useEffect } from 'react'; +import switchAccountProgresApi from '@/lib/auth/api/switchAccountProgresApi.js'; export default function Profile() { const auth = useAuth(); const [isChecked, setIsChecked] = useState(false); + const [isAprove, setIsAprove] = useState(false); const handleChange = async () => { setIsChecked(!isChecked); }; + useEffect(() => { + const loadPromo = async () => { + const progresSwitchAccount = await switchAccountProgresApi(); + if (progresSwitchAccount) { + setIsAprove(true); + } + console.log('progresSwitchAccount', progresSwitchAccount); + }; + loadPromo(); + }, []); return ( <IsAuth> <MobileView> @@ -35,7 +46,7 @@ export default function Profile() { <Menu /> </div> <div className='w-9/12 bg-white border border-gray_r-6 rounded'> - {!auth?.parentId && ( + {!auth?.parentId && !isAprove && ( <div className='text-sm p-4 flex items-center'> <Checkbox borderColor='gray.600' |
