From 3eb78e21b89bd0bdddb803767ea6ec983794994b Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Sat, 28 Sep 2024 10:01:30 +0700 Subject: update temp switch account --- .../modules/register/components/FormBisnis.tsx | 52 +++++++++++++++------- src-migrate/modules/register/index.tsx | 3 +- 2 files changed, 39 insertions(+), 16 deletions(-) (limited to 'src-migrate/modules/register') 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 = ({ type, @@ -68,7 +72,7 @@ const form: React.FC = ({ // Inside your component const [formattedNpwp, setFormattedNpwp] = useState(''); // State for formatted NPWP const [unformattedNpwp, setUnformattedNpwp] = useState(''); // State for unformatted NPWP - + const auth = useAuth() as unknown as Auth; const [industries, setIndustries] = useState([]); const [companyTypes, setCompanyTypes] = useState([]); @@ -342,22 +346,40 @@ const form: React.FC = ({ 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 = ({ className={`w-6 mr-2 hover:scale-110 transition-transform duration-200}`} /> sethasNpwp(false)} + onClick={() => setHasNpwp(false)} className='w-6 hover:scale-110 transition-transform duration-200' /> @@ -830,7 +852,7 @@ const form: React.FC = ({ className={`w-6 mr-2 hover:scale-110 transition-transform duration-200}`} /> sethasSPPKP(false)} + onClick={() => setHasSPPKP(false)} className='w-6 hover:scale-110 transition-transform duration-200' /> 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'} -- cgit v1.2.3