diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2024-11-23 11:55:59 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2024-11-23 11:55:59 +0700 |
| commit | 6bbf1dbd94355f34f58f4b72f134f3dbeac776aa (patch) | |
| tree | ff3cbc95e5c5f5cb6d2806bfeefd7112f934a761 /src/lib/pengajuan-tempo/component/informasiPerusahaan.jsx | |
| parent | 87e70c5ddc13b47ed4a9101d23174a65f52a0336 (diff) | |
<iman> update tempo
Diffstat (limited to 'src/lib/pengajuan-tempo/component/informasiPerusahaan.jsx')
| -rw-r--r-- | src/lib/pengajuan-tempo/component/informasiPerusahaan.jsx | 324 |
1 files changed, 210 insertions, 114 deletions
diff --git a/src/lib/pengajuan-tempo/component/informasiPerusahaan.jsx b/src/lib/pengajuan-tempo/component/informasiPerusahaan.jsx index 8a1b3508..6a50b0c7 100644 --- a/src/lib/pengajuan-tempo/component/informasiPerusahaan.jsx +++ b/src/lib/pengajuan-tempo/component/informasiPerusahaan.jsx @@ -8,15 +8,19 @@ import { Radio, RadioGroup, Stack, Checkbox } from '@chakra-ui/react'; import { usePengajuanTempoStore } from '../../../../src-migrate/modules/register/stores/usePengajuanTempoStore'; import useDevice from '@/core/hooks/useDevice'; import Divider from '@/core/components/elements/Divider/Divider'; +import { getAuth } from '~/libs/auth'; +import addressApi from '@/lib/address/api/addressApi'; const InformasiPerusahaan = ({ chekValid, buttonSubmitClick, isKonfirmasi, }) => { + const auth = getAuth(); const { isDesktop, isMobile } = useDevice(); const { control, watch, setValue, getValues } = useForm(); const { form, errors, validate, updateForm } = usePengajuanTempoStore(); const [industries, setIndustries] = useState([]); + const [paymentTerm, setPaymentTerm] = useState([]); const [selectedCategory, setSelectedCategory] = useState(''); const [states, setState] = useState([]); const [cities, setCities] = useState([]); @@ -59,7 +63,7 @@ const InformasiPerusahaan = ({ const watchState = watch('state'); useEffect(() => { - updateForm('city', ''); + // updateForm('city', ''); if (watchState) { updateForm('state', `${watchState}`); validate(); @@ -96,17 +100,42 @@ const InformasiPerusahaan = ({ }; loadIndustries(); }, []); - useEffect(() => { const selectedIndustryType = industries.find( - (industry) => industry.value === watch('industry_id') + (industry) => industry.value === watch('industryId') ); if (selectedIndustryType) { - updateForm('industry_id', `${selectedIndustryType?.value}`); + updateForm('industryId', `${selectedIndustryType?.value}`); validate(); setSelectedCategory(selectedIndustryType.category); } - }, [watch('industry_id'), industries]); + }, [watch('industryId'), industries]); + + useEffect(() => { + const loadPaymentTerm = async () => { + const dataPaymentTerm = await odooApi( + 'GET', + '/api/v1/partner/payment_term' + ); + console.log('dataPaymentTerm', dataPaymentTerm); + setPaymentTerm( + dataPaymentTerm?.map((o) => ({ + value: o.id, + label: o.name, + })) + ); + }; + loadPaymentTerm(); + }, []); + useEffect(() => { + const selectedPaymentTerm = paymentTerm.find( + (industry) => industry.value === watch('tempoDuration') + ); + if (selectedPaymentTerm) { + updateForm('tempoDuration', `${selectedPaymentTerm?.value}`); + validate(); + } + }, [watch('tempoDuration'), paymentTerm]); const estimasiValue = watch('estimasi'); const tempoLimitValue = watch('tempoLimit'); @@ -207,7 +236,7 @@ const InformasiPerusahaan = ({ nameRef.current.scrollIntoView(options); return; } - if (errors.industry_id && industry_idRef.current) { + if (errors.industryId && industry_idRef.current) { industry_idRef.current.scrollIntoView(options); return; } @@ -268,8 +297,8 @@ const InformasiPerusahaan = ({ loadIndustries(); }, [buttonSubmitClick, chekValid]); useEffect(() => { - if (form.industry_id) { - setValue('industry_id', parseInt(form.industry_id)); + if (form.industryId) { + setValue('industryId', parseInt(form.industryId)); } if (form.state) { setValue('state', parseInt(form.state)); @@ -278,7 +307,7 @@ const InformasiPerusahaan = ({ setValue('city', parseInt(form.city)); } if (form.tempoDuration) { - setValue('tempoDuration', form.tempoDuration); + setValue('tempoDuration', parseInt(form.tempoDuration)); } if (form.tempoLimit) { setValue('tempoLimit', form.tempoLimit); @@ -298,6 +327,52 @@ const InformasiPerusahaan = ({ } } }, [form]); + useEffect(() => { + const loadProfile = async () => { + try { + const dataProfile = await addressApi({ id: auth.parentId }); + console.log('dataProfile', dataProfile); + if (dataProfile.name) { + updateForm('name', dataProfile.name); + } + if (dataProfile.alamatBisnis) { + updateForm('street', dataProfile.alamatBisnis); + } + if (dataProfile.zip) { + updateForm('zip', dataProfile.zip); + } + if (dataProfile.phone) { + updateForm('mobile', dataProfile.phone.replace(/\D/g, '')); + } + } catch (error) { + console.error('Error loading profile:', error); + } finally { + validate(); + } + }; + + if (auth?.parentId) { + loadProfile(); + } + }, [auth?.parentId, updateForm]); + useEffect(() => { + const loadProfile = async () => { + try { + const dataProfile = await addressApi({ id: auth.parentId }); + + setValue('industryId', parseInt(dataProfile.industryId)); + setValue('state', parseInt(dataProfile.stateId.id)); + setValue('city', parseInt(dataProfile.city.id)); + } catch (error) { + console.error('Error loading profile:', error); + } + }; + + if (auth?.parentId) { + loadProfile(); + } + }, [auth?.parentId, setValue]); + console.log('form', form); return ( <> {isDesktop && ( @@ -325,16 +400,17 @@ const InformasiPerusahaan = ({ placeholder='Masukkan nama perusahaan' type='text' className='form-input' + disabled={true} aria-invalid={errors.name} value={form.name} ref={nameRef} onChange={handleInputChange} /> - {!isKonfirmasi && ( + {/* {!isKonfirmasi && ( <span className='text-xs opacity-60'> Format: PT. INDOTEKNIK DOTCOM GEMILANG </span> - )} + )} */} {chekValid && ( <div className='text-caption-2 text-danger-500 mt-1'> {errors.name} @@ -353,7 +429,7 @@ const InformasiPerusahaan = ({ </div> <div className='w-3/5'> <Controller - name='industry_id' + name='industryId' control={control} render={(props) => ( <HookFormSelect @@ -370,7 +446,7 @@ const InformasiPerusahaan = ({ )} {chekValid && ( <div className='text-caption-2 text-danger-500 mt-1'> - {errors.industry_id} + {errors.industryId} </div> )} </div> @@ -625,9 +701,13 @@ const InformasiPerusahaan = ({ Pilih durasi tempo yang anda inginkan </span> </div> - <div className='w-3/5 flex flex-row items-center'> - <div className='w-1/5' ref={tempoDurationRef}> - <RadioGroup + <div className='w-3/5 flex flex-col '> + <div className='flex flex-row items-center gap-3'> + <div + className={`${isKonfirmasi ? 'w-[75%]' : 'w-[25%]'}`} + ref={tempoDurationRef} + > + {/* <RadioGroup onChange={onChangeTempoDuration} value={form.tempoDuration} > @@ -642,101 +722,122 @@ const InformasiPerusahaan = ({ 30 Hari </Radio> </Stack> - </RadioGroup> - {chekValid && ( - <div className='text-caption-2 text-danger-500 mt-1'> - {errors.tempoDuration} - </div> - )} - </div> - {!isKonfirmasi && ( - <div className='w-4/5 flex flex-row justify-between items-center'> - <div className='w-2/5 text-nowrap'> - <label className='form-label '>Limit Tempo</label> - <span className='text-xs opacity-60'> - Ajukan nilai limit yang anda mau - </span> - </div> - <div - className='flex flex-col justify-start items-start' - ref={tempoLimitRef} - > - <RadioGroup - onChange={(value) => { - if (value === 'custom') { - setIsCustom(true); - updateForm('tempoLimit', tempoLimitValue); // Update dengan nilai input custom jika dipilih - } else { - setIsCustom(false); - onChangeTempoLimit(value); // Update dengan nilai radio button yang dipilih - } - }} - className='flex items-center justify-between' - value={isCustom ? 'custom' : form.tempoLimit} + </RadioGroup> */} + <Controller + name='tempoDuration' + control={control} + render={(props) => ( + <HookFormSelect + {...props} + options={paymentTerm} + placeholder={'Pilih Durasi Tempo'} + /> + )} + /> + + {chekValid && ( + <div className='text-caption-2 text-danger-500 mt-1'> + {errors.tempoDuration} + </div> + )} + </div> + {!isKonfirmasi && ( + <div className='w-[75%] flex flex-row justify-between items-center'> + <div className='w-2/5 text-nowrap flex justify-start items-start flex-col'> + <label className='form-label '>Limit Tempo</label> + <span className='text-xs opacity-60'> + Ajukan nilai limit yang anda mau + </span> + </div> + <div + className='flex flex-col justify-start items-start' + ref={tempoLimitRef} > - <Stack direction='row'> - {/* Kolom 1 */} - <Stack - direction='column' - spacing={2} - className='mr-4' - > - {radioOptions.slice(0, 4).map((option) => ( - <Radio - key={option.value} - colorScheme='red' - value={option.value} - > - {option.label} - </Radio> - ))} - </Stack> + <RadioGroup + onChange={(value) => { + if (value === 'custom') { + setIsCustom(true); + updateForm('tempoLimit', tempoLimitValue); // Update dengan nilai input custom jika dipilih + } else { + setIsCustom(false); + onChangeTempoLimit(value); // Update dengan nilai radio button yang dipilih + } + }} + className='flex items-center justify-between' + value={isCustom ? 'custom' : form.tempoLimit} + > + <Stack direction='row'> + {/* Kolom 1 */} + <Stack + direction='column' + spacing={2} + className='mr-4' + > + {radioOptions.slice(0, 4).map((option) => ( + <Radio + key={option.value} + colorScheme='red' + value={option.value} + > + {option.label} + </Radio> + ))} + </Stack> - {/* Kolom 2 */} - <Stack - direction='column' - className='ml-8' - spacing={2} - > - {radioOptions.slice(4).map((option) => ( - <Radio - key={option.value} - colorScheme='red' - value={option.value} - > - {option.label} - </Radio> - ))} - <div className='flex flex-row items-center'> - <Radio colorScheme='red' value='custom'></Radio> + {/* Kolom 2 */} + <Stack + direction='column' + className='ml-8' + spacing={2} + > + {radioOptions.slice(4).map((option) => ( + <Radio + key={option.value} + colorScheme='red' + value={option.value} + > + {option.label} + </Radio> + ))} + <div className='flex flex-row items-center'> + <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(tempoLimitValueEx)} // Menampilkan nilai terformat - onChange={(e) => { - const value = e.target.value; - const formattedValue = formatRupiah(value); - setTempoLimitValueEx(formattedValue); - updateForm( - 'tempoLimit', - formattedValue.replace(/^Rp\s*/, '') - ); // Mengupdate nilai di react-hook-form - }} - /> - </div> + <input + placeholder='Isi limit yang anda inginkan' + type='text' + className='border ml-2 p-1' // padding untuk memberi ruang untuk "RP" + value={formatRupiah(tempoLimitValueEx)} // Menampilkan nilai terformat + onChange={(e) => { + const value = e.target.value; + const formattedValue = + formatRupiah(value); + setTempoLimitValueEx(formattedValue); + updateForm( + 'tempoLimit', + formattedValue.replace(/^Rp\s*/, '') + ); // Mengupdate nilai di react-hook-form + }} + /> + </div> + </Stack> </Stack> - </Stack> - </RadioGroup> - {chekValid && ( - <div className='text-caption-2 text-danger-500 mt-1'> - {errors.tempoLimit} - </div> - )} + </RadioGroup> + {chekValid && ( + <div className='text-caption-2 text-danger-500 mt-1'> + {errors.tempoLimit} + </div> + )} + </div> </div> - </div> - )} + )} + </div> + <div className='text-red-500'> + *Durasi dan limit dapat berbeda sesuai dengan verifikasi + oleh tim Indoteknik.com + </div> </div> </div> {isKonfirmasi && ( @@ -822,11 +923,6 @@ const InformasiPerusahaan = ({ </div> )} - <div className='text-red-500'> - *Durasi dan limit dapat berbeda sesuai dengan verifikasi oleh - tim Indoteknik.com - </div> - <div className='flex flex-row justify-between items-start'> <div className='w-2/5'> <label className='form-label text-wrap '> @@ -878,7 +974,7 @@ const InformasiPerusahaan = ({ </div> {chekValid && ( <div className='text-caption-2 text-danger-500 mt-1'> - {errors.estimasi} + {errors.bersedia} </div> )} </div> @@ -982,7 +1078,7 @@ const InformasiPerusahaan = ({ <label className='form-label text-nowrap'>Industri</label> <div className='w-full' ref={industry_idRef}> <Controller - name='industry_id' + name='industryId' control={control} render={(props) => ( <HookFormSelect @@ -1002,7 +1098,7 @@ const InformasiPerusahaan = ({ )} {chekValid && ( <div className='text-caption-2 text-danger-500 mt-1'> - {errors.industry_id} + {errors.industryId} </div> )} </div> |
