summaryrefslogtreecommitdiff
path: root/src/pages
diff options
context:
space:
mode:
authorIndoteknik . <andrifebriyadiputra@gmail.com>2025-08-11 15:35:25 +0700
committerIndoteknik . <andrifebriyadiputra@gmail.com>2025-08-11 15:35:25 +0700
commit7647104348478302778c0afbd3a3d1b2637bc03b (patch)
treee984e65dae4c8c8a446f4d981577dc84c8d3355b /src/pages
parent930919a6f99626436bf2e24aa0ee2b0566808a88 (diff)
(andri) set true checklist ubah ke akun bisnis
Diffstat (limited to 'src/pages')
-rw-r--r--src/pages/my/profile.jsx80
1 files changed, 54 insertions, 26 deletions
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>
)}