From 49198fed8da2ab476bebc2233907063b02de0d66 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Tue, 31 Jan 2023 16:21:33 +0700 Subject: Product slider categories home page --- src/components/layouts/Header.js | 2 +- src/components/products/ProductSlider.js | 15 ++++++++++++++- src/pages/index.js | 22 +++++++++++++++++----- 3 files changed, 32 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/components/layouts/Header.js b/src/components/layouts/Header.js index bc740810..5df75c3c 100644 --- a/src/components/layouts/Header.js +++ b/src/components/layouts/Header.js @@ -31,7 +31,7 @@ const menus = [ export default function Header({ title }) { const router = useRouter(); const { q = '' } = router.query; - const [searchQuery, setSearchQuery] = useState(q); + const [searchQuery, setSearchQuery] = useState(q != '*' ? q : ''); const [suggestions, setSuggestions] = useState([]); const searchQueryRef = useRef(); const [isMenuActive, setIsMenuActive] = useState(false); diff --git a/src/components/products/ProductSlider.js b/src/components/products/ProductSlider.js index ddc505c7..cf663995 100644 --- a/src/components/products/ProductSlider.js +++ b/src/components/products/ProductSlider.js @@ -2,11 +2,24 @@ import { Swiper, SwiperSlide } from "swiper/react"; import ProductCard from "./ProductCard"; import ImagePlaceholderIcon from "../../icons/image-placeholder.svg"; import "swiper/css"; +import Image from "../elements/Image"; +import Link from "../elements/Link"; -export default function ProductSlider({ products }) { +export default function ProductSlider({ + products, + bannerMode = false +}) { return ( <> + { bannerMode && ( + {products.name} + ) } + { bannerMode && ( + + + + ) } {products?.products?.map((product, index) => ( diff --git a/src/pages/index.js b/src/pages/index.js index 35175dce..8c636616 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -27,6 +27,7 @@ export default function Home({ heroBanners }) { const [manufactures, setManufactures] = useState(null); const [readyStockProducts, setReadyStockProducts] = useState(null); const [popularProducts, setPopularProducts] = useState(null); + const [categoryProducts, setCategoryProducts] = useState(null); useEffect(() => { const getManufactures = async () => { @@ -46,6 +47,12 @@ export default function Home({ heroBanners }) { setPopularProducts(dataPopularProducts.data.response); } getPopularProducts(); + + const getCategoryProducts = async () => { + const dataCategoryProducts = await apiOdoo('GET', '/api/v1/categories_homepage'); + setCategoryProducts(dataCategoryProducts); + } + getCategoryProducts(); }, []); return ( @@ -77,14 +84,19 @@ export default function Home({ heroBanners }) { } -
+

Produk Populer

-
-

Produk Ready Stock

- -
+ + { categoryProducts?.map((categoryProduct) => ( +
+ +
+ )) }
Platform Belanja B2B Alat Teknik & Industri di Indonesia
-- cgit v1.2.3