diff options
| -rw-r--r-- | src/core/api/biteShip.js | 26 | ||||
| -rw-r--r-- | src/lib/checkout/api/ExpedisiList.js | 25 | ||||
| -rw-r--r-- | src/lib/checkout/components/Checkout.jsx | 58 | ||||
| -rw-r--r-- | src/lib/checkout/components/SectionExpedition.tsx | 12 | ||||
| -rw-r--r-- | src/lib/checkout/stores/useAdress.js | 6 |
5 files changed, 70 insertions, 57 deletions
diff --git a/src/core/api/biteShip.js b/src/core/api/biteShip.js new file mode 100644 index 00000000..9e9e8567 --- /dev/null +++ b/src/core/api/biteShip.js @@ -0,0 +1,26 @@ +import axios from 'axios'; + +const biteShipAPI = async (method, url, body = {}) => { + try { + const key = process.env.NEXT_PUBLIC_BITE_SHIP_KEY; + let axiosParameter = { + method, + url: process.env.NEXT_PUBLIC_BITE_SHIP_HOST + url, + headers: { Authorization: key, 'Content-Type': 'application/json' }, + }; + if (Object.keys(body).length > 0) + axiosParameter.data = JSON.stringify(body); + + const data = await axios(axiosParameter); + + return { success: true, data: data}; + } catch (error) { + console.log(error); + return { + success: false, + data : {} + }; + } +}; + +export default biteShipAPI; diff --git a/src/lib/checkout/api/ExpedisiList.js b/src/lib/checkout/api/ExpedisiList.js index ca22bec1..110295b7 100644 --- a/src/lib/checkout/api/ExpedisiList.js +++ b/src/lib/checkout/api/ExpedisiList.js @@ -1,8 +1,23 @@ -import odooApi from '@/core/api/odooApi' +import odooApi from '@/core/api/odooApi'; +import axios from 'axios'; +import biteShipAPI from '../../../core/api/biteShip'; const ExpedisiList = async () => { - const dataExpedisi = await odooApi('GET', '/api/v1/courier') - return dataExpedisi -} + const dataExpedisi = await odooApi('GET', '/api/v1/courier'); + return dataExpedisi; +}; -export default ExpedisiList +const GetRatesCourierBiteship = async ({ destination, items }) => { + const couriers = process.env.NEXT_PUBLIC_BITESHIP_CODE_COURIERS; + let body = { + destination, + couriers: couriers, + items + }; + + const featch = await biteShipAPI('POST', '/v1/rates/couriers', body); + + return featch; +}; + +export { GetRatesCourierBiteship, ExpedisiList} ; diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx index 97254ec0..6da27745 100644 --- a/src/lib/checkout/components/Checkout.jsx +++ b/src/lib/checkout/components/Checkout.jsx @@ -269,58 +269,6 @@ const Checkout = () => { }; }, []); - const hitungDiscountVoucher = (code, source) => { - let countDiscount = 0; - if (source === 'voucher') { - let dataVoucherIndex = listVouchers.findIndex( - (voucher) => voucher.code == code - ); - let dataActiveVoucher = listVouchers[dataVoucherIndex]; - - countDiscount = dataActiveVoucher.discountVoucher; - } else { - let dataVoucherIndex = listVoucherShippings.findIndex( - (voucher) => voucher.code == code - ); - let dataActiveVoucher = listVoucherShippings[dataVoucherIndex]; - - countDiscount = dataActiveVoucher.discountVoucher; - } - - /*if (dataActiveVoucher.discountType === 'percentage') { - countDiscount = cartCheckout?.subtotal * (dataActiveVoucher.discountAmount / 100) - if ( - dataActiveVoucher.maxDiscountAmount > 0 && - countDiscount > dataActiveVoucher.maxDiscountAmount - ) { - countDiscount = dataActiveVoucher.maxDiscountAmount - } - } else { - countDiscount = dataActiveVoucher.discountAmount - }*/ - - return countDiscount; - }; - - // useEffect(() => { - // if (!listVouchers) return; - // if (!activeVoucher) return; - - // console.log('voucher') - // const countDiscount = hitungDiscountVoucher(activeVoucher, 'voucher'); - - // SetDiscountVoucher(countDiscount); - // }, [activeVoucher, listVouchers]); - - // useEffect(() => { - // if (!listVoucherShippings) return; - // if (!activeVoucherShipping) return; - - // const countDiscount = hitungDiscountVoucher(activeVoucherShipping, 'voucher_shipping'); - - // SetDiscountVoucherOngkir(countDiscount); - // }, [activeVoucherShipping, listVoucherShippings]); - useEffect(() => { if (qVoucher === 'PASTIHEMAT' && listVouchers) { let code = qVoucher; @@ -1698,6 +1646,12 @@ const SectionValidation = ({ address }) => </BottomPopup> ); +const SectionExpedisiBiteship = ({ listExpedisi, setSelectedExpedisi }) => ( + <> + </> +); + + const SectionExpedisi = ({ address, listExpedisi, diff --git a/src/lib/checkout/components/SectionExpedition.tsx b/src/lib/checkout/components/SectionExpedition.tsx new file mode 100644 index 00000000..d2dd5763 --- /dev/null +++ b/src/lib/checkout/components/SectionExpedition.tsx @@ -0,0 +1,12 @@ +import React from 'react'; +import { GetRatesCourierBiteship } from '../api/ExpedisiList'; +import { useQuery } from 'react-query'; + +export default function SectionExpedition() { + let destination = {} + let items = {} + const fetchExpedition = async () => await GetRatesCourierBiteship({destination, items}); + const {data : coursers, isLoading} = useQuery('expedition-'+destination, fetchExpedition) + + return <div>SectionExpedition</div>; +}
\ No newline at end of file diff --git a/src/lib/checkout/stores/useAdress.js b/src/lib/checkout/stores/useAdress.js new file mode 100644 index 00000000..1c17258d --- /dev/null +++ b/src/lib/checkout/stores/useAdress.js @@ -0,0 +1,6 @@ +import { create } from "zustand"; + +export const useAddress = create((set) => ({ + address: {}, + setAddress: (address) => set({ address }), +}));
\ No newline at end of file |
