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

