From cd01ba82733062db99075ad7690bdb52fb85745a Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 3 Feb 2023 17:03:45 +0700 Subject: no message --- src/components/products/ProductCategories.js | 56 ++++++++++++++++++++++++++++ src/components/products/ProductSimilar.js | 25 +++++++++++++ src/components/variants/VariantCard.js | 43 +++++++++++++++++++-- 3 files changed, 120 insertions(+), 4 deletions(-) create mode 100644 src/components/products/ProductCategories.js create mode 100644 src/components/products/ProductSimilar.js (limited to 'src/components') diff --git a/src/components/products/ProductCategories.js b/src/components/products/ProductCategories.js new file mode 100644 index 00000000..dc1325b7 --- /dev/null +++ b/src/components/products/ProductCategories.js @@ -0,0 +1,56 @@ +import { useEffect, useState } from "react"; +import ProductSlider from "./ProductSlider"; +import apiOdoo from "@/core/utils/apiOdoo"; +import { LazyLoadComponent } from "react-lazy-load-image-component"; +import { SkeletonProduct } from "../elements/Skeleton"; + +const ProductCategory = ({ id }) => { + const [ content, setContent ] = useState(null); + + useEffect(() => { + const loadContent = async () => { + if (!content) { + const dataContent = await apiOdoo('GET', `/api/v1/categories_homepage?id=${id}`); + setContent(dataContent[0]); + } + } + loadContent(); + }, [id, content]); + + return ( +
+ { content ? ( + + ) : } +
+ ); +} + +export default function ProductCategories() { + const [ contentIds, setContentIds ] = useState([]); + + useEffect(() => { + const getContentIds = async () => { + const dataContentIds = await apiOdoo('GET', '/api/v1/categories_homepage/ids'); + setContentIds(dataContentIds); + } + getContentIds(); + }, []); + + return contentIds.map((contentId) => ( + + + + )); +} \ No newline at end of file diff --git a/src/components/products/ProductSimilar.js b/src/components/products/ProductSimilar.js new file mode 100644 index 00000000..9e2292cb --- /dev/null +++ b/src/components/products/ProductSimilar.js @@ -0,0 +1,25 @@ +import apiOdoo from '@/core/utils/apiOdoo'; +import { useEffect, useState } from 'react'; +import ProductSlider from './ProductSlider'; + +export default function ProductSimilar({ productId }) { + const [similarProducts, setSimilarProducts] = useState(null); + + useEffect(() => { + const getSimilarProducts = async () => { + if (productId && !similarProducts) { + const dataSimilarProducts = await apiOdoo('GET', `/api/v1/product/${productId}/similar?limit=20`); + setSimilarProducts(dataSimilarProducts); + } + } + getSimilarProducts(); + }, [productId, similarProducts]); + + + return ( +
+

Kamu Mungkin Juga Suka

+ +
+ ) +} \ No newline at end of file diff --git a/src/components/variants/VariantCard.js b/src/components/variants/VariantCard.js index cb4d8272..2d27371b 100644 --- a/src/components/variants/VariantCard.js +++ b/src/components/variants/VariantCard.js @@ -2,12 +2,27 @@ import { createSlug } from "@/core/utils/slug"; import Image from "../elements/Image"; import Link from "../elements/Link"; import currencyFormat from "@/core/utils/currencyFormat"; +import { useRouter } from "next/router"; +import { toast } from "react-hot-toast"; +import { createOrUpdateItemCart } from "@/core/utils/cart"; export default function VariantCard({ data, - openOnClick = true + openOnClick = true, + buyMore = false }) { let product = data; + const router = useRouter(); + + const addItemToCart = () => { + toast.success('Berhasil menambahkan ke keranjang', { duration: 1500 }); + createOrUpdateItemCart(product.id, 1); + return; + }; + + const checkoutItem = () => { + router.push(`/shop/checkout?product_id=${product.id}&qty=${product.quantity}`); + } const Card = () => (
@@ -38,9 +53,29 @@ export default function VariantCard({ if (openOnClick) { return ( - - - + <> + + + + { buyMore && ( +
+ + +
+ ) } + ); } -- cgit v1.2.3