summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src-migrate/modules/popup-information/index.tsx6
-rw-r--r--src-migrate/modules/product-detail/components/ProductDetail.tsx27
-rw-r--r--src-migrate/modules/promo/components/Voucher.tsx1
-rw-r--r--src-migrate/types/product.ts2
-rw-r--r--src-migrate/types/voucher.ts1
-rw-r--r--src/lib/checkout/components/Checkout.jsx59
6 files changed, 67 insertions, 29 deletions
diff --git a/src-migrate/modules/popup-information/index.tsx b/src-migrate/modules/popup-information/index.tsx
index d50711cc..cae50abf 100644
--- a/src-migrate/modules/popup-information/index.tsx
+++ b/src-migrate/modules/popup-information/index.tsx
@@ -15,7 +15,6 @@ const PagePopupInformation = () => {
const [data, setData] = useState<any>(null);
const [loading, setLoading] = useState(true);
-
useEffect(() => {
const getData = async () => {
const res = await fetch(`/api/hero-banner?type=popup-banner`);
@@ -44,7 +43,10 @@ const PagePopupInformation = () => {
className='w-[350px] md:w-[530px]'
onClick={() => setActive(false)}
>
- <Link href={data[0].url === false ? '/' :data[0].url} aria-label='popup'>
+ <Link
+ href={data[0].url === false ? '/' : data[0].url}
+ aria-label='popup'
+ >
<Image
src={data[0]?.image}
alt={data[0]?.name}
diff --git a/src-migrate/modules/product-detail/components/ProductDetail.tsx b/src-migrate/modules/product-detail/components/ProductDetail.tsx
index 685c107d..0660b9c0 100644
--- a/src-migrate/modules/product-detail/components/ProductDetail.tsx
+++ b/src-migrate/modules/product-detail/components/ProductDetail.tsx
@@ -73,12 +73,9 @@ const ProductDetail = ({ product }: Props) => {
// setSelectedVariant(product?.variants[0])
}, []);
-
-
// Gabungkan semua gambar produk (utama + tambahan)
const allImages = product.image_carousel ? [...product.image_carousel] : [];
-
if (product.image) {
allImages.unshift(product.image); // Tambahkan gambar utama di awal array
}
@@ -95,18 +92,18 @@ const ProductDetail = ({ product }: Props) => {
<div className='md:w-9/12 md:flex md:flex-col md:pr-4 md:pt-6'>
<div className='md:flex md:flex-wrap'>
<div className='md:w-4/12'>
- <ProductImage product={{ ...product, image: mainImage }} />
-
+ <ProductImage product={{ ...product, image: mainImage }} />
+
{/* Carousel horizontal */}
{allImages.length > 0 && (
- <div className="mt-4 overflow-x-auto">
- <div className="flex space-x-3 pb-3">
+ <div className='mt-4 overflow-x-auto'>
+ <div className='flex space-x-3 pb-3'>
{allImages.map((img, index) => (
- <div
- key={index}
+ <div
+ key={index}
className={`flex-shrink-0 w-16 h-16 cursor-pointer border-2 rounded-md transition-colors ${
- mainImage === img
- ? 'border-red-500 ring-2 ring-red-200'
+ mainImage === img
+ ? 'border-red-500 ring-2 ring-red-200'
: 'border-gray-200 hover:border-gray-300'
}`}
onClick={() => setMainImage(img)}
@@ -114,10 +111,11 @@ const ProductDetail = ({ product }: Props) => {
<img
src={img}
alt={`Thumbnail ${index + 1}`}
- className="w-full h-full object-cover rounded-sm"
- loading="lazy"
+ className='w-full h-full object-cover rounded-sm'
+ loading='lazy'
onError={(e) => {
- (e.target as HTMLImageElement).src = '/path/to/fallback-image.jpg';
+ (e.target as HTMLImageElement).src =
+ '/path/to/fallback-image.jpg';
}}
/>
</div>
@@ -125,7 +123,6 @@ const ProductDetail = ({ product }: Props) => {
</div>
</div>
)}
-
</div>
<div className='md:w-8/12 px-4 md:pl-6'>
diff --git a/src-migrate/modules/promo/components/Voucher.tsx b/src-migrate/modules/promo/components/Voucher.tsx
index 034d13e9..0c225c74 100644
--- a/src-migrate/modules/promo/components/Voucher.tsx
+++ b/src-migrate/modules/promo/components/Voucher.tsx
@@ -18,6 +18,7 @@ interface Voucher {
name: string;
description: string;
code: string;
+ voucher_category: [];
}
const VoucherComponent = () => {
diff --git a/src-migrate/types/product.ts b/src-migrate/types/product.ts
index 14ba718f..746cdd4a 100644
--- a/src-migrate/types/product.ts
+++ b/src-migrate/types/product.ts
@@ -35,7 +35,7 @@ export interface IProduct {
name: string;
logo: string;
};
- voucher_pasti_hemat : any;
+ voucher_pasti_hemat: any;
}
export interface IProductDetail extends IProduct {
diff --git a/src-migrate/types/voucher.ts b/src-migrate/types/voucher.ts
index 3e90f449..d3140372 100644
--- a/src-migrate/types/voucher.ts
+++ b/src-migrate/types/voucher.ts
@@ -3,6 +3,7 @@ export interface IVoucher {
image: string;
name: string;
code: string;
+ voucher_category: [];
description: string | false;
remaining_time: string;
}
diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx
index 1ad2782d..5256a328 100644
--- a/src/lib/checkout/components/Checkout.jsx
+++ b/src/lib/checkout/components/Checkout.jsx
@@ -39,18 +39,20 @@ const { getProductsCheckout } = require('../api/checkoutApi');
function convertToInternational(number) {
if (typeof number !== 'string') {
- throw new Error("Input harus berupa string");
+ throw new Error('Input harus berupa string');
}
if (number.startsWith('08')) {
- return '+62' + number.slice(2);
+ return '+62' + number.slice(2);
}
return 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;
@@ -145,16 +147,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 {
@@ -164,10 +181,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);
@@ -517,10 +547,12 @@ const Checkout = () => {
gtag('set', 'user_data', {
email: auth.email,
- phone_number: convertToInternational(auth.mobile) ?? convertToInternational(auth.phone),
+ phone_number:
+ convertToInternational(auth.mobile) ??
+ convertToInternational(auth.phone),
});
- gtag('config', 'AW-954540379', { ' allow_enhanced_conversions':true } ) ;
+ gtag('config', 'AW-954540379', { ' allow_enhanced_conversions': true });
for (const product of products) deleteItemCart({ productId: product.id });
if (grandTotal > 0) {
@@ -1223,7 +1255,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'>
@@ -1527,7 +1561,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'>
@@ -1710,7 +1746,8 @@ const SectionAddress = ({ address, label, url }) => (
);
const SectionValidation = ({ address }) =>
- (address?.stateId === 0 || address?.rajaongkirCityId === 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.{' '}
@@ -1724,7 +1761,7 @@ const SectionValidation = ({ address }) =>
</Link>
</div>
</BottomPopup>
- );
+ ));
const SectionExpedisi = ({
address,