From 7647104348478302778c0afbd3a3d1b2637bc03b Mon Sep 17 00:00:00 2001 From: "Indoteknik ." 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') 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() { setChangeConfirmation(false)} // Menutup popup - title='Ubah type akun' + title="Ubah type akun" > -
+
Anda akan mengubah type akun anda?
-
+