diff options
| author | trisusilo48 <tri.susilo@altama.co.id> | 2024-07-22 15:08:07 +0700 |
|---|---|---|
| committer | trisusilo48 <tri.susilo@altama.co.id> | 2024-07-22 15:08:07 +0700 |
| commit | 0433d92034937c76135ceb83ef88402464006866 (patch) | |
| tree | 5afac17eac262edf6505c1be225abe8230bcedf9 /src/lib | |
| parent | d0f97021c611d07944f3cbc7e2610b1d495d897f (diff) | |
get new voucher
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/checkout/api/getVoucher.js | 10 | ||||
| -rw-r--r-- | src/lib/checkout/components/Checkout.jsx | 24 |
2 files changed, 27 insertions, 7 deletions
diff --git a/src/lib/checkout/api/getVoucher.js b/src/lib/checkout/api/getVoucher.js index 07cf376e..15c6abbb 100644 --- a/src/lib/checkout/api/getVoucher.js +++ b/src/lib/checkout/api/getVoucher.js @@ -1,4 +1,5 @@ import odooApi from '@/core/api/odooApi' +import { getAuth } from '@/core/utils/auth' export const getVoucher = async (id, source) => { let dataVoucher = null @@ -19,3 +20,12 @@ export const findVoucher = async (code, id, source) => { } return dataVoucher } + + +export const getVoucherNew = async (source) => { + const id = getAuth()?.id; + const dataVoucher = await odooApi('GET', `/api/v1/user/${id}/voucher?${source}`) + + return dataVoucher + +}
\ No newline at end of file diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx index 92e14db6..61410bdf 100644 --- a/src/lib/checkout/components/Checkout.jsx +++ b/src/lib/checkout/components/Checkout.jsx @@ -30,7 +30,7 @@ import whatsappUrl from '@/core/utils/whatsappUrl'; import addressesApi from '@/lib/address/api/addressesApi'; import CartItem from '~/modules/cart/components/Item.tsx'; import ExpedisiList from '../api/ExpedisiList'; -import { findVoucher, getVoucher } from '../api/getVoucher'; +import { findVoucher, getVoucher, getVoucherNew } from '../api/getVoucher'; const SELF_PICKUP_ID = 32; @@ -40,6 +40,7 @@ const { getProductsCheckout } = require('../api/checkoutApi'); const Checkout = () => { const router = useRouter(); const query = router.query.source ?? null; + const qVoucher = router.query.voucher ?? null; const auth = useAuth(); const [activeVoucher, SetActiveVoucher] = useState(null); @@ -119,7 +120,8 @@ const Checkout = () => { const voucher = async () => { if (!listVouchers) { try { - let dataVoucher = await getVoucher(auth?.id, query); + let source = 'source=' + query; + let dataVoucher = await getVoucherNew(source); SetListVoucher(dataVoucher); } finally { setLoadingVoucher(false); @@ -127,14 +129,16 @@ const Checkout = () => { } }; const VoucherCode = async (code) => { - let dataVoucher = await findVoucher(code, auth.id, query); + const source = 'code=' + code+'&source='+query; + // let dataVoucher = await findVoucher(code, auth.id, query); + let dataVoucher = await getVoucherNew(source); if (dataVoucher.length <= 0) { SetFindVoucher(1); return; } let addNewLine = dataVoucher[0]; - let checkList = listVouchers.findIndex( + let checkList = listVouchers?.findIndex( (voucher) => voucher.code == addNewLine.code ); if (checkList >= 0) { @@ -166,6 +170,8 @@ const Checkout = () => { }, [bottomPopup]); useEffect(() => { + + // voucher() const loadExpedisi = async () => { let dataExpedisi = await ExpedisiList(); dataExpedisi = dataExpedisi.map((expedisi) => ({ @@ -176,6 +182,10 @@ const Checkout = () => { setExpedisi(dataExpedisi); }; loadExpedisi(); + if(qVoucher === 'PASTIHEMAT'){ + let code = qVoucher; + handleUseVoucher(code, !isChecked); + } const handlePopState = () => { router.push('/shop/cart'); @@ -186,7 +196,7 @@ const Checkout = () => { return () => { window.onpopstate = null; }; - // voucher() + }, []); const hitungDiscountVoucher = (code) => { @@ -407,13 +417,13 @@ const Checkout = () => { } else { SetActiveVoucher(code); SetFindVoucher(null); - document.getElementById('uniqCode').value = ''; + document.getElementById('uniqCode') ? document.getElementById('uniqCode').value = '' : ''; SetButtonTerapkan(false); } } else { SetActiveVoucher(code); SetFindVoucher(null); - document.getElementById('uniqCode').value = ''; + document.getElementById('uniqCode') ? document.getElementById('uniqCode').value = '' : ''; SetButtonTerapkan(false); } }; |
