From 82e03978b89938219958032efb1448cc76baa181 Mon Sep 17 00:00:00 2001
From: Saumit <justsaumit@protonmail.com>
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<HTMLDivElement>(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 ? (
+    <S.CartDropdown ref={ref} data-cy={CypressFields.CartDropdown}>
+      <div>
+        <S.Header>
+          <S.Title>Shopping Cart</S.Title>
+          <span onClick={onClose}>Close</span>
+        </S.Header>
+        <S.ItemList>
+          {!productList.length && <S.EmptyCart>Your shopping cart is empty</S.EmptyCart>}
+          {productList.map(
+            ({ quantity, product: { name, picture, id, priceUsd = { nanos: 0, currencyCode: 'USD', units: 0 } } }) => (
+              <S.Item key={id} data-cy={CypressFields.CartDropdownItem}>
+                <S.ItemImage src={"/images/products/" + picture} alt={name} />
+                <S.ItemDetails>
+                  <S.ItemName>{name}</S.ItemName>
+                  <ProductPrice price={priceUsd} />
+                  <S.ItemQuantity>Quantity: {quantity}</S.ItemQuantity>
+                </S.ItemDetails>
+              </S.Item>
+            )
+          )}
+        </S.ItemList>
+      </div>
+      <Link href="/cart">
+        <S.CartButton data-cy={CypressFields.CartGoToShopping}>Go to Shopping Cart</S.CartButton>
+      </Link>
+    </S.CartDropdown>
+  ) : null;
+};
+
+export default CartDropdown;
-- 
cgit v1.2.3

