summaryrefslogtreecommitdiff
path: root/src/lib/auth/components/CompanyProfile.jsx
blob: d66a0209ef27dfeca2fad21866e635af48976c2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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