diff options
| -rw-r--r-- | src-migrate/modules/register/components/FormBisnis.tsx | 52 | ||||
| -rw-r--r-- | src-migrate/modules/register/index.tsx | 3 | ||||
| -rw-r--r-- | src/lib/auth/components/Menu.jsx | 22 | ||||
| -rw-r--r-- | src/pages/my/profile.jsx | 10 |
4 files changed, 63 insertions, 24 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'} diff --git a/src/lib/auth/components/Menu.jsx b/src/lib/auth/components/Menu.jsx index 979de83b..042b1842 100644 --- a/src/lib/auth/components/Menu.jsx +++ b/src/lib/auth/components/Menu.jsx @@ -3,20 +3,36 @@ import { useRouter } from 'next/router'; import ImageNext from 'next/image'; import whatsappUrl from '@/core/utils/whatsappUrl'; import useAuth from '@/core/hooks/useAuth'; -import Divider from '@/core/components/elements/Divider/Divider'; +import switchAccountProgresApi from '@/lib/auth/api/switchAccountProgresApi.js'; +import { useState, useEffect } from 'react'; const Menu = () => { const router = useRouter(); const auth = useAuth(); + // console.log('auth', auth); + const [ubahAkun, setUbahAkun] = useState(); + // const [isAprove, setIsAprove] = useState(); + useEffect(() => { + const loadProgres = async () => { + const progresSwitchAccount = await switchAccountProgresApi(); + console.log('progresSwitchAccount', progresSwitchAccount); + // if (progresSwitchAccount) { + // setIsAprove(progresSwitchAccount.status); + setUbahAkun(progresSwitchAccount.status); + // } + }; + loadProgres(); + }, []); const routeStartWith = (route) => router.pathname.startsWith(route); return ( <div className='grid grid-cols-1 bg-white border border-gray_r-6 rounded py-2 px-4 sticky top-48'> <div className='flex justify-between py-4'> <div className='font-semibold text-gray_r-12'>Akun Saya</div> - {auth?.company && ( + {auth?.company && !ubahAkun && ( <div className='badge-solid-red mt-1 p-2'>Akun Bisnis</div> )} - {!auth?.company && ( + {ubahAkun && <div className='badge-solid-red mt-1 p-2'>Review</div>} + {!auth?.company && !ubahAkun && ( <div className='badge-gray mt-1 p-2'>Akun Individu</div> )} </div> diff --git a/src/pages/my/profile.jsx b/src/pages/my/profile.jsx index f6063ff2..ee0cd907 100644 --- a/src/pages/my/profile.jsx +++ b/src/pages/my/profile.jsx @@ -9,7 +9,7 @@ import SwitchAccount from '@/lib/auth/components/SwitchAccount'; import IsAuth from '@/lib/auth/components/IsAuth'; import Menu from '@/lib/auth/components/Menu'; import PersonalProfile from '@/lib/auth/components/PersonalProfile'; -import StatusSwitchAccount from '@/lib/auth/components/StatusSwitchAccount'; +// import StatusSwitchAccount from '@/lib/auth/components/StatusSwitchAccount'; import { Checkbox } from '@chakra-ui/react'; import { useState, useEffect } from 'react'; import switchAccountProgresApi from '@/lib/auth/api/switchAccountProgresApi.js'; @@ -89,12 +89,12 @@ export default function Profile() { <Divider /> </div> )} - {!auth?.parentId + {/* {!auth?.parentId ? auth?.parentId : auth?.parent_id && isAprove != 'unknown' && ( <StatusSwitchAccount status={isAprove} /> - )} + )} */} <PersonalProfile /> <Divider /> {auth?.parentId && <CompanyProfile />} @@ -126,12 +126,12 @@ export default function Profile() { <Divider /> </div> )} - {!auth?.parentId + {/* {!auth?.parentId ? auth?.parentId : auth?.parent_id && isAprove != 'unknown' && ( <StatusSwitchAccount status={isAprove} /> - )} + )} */} <PersonalProfile /> <Divider /> {auth?.parentId && <CompanyProfile />} |
