From 81abbbabd11df17b5fe795e725f5841273fbf125 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Thu, 24 Apr 2025 14:31:48 +0700 Subject: Make Popup Banner show in product detail for non auth user --- src-migrate/modules/popup-information/index.tsx | 34 +++++++++++++++++----- .../product-detail/components/ProductDetail.tsx | 3 ++ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src-migrate/modules/popup-information/index.tsx b/src-migrate/modules/popup-information/index.tsx index d50711cc..5c3bc8fa 100644 --- a/src-migrate/modules/popup-information/index.tsx +++ b/src-migrate/modules/popup-information/index.tsx @@ -10,11 +10,21 @@ import dynamic from 'next/dynamic'; const PagePopupInformation = () => { const router = useRouter(); const isHomePage = router.pathname === '/'; + // Updated to match your URL structure with /shop/product/ + const isProductDetail = router.pathname.includes('/shop/product/'); const auth = getAuth(); const [active, setActive] = useState(false); const [data, setData] = useState(null); const [loading, setLoading] = useState(true); + const [hasClosedPopup, setHasClosedPopup] = useState(false); + useEffect(() => { + // Check if user has closed the popup in this session + const popupClosed = sessionStorage.getItem('popupClosed'); + if (popupClosed) { + setHasClosedPopup(true); + } + }, []); useEffect(() => { const getData = async () => { @@ -26,25 +36,33 @@ const PagePopupInformation = () => { setLoading(false); }; - if (isHomePage && !auth) { + // Show popup if user is on homepage OR product detail page AND not authenticated AND hasn't closed popup + if ((isHomePage || isProductDetail) && !auth && !hasClosedPopup) { setActive(true); getData(); } - }, [isHomePage, auth]); + }, [isHomePage, isProductDetail, auth, hasClosedPopup]); + + const handleClose = () => { + setActive(false); + // Set session storage to remember user closed the popup + sessionStorage.setItem('popupClosed', 'true'); + }; + return (
{data && !loading && ( setActive(false)} + close={handleClose} mode='desktop' > -
setActive(false)} - > - +
+ {data[0]?.name} {
+
-- cgit v1.2.3 From d9dd7fd69d2f895f8e503f8d6becd4be3af18b15 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Thu, 24 Apr 2025 15:16:10 +0700 Subject: Remove session storage --- src-migrate/modules/popup-information/index.tsx | 29 ++++++------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/src-migrate/modules/popup-information/index.tsx b/src-migrate/modules/popup-information/index.tsx index 5c3bc8fa..68e0805b 100644 --- a/src-migrate/modules/popup-information/index.tsx +++ b/src-migrate/modules/popup-information/index.tsx @@ -10,21 +10,11 @@ import dynamic from 'next/dynamic'; const PagePopupInformation = () => { const router = useRouter(); const isHomePage = router.pathname === '/'; - // Updated to match your URL structure with /shop/product/ const isProductDetail = router.pathname.includes('/shop/product/'); const auth = getAuth(); const [active, setActive] = useState(false); const [data, setData] = useState(null); const [loading, setLoading] = useState(true); - const [hasClosedPopup, setHasClosedPopup] = useState(false); - - useEffect(() => { - // Check if user has closed the popup in this session - const popupClosed = sessionStorage.getItem('popupClosed'); - if (popupClosed) { - setHasClosedPopup(true); - } - }, []); useEffect(() => { const getData = async () => { @@ -36,29 +26,24 @@ const PagePopupInformation = () => { setLoading(false); }; - // Show popup if user is on homepage OR product detail page AND not authenticated AND hasn't closed popup - if ((isHomePage || isProductDetail) && !auth && !hasClosedPopup) { + if ((isHomePage || isProductDetail) && !auth) { setActive(true); getData(); } - }, [isHomePage, isProductDetail, auth, hasClosedPopup]); - - const handleClose = () => { - setActive(false); - // Set session storage to remember user closed the popup - sessionStorage.setItem('popupClosed', 'true'); - }; - + }, [isHomePage, isProductDetail, auth]); return (
{data && !loading && ( setActive(false)} mode='desktop' > -
+
setActive(false)} + > Date: Wed, 7 May 2025 09:20:55 +0700 Subject: voucher category --- src-migrate/modules/promo/components/Voucher.tsx | 1 + src-migrate/types/voucher.ts | 1 + src/lib/checkout/api/checkoutApi.js | 8 +++ src/lib/checkout/components/Checkout.jsx | 67 ++++++++++++++++++++---- 4 files changed, 66 insertions(+), 11 deletions(-) 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/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/api/checkoutApi.js b/src/lib/checkout/api/checkoutApi.js index fd982fff..39d25068 100644 --- a/src/lib/checkout/api/checkoutApi.js +++ b/src/lib/checkout/api/checkoutApi.js @@ -18,3 +18,11 @@ export const getProductsCheckout = async (query) => { const result = await odooApi('GET', url); return result; }; + +async function checkVoucherApplicability(voucherId, productCategoryId) { + const response = await fetch( + `/api/voucher/${voucherId}/check_applicability?category_id=${productCategoryId}` + ); + const data = await response.json(); + return data.is_applicable; // true jika voucher berlaku untuk kategori, false jika tidak +} diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx index c9bff3c1..9ccebe72 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,37 @@ const Checkout = () => { if (!listVouchers) { try { setLoadingVoucher(true); + const productCategories = products + ?.reduce((categories, product) => { + console.log('Processing product:', product.name); + console.log('Product categories:', product.categories); + + 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(','); + + console.log('Final categories string:', productCategories); + 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 }); + console.log('All vouchers received:', dataVoucher); SetListVoucher(dataVoucher); let dataVoucherShipping = await getVoucher(auth?.id, { source: query, type: 'shipping', + voucher_category: productCategories, // Add the product categories }); SetListVoucherShipping(dataVoucherShipping); } finally { @@ -164,10 +187,25 @@ 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(','); + + console.log('Voucher code search with categories:', productCategories); + 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 +555,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 +1263,9 @@ const Checkout = () => {
{currencyFormat(cartCheckout?.subtotal)}
-
PPN {((PPN - 1) * 100).toFixed(0)}%
+
+ PPN {((PPN - 1) * 100).toFixed(0)}% +
{currencyFormat(cartCheckout?.tax)}
@@ -1527,7 +1569,9 @@ const Checkout = () => {
{currencyFormat(cartCheckout?.subtotal)}
-
PPN {((PPN - 1) * 100).toFixed(0)}%
+
+ PPN {((PPN - 1) * 100).toFixed(0)}% +
{currencyFormat(cartCheckout?.tax)}
@@ -1710,7 +1754,8 @@ const SectionAddress = ({ address, label, url }) => ( ); const SectionValidation = ({ address }) => - address?.stateId == 0 || address?.rajaongkirCityId == 0 && ( + address?.stateId == 0 || + (address?.rajaongkirCityId == 0 && (
Mohon untuk memperbarui alamat Anda dengan mengklik tombol di bawah ini.{' '} @@ -1724,7 +1769,7 @@ const SectionValidation = ({ address }) =>
- ); + )); const SectionExpedisi = ({ address, -- cgit v1.2.3 From 4ca48d5b2b8da512447d04bb7e6540ea2b76294b Mon Sep 17 00:00:00 2001 From: Miqdad Date: Wed, 7 May 2025 09:53:12 +0700 Subject: merge --- src-migrate/modules/popup-information/index.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src-migrate/modules/popup-information/index.tsx b/src-migrate/modules/popup-information/index.tsx index 68e0805b..cae50abf 100644 --- a/src-migrate/modules/popup-information/index.tsx +++ b/src-migrate/modules/popup-information/index.tsx @@ -10,7 +10,6 @@ import dynamic from 'next/dynamic'; const PagePopupInformation = () => { const router = useRouter(); const isHomePage = router.pathname === '/'; - const isProductDetail = router.pathname.includes('/shop/product/'); const auth = getAuth(); const [active, setActive] = useState(false); const [data, setData] = useState(null); @@ -26,11 +25,11 @@ const PagePopupInformation = () => { setLoading(false); }; - if ((isHomePage || isProductDetail) && !auth) { + if (isHomePage && !auth) { setActive(true); getData(); } - }, [isHomePage, isProductDetail, auth]); + }, [isHomePage, auth]); return (
{data && !loading && ( -- cgit v1.2.3 From 29db3ca16589f1c6bad42545b56b1cb3a6039f4c Mon Sep 17 00:00:00 2001 From: Miqdad Date: Wed, 7 May 2025 11:47:08 +0700 Subject: remove unused function --- src-migrate/types/product.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src-migrate/types/product.ts b/src-migrate/types/product.ts index 14ba718f..e2121dab 100644 --- a/src-migrate/types/product.ts +++ b/src-migrate/types/product.ts @@ -35,7 +35,21 @@ export interface IProduct { name: string; logo: string; }; - voucher_pasti_hemat : any; + voucher_pasti_hemat: any; + available_voucher?: IVoucher[]; +} + +export interface IVoucher { + id: number; + name: string; + code: string; + description: string; + image: string; + canApply: boolean; + discountVoucher: number; + termsConditions: string; + remaining_time: string; + apply_type: 'all' | 'shipping' | 'brand'; } export interface IProductDetail extends IProduct { -- cgit v1.2.3 From 11ea9426239b88181e5074a8e7246f8955346180 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Wed, 7 May 2025 11:51:15 +0700 Subject: Remove unused code --- src-migrate/types/product.ts | 14 -------------- src/lib/checkout/api/checkoutApi.js | 8 -------- 2 files changed, 22 deletions(-) diff --git a/src-migrate/types/product.ts b/src-migrate/types/product.ts index e2121dab..746cdd4a 100644 --- a/src-migrate/types/product.ts +++ b/src-migrate/types/product.ts @@ -36,20 +36,6 @@ export interface IProduct { logo: string; }; voucher_pasti_hemat: any; - available_voucher?: IVoucher[]; -} - -export interface IVoucher { - id: number; - name: string; - code: string; - description: string; - image: string; - canApply: boolean; - discountVoucher: number; - termsConditions: string; - remaining_time: string; - apply_type: 'all' | 'shipping' | 'brand'; } export interface IProductDetail extends IProduct { diff --git a/src/lib/checkout/api/checkoutApi.js b/src/lib/checkout/api/checkoutApi.js index 39d25068..fd982fff 100644 --- a/src/lib/checkout/api/checkoutApi.js +++ b/src/lib/checkout/api/checkoutApi.js @@ -18,11 +18,3 @@ export const getProductsCheckout = async (query) => { const result = await odooApi('GET', url); return result; }; - -async function checkVoucherApplicability(voucherId, productCategoryId) { - const response = await fetch( - `/api/voucher/${voucherId}/check_applicability?category_id=${productCategoryId}` - ); - const data = await response.json(); - return data.is_applicable; // true jika voucher berlaku untuk kategori, false jika tidak -} -- cgit v1.2.3 From 89a0e7f37d7537c2d0d3715817453279443d518b Mon Sep 17 00:00:00 2001 From: Miqdad Date: Wed, 7 May 2025 15:06:32 +0700 Subject: Fix conflict --- .../product-detail/components/ProductDetail.tsx | 30 +++++++++------------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src-migrate/modules/product-detail/components/ProductDetail.tsx b/src-migrate/modules/product-detail/components/ProductDetail.tsx index bd2c895f..0660b9c0 100644 --- a/src-migrate/modules/product-detail/components/ProductDetail.tsx +++ b/src-migrate/modules/product-detail/components/ProductDetail.tsx @@ -23,8 +23,6 @@ import PriceAction from './PriceAction'; import SimilarBottom from './SimilarBottom'; import SimilarSide from './SimilarSide'; -import PagePopupInformation from '~/modules/popup-information'; - import { gtagProductDetail } from '@/core/utils/googleTag'; type Props = { @@ -75,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,21 +90,20 @@ const ProductDetail = ({ product }: Props) => {
-
- - + + {/* Carousel horizontal */} {allImages.length > 0 && ( -
-
+
+
{allImages.map((img, index) => ( -
setMainImage(img)} @@ -117,10 +111,11 @@ const ProductDetail = ({ product }: Props) => { {`Thumbnail { - (e.target as HTMLImageElement).src = '/path/to/fallback-image.jpg'; + (e.target as HTMLImageElement).src = + '/path/to/fallback-image.jpg'; }} />
@@ -128,7 +123,6 @@ const ProductDetail = ({ product }: Props) => {
)} -
-- cgit v1.2.3 From a9a92c02e24bf77b9e490be51d7002cc2ef41bf1 Mon Sep 17 00:00:00 2001 From: Miqdad Date: Thu, 8 May 2025 17:31:04 +0700 Subject: Remove log --- src/lib/checkout/components/Checkout.jsx | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/lib/checkout/components/Checkout.jsx b/src/lib/checkout/components/Checkout.jsx index be490d32..5256a328 100644 --- a/src/lib/checkout/components/Checkout.jsx +++ b/src/lib/checkout/components/Checkout.jsx @@ -149,9 +149,6 @@ const Checkout = () => { setLoadingVoucher(true); const productCategories = products ?.reduce((categories, product) => { - console.log('Processing product:', product.name); - console.log('Product categories:', product.categories); - if (product.categories && Array.isArray(product.categories)) { product.categories.forEach((category) => { if (category.id && !categories.includes(category.id)) { @@ -163,15 +160,12 @@ const Checkout = () => { }, []) .join(','); - console.log('Final categories string:', productCategories); - let dataVoucher = await getVoucher(auth?.id, { source: query, type: 'all,brand', partner_id: auth?.partnerId, voucher_category: productCategories, // Add the product categories }); - console.log('All vouchers received:', dataVoucher); SetListVoucher(dataVoucher); let dataVoucherShipping = await getVoucher(auth?.id, { @@ -200,8 +194,6 @@ const Checkout = () => { }, []) .join(','); - console.log('Voucher code search with categories:', productCategories); - let dataVoucher = await getVoucher(auth?.id, { source: query, code: code, -- cgit v1.2.3