diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2024-06-18 14:23:16 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2024-06-18 14:23:16 +0700 |
| commit | 78575ef59454214f61f77b1a826af30497cfdc5f (patch) | |
| tree | 0a5cda43254e619a445504a1968a0d6be3b7aa2e /src | |
| parent | 72f1101ff077864ac202cc03679662bfd7904f19 (diff) | |
<iman> update url page promotion program
Diffstat (limited to 'src')
| -rw-r--r-- | src/pages/shop/promo/[slug].tsx | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/pages/shop/promo/[slug].tsx b/src/pages/shop/promo/[slug].tsx index 19592f6e..667a26ce 100644 --- a/src/pages/shop/promo/[slug].tsx +++ b/src/pages/shop/promo/[slug].tsx @@ -21,7 +21,7 @@ import { formatCurrency } from '../../../core/utils/formatValue'; import Pagination from '../../../core/components/elements/Pagination/Pagination'; import SideBanner from '../../../../src-migrate/modules/side-banner'; import whatsappUrl from '../../../core/utils/whatsappUrl'; -import { toQuery } from 'lodash-contrib'; +import { cons, toQuery } from 'lodash-contrib'; import _ from 'lodash'; import useActive from '../../../core/hooks/useActive'; @@ -42,6 +42,7 @@ export default function PromoDetail() { const [categoryValues, setCategoryValues] = useState<string[]>([]); const [orderBy, setOrderBy] = useState(router.query?.orderBy || 'popular'); const popup = useActive(); + const prefixUrl = `/shop/promo/${slug}` useEffect(() => { if (router.query.brand) { @@ -287,8 +288,18 @@ export default function PromoDetail() { }; const visiblePromotions = promoData?.slice( (currentPage-1) * itemsPerPage, currentPage * 12) + + const toQuery = (obj) => { + const str = Object.keys(obj) + .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`) + .join('&') + return str + } const whatPromo = capitalizeFirstLetter(slug) + const queryWithoutSlug = _.omit(router.query, ['slug']) + const queryString = toQuery(queryWithoutSlug) + return ( <BasicLayout> <Seo @@ -328,7 +339,7 @@ export default function PromoDetail() { <> <div className='grid grid-cols-1 gap-x-1 gap-y-1'> {visiblePromotions?.map((promotion) => ( - <div key={promotion.id} className="min-w-[365px] max-w-[365px] mb-[20px] sm:w-full md:w-1/2 lg:w-1/3 xl:w-1/4 "> + <div key={promotion.id} className="min-w-[360px] max-w-[360px] mb-[20px] sm:w-full md:w-1/2 lg:w-1/3 xl:w-1/4 "> <ProductPromoCard promotion={promotion}/> </div> ))} @@ -343,7 +354,7 @@ export default function PromoDetail() { <Pagination pageCount={Math.ceil((promoData?.length ?? 0) / itemsPerPage)} currentPage={currentPage} - url={router.asPath.includes('?') ? `${router.asPath}` : `${router.asPath}?`} + url={`${prefixUrl}?${toQuery(_.omit(queryWithoutSlug, ['page']))}`} className='mt-6 mb-2' /> <ProductFilter @@ -352,7 +363,6 @@ export default function PromoDetail() { brands={brands || []} categories={categories || []} prefixUrl={router.asPath.includes('?') ? `${router.asPath}` : `${router.asPath}?`} - // prefixUrl={`${router.query}?`} defaultBrand={null} /> </div> @@ -425,10 +435,12 @@ export default function PromoDetail() { </div> </div> + + <Pagination pageCount={Math.ceil((promoData?.length ?? 0) / itemsPerPage)} currentPage={currentPage} - url={router.asPath.includes('?') ? `${router.asPath}` : `${router.asPath}?`} + url={`${prefixUrl}?${toQuery(_.omit(queryWithoutSlug, ['page']))}`} className='mt-6 mb-2' /> </div> |
