summaryrefslogtreecommitdiff
path: root/src/lib/checkout/components/Checkout.jsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/checkout/components/Checkout.jsx')
-rw-r--r--src/lib/checkout/components/Checkout.jsx57
1 files changed, 46 insertions, 11 deletions
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index 637706a2..77c8ede7 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -55,7 +55,9 @@ function convertToInternational(number) {
}
const Checkout = () => {
- const PPN = process.env.NEXT_PUBLIC_PPN ? parseFloat(process.env.NEXT_PUBLIC_PPN) : 0;
+ const PPN = process.env.NEXT_PUBLIC_PPN
+ ? parseFloat(process.env.NEXT_PUBLIC_PPN)
+ : 0;
const router = useRouter();
const query = router.query.source ?? null;
const qVoucher = router.query.voucher ?? null;
@@ -181,16 +183,31 @@ const Checkout = () => {
if (!listVouchers) {
try {
setLoadingVoucher(true);
+ const productCategories = products
+ ?.reduce((categories, product) => {
+ if (product.categories && Array.isArray(product.categories)) {
+ product.categories.forEach((category) => {
+ if (category.id && !categories.includes(category.id)) {
+ categories.push(category.id);
+ }
+ });
+ }
+ return categories;
+ }, [])
+ .join(',');
+
let dataVoucher = await getVoucher(auth?.id, {
source: query,
type: 'all,brand',
- partner_id : auth?.partnerId,
+ partner_id: auth?.partnerId,
+ voucher_category: productCategories, // Add the product categories
});
SetListVoucher(dataVoucher);
let dataVoucherShipping = await getVoucher(auth?.id, {
source: query,
type: 'shipping',
+ voucher_category: productCategories, // Add the product categories
});
SetListVoucherShipping(dataVoucherShipping);
} finally {
@@ -200,10 +217,23 @@ const Checkout = () => {
};
const VoucherCode = async (code) => {
- // let dataVoucher = await findVoucher(code, auth.id, query);
+ const productCategories = products
+ ?.reduce((categories, product) => {
+ if (product.categories && Array.isArray(product.categories)) {
+ product.categories.forEach((category) => {
+ if (category.id && !categories.includes(category.id)) {
+ categories.push(category.id);
+ }
+ });
+ }
+ return categories;
+ }, [])
+ .join(',');
+
let dataVoucher = await getVoucher(auth?.id, {
source: query,
code: code,
+ voucher_category: productCategories, // Add the product categories
});
if (dataVoucher.length <= 0) {
SetFindVoucher(1);
@@ -1028,7 +1058,7 @@ const Checkout = () => {
)}
<Divider />
<SectionValidation address={selectedAddress.invoicing} />
- {/* <SectionExpedisi
+ <SectionExpedisi
address={selectedAddress.shipping}
listExpedisi={listExpedisi}
setSelectedExpedisi={setSelectedExpedisi}
@@ -1041,7 +1071,7 @@ const Checkout = () => {
<SectionListService
listserviceExpedisi={listserviceExpedisi}
setSelectedServiceType={setSelectedServiceType}
- /> */}
+ />
<div className='p-4 flex flex-col gap-y-4'>
{!!products &&
@@ -1123,7 +1153,9 @@ const Checkout = () => {
<div>{currencyFormat(cartCheckout?.subtotal)}</div>
</div>
<div className='flex gap-x-2 justify-between'>
- <div className='text-gray_r-11'>PPN {((PPN - 1) * 100).toFixed(0)}%</div>
+ <div className='text-gray_r-11'>
+ PPN {((PPN - 1) * 100).toFixed(0)}%
+ </div>
<div>{currencyFormat(cartCheckout?.tax)}</div>
</div>
<div className='flex gap-x-2 justify-between'>
@@ -1329,7 +1361,7 @@ const Checkout = () => {
{products && <SectionExpedition products={products} />}
<Divider />
<SectionValidation address={selectedAddress.invoicing} />
- {/* <SectionExpedisi
+ <SectionExpedisi
address={selectedAddress.shipping}
listExpedisi={listExpedisi}
setSelectedExpedisi={setSelectedExpedisi}
@@ -1342,7 +1374,7 @@ const Checkout = () => {
<SectionListService
listserviceExpedisi={listserviceExpedisi}
setSelectedServiceType={setSelectedServiceType}
- /> */}
+ />
<div className='p-4'>
<div className='font-medium mb-6'>Detail Pesanan</div>
@@ -1430,7 +1462,9 @@ const Checkout = () => {
<div>{currencyFormat(cartCheckout?.subtotal)}</div>
</div>
<div className='flex gap-x-2 justify-between'>
- <div className='text-gray_r-11'>PPN {((PPN - 1) * 100).toFixed(0)}%</div>
+ <div className='text-gray_r-11'>
+ PPN {((PPN - 1) * 100).toFixed(0)}%
+ </div>
<div>{currencyFormat(cartCheckout?.tax)}</div>
</div>
<div className='flex gap-x-2 justify-between'>
@@ -1630,7 +1664,8 @@ const SectionAddress = ({ address, label, url }) => (
);
const SectionValidation = ({ address }) =>
- address?.stateId == 0 && (
+ address?.stateId == 0 ||
+ (address?.rajaongkirCityId == 0 && (
<BottomPopup active={true} title='Update Alamat'>
<div className='leading-7 text-gray_r-12/80'>
Mohon untuk memperbarui alamat Anda dengan mengklik tombol di bawah ini.{' '}
@@ -1644,7 +1679,7 @@ const SectionValidation = ({ address }) =>
</Link>
</div>
</BottomPopup>
- );
+ ));
const SectionExpedisi = ({
address,