// Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 import Link from 'next/link'; import { useEffect, useRef } from 'react'; import { CypressFields } from '../../utils/Cypress'; import { IProductCartItem } from '../../types/Cart'; import ProductPrice from '../ProductPrice'; import * as S from './CartDropdown.styled'; interface IProps { isOpen: boolean; onClose(): void; productList: IProductCartItem[]; } const CartDropdown = ({ productList, isOpen, onClose }: IProps) => { const ref = useRef(null); useEffect(() => { const handleClickOutside = (event: Event) => { if (ref.current && !ref.current.contains(event.target as Node)) { onClose(); } }; // Bind the event listener document.addEventListener('mousedown', handleClickOutside); return () => { // Unbind the event listener on clean up document.removeEventListener('mousedown', handleClickOutside); }; }, [ref]); return isOpen ? (
Shopping Cart Close {!productList.length && Your shopping cart is empty} {productList.map( ({ quantity, product: { name, picture, id, priceUsd = { nanos: 0, currencyCode: 'USD', units: 0 } } }) => ( {name} Quantity: {quantity} ) )}
Go to Shopping Cart
) : null; }; export default CartDropdown;