diff options
| author | HATEC\SPVDEV001 <tri.susilo@altama.co.id> | 2023-06-27 09:07:22 +0700 |
|---|---|---|
| committer | HATEC\SPVDEV001 <tri.susilo@altama.co.id> | 2023-06-27 09:07:22 +0700 |
| commit | 84ae09f61f05f212ec098da1fd4ed14960119527 (patch) | |
| tree | ace07ea0aad2730fa91abefc32490f0a3b855310 /src/lib/product/components | |
| parent | 88be517479704ee6b40334e0cabcfc86b824419b (diff) | |
promotion detail
Diffstat (limited to 'src/lib/product/components')
| -rw-r--r-- | src/lib/product/components/Product/ProductDesktop.jsx | 48 |
1 files changed, 16 insertions, 32 deletions
diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx index 25b12911..507d676c 100644 --- a/src/lib/product/components/Product/ProductDesktop.jsx +++ b/src/lib/product/components/Product/ProductDesktop.jsx @@ -28,7 +28,8 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => { const [addCartAlert, setAddCartAlert] = useState(false) const [promotionType, setPromotionType] = useState(false) - const [promotionList, setPromotionList] = useState(null) + const [promotionActiveId, setPromotionActiveId] = useState(null) + const [quantity, setQuantity] = useState(null) const getLowestPrice = useCallback(() => { const prices = product.variants.map((variant) => variant.price) @@ -39,18 +40,6 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => { }, [product]) useEffect(() => { - if(product.variants.length == 1){ - const id = product.variants[0].id - const listProgram = async () => { - const programs = await getPromotionProgram({id}) - setPromotionList(programs) - console.log('list program', promotionList) - } - listProgram() - } - },[]) - - useEffect(() => { const lowest = getLowestPrice() setLowestPrice(lowest) }, [getLowestPrice]) @@ -60,6 +49,9 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => { const variantQuantityRefs = useRef([]) const setVariantQuantityRef = (variantId) => (element) => { + if (element) { + setQuantity(element.value) + } variantQuantityRefs.current[variantId] = element } @@ -82,6 +74,7 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => { updateItemCart({ productId: variantId, quantity, + programLineId:promotionActiveId, selected: true }) setAddCartAlert(true) @@ -183,7 +176,12 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => { {product.variants.length <= 1 && ( <div className='pt-3'> <div className='flex mt-1'> - <PromotionType></PromotionType> + <PromotionType + variantId={product.variants[0].id} + setPromotionActiveId={setPromotionActiveId} + promotionActiveId={promotionActiveId} + quantity={quantity} + ></PromotionType> </div> </div> )} @@ -260,16 +258,6 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => { </span> )} </h3> - {/* <div className='mt-5'> - <button - type='button' - onClick={() => setPromotionType(true)} - className='text-gray-900 flex items-center justify-center rounded-lg bg-white border font-medium border-gray-300 hover:bg-gray-100 py-2.5 h-[50px] w-[100%]' - > - <span className='text-left'>%</span> - <span className='text-left ml-5'>Makin Hemat Pakai Promo </span> - </button> - </div> */} {product.variants.length > 1 ? ( <button type='button' @@ -284,6 +272,7 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => { type='number' className='form-input w-16 py-2 text-center bg-gray_r-1' ref={setVariantQuantityRef(product.variants[0].id)} + onChange={setVariantQuantityRef(product.variants[0].id)} defaultValue={1} /> <button @@ -434,16 +423,16 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => { <ProductSimilar query={productSimilarQuery} /> </LazyLoad> </div> - <BottomPopup + {/* <BottomPopup className=' !h-[75%]' title='Pakai Promo' active={promotionType} close={() => setPromotionType(false)} > <div className='flex mt-4'> - <PromotionType isModal={true}></PromotionType> + <PromotionType isModal={true} ></PromotionType> </div> - </BottomPopup> + </BottomPopup> */} <BottomPopup className='!container' title='Berhasil Ditambahkan' @@ -500,9 +489,4 @@ const TabContent = ({ children, active, className = '', ...props }) => ( </div> ) -const getPromotionProgram = async ({id}) => { - const listProgram = await odooApi('GET', `/api/v1/product_variant/${id}/promotions`) - - return listProgram -} export default ProductDesktop |
