From f0d03727f69a84daff484ea9a7944d9c29daa5c3 Mon Sep 17 00:00:00 2001 From: trisusilo48 Date: Thu, 24 Oct 2024 15:02:04 +0700 Subject: done page category brand --- src/pages/api/shop/search.js | 9 ++++-- src/pages/api/shop/url-category_brand.js | 17 +++++++++++ src/pages/shop/find/[slug].jsx | 51 ++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 src/pages/api/shop/url-category_brand.js create mode 100644 src/pages/shop/find/[slug].jsx (limited to 'src') diff --git a/src/pages/api/shop/search.js b/src/pages/api/shop/search.js index 49a5fe69..bc1c014b 100644 --- a/src/pages/api/shop/search.js +++ b/src/pages/api/shop/search.js @@ -88,7 +88,10 @@ export default async function handler(req, res) { 'price_tier1_v2_f:[1 TO *]', ]; - const fq_ = filterQueries.join('AND '); + if(fq){ + filterQueries.push(fq); + } + const fq_ = filterQueries.join(' AND '); let offset = (page - 1) * limit; let parameter = [ @@ -106,7 +109,7 @@ export default async function handler(req, res) { : formattedQuery }`, `defType=edismax`, - 'qf=name_s description_clean_t category_name manufacture_name_s variants_code_t variants_name_t category_id_ids default_code_s', + 'qf=name_s description_clean_t category_name manufacture_name_s variants_code_t variants_name_t category_id_ids default_code_s manufacture_id_i category_id_i ', `start=${parseInt(offset)}`, `rows=${limit}`, `sort=${paramOrderBy}`, @@ -149,7 +152,7 @@ export default async function handler(req, res) { if (stock) parameter.push(`fq=stock_total_f:{1 TO *}`); // Single fq in url params - if (typeof fq === 'string') parameter.push(`fq=${encodeURIComponent(fq)}`); + // if (typeof fq === 'string') parameter.push(`fq=${encodeURIComponent(fq)}`); // Multi fq in url params if (Array.isArray(fq)) parameter = parameter.concat( diff --git a/src/pages/api/shop/url-category_brand.js b/src/pages/api/shop/url-category_brand.js new file mode 100644 index 00000000..cfcc7d73 --- /dev/null +++ b/src/pages/api/shop/url-category_brand.js @@ -0,0 +1,17 @@ +import axios from 'axios'; + +export default async function handler(req, res) { + const { url = '' } = req.query; + + const params = [`q.op=AND`, `q=url_s:"${url}"`, `indent=true`]; + try { + let result = await axios( + process.env.SOLR_HOST + + `/solr/url_category_brand/select?` + + params.join('&') + ); + res.status(200).json(result.data); + } catch (error) { + res.status(500).json({ error: 'Internal Server Error' }); + } +} diff --git a/src/pages/shop/find/[slug].jsx b/src/pages/shop/find/[slug].jsx new file mode 100644 index 00000000..4666add5 --- /dev/null +++ b/src/pages/shop/find/[slug].jsx @@ -0,0 +1,51 @@ +import axios from 'axios'; +import { useRouter } from 'next/router'; +import { useEffect, useState } from 'react'; +import Seo from '@/core/components/Seo'; +import dynamic from 'next/dynamic'; + +const BasicLayout = dynamic(() => + import('@/core/components/layouts/BasicLayout') +); +const ProductSearch = dynamic(() => + import('@/lib/product/components/ProductSearch') +); + +const BASE_URL = 'https://indoteknik.com'; +export default function FindPage() { + const route = useRouter(); + const url = BASE_URL + route.asPath; + const [result, setResult] = useState(null); + const [query, setQuery] = useState(null); + + const getUrls = async (url) => { + try { + let response = await axios( + `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/url-category_brand?url=${url}` + ); + let result = response?.data?.response?.docs[0] || null; + setResult(result); + } catch (error) { + console.error('Error fetching data:', error); + } + }; + + useEffect(() => { + getUrls(url); + }, []); + + useEffect(() => { + if (result) { + let fq = `category_parent_ids:${result.category_id_i} AND manufacture_id_i:${result.brand_id_i}`; + setQuery({ + fq : fq + }); + } + }, [result]); + + return ( + + {query && } + + ); +} -- cgit v1.2.3 From 2657955cb4dc4cbe703d77bb43a6394a8ee98f74 Mon Sep 17 00:00:00 2001 From: trisusilo48 Date: Thu, 24 Oct 2024 16:27:54 +0700 Subject: add seo --- src/pages/shop/find/[slug].jsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/pages/shop/find/[slug].jsx b/src/pages/shop/find/[slug].jsx index 4666add5..50797153 100644 --- a/src/pages/shop/find/[slug].jsx +++ b/src/pages/shop/find/[slug].jsx @@ -3,6 +3,8 @@ import { useRouter } from 'next/router'; import { useEffect, useState } from 'react'; import Seo from '@/core/components/Seo'; import dynamic from 'next/dynamic'; +import { get } from 'lodash-contrib'; +import { getIdFromSlug, getNameFromSlug } from '@/core/utils/slug'; const BasicLayout = dynamic(() => import('@/core/components/layouts/BasicLayout') @@ -18,6 +20,7 @@ export default function FindPage() { const [result, setResult] = useState(null); const [query, setQuery] = useState(null); + const slug = getNameFromSlug( route.query.slug) +' '+ getIdFromSlug( route.query.slug) const getUrls = async (url) => { try { let response = await axios( @@ -38,13 +41,24 @@ export default function FindPage() { if (result) { let fq = `category_parent_ids:${result.category_id_i} AND manufacture_id_i:${result.brand_id_i}`; setQuery({ - fq : fq + fq: fq, }); } }, [result]); return ( + {query && } ); -- cgit v1.2.3 From bb2fc00e1f399be919d7b777dd0ae17edd6b2a2e Mon Sep 17 00:00:00 2001 From: trisusilo48 Date: Fri, 25 Oct 2024 10:04:34 +0700 Subject: sitemap categories brand --- src/pages/api/shop/url-category_brand.js | 7 +++-- src/pages/shop/find/[slug].jsx | 3 +- src/pages/sitemap/categories-brand.xml.js | 35 ++++++++++++++++++++++ src/pages/sitemap/categories-brand/[page].js | 43 ++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 src/pages/sitemap/categories-brand.xml.js create mode 100644 src/pages/sitemap/categories-brand/[page].js (limited to 'src') diff --git a/src/pages/api/shop/url-category_brand.js b/src/pages/api/shop/url-category_brand.js index cfcc7d73..160aa166 100644 --- a/src/pages/api/shop/url-category_brand.js +++ b/src/pages/api/shop/url-category_brand.js @@ -1,9 +1,12 @@ import axios from 'axios'; export default async function handler(req, res) { - const { url = '' } = req.query; + const { url = '', page = 1, limit = 30 } = req.query; + + let offset = (page - 1) * limit; - const params = [`q.op=AND`, `q=url_s:"${url}"`, `indent=true`]; + const params = [`q.op=AND`, `q=${url ? `"${url}"` : '*'}`, `indent=true`, `rows=${limit}`, `start=${offset}`]; + try { let result = await axios( process.env.SOLR_HOST + diff --git a/src/pages/shop/find/[slug].jsx b/src/pages/shop/find/[slug].jsx index 50797153..85e780ff 100644 --- a/src/pages/shop/find/[slug].jsx +++ b/src/pages/shop/find/[slug].jsx @@ -16,11 +16,12 @@ const ProductSearch = dynamic(() => const BASE_URL = 'https://indoteknik.com'; export default function FindPage() { const route = useRouter(); + const qSlug = route?.query?.slug || null; const url = BASE_URL + route.asPath; const [result, setResult] = useState(null); const [query, setQuery] = useState(null); - const slug = getNameFromSlug( route.query.slug) +' '+ getIdFromSlug( route.query.slug) + const slug = qSlug ? getNameFromSlug(route?.query?.slug) +' '+ getIdFromSlug(route?.query?.slug) : ''; const getUrls = async (url) => { try { let response = await axios( diff --git a/src/pages/sitemap/categories-brand.xml.js b/src/pages/sitemap/categories-brand.xml.js new file mode 100644 index 00000000..b23363e9 --- /dev/null +++ b/src/pages/sitemap/categories-brand.xml.js @@ -0,0 +1,35 @@ +import productSearchApi from '@/lib/product/api/productSearchApi' +import { create } from 'xmlbuilder' +import _ from 'lodash-contrib' +import axios from 'axios' + +export async function getServerSideProps({ res }) { + const baseUrl = process.env.SELF_HOST + '/sitemap/categories-brand' + const limit = 500 + const categories = await axios( + `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/url-category_brand?limit=${limit}` + ) + const pageCount = Math.ceil(categories.data.response.numFound / limit) + const pages = Array.from({ length: pageCount }, (_, i) => i + 1) + const sitemapIndex = create('sitemapindex', { encoding: 'UTF-8' }).att( + 'xmlns', + 'http://www.sitemaps.org/schemas/sitemap/0.9' + ) + + const date = new Date() + pages.forEach((page) => { + const sitemap = sitemapIndex.ele('sitemap') + sitemap.ele('loc', `${baseUrl}/${page}.xml`) + sitemap.ele('lastmod', date.toISOString().slice(0, 10)) + }) + + res.setHeader('Content-Type', 'text/xml') + res.write(sitemapIndex.end()) + res.end() + + return { props: {} } +} + +export default function SitemapProducts() { + return null +} diff --git a/src/pages/sitemap/categories-brand/[page].js b/src/pages/sitemap/categories-brand/[page].js new file mode 100644 index 00000000..6b55e426 --- /dev/null +++ b/src/pages/sitemap/categories-brand/[page].js @@ -0,0 +1,43 @@ + +import productSearchApi from '@/lib/product/api/productSearchApi' +import { create } from 'xmlbuilder' +import _ from 'lodash-contrib' +import { createSlug } from '@/core/utils/slug' +import axios from 'axios' + +export async function getServerSideProps({ query, res }) { + const baseUrl = process.env.SELF_HOST + '/shop/product/' + const { page } = query + const limit = 500 + const categories = await axios( + `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/url-category_brand?limit=${limit}&page=${page.replace( + '.xml', + '' + )}` + ) + + const sitemap = create('urlset', { encoding: 'utf-8' }).att( + 'xmlns', + 'http://www.sitemaps.org/schemas/sitemap/0.9' + ) + + const date = new Date() + categories.data.response.docs.forEach((product) => { + const url = sitemap.ele('url') + const loc = product.url_s; + url.ele('loc', loc) + url.ele('lastmod', date.toISOString().slice(0, 10)) + url.ele('changefreq', 'daily') + url.ele('priority', '0.8') + }) + + res.setHeader('Content-Type', 'text/xml') + res.write(sitemap.end()) + res.end() + + return { props: {} } +} + +export default function SitemapProducts() { + return null +} -- cgit v1.2.3 From 16e46197ee2c9879ae8ef9a68d4ce67ae68843e3 Mon Sep 17 00:00:00 2001 From: trisusilo48 Date: Fri, 25 Oct 2024 10:24:24 +0700 Subject: seo title --- src/pages/shop/find/[slug].jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/pages/shop/find/[slug].jsx b/src/pages/shop/find/[slug].jsx index 85e780ff..e7b8bd48 100644 --- a/src/pages/shop/find/[slug].jsx +++ b/src/pages/shop/find/[slug].jsx @@ -50,7 +50,7 @@ export default function FindPage() { return ( Date: Fri, 25 Oct 2024 15:47:18 +0700 Subject: update tampilan mobile --- src/lib/product/components/Product/ProductMobileVariant.jsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/lib/product/components/Product/ProductMobileVariant.jsx b/src/lib/product/components/Product/ProductMobileVariant.jsx index c1d7ffe0..4018ac15 100644 --- a/src/lib/product/components/Product/ProductMobileVariant.jsx +++ b/src/lib/product/components/Product/ProductMobileVariant.jsx @@ -183,7 +183,9 @@ const ProductMobileVariant = ({ product, wishlist, toggleWishlist }) => { )} -

{activeVariant?.name}

+

+ {activeVariant?.name} +

{activeVariant.isFlashSale && activeVariant?.price?.discountPercentage > 0 ? ( -- cgit v1.2.3 From 5cfc93d26d29c131564853810dcc3fac7167780a Mon Sep 17 00:00:00 2001 From: trisusilo48 Date: Mon, 28 Oct 2024 09:33:24 +0700 Subject: capitalizeEachWord --- src/pages/shop/find/[slug].jsx | 9 ++++++--- src/utils/capializeFIrstWord.js | 9 +++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 src/utils/capializeFIrstWord.js (limited to 'src') diff --git a/src/pages/shop/find/[slug].jsx b/src/pages/shop/find/[slug].jsx index e7b8bd48..7174a9fb 100644 --- a/src/pages/shop/find/[slug].jsx +++ b/src/pages/shop/find/[slug].jsx @@ -5,6 +5,7 @@ import Seo from '@/core/components/Seo'; import dynamic from 'next/dynamic'; import { get } from 'lodash-contrib'; import { getIdFromSlug, getNameFromSlug } from '@/core/utils/slug'; +import { capitalizeEachWord } from '../../../utils/capializeFIrstWord'; const BasicLayout = dynamic(() => import('@/core/components/layouts/BasicLayout') @@ -17,11 +18,13 @@ const BASE_URL = 'https://indoteknik.com'; export default function FindPage() { const route = useRouter(); const qSlug = route?.query?.slug || null; - const url = BASE_URL + route.asPath; + const url = BASE_URL + route.asPath.split('?')[0]; const [result, setResult] = useState(null); const [query, setQuery] = useState(null); - const slug = qSlug ? getNameFromSlug(route?.query?.slug) +' '+ getIdFromSlug(route?.query?.slug) : ''; + const __slug = qSlug ? getNameFromSlug(route?.query?.slug) +' '+ getIdFromSlug(route?.query?.slug) : ''; + const slug = capitalizeEachWord(__slug); + const getUrls = async (url) => { try { let response = await axios( @@ -50,7 +53,7 @@ export default function FindPage() { return ( { + return str + .split(' ') // Pisahkan string menjadi array kata-kata + .map((word) => // Ubah huruf pertama setiap kata menjadi besar + word.charAt(0).toUpperCase() + word.slice(1).toLowerCase() + ) + .join(' '); // Gabungkan kembali menjadi string + }; + \ No newline at end of file -- cgit v1.2.3 From 2d30aea4e9d225298594ee92f474a38225b91206 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 28 Oct 2024 12:07:09 +0700 Subject: update informasi product varian --- .../components/Product/ProductDesktopVariant.jsx | 84 ++++++++++++++++------ .../components/Product/ProductMobileVariant.jsx | 12 +++- src/pages/api/shop/search.js | 2 +- 3 files changed, 73 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/lib/product/components/Product/ProductDesktopVariant.jsx b/src/lib/product/components/Product/ProductDesktopVariant.jsx index 4ecd15c8..a4cc62dd 100644 --- a/src/lib/product/components/Product/ProductDesktopVariant.jsx +++ b/src/lib/product/components/Product/ProductDesktopVariant.jsx @@ -4,8 +4,11 @@ import { Info } from 'lucide-react'; import { useRouter } from 'next/router'; import { useCallback, useEffect, useRef, useState } from 'react'; import { toast } from 'react-hot-toast'; +import { MessageCircleIcon, Share2Icon } from 'lucide-react'; +import AddToWishlist from '../../../../../src-migrate/modules/product-detail/components/AddToWishlist'; +import { RWebShare } from 'react-web-share'; import LazyLoad from 'react-lazy-load'; - +import { Button } from '@chakra-ui/react'; import { useProductCartContext } from '@/contexts/ProductCartContext'; import odooApi from '@/core/api/odooApi'; import Image from '@/core/components/elements/Image/Image'; @@ -18,11 +21,11 @@ import currencyFormat from '@/core/utils/currencyFormat'; import { createSlug } from '@/core/utils/slug'; import whatsappUrl from '@/core/utils/whatsappUrl'; import { getAuth } from '~/libs/auth'; - +import SimilarBottom from '~/modules/product-detail/components/SimilarBottom'; import productSimilarApi from '../../api/productSimilarApi'; import ProductCard from '../ProductCard'; import ProductSimilar from '../ProductSimilar'; - +const SELF_HOST = process.env.NEXT_PUBLIC_SELF_HOST; const ProductDesktopVariant = ({ product, wishlist, @@ -33,6 +36,7 @@ const ProductDesktopVariant = ({ let auth = useAuth(); const { slug } = router.query; const { srsltid } = router.query; + const [askAdminUrl, setAskAdminUrl, isApproval] = useState(); const [lowestPrice, setLowestPrice] = useState(null); const [addCartAlert, setAddCartAlert] = useState(false); @@ -40,6 +44,20 @@ const ProductDesktopVariant = ({ const { setRefreshCart } = useProductCartContext(); + useEffect(() => { + const createdAskUrl = whatsappUrl({ + template: 'product', + payload: { + manufacture: product.manufacture.name, + productName: product.name, + url: process.env.NEXT_PUBLIC_SELF_HOST + router.asPath, + }, + fallbackUrl: router.asPath, + }); + + setAskAdminUrl(createdAskUrl); + }, [router.asPath, product.manufacture.name, product.name, setAskAdminUrl]); + const getLowestPrice = useCallback(() => { const lowest = product.price; /* const lowest = prices.reduce((lowest, price) => { @@ -190,7 +208,7 @@ const ProductDesktopVariant = ({ /> -
+

{product?.name}

@@ -289,9 +307,40 @@ const ProductDesktopVariant = ({
+
+
+ + + + + + + +
-
+

Informasi Produk

@@ -388,24 +437,11 @@ const ProductDesktopVariant = ({ Beli
-
- -
Produk Serupa
-
+
{productSimilarInBrand && productSimilarInBrand?.map((product) => (
@@ -422,8 +458,11 @@ const ProductDesktopVariant = ({ Kamu Mungkin Juga Suka
- + + {/* + + */}
- + + {/* + + */}
diff --git a/src/lib/product/components/Product/ProductMobileVariant.jsx b/src/lib/product/components/Product/ProductMobileVariant.jsx index 4018ac15..790dbbe0 100644 --- a/src/lib/product/components/Product/ProductMobileVariant.jsx +++ b/src/lib/product/components/Product/ProductMobileVariant.jsx @@ -17,7 +17,7 @@ import { gtagAddToCart } from '@/core/utils/googleTag'; import { createSlug } from '@/core/utils/slug'; import whatsappUrl from '@/core/utils/whatsappUrl'; import { getAuth } from '~/libs/auth'; - +import SimilarBottom from '~/modules/product-detail/components/SimilarBottom'; import ProductSimilar from '../ProductSimilar'; const ProductMobileVariant = ({ product, wishlist, toggleWishlist }) => { @@ -411,8 +411,11 @@ const ProductMobileVariant = ({ product, wishlist, toggleWishlist }) => {

Kamu Mungkin Juga Suka

- + + {/* + + */}
{ Kamu Mungkin Juga Suka
- + + {/* + + */} diff --git a/src/pages/api/shop/search.js b/src/pages/api/shop/search.js index bc1c014b..ace281f7 100644 --- a/src/pages/api/shop/search.js +++ b/src/pages/api/shop/search.js @@ -88,7 +88,7 @@ export default async function handler(req, res) { 'price_tier1_v2_f:[1 TO *]', ]; - if(fq){ + if (fq && source != 'similar') { filterQueries.push(fq); } const fq_ = filterQueries.join(' AND '); -- cgit v1.2.3 From 90b5b3f35e230f863b5bd7e44154497283759f03 Mon Sep 17 00:00:00 2001 From: trisusilo48 Date: Tue, 29 Oct 2024 14:19:42 +0700 Subject: CR meta title page category brand --- src/pages/shop/find/[slug].jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/pages/shop/find/[slug].jsx b/src/pages/shop/find/[slug].jsx index 7174a9fb..dc243b73 100644 --- a/src/pages/shop/find/[slug].jsx +++ b/src/pages/shop/find/[slug].jsx @@ -53,7 +53,7 @@ export default function FindPage() { return ( Date: Wed, 30 Oct 2024 10:03:28 +0700 Subject: page garansi resmi & pembayaran tempo --- src/lib/home/components/ServiceList.jsx | 4 ++-- src/pages/garansi-resmi.jsx | 13 +++++++++++++ src/pages/pembayaran-tempo.jsx | 13 +++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 src/pages/garansi-resmi.jsx create mode 100644 src/pages/pembayaran-tempo.jsx (limited to 'src') diff --git a/src/lib/home/components/ServiceList.jsx b/src/lib/home/components/ServiceList.jsx index 5b16915d..b3cc8fe5 100644 --- a/src/lib/home/components/ServiceList.jsx +++ b/src/lib/home/components/ServiceList.jsx @@ -32,7 +32,7 @@ const ServiceList = () => {
@@ -57,7 +57,7 @@ const ServiceList = () => {
diff --git a/src/pages/garansi-resmi.jsx b/src/pages/garansi-resmi.jsx new file mode 100644 index 00000000..7384a89d --- /dev/null +++ b/src/pages/garansi-resmi.jsx @@ -0,0 +1,13 @@ +import Seo from '@/core/components/Seo' +import BasicLayout from '@/core/components/layouts/BasicLayout' +import IframeContent from '@/lib/iframe/components/IframeContent' + +export default function GaransiResmi() { + return ( + + + + + + ) +} diff --git a/src/pages/pembayaran-tempo.jsx b/src/pages/pembayaran-tempo.jsx new file mode 100644 index 00000000..363e3099 --- /dev/null +++ b/src/pages/pembayaran-tempo.jsx @@ -0,0 +1,13 @@ +import Seo from '@/core/components/Seo' +import BasicLayout from '@/core/components/layouts/BasicLayout' +import IframeContent from '@/lib/iframe/components/IframeContent' + +export default function PembnayaranTempo() { + return ( + + + + + + ) +} -- cgit v1.2.3 From 4e48c548c9802046cf319873a9472149b32017be Mon Sep 17 00:00:00 2001 From: trisusilo48 Date: Fri, 1 Nov 2024 13:50:53 +0700 Subject: cr seo page find category brand --- src/pages/shop/find/[slug].jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/pages/shop/find/[slug].jsx b/src/pages/shop/find/[slug].jsx index dc243b73..268b1e56 100644 --- a/src/pages/shop/find/[slug].jsx +++ b/src/pages/shop/find/[slug].jsx @@ -53,12 +53,12 @@ export default function FindPage() { return ( Date: Wed, 6 Nov 2024 09:51:17 +0700 Subject: update bug products_inactive on user carts --- src/lib/cart/components/Cartheader.jsx | 354 +++++++++++++++++++++------------ 1 file changed, 223 insertions(+), 131 deletions(-) (limited to 'src') diff --git a/src/lib/cart/components/Cartheader.jsx b/src/lib/cart/components/Cartheader.jsx index ddb77c1f..1c30bb13 100644 --- a/src/lib/cart/components/Cartheader.jsx +++ b/src/lib/cart/components/Cartheader.jsx @@ -1,105 +1,115 @@ -import { useCallback, useEffect, useMemo, useState } from 'react' -import { getCartApi } from '../api/CartApi' -import currencyFormat from '@/core/utils/currencyFormat' -import { createSlug } from '@/core/utils/slug' -import useAuth from '@/core/hooks/useAuth' -import { useRouter } from 'next/router' -import odooApi from '@/core/api/odooApi' -import { useProductCartContext } from '@/contexts/ProductCartContext' -import Image from '@/core/components/elements/Image/Image' -import whatsappUrl from '@/core/utils/whatsappUrl' -import { AnimatePresence, motion } from 'framer-motion' -import style from '../../../../src-migrate/modules/cart/styles/item-promo.module.css' -const { ShoppingCartIcon, PhotoIcon } = require('@heroicons/react/24/outline') -const { default: Link } = require('next/link') +import { useCallback, useEffect, useMemo, useState } from 'react'; +import { getCartApi } from '../api/CartApi'; +import currencyFormat from '@/core/utils/currencyFormat'; +import { createSlug } from '@/core/utils/slug'; +import useAuth from '@/core/hooks/useAuth'; +import { useRouter } from 'next/router'; +import odooApi from '@/core/api/odooApi'; +import { useProductCartContext } from '@/contexts/ProductCartContext'; +import Image from '@/core/components/elements/Image/Image'; +import whatsappUrl from '@/core/utils/whatsappUrl'; +import { AnimatePresence, motion } from 'framer-motion'; +import style from '../../../../src-migrate/modules/cart/styles/item-promo.module.css'; +const { ShoppingCartIcon, PhotoIcon } = require('@heroicons/react/24/outline'); +const { default: Link } = require('next/link'); const Cardheader = (cartCount) => { - - const router = useRouter() - const [subTotal, setSubTotal] = useState(null) - const [buttonLoading, SetButtonTerapkan] = useState(false) - const itemLoading = [1, 2, 3] - const auth = useAuth() - const [countCart, setCountCart] = useState(null) - const { productCart, setRefreshCart, setProductCart, refreshCart, isLoading, setIsloading } = - useProductCartContext() + const router = useRouter(); + const [subTotal, setSubTotal] = useState(null); + const [buttonLoading, SetButtonTerapkan] = useState(false); + const itemLoading = [1, 2, 3]; + const auth = useAuth(); + const [countCart, setCountCart] = useState(null); + const { + productCart, + setRefreshCart, + setProductCart, + refreshCart, + isLoading, + setIsloading, + } = useProductCartContext(); - const [isHovered, setIsHovered] = useState(false) - const [isTop, setIsTop] = useState(true) + const [isHovered, setIsHovered] = useState(false); + const [isTop, setIsTop] = useState(true); const products = useMemo(() => { - return productCart?.products || [] - }, [productCart]) + return productCart?.products || []; + }, [productCart]); const handleMouseEnter = () => { - setIsHovered(true) - getCart() - } + setIsHovered(true); + getCart(); + }; const handleMouseLeave = () => { - setIsHovered(false) - } + setIsHovered(false); + }; const getCart = () => { if (!productCart && auth) { - refreshCartf() + refreshCartf(); } - } + }; const refreshCartf = useCallback(async () => { - setIsloading(true) - let cart = await getCartApi() - setProductCart(cart) - setCountCart(cart?.productTotal) - setIsloading(false) - }, [setProductCart, setIsloading]) + setIsloading(true); + let cart = await getCartApi(); + setProductCart(cart); + setCountCart(cart?.products?.length); + setIsloading(false); + }, [setProductCart, setIsloading]); useEffect(() => { - if (!products) return + if (!products) return; - let calculateTotalPriceBeforeTax = 0 - let calculateTotalTaxAmount = 0 - let calculateTotalDiscountAmount = 0 + let calculateTotalPriceBeforeTax = 0; + let calculateTotalTaxAmount = 0; + let calculateTotalDiscountAmount = 0; for (const product of products) { - if (product.quantity == '') continue + if (product.quantity == '') continue; - let priceBeforeTax = product.price.price / 1.11 - calculateTotalPriceBeforeTax += priceBeforeTax * product.quantity - calculateTotalTaxAmount += (product.price.price - priceBeforeTax) * product.quantity + let priceBeforeTax = product.price.price / 1.11; + calculateTotalPriceBeforeTax += priceBeforeTax * product.quantity; + calculateTotalTaxAmount += + (product.price.price - priceBeforeTax) * product.quantity; calculateTotalDiscountAmount += - (product.price.price - product.price.priceDiscount) * product.quantity + (product.price.price - product.price.priceDiscount) * product.quantity; } let subTotal = - calculateTotalPriceBeforeTax - calculateTotalDiscountAmount + calculateTotalTaxAmount - setSubTotal(subTotal) - }, [products]) + calculateTotalPriceBeforeTax - + calculateTotalDiscountAmount + + calculateTotalTaxAmount; + setSubTotal(subTotal); + }, [products]); useEffect(() => { if (refreshCart) { - refreshCartf() + refreshCartf(); } - setRefreshCart(false) - }, [refreshCart, refreshCartf, setRefreshCart]) + setRefreshCart(false); + }, [refreshCart, refreshCartf, setRefreshCart]); useEffect(() => { - setCountCart(cartCount.cartCount) - setRefreshCart(false) - }, [cartCount]) + setCountCart(cartCount.cartCount); + setRefreshCart(false); + }, [cartCount]); useEffect(() => { const handleScroll = () => { - setIsTop(window.scrollY === 0) - } - window.addEventListener('scroll', handleScroll) + setIsTop(window.scrollY === 0); + }; + window.addEventListener('scroll', handleScroll); return () => { - window.removeEventListener('scroll', handleScroll) - } - }, []) + window.removeEventListener('scroll', handleScroll); + }; + }, []); const handleCheckout = async () => { - SetButtonTerapkan(true) - let checkoutAll = await odooApi('POST', `/api/v1/user/${auth.id}/cart/select-all`) - router.push('/shop/checkout') - } - + SetButtonTerapkan(true); + let checkoutAll = await odooApi( + 'POST', + `/api/v1/user/${auth.id}/cart/select-all` + ); + router.push('/shop/checkout'); + }; return (
@@ -152,8 +162,13 @@ const Cardheader = (cartCount) => { className='w-full max-w-md p-2 bg-white border border-gray-200 rounded-lg shadow overflow-hidden' >
-
Keranjang Belanja
- +
+ Keranjang Belanja +
+ Lihat Semua
@@ -163,7 +178,10 @@ const Cardheader = (cartCount) => {

Silahkan{' '} - + Login {' '} Untuk Melihat Daftar Keranjang Belanja Anda @@ -172,7 +190,11 @@ const Cardheader = (cartCount) => { )} {isLoading && itemLoading.map((item) => ( -

+
@@ -194,14 +216,17 @@ const Cardheader = (cartCount) => { )} {auth && products.length > 0 && !isLoading && ( <> -
    +
      {products && products?.map((product, index) => ( <>
    • - {product.cartType === 'promotion' && ( + {product.cartType === 'promotion' && ( {product.name} {
      {product.cartType === 'promotion' && ( -

      - {product.name} -

      - )} +

      + {product.name} +

      + )} {product.cartType === 'product' && ( { {product?.price?.discountPercentage}%
      - {currencyFormat(product?.price?.price)} + {currencyFormat( + product?.price?.price + )}
      )} - +
      {product?.price?.priceDiscount > 0 ? ( - currencyFormat(product?.price?.priceDiscount) + currencyFormat( + product?.price?.priceDiscount + ) ) : ( {
-
- {product.products?.map((product) => -
- - {product?.image && {product.name}} - - -
- - {product.displayName} - - -
-
- {/*
{product.code}
*/} -
- Berat Barang: - {product.packageWeight} Kg -
-
+
+ {product.products?.map((product) => ( +
+ + {product?.image && ( + {product.name} + )} + + +
+ + {product.displayName} + + +
+
+ {/*
{product.code}
*/} +
+ + Berat Barang:{' '} + + + {product.packageWeight} Kg +
-
+
+
+ ))} + {product.freeProducts?.map((product) => ( +
+ -
- - {product?.image && {product.name}} + className='md:h-12 md:w-12 md:min-w-[48px] h-10 w-10 min-w-[40px] border border-gray-300 rounded ' + > + {product?.image && ( + {product.name} + )} + + +
+ + {product.displayName} - -
- - {product.displayName} - - -
-
- {/*
{product.code}
*/} -
- Berat Barang: - {product.packageWeight} Kg -
-
+ +
+
+ {/*
{product.code}
*/} +
+ + Berat Barang:{' '} + + + {product.packageWeight} Kg +
-
- )} +
+ ))} +
))} @@ -347,8 +433,12 @@ const Cardheader = (cartCount) => { {auth && products.length > 0 && !isLoading && ( <>
- Subtotal Sebelum PPN : - {currencyFormat(subTotal)} + + Subtotal Sebelum PPN :{' '} + + + {currencyFormat(subTotal)} +
@@ -368,7 +460,7 @@ const Cardheader = (cartCount) => { )}
- ) -} + ); +}; -export default Cardheader +export default Cardheader; -- cgit v1.2.3