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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
|
import React, { useState, useEffect } from 'react';
import * as Yup from 'yup';
import { yupResolver } from '@hookform/resolvers/yup';
import { Controller, useForm } from 'react-hook-form';
import HookFormSelect from '@/core/components/elements/Select/HookFormSelect';
import odooApi from '~/libs/odooApi';
import stateApi from '@/lib/address/api/stateApi.js';
import cityApi from '@/lib/address/api/cityApi';
import { Radio, RadioGroup, Stack, Checkbox } from '@chakra-ui/react';
const informasiPerusahaan = ({}) => {
const {
register,
handleSubmit,
formState: { errors },
control,
reset,
watch,
setValue,
getValues,
values,
} = useForm({
resolver: yupResolver(validationSchema),
defaultValues,
});
const [industries, setIndustries] = useState([]);
const [selectedCategory, setSelectedCategory] = useState('');
const [states, setState] = useState([]);
const [cities, setCities] = useState([]);
const [bersedia, setBersedia] = useState(true);
const category_produk = [
{ id: 1, name: 'Pengaman, Kesehatan & Keamanan' },
{ id: 2, name: 'Perkakas Tangan, Listrik & Pneumatic' },
{ id: 3, name: 'Mesin Industrial' },
{ id: 4, name: 'Mesin Pertanian & Perkebunan' },
{ id: 5, name: 'Mesin Pembersih & Janitorial' },
{ id: 6, name: 'Cairan Berbahan Kimia' },
{ id: 7, name: 'Perlengkapan Pengukuran & Pengujian' },
{ id: 8, name: 'Peralatan Listrik & Elektronik' },
{ id: 9, name: 'Perlengkapan Logistik & Gudang' },
{ id: 10, name: 'Peralatan Kantor & Stationery' },
{ id: 11, name: 'Komponen & Aksesoris' },
{ id: 12, name: 'Peralatan Horeca & Food Service' },
];
console.log('defaultValues', getValues());
useEffect(() => {
const loadState = async () => {
let dataState = await stateApi();
dataState = dataState.map((state) => ({
value: state.id,
label: state.name,
}));
setState(dataState);
};
loadState();
}, []);
const watchState = watch('state');
useEffect(() => {
setValue('city', '');
if (watchState) {
const loadCities = async () => {
let dataCities = await cityApi({ stateId: watchState });
dataCities = dataCities.map((city) => ({
value: city.id,
label: city.name,
}));
setCities(dataCities);
};
loadCities();
}
}, [watchState, setValue]);
useEffect(() => {
const loadIndustries = async () => {
const dataIndustries = await odooApi('GET', '/api/v1/partner/industry');
setIndustries(
dataIndustries?.map((o) => ({
value: o.id,
label: o.name,
category: o.category,
}))
);
};
loadIndustries();
}, []);
useEffect(() => {
const selectedIndustryType = industries.find(
(industry) => industry.value === watch('industry_id')
);
if (selectedIndustryType) {
// updateForm('industry_id', `${selectedIndustryType?.value}`);
setSelectedCategory(selectedIndustryType.category);
}
}, [watch('industry_id'), industries]);
const onSubmitHandler = async (values) => {
setValue('bersedia', `${bersedia}`);
console.log('values', values);
};
const estimasiValue = watch('estimasi');
const tempoLimitValue = watch('tempoLimit');
// Memformat angka menjadi format rupiah
const formatRupiah = (value) => {
if (!value) return '';
const numberString = value.replace(/[^0-9]/g, ''); // Menghapus karakter non-digit
return numberString
? 'Rp ' + new Intl.NumberFormat('id-ID').format(numberString)
: '';
};
// Memperbarui nilai input dengan format rupiah
const handleChange = (e) => {
const value = e.target.value;
const formattedValue = formatRupiah(value);
setValue('estimasi', formattedValue); // Mengupdate nilai di react-hook-form
};
const onChangeTempoDuration = (e) => {
setValue('tempoDuration', `${e}`); // Mengupdate nilai di react-hook-form
};
const onChangeTempoLimit = (e) => {
setValue('tempoLimit', `${e}`); // Mengupdate nilai di react-hook-form
};
const handleBersediaChange = () => {
setBersedia(!bersedia);
setValue('bersedia', `${bersedia}`);
};
const [selectedIds, setSelectedIds] = useState([]);
const handleCheckboxChange = (id) => {
setSelectedIds((prevSelected) =>
prevSelected.includes(id)
? prevSelected.filter((selectedId) => selectedId !== id)
: [...prevSelected, id]
);
setValue('categoryProduk', `${selectedIds}`);
};
const midIndex = Math.ceil(category_produk.length / 2);
const firstColumn = category_produk.slice(0, midIndex);
const secondColumn = category_produk.slice(midIndex);
return (
<>
<div className='flex justify-start'>
<h1>Informasi Perusahaan</h1>
</div>
<form
onSubmit={handleSubmit(onSubmitHandler)}
className='flex mt-4 flex-col w-full '
>
<div className='w-full grid grid-row-2 gap-5'>
<div className='flex flex-row justify-between items-start'>
<div>
<label className='form-label w-2/5 text-nowrap'>
Nama Perusahaan
</label>
<span className='text-xs opacity-60'>
isi detail perusahaan sesuai dengan nama yang terdaftar{' '}
</span>
</div>
<div className='w-3/5'>
<input
{...register('name')}
placeholder='Masukkan nama perusahaan'
type='text'
className='form-input'
aria-invalid={errors.name?.message}
/>
<span className='text-xs opacity-60'>
Format: PT. INDOTEKNIK DOTCOM GEMILANG
</span>
<div className='text-caption-2 text-danger-500 mt-1'>
{errors.name?.message}
</div>
</div>
</div>
<div className='flex flex-row justify-between items-start'>
<div>
<label className='form-label w-2/5 text-nowrap'>Industri</label>
<span className='text-xs opacity-60'>
isi detail perusahaan sesuai dengan nama yang terdaftar
</span>
</div>
<div className='w-3/5'>
<Controller
{...register('industry_id')}
control={control}
render={(props) => (
<HookFormSelect
{...props}
options={industries}
placeholder={'Pilih industri bisnis anda'}
/>
)}
/>
{selectedCategory && (
<span className='text-gray_r-11 text-xs opacity-60'>
Kategori : {selectedCategory}
</span>
)}
<div className='text-caption-2 text-danger-500 mt-1'>
{errors.industry_id?.message}
</div>
</div>
</div>
<div className='flex flex-row justify-between items-start'>
<div>
<label className='form-label w-2/5 text-nowrap'>
Alamat Perusahaan
</label>
<span className='text-xs opacity-60'>
alamat sesuai dengan alamat kantor pusat
</span>
</div>
<div className='w-3/5 flex gap-3 flex-col'>
<div>
<input
{...register('street')}
placeholder='Masukkan alamat lengkap perusahaan'
type='text'
className='form-input'
/>
<div className='text-caption-2 text-danger-500 mt-1'>
{errors.street?.message}
</div>
</div>
<div className='sub-alamat flex flex-row w-full gap-3'>
<div className='w-2/5'>
<Controller
name='state'
control={control}
render={(props) => (
<HookFormSelect
{...props}
options={states}
placeholder='Provinsi'
/>
)}
/>
<div className='text-caption-2 text-danger-500 mt-1'>
{errors.state?.message}
</div>
</div>
<div className='w-1/3'>
<Controller
name='city'
control={control}
render={(props) => (
<HookFormSelect
{...props}
options={cities}
disabled={!watchState}
placeholder='Kota'
/>
)}
/>
<div className='text-caption-2 text-danger-500 mt-1'>
{errors.city?.message}
</div>
</div>
<div className='w-1/3'>
<input
{...register('zip')}
placeholder='Kode Pos'
type='number'
className='form-input'
/>
<div className='text-caption-2 text-danger-500 mt-1'>
{errors.zip?.message}
</div>
</div>
</div>
</div>
</div>
<div className='flex flex-row justify-between items-start'>
<div>
<label className='form-label w-2/5 text-nowrap'>
No. Telfon Perusahaan
</label>
<span className='text-xs opacity-60'>
isi no telfon perusahaan yang sesuai
</span>
</div>
<div className='w-3/5'>
<input
{...register('mobile')}
placeholder='Masukkan nomor telfon perusahaan'
type='text'
className='form-input'
aria-invalid={errors.mobile?.message}
/>
<div className='text-caption-2 text-danger-500 mt-1'>
{errors.mobile?.message}
</div>
</div>
</div>
<div className='flex flex-row justify-between items-start'>
<div>
<label className='form-label w-2/5 text-nowrap'>Data Bank</label>
<span className='text-xs opacity-60'>
Isi detail data bank perusahaan anda
</span>
</div>
<div className='w-3/5 flex gap-3 flex-row'>
<div>
<input
{...register('bankName')}
placeholder='Nama bank'
type='text'
className='form-input'
/>
<span className='text-xs opacity-60'>
Format: BCA, Mandiri, CIMB, BNI dll
</span>
<div className='text-caption-2 text-danger-500 mt-1'>
{errors.bankName?.message}
</div>
</div>
<div>
<input
{...register('accountName')}
placeholder='Nama Rekening'
type='text'
className='form-input'
/>
<span className='text-xs opacity-60'>Format: John Doe</span>
<div className='text-caption-2 text-danger-500 mt-1'>
{errors.accountName?.message}
</div>
</div>
<div>
<input
{...register('accountNumber')}
placeholder='Nomor Rekening Bank'
type='text'
className='form-input'
/>
<span className='text-xs opacity-60'>Format: 01234567896</span>
<div className='text-caption-2 text-danger-500 mt-1'>
{errors.accountNumber?.message}
</div>
</div>
</div>
</div>
<div className='flex flex-row justify-between items-start'>
<div>
<label className='form-label w-2/5 text-nowrap'>
Website <span className=' opacity-60'>(Opsional)</span>
</label>
<span className='text-xs opacity-60'>
isi no telfon perusahaan yang sesuai
</span>
</div>
<div className='w-3/5'>
<input
{...register('website')}
placeholder='www.indoteknik.com'
type='text'
className='form-input'
/>
</div>
</div>
<div className='flex flex-row justify-between items-start'>
<div>
<label className='form-label w-2/5 text-nowrap'>
Estimasi Pembelian pertahun
</label>
</div>
<div className='w-3/5'>
<div className='relative'>
<input
{...register('estimasi', {
setValueAs: (value) => value.replace(/^Rp\s*/, ''), // Menyimpan hanya angka
})}
placeholder='Isi estimasi pembelian produk pertahun'
type='text'
className='form-input' // padding untuk memberi ruang untuk "RP"
value={formatRupiah(estimasiValue)} // Menampilkan nilai terformat
onChange={handleChange} // Mengatur perubahan input
/>
</div>
<div className='text-caption-2 text-danger-500 mt-1'>
{errors.estimasi?.message}
</div>
</div>
</div>
<div className='flex flex-row justify-between items-center'>
<div>
<label className='form-label w-2/5 text-nowrap'>
Durasi Tempo
</label>
<span className='text-xs opacity-60'>
Pilih durasi tempo yang anda inginkan
</span>
</div>
<div className='w-3/5 flex flex-row items-center'>
<div className='w-1/5 '>
<RadioGroup
onChange={onChangeTempoDuration}
// value={selectedValue}
>
<Stack direction='column' className=''>
<Radio colorScheme='red' value='7'>
7 Hari
</Radio>
<Radio colorScheme='red' value='14' className=''>
14 Hari
</Radio>
<Radio colorScheme='red' value='30' className=''>
30 Hari
</Radio>
</Stack>
</RadioGroup>
</div>
<div className='w-4/5 flex flex-row justify-between items-center '>
<div>
<label className='form-label w-2/5 text-nowrap'>
Limit Tempo
</label>
<span className='text-xs opacity-60'>
Ajukan nilai limit yang anda mau
</span>
</div>
<div className='flex items-center'>
<RadioGroup
onChange={onChangeTempoLimit}
className='flex items-center justify-between'
>
<Stack direction='row' className=''>
{/* Kolom 1 */}
<Stack direction='column' spacing={2} className='mr-4'>
<Radio colorScheme='red' value='5.000.000'>
5.000.000
</Radio>
<Radio colorScheme='red' value='10.000.000'>
10.000.000
</Radio>
<Radio colorScheme='red' value='15.000.000'>
15.000.000
</Radio>
<Radio colorScheme='red' value='20.000.000'>
20.000.000
</Radio>
</Stack>
{/* Kolom 2 */}
<Stack direction='column' className='ml-8' spacing={2}>
<Radio colorScheme='red' value='25.000.000'>
25.000.000
</Radio>
<Radio colorScheme='red' value='30.000.000'>
30.000.000
</Radio>
<Radio colorScheme='red' value='35.000.000'>
35.000.000
</Radio>
<div className='flex flex-row'>
<Radio colorScheme='red' value='custom'></Radio>
<input
placeholder='Isi limit yang anda inginkan'
type='text'
className='border ml-2 p-1' // padding untuk memberi ruang untuk "RP"
value={formatRupiah(tempoLimitValue)} // Menampilkan nilai terformat
onChange={(e) => {
const value = e.target.value;
const formattedValue = formatRupiah(value);
setValue('tempoLimit', formattedValue); // Mengupdate nilai di react-hook-form
}}
/>
</div>
</Stack>
</Stack>
</RadioGroup>
</div>
</div>
{/* <input
{...register('tempoDuration')}
placeholder='Nomor Rekening Bank'
type='text'
className='form-input'
/> */}
<div className='text-caption-2 text-danger-500 mt-1'>
{errors.tempoDuration?.message}
</div>
</div>
</div>
<div className='text-red-500'>
*Durasi dan limit dapat berbeda sesuaui dengan verifikasi oleh tim
Indoteknik.com
</div>
<div className='flex flex-row justify-between items-start'>
<div>
<label className='form-label w-2/5 text-nowrap'>
Apakah bersedia transaksi via website?
</label>
<span className='text-xs opacity-60'>
Pilih produk bisa lebih dari 1
</span>
</div>
<div className='w-3/5 flex justify-start'>
<div className='flex gap-x-4'>
<Checkbox
borderColor='gray.600'
colorScheme='red'
isChecked={bersedia}
onChange={handleBersediaChange}
value={true}
size='md'
>
Saya bersedia
</Checkbox>
<Checkbox
borderColor='gray.600'
colorScheme='red'
isChecked={!bersedia}
onChange={handleBersediaChange}
value={false}
size='md'
>
Tidak bersedia
</Checkbox>
</div>
<div className='text-caption-2 text-danger-500 mt-1'>
{errors.estimasi?.message}
</div>
</div>
</div>
<div className='flex flex-row justify-between items-start'>
<div>
<label className='form-label w-2/5 text-nowrap'>
Kategori Produk yang Digunakan
</label>
<span className='text-xs opacity-60'>
Pilih produk bisa lebih dari 1
</span>
</div>
<div className='w-3/5 flex flex-row justify-between'>
<div className='flex flex-col gap-2'>
{firstColumn.map((item) => (
<Checkbox
key={item.id}
onChange={() => handleCheckboxChange(item.id)}
>
{item.name}
</Checkbox>
))}
</div>
<div className='flex flex-col gap-2'>
{secondColumn.map((item) => (
<Checkbox
key={item.id}
onChange={() => handleCheckboxChange(item.id)}
>
{item.name}
</Checkbox>
))}
</div>
</div>
</div>
<div className='flex flex-row justify-end items-center gap-4 mb-8'>
<span className='text-xs opacity-60'>
*Pastikan data yang anda masukan sudah benar dan sesuai
</span>
<button
type='submit'
className='bg-red-600 border border-red-600 rounded-md text-sm text-white w-28 h-11 mb-1 content-center flex flex-row justify-center items-center'
>
<p>Selanjutnya</p>
</button>
</div>
</div>
</form>
</>
);
};
const validationSchema = Yup.object().shape({
// email: Yup.string()
// .email('Format harus seperti contoh@email.com')
// .required('Harus di-isi'),
name: Yup.string().required('Harus di-isi'),
industry_id: Yup.string().required('Harus di-pilih'),
street: Yup.string().required('Harus di-isi'),
zip: Yup.string().required('Harus di-isi'),
state: Yup.string().required('Harus di-pilih'),
city: Yup.string().required('Harus di-pilih'),
mobile: Yup.string().required('Harus di-isi'),
bankName: Yup.string().required('Harus di-isi'),
accountName: Yup.string().required('Harus di-isi'),
accountNumber: Yup.string().required('Harus di-isi'),
estimasi: Yup.string().required('Harus di-isi'),
tempoDuration: Yup.string().required('Harus di-isi'),
bersedia: Yup.string().required('Harus di-pilih'),
});
const defaultValues = {
// email: '',
name: '',
industry_id: '',
street: '',
state: '',
city: '',
zip: '',
mobile: '',
bankName: '',
accountName: '',
accountNumber: '',
estimasi: '',
tempoDuration: '',
bersedia: '',
};
export default informasiPerusahaan;
|