From 7647104348478302778c0afbd3a3d1b2637bc03b Mon Sep 17 00:00:00 2001
From: "Indoteknik ." <andrifebriyadiputra@gmail.com>
Date: Mon, 11 Aug 2025 15:35:25 +0700
Subject: (andri) set true checklist ubah ke akun bisnis

---
 src/pages/my/profile.jsx | 80 ++++++++++++++++++++++++++++++++----------------
 1 file changed, 54 insertions(+), 26 deletions(-)

(limited to 'src/pages/my/profile.jsx')

diff --git a/src/pages/my/profile.jsx b/src/pages/my/profile.jsx
index 859b6960..663ff97a 100644
--- a/src/pages/my/profile.jsx
+++ b/src/pages/my/profile.jsx
@@ -14,19 +14,26 @@ import { Checkbox } from '@chakra-ui/react';
 import { useState, useEffect } from 'react';
 import switchAccountProgresApi from '@/lib/auth/api/switchAccountProgresApi.js';
 import BottomPopup from '@/core/components/elements/Popup/BottomPopup';
+import { useRouter } from 'next/router';
+
 export default function Profile() {
   const auth = useAuth();
   const [isChecked, setIsChecked] = useState(false);
   const [ubahAkun, setUbahAkun] = useState(false);
   const [isAprove, setIsAprove] = useState();
   const [changeConfirmation, setChangeConfirmation] = useState(false);
-  const handleChange = async () => {
+  const router = useRouter();
+
+  // Handle checkbox toggle
+  const handleChange = () => {
     if (isChecked) {
-      setIsChecked(!isChecked);
+      setIsChecked(false);
     } else {
       setChangeConfirmation(true);
     }
   };
+
+  // Load status dan cek localStorage "autoCheckProfile"
   useEffect(() => {
     const loadPromo = async () => {
       const progresSwitchAccount = await switchAccountProgresApi();
@@ -36,7 +43,28 @@ export default function Profile() {
       }
     };
     loadPromo();
-  }, []);
+
+    if (typeof window !== 'undefined') {
+      const autoCheck = localStorage.getItem('autoCheckProfile');
+      if (autoCheck === 'true') {
+        setIsChecked(true);
+        localStorage.removeItem('autoCheckProfile');
+
+        // Hapus query param supaya URL bersih
+        if (router.query.autoCheck) {
+          const cleanQuery = { ...router.query };
+          delete cleanQuery.autoCheck;
+          router.replace(
+            { pathname: router.pathname, query: cleanQuery },
+            undefined,
+            { shallow: true }
+          );
+        }
+      }
+    }
+  }, [router]);
+
+  // Confirm checkbox change from popup
   const handleConfirmSubmit = () => {
     setChangeConfirmation(false);
     setIsChecked(true);
@@ -46,22 +74,22 @@ export default function Profile() {
       <BottomPopup
         active={changeConfirmation}
         close={() => setChangeConfirmation(false)} // Menutup popup
-        title='Ubah type akun'
+        title="Ubah type akun"
       >
-        <div className='leading-7 text-gray_r-12/80'>
+        <div className="leading-7 text-gray_r-12/80">
           Anda akan mengubah type akun anda?
         </div>
-        <div className='flex mt-6 gap-x-4 md:justify-end'>
+        <div className="flex mt-6 gap-x-4 md:justify-end">
           <button
-            className='btn-solid-red flex-1 md:flex-none'
-            type='button'
+            className="btn-solid-red flex-1 md:flex-none"
+            type="button"
             onClick={handleConfirmSubmit}
           >
             Yakin
           </button>
           <button
-            className='btn-light flex-1 md:flex-none'
-            type='button'
+            className="btn-light flex-1 md:flex-none"
+            type="button"
             onClick={() => setChangeConfirmation(false)}
           >
             Batal
@@ -70,23 +98,23 @@ export default function Profile() {
       </BottomPopup>
       <IsAuth>
         <MobileView>
-          <AppLayout title='Akun Saya'>
+          <AppLayout title="Akun Saya">
             {auth?.company ||
               (!ubahAkun && (
-                <div className='text-sm p-4 flex items-center'>
+                <div className="text-sm p-4 flex items-center">
                   <Checkbox
-                    borderColor='gray.600'
-                    colorScheme='red'
-                    size='lg'
+                    borderColor="gray.600"
+                    colorScheme="red"
+                    size="lg"
                     isChecked={isChecked}
                     onChange={handleChange}
                   />
-                  <p className='ml-2'>Ubah ke akun bisnis</p>
+                  <p className="ml-2">Ubah ke akun bisnis</p>
                 </div>
               ))}
             {isChecked && (
               <div>
-                <SwitchAccount company_type='nonpkp' />
+                <SwitchAccount company_type="nonpkp" />
                 <Divider />
               </div>
             )}
@@ -104,27 +132,27 @@ export default function Profile() {
 
         <DesktopView>
           <BasicLayout>
-            <div className='container mx-auto flex py-10'>
-              <div className='w-3/12 pr-4'>
+            <div className="container mx-auto flex py-10">
+              <div className="w-3/12 pr-4">
                 <Menu />
               </div>
-              <div className='w-9/12 bg-white border border-gray_r-6 rounded'>
+              <div className="w-9/12 bg-white border border-gray_r-6 rounded">
                 {auth?.company ||
                   (!ubahAkun && (
-                    <div className='text-sm p-4 flex items-center'>
+                    <div className="text-sm p-4 flex items-center">
                       <Checkbox
-                        borderColor='gray.600'
-                        colorScheme='red'
-                        size='lg'
+                        borderColor="gray.600"
+                        colorScheme="red"
+                        size="lg"
                         isChecked={isChecked}
                         onChange={handleChange}
                       />
-                      <p className='ml-2'>Ubah ke akun bisnis</p>
+                      <p className="ml-2">Ubah ke akun bisnis</p>
                     </div>
                   ))}
                 {isChecked && (
                   <div>
-                    <SwitchAccount company_type='nonpkp' />
+                    <SwitchAccount company_type="nonpkp" />
                     <Divider />
                   </div>
                 )}
-- 
cgit v1.2.3


From c527fa8fe9772b456a11a52f52c7ee091504d734 Mon Sep 17 00:00:00 2001
From: "Indoteknik ." <andrifebriyadiputra@gmail.com>
Date: Tue, 12 Aug 2025 17:31:31 +0700
Subject: (andri) fix switch account ke bisnis

---
 src/pages/my/profile.jsx | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

(limited to 'src/pages/my/profile.jsx')

diff --git a/src/pages/my/profile.jsx b/src/pages/my/profile.jsx
index 663ff97a..887489e0 100644
--- a/src/pages/my/profile.jsx
+++ b/src/pages/my/profile.jsx
@@ -99,8 +99,7 @@ export default function Profile() {
       <IsAuth>
         <MobileView>
           <AppLayout title="Akun Saya">
-            {auth?.company ||
-              (!ubahAkun && (
+            {auth?.company || ((isChecked || (!ubahAkun && ubahAkun !== 'pending')) && (
                 <div className="text-sm p-4 flex items-center">
                   <Checkbox
                     borderColor="gray.600"
@@ -137,8 +136,7 @@ export default function Profile() {
                 <Menu />
               </div>
               <div className="w-9/12 bg-white border border-gray_r-6 rounded">
-                {auth?.company ||
-                  (!ubahAkun && (
+                {auth?.company || ((isChecked || (!ubahAkun && ubahAkun !== 'pending')) && (
                     <div className="text-sm p-4 flex items-center">
                       <Checkbox
                         borderColor="gray.600"
-- 
cgit v1.2.3


From b1bdfbb9f780a1a1305e02c4b9c338b98c7a4556 Mon Sep 17 00:00:00 2001
From: "Indoteknik ." <andrifebriyadiputra@gmail.com>
Date: Fri, 15 Aug 2025 13:58:59 +0700
Subject: (andri) fix switch account

---
 src/pages/my/profile.jsx | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

(limited to 'src/pages/my/profile.jsx')

diff --git a/src/pages/my/profile.jsx b/src/pages/my/profile.jsx
index 887489e0..b65a5e4d 100644
--- a/src/pages/my/profile.jsx
+++ b/src/pages/my/profile.jsx
@@ -18,6 +18,7 @@ import { useRouter } from 'next/router';
 
 export default function Profile() {
   const auth = useAuth();
+  console.log('auth', auth);
   const [isChecked, setIsChecked] = useState(false);
   const [ubahAkun, setUbahAkun] = useState(false);
   const [isAprove, setIsAprove] = useState();
@@ -111,9 +112,9 @@ export default function Profile() {
                   <p className="ml-2">Ubah ke akun bisnis</p>
                 </div>
               ))}
-            {isChecked && (
+            {isChecked && ubahAkun !== 'pending'  && (
               <div>
-                <SwitchAccount company_type="nonpkp" />
+                <SwitchAccount company_type="nonpkp" setIsAprove={setIsAprove} setUbahAkun={setUbahAkun}/>
                 <Divider />
               </div>
             )}
@@ -148,9 +149,9 @@ export default function Profile() {
                       <p className="ml-2">Ubah ke akun bisnis</p>
                     </div>
                   ))}
-                {isChecked && (
+                {isChecked && ubahAkun !== 'pending'  && (
                   <div>
-                    <SwitchAccount company_type="nonpkp" />
+                    <SwitchAccount company_type="nonpkp" setIsAprove={setIsAprove} setUbahAkun={setUbahAkun}/>
                     <Divider />
                   </div>
                 )}
-- 
cgit v1.2.3

