summaryrefslogtreecommitdiff
path: root/src/pages
diff options
context:
space:
mode:
Diffstat (limited to 'src/pages')
-rw-r--r--src/pages/api/shop/search.js51
-rw-r--r--src/pages/my/menu.jsx11
-rw-r--r--src/pages/my/profile.jsx93
3 files changed, 88 insertions, 67 deletions
diff --git a/src/pages/api/shop/search.js b/src/pages/api/shop/search.js
index e14b0ca2..8c9782cb 100644
--- a/src/pages/api/shop/search.js
+++ b/src/pages/api/shop/search.js
@@ -19,7 +19,6 @@ export default async function handler(req, res) {
source = '',
} = req.query;
-
let { stock = '' } = req.query;
let paramOrderBy = '';
switch (orderBy) {
@@ -73,7 +72,7 @@ export default async function handler(req, res) {
const formattedQuery = `(${newQ
.split(' ')
- .map((term) => (term.length < 2 ? term : `${term}*`)) // Tambahkan '*' hanya jika panjang kata >= 2
+ .map((term) => (term.length < 2 ? term : `${term}*`))
.join(' ')})`;
const mm =
@@ -90,7 +89,7 @@ export default async function handler(req, res) {
];
if (orderBy === 'stock') {
- filterQueries.push('stock_total_f:{0 TO *}');
+ filterQueries.push('stock_total_f:[1 TO *]');
}
if (fq && source != 'similar' && typeof fq != 'string') {
@@ -112,8 +111,9 @@ export default async function handler(req, res) {
let offset = (page - 1) * limit;
let parameter = [
- 'facet.field=manufacture_name_s',
- 'facet.field=category_name',
+ // === Facet disjunctive: exclude filter brand/cat saat hitung facet ===
+ 'facet.field={!ex=brand}manufacture_name_s',
+ 'facet.field={!ex=cat}category_name',
'facet=true',
'indent=true',
`facet.query=${escapeSolrQuery(q)}`,
@@ -142,25 +142,29 @@ export default async function handler(req, res) {
if (auth.feature.onlyReadyStock) stock = true;
}
- if (brand)
- parameter.push(
- `fq=${brand
- .split(',')
- .map(
- (manufacturer) =>
- `manufacture_name:"${encodeURIComponent(manufacturer)}"`
- )
- .join(' OR ')}`
- );
- if (category)
- parameter.push(
- `fq=${category
- .split(',')
- .map((cat) => `category_name:"${encodeURIComponent(cat)}"`)
- .join(' OR ')}`
- );
+ if (brand) {
+ // bentuk ekspresi sama seperti versi kamu, tapi dibungkus tag brand
+ const brandExpr = brand
+ .split(',')
+ .map(
+ (manufacturer) =>
+ `manufacture_name:"${encodeURIComponent(manufacturer)}"`
+ )
+ .join(' OR ');
+ parameter.push(`fq={!tag=brand}(${brandExpr})`);
+ }
+
+ if (category) {
+ // sama: tag kategori
+ const catExpr = category
+ .split(',')
+ .map((cat) => `category_name:"${encodeURIComponent(cat)}"`)
+ .join(' OR ');
+ parameter.push(`fq={!tag=cat}(${catExpr})`);
+ }
+
// if (category) parameter.push(`fq=category_name:${capitalizeFirstLetter(category.replace(/,/g, ' OR '))}`)
- if (stock) parameter.push(`fq=stock_total_f:{1 TO *}`);
+ if (stock) parameter.push(`fq=stock_total_f:(1 TO *)`);
// Single fq in url params
if (typeof fq === 'string') parameter.push(`fq=${encodeURIComponent(fq)}`);
@@ -169,6 +173,7 @@ export default async function handler(req, res) {
parameter = parameter.concat(
fq.map((val) => `fq=${encodeURIComponent(val)}`)
);
+
let result = await axios(
process.env.SOLR_HOST + '/solr/product/select?' + parameter.join('&')
);
diff --git a/src/pages/my/menu.jsx b/src/pages/my/menu.jsx
index 2a46d866..fa656ed4 100644
--- a/src/pages/my/menu.jsx
+++ b/src/pages/my/menu.jsx
@@ -48,17 +48,6 @@ export default function Menu() {
<MenuHeader>Aktivitas Pembelian</MenuHeader>
<div className='divide-y divide-gray_r-6 border-y border-gray_r-6 mt-4'>
- <LinkItem href='/my/quotations'>
- {' '}
- <div className='flex gap-x-3 items-center'>
- <ImageNext
- src='/images/icon/icon_daftar_quotation.svg'
- width={18}
- height={20}
- />
- <p>Daftar Quotation</p>
- </div>
- </LinkItem>
<LinkItem href='/my/transactions'>
<div className='flex gap-x-3 items-center'>
<ImageNext
diff --git a/src/pages/my/profile.jsx b/src/pages/my/profile.jsx
index 859b6960..92e3956c 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);
@@ -45,23 +74,23 @@ export default function Profile() {
<>
<BottomPopup
active={changeConfirmation}
- close={() => setChangeConfirmation(false)} // Menutup popup
- title='Ubah type akun'
+ close={() => setChangeConfirmation(false)} //Menutup popup
+ 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>
)}