summaryrefslogtreecommitdiff
path: root/src/lib/auth/components
diff options
context:
space:
mode:
authorRafi Zadanly <zadanlyr@gmail.com>2023-02-22 22:57:48 +0700
committerRafi Zadanly <zadanlyr@gmail.com>2023-02-22 22:57:48 +0700
commit321e0c09be4b26d72b470407217262d10c88089d (patch)
tree999e3db07ef3d5897cd6a585a6a4fc8aea120c72 /src/lib/auth/components
parentc6a489da2f3df46b867891c12a3c5f4121f920b0 (diff)
fix
Diffstat (limited to 'src/lib/auth/components')
-rw-r--r--src/lib/auth/components/CompanyProfile.jsx97
-rw-r--r--src/lib/auth/components/PersonalProfile.jsx115
2 files changed, 212 insertions, 0 deletions
diff --git a/src/lib/auth/components/CompanyProfile.jsx b/src/lib/auth/components/CompanyProfile.jsx
new file mode 100644
index 00000000..d66a0209
--- /dev/null
+++ b/src/lib/auth/components/CompanyProfile.jsx
@@ -0,0 +1,97 @@
+import useAuth from '@/core/hooks/useAuth'
+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'
+
+const PersonalProfile = () => {
+ const auth = useAuth()
+ const [isOpen, setIsOpen] = useState(false)
+ const toggle = () => setIsOpen(!isOpen)
+ const { register, setValue } = useForm({
+ defaultValues: {
+ email: '',
+ name: '',
+ mobile: '',
+ 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])
+
+ return (
+ <>
+ <button
+ type='button'
+ onClick={toggle}
+ className='p-4 flex items-center text-left'
+ >
+ <div>
+ <div className='font-semibold mb-2'>Informasi Akun</div>
+ <div className='text-gray_r-11'>
+ Dibawah ini adalah data diri yang anda masukkan, periksa kembali data diri anda
+ </div>
+ </div>
+ <div className='p-2 bg-gray_r-3 rounded'>
+ {!isOpen && <ChevronDownIcon className='w-6' />}
+ {isOpen && <ChevronUpIcon className='w-6' />}
+ </div>
+ </button>
+
+ {isOpen && (
+ <form className='p-4 border-t border-gray_r-6 flex flex-col gap-y-4'>
+ <div>
+ <label>Email</label>
+ <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'
+ />
+ </div>
+ <div>
+ <label>No. Handphone</label>
+ <input
+ {...register('mobile')}
+ type='text'
+ className='form-input mt-3'
+ />
+ </div>
+ <div>
+ <label>Kata Sandi</label>
+ <input
+ {...register('password')}
+ type='password'
+ className='form-input mt-3'
+ placeholder='Isi jika ingin mengubah kata sandi'
+ />
+ </div>
+ <button
+ type='submit'
+ className='btn-yellow w-full'
+ >
+ Simpan
+ </button>
+ </form>
+ )}
+ </>
+ )
+}
+
+export default PersonalProfile
diff --git a/src/lib/auth/components/PersonalProfile.jsx b/src/lib/auth/components/PersonalProfile.jsx
new file mode 100644
index 00000000..29628be9
--- /dev/null
+++ b/src/lib/auth/components/PersonalProfile.jsx
@@ -0,0 +1,115 @@
+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(false)
+ const toggle = () => setIsOpen(!isOpen)
+ const { register, setValue, handleSubmit } = useForm({
+ defaultValues: {
+ email: '',
+ name: '',
+ mobile: '',
+ 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 onSubmitHandler = async (values) => {
+ let data = values
+ if (!values.password) delete data.password
+ const isUpdated = await editPersonalProfileApi({ data })
+ console.log(isUpdated)
+ if (isUpdated?.user) {
+ setAuth(isUpdated.user)
+ setValue('password', '')
+ setIsOpen(false)
+ toast.success('Berhasil mengubah profil', { duration: 1500 })
+ return
+ }
+ toast.error('Terjadi kesalahan internal')
+ }
+
+ return (
+ <>
+ <button
+ type='button'
+ onClick={toggle}
+ className='p-4 flex items-center text-left'
+ >
+ <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
+ </div>
+ </div>
+ <div className='p-2 bg-gray_r-3 rounded'>
+ {!isOpen && <ChevronDownIcon className='w-6' />}
+ {isOpen && <ChevronUpIcon className='w-6' />}
+ </div>
+ </button>
+
+ {isOpen && (
+ <form className='p-4 border-t border-gray_r-6 flex flex-col gap-y-4' onSubmit={handleSubmit(onSubmitHandler)}>
+ <div>
+ <label>Email</label>
+ <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'
+ />
+ </div>
+ <div>
+ <label>No. Handphone</label>
+ <input
+ {...register('mobile')}
+ type='text'
+ className='form-input mt-3'
+ />
+ </div>
+ <div>
+ <label>Kata Sandi</label>
+ <input
+ {...register('password')}
+ type='password'
+ className='form-input mt-3'
+ placeholder='Isi jika ingin mengubah kata sandi'
+ />
+ </div>
+ <button
+ type='submit'
+ className='btn-yellow w-full mt-2'
+ >
+ Simpan
+ </button>
+ </form>
+ )}
+ </>
+ )
+}
+
+export default PersonalProfile