summaryrefslogtreecommitdiff
path: root/src-migrate/modules/register/components/RegistrasiBisnis.tsx
blob: 5933b5f2f3adcbe5e3ec6c40936713de28b78ebd (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import { useEffect, useMemo, useState } from 'react';
import FormBisnis from './FormBisnis';
import Form from './Form';
import { Radio, RadioGroup, Stack, Divider, Button } from '@chakra-ui/react';
import React from 'react';
import { ChevronDownIcon, ChevronRightIcon } from '@heroicons/react/24/outline';
import { useRegisterStore } from '../stores/useRegisterStore';
interface FormProps {
  chekValid: boolean;
  buttonSubmitClick: boolean;
}
const RegistrasiBisnis: React.FC<FormProps> = ({
  chekValid,
  buttonSubmitClick,
}) => {
  const [isPKP, setIsPKP] = useState(false);
  const [isTerdaftar, setIsTerdaftar] = useState(false);
  const [isDropIndividu, setIsDropIndividu] = useState(true);
  const [isBisnisClicked, setisBisnisClicked] = useState(true);
  const [selectedValue, setSelectedValue] = useState('Non-PKP');
  const [selectedValueBisnis, setSelectedValueBisnis] = useState('false');
  const { validate, updateForm } = useRegisterStore();

  useEffect(() => {
    if (selectedValue === 'PKP') {
      updateForm('is_pkp', 'true');
      validate();
    } else {
      updateForm('is_pkp', 'false');
      validate();
    }
  }, [selectedValue]);

  useEffect(() => {
    if (isTerdaftar) {
      updateForm('is_terdaftar', 'true');
      validate();
    } else {
      updateForm('is_terdaftar', 'false');
      validate();
    }
  }, [isTerdaftar]);

  const handleChange = (value: string) => {
    setSelectedValue(value);
    if (value === 'PKP') {
      validate();
      setIsPKP(true);
    } else {
      validate();
      setIsPKP(false);
      setIsPKP(false);
    }
  };

  const handleChangeBisnis = (value: string) => {
    setSelectedValueBisnis(value);
    if (value === 'true') {
      validate();
      setIsTerdaftar(true);
    } else {
      validate();
      setIsTerdaftar(false);
    }
  };

  const handleClick = () => {
    setIsDropIndividu(!isDropIndividu);
  };

  const handleClickBisnis = () => {
    setisBisnisClicked(!isBisnisClicked);
  };

  return (
    <>
      <div className='mt-4 border'>
        <div className='p-4'>
          <div onClick={handleClick} className='flex justify-between'>
            <p className='text-2xl font-semibold text-center md:text-left'>
              Data Akun
            </p>
            {isDropIndividu ? (
              <div className='flex'>
                <ChevronDownIcon
                  onClick={handleClick}
                  className='h-6 w-6 text-black'
                />
              </div>
            ) : (
              <ChevronRightIcon
                onClick={handleClick}
                className='h-6 w-6 text-black'
              />
            )}
          </div>
          {isDropIndividu && (
            <div>
              <Divider my={4} />
              <Form
                type='bisnis'
                required={true}
                isBisnisRegist={true}
                chekValid={chekValid}
                buttonSubmitClick={buttonSubmitClick}
              />
            </div>
          )}
        </div>
      </div>
      <div className='mt-4 border'>
        <div className='p-4'>
          <div onClick={handleClickBisnis} className='flex justify-between'>
            <p className='text-2xl font-semibold text-center md:text-left'>
              Data Bisnis
            </p>
            {isBisnisClicked ? (
              <div className='flex'>
                <ChevronDownIcon
                  onClick={handleClickBisnis}
                  className='h-6 w-6 text-black'
                />
              </div>
            ) : (
              <ChevronRightIcon
                onClick={handleClickBisnis}
                className='h-6 w-6 text-black'
              />
            )}
          </div>
          {isBisnisClicked && (
            <div>
              <Divider my={4} />
              <div>
                <p className='text-black font-bold mb-2'>
                  Bisnis Terdaftar di Indoteknik?
                </p>
                <RadioGroup
                  onChange={handleChangeBisnis}
                  value={selectedValueBisnis}
                >
                  <Stack direction='row'>
                    <Radio colorScheme='red' value='true'>
                      Sudah Terdaftar
                    </Radio>
                    <Radio colorScheme='red' value='false' className='ml-2'>
                      Belum Terdaftar
                    </Radio>
                  </Stack>
                </RadioGroup>
              </div>
              {!isTerdaftar && (
                <div className='mt-4'>
                  <p className='text-black font-bold mb-2'>Tipe Bisnis</p>
                  <RadioGroup onChange={handleChange} value={selectedValue}>
                    <Stack direction='row' className='font-bold'>
                      <Radio colorScheme='red' value='PKP'>
                        PKP
                      </Radio>
                      <Radio colorScheme='red' value='Non-PKP' className='ml-4'>
                        Non-PKP
                      </Radio>
                    </Stack>
                  </RadioGroup>
                </div>
              )}
              <FormBisnis
                type='bisnis'
                required={isTerdaftar}
                isPKP={isPKP}
                chekValid={chekValid}
                buttonSubmitClick={buttonSubmitClick}
              />
            </div>
          )}
        </div>
      </div>

      <h1 className=''></h1>
    </>
  );
};

export default RegistrasiBisnis;