diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2024-09-28 10:01:30 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2024-09-28 10:01:30 +0700 |
| commit | 3eb78e21b89bd0bdddb803767ea6ec983794994b (patch) | |
| tree | f5ced7fe061f1be40bbfbeeb0d4ff1e2b5de5310 /src-migrate | |
| parent | 6de06f74f0a004900ecc415b91eb03d1b58a872f (diff) | |
<iman> update temp switch account
Diffstat (limited to 'src-migrate')
| -rw-r--r-- | src-migrate/modules/register/components/FormBisnis.tsx | 52 | ||||
| -rw-r--r-- | src-migrate/modules/register/index.tsx | 3 |
2 files changed, 39 insertions, 16 deletions
diff --git a/src-migrate/modules/register/components/FormBisnis.tsx b/src-migrate/modules/register/components/FormBisnis.tsx index cc05a3bf..932bd326 100644 --- a/src-migrate/modules/register/components/FormBisnis.tsx +++ b/src-migrate/modules/register/components/FormBisnis.tsx @@ -51,6 +51,10 @@ interface companyType { value: string; label: string; } +interface Auth { + id: string; + parentId: string; +} const form: React.FC<FormProps> = ({ type, @@ -68,7 +72,7 @@ const form: React.FC<FormProps> = ({ // Inside your component const [formattedNpwp, setFormattedNpwp] = useState<string>(''); // State for formatted NPWP const [unformattedNpwp, setUnformattedNpwp] = useState<string>(''); // State for unformatted NPWP - + const auth = useAuth() as unknown as Auth; const [industries, setIndustries] = useState<industry_id[]>([]); const [companyTypes, setCompanyTypes] = useState<companyType[]>([]); @@ -342,22 +346,40 @@ const form: React.FC<FormProps> = ({ const [fileUrl, setFileUrl] = useState(''); const [popUpNPWP, setPopUpNpwp] = useState(false); const [popSppkp, setPopUpSppkp] = useState(false); - const [hasNPWP, sethasNpwp] = useState(false); - const [hasSPPKP, sethasSPPKP] = useState(false); + const [hasNPWP, setHasNpwp] = useState(false); + const [hasSPPKP, setHasSPPKP] = useState(false); const [fileUrlSppkp, setFileUrlSppkp] = useState(''); useEffect(() => { - const url = `${process.env.NEXT_PUBLIC_ODOO_API_HOST}/api/v1/user/download/npwp/109119`; - if (url) { - setFileUrl(url); - sethasNpwp(true); - } - const urlSppkp = `${process.env.NEXT_PUBLIC_ODOO_API_HOST}/api/v1/user/download/sppkp/109119`; - if (urlSppkp) { - setFileUrlSppkp(urlSppkp); - sethasSPPKP(true); + const checkUrl = async (url: string | URL | Request) => { + try { + const response = await fetch(url, { method: 'HEAD' }); + return response.ok; // Returns true if status is 200-299 + } catch (error) { + console.error('Error accessing URL:', url, error); + return false; + } + }; + + const npwpUrl = `${process.env.NEXT_PUBLIC_ODOO_API_HOST}/api/v1/user/download/npwp/${auth?.parentId}`; + const sppkpUrl = `${process.env.NEXT_PUBLIC_ODOO_API_HOST}/api/v1/user/download/sppkp/${auth?.parentId}`; + + if (auth?.parentId) { + checkUrl(npwpUrl).then((isAccessible) => { + if (isAccessible) { + setFileUrl(npwpUrl); + setHasNpwp(true); + } + }); + + checkUrl(sppkpUrl).then((isAccessible) => { + if (isAccessible) { + setFileUrlSppkp(sppkpUrl); + setHasSPPKP(true); + } + }); } - }, []); + }, [auth?.parentId]); return ( <> @@ -783,7 +805,7 @@ const form: React.FC<FormProps> = ({ className={`w-6 mr-2 hover:scale-110 transition-transform duration-200}`} /> <XCircleIcon - onClick={() => sethasNpwp(false)} + onClick={() => setHasNpwp(false)} className='w-6 hover:scale-110 transition-transform duration-200' /> </div> @@ -830,7 +852,7 @@ const form: React.FC<FormProps> = ({ className={`w-6 mr-2 hover:scale-110 transition-transform duration-200}`} /> <XCircleIcon - onClick={() => sethasSPPKP(false)} + onClick={() => setHasSPPKP(false)} className='w-6 hover:scale-110 transition-transform duration-200' /> </div> diff --git a/src-migrate/modules/register/index.tsx b/src-migrate/modules/register/index.tsx index da41fd8b..3d6158c8 100644 --- a/src-migrate/modules/register/index.tsx +++ b/src-migrate/modules/register/index.tsx @@ -170,7 +170,8 @@ const Register = () => { size='lg' onClick={handleSubmit} isDisabled={ - !isCheckedTNC || mutation.isLoading || !isValidCaptcha + // !isCheckedTNC || mutation.isLoading || !isValidCaptcha + !isCheckedTNC || mutation.isLoading } > {mutation.isLoading ? 'Loading...' : 'Daftar'} |
