From 2a030239105dba1f78a3fdc51ccc49a46bc60ca2 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Mon, 30 Sep 2024 13:57:59 +0700
Subject: <iman> update switch account

---
 .../modules/register/components/FormBisnis.tsx     | 31 +++++++++++++++-------
 1 file changed, 21 insertions(+), 10 deletions(-)

(limited to 'src-migrate/modules/register/components/FormBisnis.tsx')

diff --git a/src-migrate/modules/register/components/FormBisnis.tsx b/src-migrate/modules/register/components/FormBisnis.tsx
index 97c0acad..16747ff3 100644
--- a/src-migrate/modules/register/components/FormBisnis.tsx
+++ b/src-migrate/modules/register/components/FormBisnis.tsx
@@ -348,12 +348,22 @@ const form: React.FC<FormProps> = ({
   const [hasNPWP, setHasNpwp] = useState(false);
   const [hasSPPKP, setHasSPPKP] = useState(false);
   const [fileUrlSppkp, setFileUrlSppkp] = useState('');
-
   useEffect(() => {
-    const checkUrl = async (url: string | URL | Request) => {
+    const checkUrlNPWP = async (url: string | URL | Request) => {
+      try {
+        const response = `${process.env.NEXT_PUBLIC_ODOO_API_HOST}/api/v1/user/chek/npwp/${auth?.parentId}`;
+
+        return response; // Returns true if status is 200-299
+      } catch (error) {
+        console.error('Error accessing URL:', url, error);
+        return false;
+      }
+    };
+    const checkUrlSPPKP = async (url: string | URL | Request) => {
       try {
-        const response = await fetch(url, { method: 'HEAD' });
-        return response.ok; // Returns true if status is 200-299
+        const response = `${process.env.NEXT_PUBLIC_ODOO_API_HOST}/api/v1/user/chek/sppkp/${auth?.parentId}`;
+
+        return response; // Returns true if status is 200-299
       } catch (error) {
         console.error('Error accessing URL:', url, error);
         return false;
@@ -364,14 +374,16 @@ const form: React.FC<FormProps> = ({
     const sppkpUrl = `${process.env.NEXT_PUBLIC_ODOO_API_HOST}/api/v1/user/download/sppkp/${auth?.parentId}`;
 
     if (auth?.parentId) {
-      checkUrl(npwpUrl).then((isAccessible) => {
+      checkUrlNPWP(npwpUrl).then((isAccessible) => {
         if (isAccessible) {
           setFileUrl(npwpUrl);
           setHasNpwp(true);
+          updateForm('npwp_document', ' ');
+          updateForm('sppkp_document', ' ');
         }
       });
 
-      checkUrl(sppkpUrl).then((isAccessible) => {
+      checkUrlSPPKP(sppkpUrl).then((isAccessible) => {
         if (isAccessible) {
           setFileUrlSppkp(sppkpUrl);
           setHasSPPKP(true);
@@ -835,6 +847,9 @@ const form: React.FC<FormProps> = ({
             accept='.pdf,.png,.jpg,.jpeg'
             content='lagu.jpg'
           />
+          {chekValid && isPKP && !required && !!errors.sppkp_document && (
+            <span className='form-msg-danger'>{errors.sppkp_document}</span>
+          )}
           <span className='form-msg-danger ml-4 text-xs mb-2'>
             Format: .pdf, .png, .jpg, atau .jpeg, Maks 2MB
           </span>
@@ -858,10 +873,6 @@ const form: React.FC<FormProps> = ({
               </div>
             </div>
           )}
-
-          {chekValid && isPKP && !required && !!errors.sppkp_document && (
-            <span className='form-msg-danger'>{errors.sppkp_document}</span>
-          )}
         </div>
       </form>
     </>
-- 
cgit v1.2.3

