summaryrefslogtreecommitdiff
path: root/src/pages
diff options
context:
space:
mode:
authorMiqdad <ahmadmiqdad27@gmail.com>2025-08-16 08:16:10 +0700
committerMiqdad <ahmadmiqdad27@gmail.com>2025-08-16 08:16:10 +0700
commit91b73f89b35874df3e0b88c67cf906df06965782 (patch)
tree8a4bac4fb6e67c086a493e6683ce43f733468eba /src/pages
parent0fa70adbf4a9fab74337d35dcfd21722370ac93e (diff)
parent1a68a24e9fb58ecc1ade9d1d792ea06b432e4989 (diff)
Merge branch 'new-release' of https://bitbucket.org/altafixco/next-indoteknik into fix-map
Diffstat (limited to 'src/pages')
-rw-r--r--src/pages/api/shop/search.js3
-rw-r--r--src/pages/my/profile.jsx91
2 files changed, 61 insertions, 33 deletions
diff --git a/src/pages/api/shop/search.js b/src/pages/api/shop/search.js
index e14b0ca2..3d258a97 100644
--- a/src/pages/api/shop/search.js
+++ b/src/pages/api/shop/search.js
@@ -90,7 +90,8 @@ export default async function handler(req, res) {
];
if (orderBy === 'stock') {
- filterQueries.push('stock_total_f:{0 TO *}');
+ filterQueries.push('stock_total_f:{1 TO *}&sort=stock_total_f desc');
+ // filterQueries.push(`stock_total_f DESC`)
}
if (fq && source != 'similar' && typeof fq != 'string') {
diff --git a/src/pages/my/profile.jsx b/src/pages/my/profile.jsx
index 859b6960..b65a5e4d 100644
--- a/src/pages/my/profile.jsx
+++ b/src/pages/my/profile.jsx
@@ -14,19 +14,27 @@ 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();
+ console.log('auth', auth);
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 +44,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 +75,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 +99,22 @@ export default function Profile() {
</BottomPopup>
<IsAuth>
<MobileView>
- <AppLayout title='Akun Saya'>
- {auth?.company ||
- (!ubahAkun && (
- <div className='text-sm p-4 flex items-center'>
+ <AppLayout title="Akun Saya">
+ {auth?.company || ((isChecked || (!ubahAkun && ubahAkun !== 'pending')) && (
+ <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 && (
+ {isChecked && ubahAkun !== 'pending' && (
<div>
- <SwitchAccount company_type='nonpkp' />
+ <SwitchAccount company_type="nonpkp" setIsAprove={setIsAprove} setUbahAkun={setUbahAkun}/>
<Divider />
</div>
)}
@@ -104,27 +132,26 @@ 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'>
- {auth?.company ||
- (!ubahAkun && (
- <div className='text-sm p-4 flex items-center'>
+ <div className="w-9/12 bg-white border border-gray_r-6 rounded">
+ {auth?.company || ((isChecked || (!ubahAkun && ubahAkun !== 'pending')) && (
+ <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 && (
+ {isChecked && ubahAkun !== 'pending' && (
<div>
- <SwitchAccount company_type='nonpkp' />
+ <SwitchAccount company_type="nonpkp" setIsAprove={setIsAprove} setUbahAkun={setUbahAkun}/>
<Divider />
</div>
)}