From 82e03978b89938219958032efb1448cc76baa181 Mon Sep 17 00:00:00 2001 From: Saumit Date: Sat, 27 Sep 2025 02:14:26 +0530 Subject: Initial snapshot - OpenTelemetry demo 2.1.3 -f --- .../components/CartDropdown/CartDropdown.tsx | 65 ++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/frontend/components/CartDropdown/CartDropdown.tsx (limited to 'src/frontend/components/CartDropdown/CartDropdown.tsx') diff --git a/src/frontend/components/CartDropdown/CartDropdown.tsx b/src/frontend/components/CartDropdown/CartDropdown.tsx new file mode 100644 index 0000000..cd0703e --- /dev/null +++ b/src/frontend/components/CartDropdown/CartDropdown.tsx @@ -0,0 +1,65 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +import Link from 'next/link'; +import { useEffect, useRef } from 'react'; +import { CypressFields } from '../../utils/enums/CypressFields'; +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, onClose]); + + 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; -- cgit v1.2.3