summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortrisusilo48 <tri.susilo@altama.co.id>2024-08-29 14:53:38 +0700
committertrisusilo48 <tri.susilo@altama.co.id>2024-08-29 14:53:38 +0700
commit38e9859f2d28af3b0c259eab620290254806d04c (patch)
treeb946c81b37727f0a22c038659a0f30846ca8055a /src/lib
parentaf6494b92528cee8fae7173e8290c4ebbc334efa (diff)
parentc6e970598c6c23f0606d1bc19036f0decd57cc05 (diff)
Merge branch 'release' into CR/search_enggine
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/checkout/components/Checkout.jsx202
-rw-r--r--src/lib/tracking-order/api/trackingOrder.js8
-rw-r--r--src/lib/tracking-order/component/TrackingOrder.jsx139
-rw-r--r--src/lib/treckingAwb/component/Manifest.jsx16
4 files changed, 305 insertions, 60 deletions
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index 58d1403a..54acdf7c 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -131,6 +131,7 @@ const Checkout = () => {
setLoadingVoucher(true);
let dataVoucher = await getVoucher(auth?.id, {
source: query,
+ type: 'all,brand',
});
SetListVoucher(dataVoucher);
@@ -146,40 +147,91 @@ const Checkout = () => {
};
const VoucherCode = async (code) => {
- const source = 'code=' + code + '&source=' + query;
// let dataVoucher = await findVoucher(code, auth.id, query);
- let dataVoucher = await getVoucherNew(source);
+ let dataVoucher = await getVoucher(auth?.id, {
+ source: query,
+ code: code,
+ });
if (dataVoucher.length <= 0) {
SetFindVoucher(1);
return;
}
- let addNewLine = dataVoucher[0];
- let checkList = listVouchers?.findIndex(
- (voucher) => voucher.code == addNewLine.code
- );
- if (checkList >= 0) {
- if (listVouchers[checkList].canApply) {
- ToggleSwitch(code);
- SetCodeVoucher(null);
+ dataVoucher.forEach((addNewLine) => {
+ if (addNewLine.applyType !== 'shipping') {
+ // Mencari voucher dalam listVouchers
+ let checkList = listVouchers?.findIndex(
+ (voucher) => voucher.code === addNewLine.code
+ );
+
+ if (checkList >= 0) {
+ if (listVouchers[checkList].canApply) {
+ ToggleSwitch(addNewLine.code); // Perbaikan: Gunakan code voucher yang benar
+ SetCodeVoucher(null);
+ } else {
+ SetSelisihHargaCode(listVouchers[checkList].differenceToApply);
+ SetFindVoucher(2);
+ }
+ return; // Hentikan eksekusi lebih lanjut pada iterasi ini
+ }
+
+ // Memeriksa apakah subtotal memenuhi syarat minimal pembelian
+ if (cartCheckout?.subtotal < addNewLine.minPurchaseAmount) {
+ SetSelisihHargaCode(
+ currencyFormat(
+ addNewLine.minPurchaseAmount - cartCheckout?.subtotal
+ )
+ );
+ SetFindVoucher(2);
+ return;
+ } else {
+ SetFindVoucher(3);
+ SetButtonTerapkan(true);
+ }
+
+ // Tambahkan voucher ke list dan set voucher aktif
+ SetListVoucher((prevList) => [addNewLine, ...prevList]);
+ SetActiveVoucher(addNewLine.code);
} else {
- SetSelisihHargaCode(listVouchers[checkList].differenceToApply);
- SetFindVoucher(2);
+ // Mencari voucher dalam listVoucherShippings
+ let checkList = listVoucherShippings?.findIndex(
+ (voucher) => voucher.code === addNewLine.code
+ );
+
+ if (checkList >= 0) {
+ if (listVoucherShippings[checkList].canApply) {
+ ToggleSwitch(addNewLine.code); // Perbaikan: Gunakan code voucher yang benar
+ SetCodeVoucher(null);
+ } else {
+ SetSelisihHargaCode(
+ listVoucherShippings[checkList].differenceToApply
+ );
+ SetFindVoucher(2);
+ }
+ return; // Hentikan eksekusi lebih lanjut pada iterasi ini
+ }
+
+ // Memeriksa apakah subtotal memenuhi syarat minimal pembelian
+ if (cartCheckout?.subtotal < addNewLine.minPurchaseAmount) {
+ SetSelisihHargaCode(
+ currencyFormat(
+ addNewLine.minPurchaseAmount - cartCheckout?.subtotal
+ )
+ );
+ SetFindVoucher(2);
+ return;
+ } else {
+ SetFindVoucher(3);
+ SetButtonTerapkan(true);
+ }
+
+ // Tambahkan voucher ke list pengiriman dan set voucher aktif pengiriman
+ SetListVoucherShipping((prevList) => [addNewLine, ...prevList]);
+ setActiveVoucherShipping(addNewLine.code);
}
- return;
- }
- if (cartCheckout?.subtotal < addNewLine.minPurchaseAmount) {
- SetSelisihHargaCode(
- currencyFormat(addNewLine.minPurchaseAmount - cartCheckout?.subtotal)
- );
- SetFindVoucher(2);
- return;
- } else {
- SetFindVoucher(3);
- SetButtonTerapkan(true);
- }
- SetListVoucher((prevList) => [addNewLine, ...prevList]);
- SetActiveVoucher(addNewLine.code);
+ });
+
+ // let addNewLine = dataVoucher[0];
};
useEffect(() => {
@@ -187,7 +239,7 @@ const Checkout = () => {
}, [bottomPopup]);
useEffect(() => {
- voucher();
+ // voucher();
const loadExpedisi = async () => {
let dataExpedisi = await ExpedisiList();
dataExpedisi = dataExpedisi.map((expedisi) => ({
@@ -210,13 +262,23 @@ const Checkout = () => {
};
}, []);
- const hitungDiscountVoucher = (code) => {
- let dataVoucherIndex = listVouchers.findIndex(
- (voucher) => voucher.code == code
- );
- let dataActiveVoucher = listVouchers[dataVoucherIndex];
+ const hitungDiscountVoucher = (code, source) => {
+ let countDiscount = 0;
+ if (source === 'voucher') {
+ let dataVoucherIndex = listVouchers.findIndex(
+ (voucher) => voucher.code == code
+ );
+ let dataActiveVoucher = listVouchers[dataVoucherIndex];
- let countDiscount = dataActiveVoucher.discountVoucher;
+ 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)
@@ -233,14 +295,24 @@ const Checkout = () => {
return countDiscount;
};
- useEffect(() => {
- if (!listVouchers) return;
- if (!activeVoucher) return;
+ // useEffect(() => {
+ // if (!listVouchers) return;
+ // if (!activeVoucher) return;
- const countDiscount = hitungDiscountVoucher(activeVoucher);
+ // console.log('voucher')
+ // const countDiscount = hitungDiscountVoucher(activeVoucher, 'voucher');
- SetDiscountVoucher(countDiscount);
- }, [activeVoucher, listVouchers]);
+ // 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) {
@@ -499,6 +571,10 @@ const Checkout = () => {
const finalShippingAmt = biayaKirim - discShippingAmt;
+ const totalDiscountVoucher =
+ cartCheckout?.discountVoucher +
+ (cartCheckout?.discountVoucherShipping || 0);
+
return (
<>
<BottomPopup
@@ -609,10 +685,23 @@ const Checkout = () => {
)}
<hr className='mt-8 mb-4 border-gray_r-8' />
+ {/* {!loadingVoucher &&
+ listVouchers?.length === 1 &&
+ listVoucherShippings?.length === 1}
+ {
+ <div className='flex items-center justify-center mt-4 mb-4'>
+ <div className='text-center'>
+ <h1 className='font-bold mb-4'>Tidak ada voucher tersedia</h1>
+ <p className='text-gray-500'>
+ Maaf, saat ini tidak ada voucher yang tersedia.
+ </p>
+ </div>
+ </div>
+ } */}
{listVoucherShippings && listVoucherShippings?.length > 0 && (
<div>
- <h3 className='font-semibold mb-4'>Promo Gratis Ongkir</h3>
+ <h3 className='font-semibold mb-4'>Promo Extra Potongan Ongkir</h3>
{listVoucherShippings?.map((item) => (
<div key={item.id} className='relative'>
<div
@@ -747,16 +836,7 @@ const Checkout = () => {
<hr className='mt-8 mb-4 border-gray_r-8' />
<div>
- {!loadingVoucher && listVouchers?.length === 0 ? (
- <div className='flex items-center justify-center mt-4 mb-4'>
- <div className='text-center'>
- <h1 className='font-bold mb-4'>Tidak ada voucher tersedia</h1>
- <p className='text-gray-500'>
- Maaf, saat ini tidak ada voucher yang tersedia.
- </p>
- </div>
- </div>
- ) : (
+ {!loadingVoucher && listVouchers?.length > 0 && (
<h3 className='font-semibold mb-4'>
Promo Khusus Untuk {auth?.name}
</h3>
@@ -1020,7 +1100,12 @@ const Checkout = () => {
<div className='p-4 flex flex-col gap-y-4'>
{!!products &&
snakecaseKeys(products).map((item, index) => (
- <CartItem key={index} item={item} editable={false} selfPicking={selectedExpedisi === '1,32' ? true : false}/>
+ <CartItem
+ key={index}
+ item={item}
+ editable={false}
+ selfPicking={selectedExpedisi === '1,32' ? true : false}
+ />
))}
</div>
@@ -1083,7 +1168,7 @@ const Checkout = () => {
<div className='flex gap-x-2 justify-between'>
<div className='text-gray_r-11'>Diskon Voucher</div>
<div className='text-danger-500'>
- - {currencyFormat(discountVoucher)}
+ - {currencyFormat(cartCheckout?.discountVoucher)}
</div>
</div>
)}
@@ -1311,7 +1396,12 @@ const Checkout = () => {
<div className='flex flex-col gap-y-8 border-t border-gray-300 pt-8'>
{!!products &&
snakecaseKeys(products).map((item, index) => (
- <CartItem key={index} item={item} editable={false} selfPicking={selectedExpedisi === '1,32' ? true : false} />
+ <CartItem
+ key={index}
+ item={item}
+ editable={false}
+ selfPicking={selectedExpedisi === '1,32' ? true : false}
+ />
))}
</div>
</div>
@@ -1378,7 +1468,7 @@ const Checkout = () => {
<div className='flex gap-x-2 justify-between'>
<div className='text-gray_r-11'>Diskon Voucher</div>
<div className='text-danger-500'>
- - {currencyFormat(discountVoucher)}
+ - {currencyFormat(cartCheckout?.discountVoucher)}
</div>
</div>
)}
@@ -1447,10 +1537,10 @@ const Checkout = () => {
className='object-contain object-center h-6 w-full rounded-md'
/>
</span>
- {activeVoucher ? (
+ {activeVoucher || activeVoucherShipping ? (
<div className=''>
<div className='text-left text-sm text-black font-semibold'>
- Hemat {currencyFormat(discountVoucher)}
+ Hemat {currencyFormat(totalDiscountVoucher)}
</div>
<div className='text-left mt-1 text-green-600 text-xs'>
Voucher berhasil digunakan
diff --git a/src/lib/tracking-order/api/trackingOrder.js b/src/lib/tracking-order/api/trackingOrder.js
new file mode 100644
index 00000000..cc48c40c
--- /dev/null
+++ b/src/lib/tracking-order/api/trackingOrder.js
@@ -0,0 +1,8 @@
+import odooApi from "@/core/api/odooApi";
+
+export const trackingOrder = async ({query}) => {
+ const params = new URLSearchParams(query).toString();
+ const list = await odooApi('GET', `/api/v1/tracking_order?${params}`)
+
+ return list;
+}
diff --git a/src/lib/tracking-order/component/TrackingOrder.jsx b/src/lib/tracking-order/component/TrackingOrder.jsx
new file mode 100644
index 00000000..394979c1
--- /dev/null
+++ b/src/lib/tracking-order/component/TrackingOrder.jsx
@@ -0,0 +1,139 @@
+import { yupResolver } from '@hookform/resolvers/yup'
+import React, { useEffect, useState } from 'react'
+import { useForm } from 'react-hook-form'
+import * as Yup from 'yup'
+import Manifest from '@/lib/treckingAwb/component/Manifest'
+import { trackingOrder } from '../api/trackingOrder'
+import { useQuery } from 'react-query'
+import { Spinner } from '@chakra-ui/react';
+import { Search } from 'lucide-react';
+import whatsappUrl from '@/core/utils/whatsappUrl';
+import Link from 'next/link'
+
+const TrackingOrder = () => {
+ const [idAWB, setIdAWB] = useState(null)
+ const [inputQuery, setInputQuery] = useState(null)
+ const [buttonClick, setButtonClick] = useState(false)
+ const [apiError, setApiError] = useState(null) // State to store API error message
+
+ const closePopup = () => {
+ setIdAWB(null)
+ setButtonClick(false)
+ setInputQuery(null)
+ setApiError(null) // Reset error message on close
+ }
+
+ const {
+ register,
+ handleSubmit,
+ formState: { errors },
+ control,
+ reset
+ } = useForm({
+ resolver: yupResolver(validationSchema),
+ defaultValues
+ })
+
+ const query = {
+ email: inputQuery?.email,
+ so: inputQuery?.id
+ }
+
+ const { data: tracking, isLoading, isError, error } = useQuery(
+ ['tracking', query],
+ () => trackingOrder({ query: query }),
+ {
+ enabled: !!query.email && !!query.so,
+ onSuccess: (data) => {
+ if (buttonClick) {
+ if (data?.code === 403 || data?.code === 400 || data?.code === 404) {
+ setApiError(data?.description);
+ } else if (data?.pickings?.length > 0) {
+ setIdAWB(data.pickings[0]?.id);
+ } else {
+ setApiError('No pickings data available');
+ }
+ setButtonClick(false);
+ setInputQuery(null);
+ }
+ },
+ }
+ );
+
+ const onSubmitHandler = async (values) => {
+ setInputQuery(values)
+ setButtonClick(true)
+ }
+
+ return (
+ <div className='container mx-auto flex py-10 flex-col'>
+ <h1 className='text-h-sm md:text-title-sm font-semibold mb-6'>Tracking Order</h1>
+ <div className='flex justify-start items-start'>
+ <span className='text-base w-full'>
+ {`Untuk melacak pesanan Anda, masukkan Nomor Transaksi di kotak bawah ini dan masukkan Email login anda lalu tekan tombol "Lacak". Nomor Transaksi ini dapat Anda lihat dalam menu `}
+ <Link href='/my/transactions' className='text-red-500'>
+ Daftar Transaksi
+ </Link>
+ {`. Jika mengalami kesulitan `}
+ <Link href='https://wa.me/6281717181922' target='_blank' rel='noreferrer' className='text-red-500'>
+ hubungi kami
+ </Link>
+ {`.`}
+ </span>
+ </div>
+ <div>
+ <form onSubmit={handleSubmit(onSubmitHandler)} className='flex mt-4 flex-row w-full '>
+ <div className='w-[90%] grid grid-cols-2 gap-4'>
+ <div className='flex flex-col '>
+ <label className='form-label mb-2'>ID Pesanan*</label>
+ <input
+ {...register('id')}
+ placeholder='dapat dilihat pada email konfirmasi anda'
+ type='text'
+ className='form-input mb-2'
+ aria-invalid={errors.id?.message}
+ />
+ <div className='text-caption-2 text-danger-500 mt-1'>{errors.id?.message}</div>
+ </div>
+ <div className='flex flex-col '>
+ <label className='form-label mb-2'>Email Penagihan*</label>
+ <input
+ {...register('email')}
+ placeholder='Email yang anda gunakan saat pembayaran'
+ type='text'
+ className='form-input'
+ aria-invalid={errors.email?.message}
+ />
+ <div className='text-caption-2 text-danger-500 mt-1'>{errors.email?.message}</div>
+ </div>
+ </div>
+ <div className={` ${errors.id?.message ? 'mt-2' : 'mt-5'} flex items-center ml-4`}>
+ <button
+ type='submit'
+ className='bg-red-600 border border-red-600 rounded-md text-sm text-white w-24 h-11 mb-1 content-center flex flex-row justify-center items-center'
+ >
+ {isLoading && <Spinner size='xs' className='mr-2'/>}
+ {!isLoading && <Search size={16} strokeWidth={1} className='mr-2'/>}
+ <p>Lacak</p>
+ </button>
+ </div>
+ </form>
+ {/* Display the API error message */}
+ {apiError && <div className='text-danger-500 mt-4'>{apiError}</div>}
+ <Manifest idAWB={idAWB} closePopup={closePopup} />
+ </div>
+ </div>
+ )
+}
+
+const validationSchema = Yup.object().shape({
+ email: Yup.string().email('Format harus seperti contoh@email.com').required('Harus di-isi'),
+ id: Yup.string().required('Harus di-isi'),
+})
+
+const defaultValues = {
+ email: '',
+ id: ''
+}
+
+export default TrackingOrder
diff --git a/src/lib/treckingAwb/component/Manifest.jsx b/src/lib/treckingAwb/component/Manifest.jsx
index cf2fa4ed..fbc95702 100644
--- a/src/lib/treckingAwb/component/Manifest.jsx
+++ b/src/lib/treckingAwb/component/Manifest.jsx
@@ -40,10 +40,18 @@ const Manifest = ({ idAWB, closePopup }) => {
const getManifest = async () => {
setIsLoading(true)
const auth = getAuth()
- const list = await odooApi(
- 'GET',
- `/api/v1/partner/${auth.partnerId}/stock-picking/${idAWB}/tracking`
- )
+ let list
+ if(auth){
+ list = await odooApi(
+ 'GET',
+ `/api/v1/partner/${auth.partnerId}/stock-picking/${idAWB}/tracking`
+ )
+ }else{
+ list = await odooApi(
+ 'GET',
+ `/api/v1/stock-picking/${idAWB}/tracking`
+ )
+ }
setManifests(list)
setIsLoading(false)
}