From fad165af76bb008076e96199f173fbe27b7835a8 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Wed, 18 Sep 2024 17:18:47 +0700 Subject: update alamat yang sama --- src/lib/auth/components/CompanyProfile.jsx | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/lib/auth') diff --git a/src/lib/auth/components/CompanyProfile.jsx b/src/lib/auth/components/CompanyProfile.jsx index d4cf8657..ee9c1f58 100644 --- a/src/lib/auth/components/CompanyProfile.jsx +++ b/src/lib/auth/components/CompanyProfile.jsx @@ -24,6 +24,45 @@ const CompanyProfile = () => { alamat_bisnis: '', }, }); + + const formatNpwp = (value) => { + try { + const cleaned = ('' + value).replace(/\D/g, ''); + let match; + if (cleaned.length <= 15) { + match = cleaned.match( + /(\d{0,2})?(\d{0,3})?(\d{0,3})?(\d{0,1})?(\d{0,3})?(\d{0,3})$/ + ); + } else { + match = cleaned.match( + /(\d{0,3})?(\d{0,3})?(\d{0,3})?(\d{0,1})?(\d{0,3})?(\d{0,3})$/ + ); + } + + if (match) { + return [ + match[1], + match[2] ? '.' : '', + match[2], + match[3] ? '.' : '', + match[3], + match[4] ? '.' : '', + match[4], + match[5] ? '-' : '', + match[5], + match[6] ? '.' : '', + match[6], + ].join(''); + } + + // If match is null, return the original cleaned string or handle as needed + return cleaned; + } catch (error) { + // Handle error or return a default value + console.error('Error formatting NPWP:', error); + return value; + } + }; const [industries, setIndustries] = useState([]); useEffect(() => { const loadIndustries = async () => { @@ -206,6 +245,7 @@ const CompanyProfile = () => { {...register('npwp')} type='text' className='form-input mt-3' + maxLength={16} /> -- cgit v1.2.3 From ee88c2f776f5dbacfacb78d3a2f04155e0d93a15 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 20 Sep 2024 14:37:00 +0700 Subject: add error handling --- src/lib/auth/components/CompanyProfile.jsx | 86 +++++++++++++----------------- 1 file changed, 38 insertions(+), 48 deletions(-) (limited to 'src/lib/auth') diff --git a/src/lib/auth/components/CompanyProfile.jsx b/src/lib/auth/components/CompanyProfile.jsx index ee9c1f58..6d5790b4 100644 --- a/src/lib/auth/components/CompanyProfile.jsx +++ b/src/lib/auth/components/CompanyProfile.jsx @@ -7,62 +7,25 @@ import { useEffect, useState } from 'react'; import { Controller, useForm } from 'react-hook-form'; import { toast } from 'react-hot-toast'; import BottomPopup from '@/core/components/elements/Popup/BottomPopup'; +import { yupResolver } from '@hookform/resolvers/yup'; +import * as Yup from 'yup'; const CompanyProfile = () => { const [changeConfirmation, setChangeConfirmation] = useState(false); const auth = useAuth(); const [isOpen, setIsOpen] = useState(false); const toggle = () => setIsOpen(!isOpen); - const { register, setValue, control, handleSubmit } = useForm({ - defaultValues: { - industry: '', - companyType: '', - name: '', - taxName: '', - npwp: '', - alamat_wajib_pajak: '', - alamat_bisnis: '', - }, + const { + register, + formState: { errors }, + setValue, + control, + handleSubmit, + } = useForm({ + resolver: yupResolver(validationSchema), + defaultValues, }); - const formatNpwp = (value) => { - try { - const cleaned = ('' + value).replace(/\D/g, ''); - let match; - if (cleaned.length <= 15) { - match = cleaned.match( - /(\d{0,2})?(\d{0,3})?(\d{0,3})?(\d{0,1})?(\d{0,3})?(\d{0,3})$/ - ); - } else { - match = cleaned.match( - /(\d{0,3})?(\d{0,3})?(\d{0,3})?(\d{0,1})?(\d{0,3})?(\d{0,3})$/ - ); - } - - if (match) { - return [ - match[1], - match[2] ? '.' : '', - match[2], - match[3] ? '.' : '', - match[3], - match[4] ? '.' : '', - match[4], - match[5] ? '-' : '', - match[5], - match[6] ? '.' : '', - match[6], - ].join(''); - } - - // If match is null, return the original cleaned string or handle as needed - return cleaned; - } catch (error) { - // Handle error or return a default value - console.error('Error formatting NPWP:', error); - return value; - } - }; const [industries, setIndustries] = useState([]); useEffect(() => { const loadIndustries = async () => { @@ -91,6 +54,7 @@ const CompanyProfile = () => { useEffect(() => { const loadProfile = async () => { const dataProfile = await addressApi({ id: auth.parentId }); + console.log('dataProfile', dataProfile); setValue('name', dataProfile.name); setValue('industry', dataProfile.industryId); setValue('companyType', dataProfile.companyTypeId); @@ -103,6 +67,7 @@ const CompanyProfile = () => { }, [auth, setValue]); const onSubmitHandler = async (values) => { + console.log('values', values); if (changeConfirmation) { const data = { ...values, @@ -222,6 +187,9 @@ const CompanyProfile = () => { type='text' className='form-input mt-3' /> +
+ {errors.taxName?.message} +
@@ -230,6 +198,9 @@ const CompanyProfile = () => { type='text' className='form-input mt-3' /> +
+ {errors.alamat_wajib_pajak?.message} +
@@ -238,6 +209,9 @@ const CompanyProfile = () => { type='text' className='form-input mt-3' /> +
+ {errors.alamat_bisnis?.message} +
@@ -259,3 +233,19 @@ const CompanyProfile = () => { }; export default CompanyProfile; + +const validationSchema = Yup.object().shape({ + alamat_bisnis: Yup.string().required('Harus di-isi'), + alamat_wajib_pajak: Yup.string().required('Harus di-isi'), + taxName: Yup.string().required('Harus di-isi'), +}); + +const defaultValues = { + industry: '', + companyType: '', + name: '', + taxName: '', + npwp: '', + alamat_wajib_pajak: '', + alamat_bisnis: '', +}; -- cgit v1.2.3 From 5b0a6e9c8660c5cc427a66bd2540206513225075 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 20 Sep 2024 14:41:18 +0700 Subject: delete console log --- src/lib/auth/components/CompanyProfile.jsx | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/lib/auth') diff --git a/src/lib/auth/components/CompanyProfile.jsx b/src/lib/auth/components/CompanyProfile.jsx index 6d5790b4..80b424dc 100644 --- a/src/lib/auth/components/CompanyProfile.jsx +++ b/src/lib/auth/components/CompanyProfile.jsx @@ -54,7 +54,6 @@ const CompanyProfile = () => { useEffect(() => { const loadProfile = async () => { const dataProfile = await addressApi({ id: auth.parentId }); - console.log('dataProfile', dataProfile); setValue('name', dataProfile.name); setValue('industry', dataProfile.industryId); setValue('companyType', dataProfile.companyTypeId); @@ -67,7 +66,6 @@ const CompanyProfile = () => { }, [auth, setValue]); const onSubmitHandler = async (values) => { - console.log('values', values); if (changeConfirmation) { const data = { ...values, -- cgit v1.2.3 From 09378e8389ad7dcca805e9dde10e26cf097ad97c Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 20 Sep 2024 14:50:01 +0700 Subject: update new register --- src/lib/auth/components/CompanyProfile.jsx | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/lib/auth') diff --git a/src/lib/auth/components/CompanyProfile.jsx b/src/lib/auth/components/CompanyProfile.jsx index 80b424dc..9e1dd1f9 100644 --- a/src/lib/auth/components/CompanyProfile.jsx +++ b/src/lib/auth/components/CompanyProfile.jsx @@ -236,6 +236,9 @@ const validationSchema = Yup.object().shape({ alamat_bisnis: Yup.string().required('Harus di-isi'), alamat_wajib_pajak: Yup.string().required('Harus di-isi'), taxName: Yup.string().required('Harus di-isi'), + npwp: Yup.string().required('Harus di-isi'), + industry: Yup.string().required('Harus di-pilih'), + companyType: Yup.string().required('Harus di-pilih'), }); const defaultValues = { -- cgit v1.2.3 From e7082aec2592932c8f27e4d191476b69aac7475b Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 20 Sep 2024 14:53:52 +0700 Subject: update --- src/lib/auth/components/CompanyProfile.jsx | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/lib/auth') diff --git a/src/lib/auth/components/CompanyProfile.jsx b/src/lib/auth/components/CompanyProfile.jsx index 9e1dd1f9..606f56ea 100644 --- a/src/lib/auth/components/CompanyProfile.jsx +++ b/src/lib/auth/components/CompanyProfile.jsx @@ -176,6 +176,9 @@ const CompanyProfile = () => { className='form-input' placeholder='Cth: Indoteknik Dotcom Gemilang' /> +
+ {errors.name?.message} +
@@ -219,6 +222,9 @@ const CompanyProfile = () => { className='form-input mt-3' maxLength={16} /> +
+ {errors.npwp?.message} +