diff --git a/api/nohup.out b/api/nohup.out new file mode 100644 index 0000000..67db272 --- /dev/null +++ b/api/nohup.out @@ -0,0 +1,13 @@ +Configured CORS origins: [ + 'http://localhost:5137', + 'http://localhost:3001', + /^https:\/\/.*\.app\.github\.dev$/ +] +πŸš€ Initializing database... +πŸš€ Initializing database... +πŸš€ Starting database migration... +βœ… No pending migrations. Database is up to date. +βœ… Database initialization complete! +βœ… Database initialized successfully +Server is running on port 3000 +API documentation is available at http://localhost:3000/api-docs diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 29b9f53..bf0bcca 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -4,9 +4,11 @@ import Welcome from './components/Welcome'; import About from './components/About'; import Footer from './components/Footer'; import Products from './components/entity/product/Products'; +import Cart from './components/entity/Cart'; import Login from './components/Login'; import { AuthProvider } from './context/AuthContext'; import { ThemeProvider } from './context/ThemeContext'; +import { CartProvider } from './context/CartContext'; import AdminProducts from './components/admin/AdminProducts'; import { useTheme } from './context/ThemeContext'; @@ -25,6 +27,7 @@ function ThemedApp() { } /> } /> } /> + } /> } /> } /> @@ -39,7 +42,9 @@ function App() { return ( - + + + ); diff --git a/frontend/src/components/Navigation.tsx b/frontend/src/components/Navigation.tsx index 5f35e12..f38acf3 100644 --- a/frontend/src/components/Navigation.tsx +++ b/frontend/src/components/Navigation.tsx @@ -1,11 +1,13 @@ import { Link } from 'react-router-dom'; import { useAuth } from '../context/AuthContext'; import { useTheme } from '../context/ThemeContext'; +import { useCart } from '../context/CartContext'; import { useState } from 'react'; export default function Navigation() { const { isLoggedIn, isAdmin, logout } = useAuth(); const { darkMode, toggleTheme } = useTheme(); + const { totalItems } = useCart(); const [adminMenuOpen, setAdminMenuOpen] = useState(false); return ( @@ -85,6 +87,31 @@ export default function Navigation() {
+ + + + + {totalItems > 0 && ( + + {totalItems} + + )} + + + {item.quantity} + + +
+ + + ${(itemPrice * item.quantity).toFixed(2)} + + + + + + ); + })} + + +
+
+ + Total + + ${totalPrice.toFixed(2)} +
+ +
+ + + Continue Shopping + +
+
+ + + ); +} diff --git a/frontend/src/components/entity/product/Products.tsx b/frontend/src/components/entity/product/Products.tsx index bb7790e..33f9ce0 100644 --- a/frontend/src/components/entity/product/Products.tsx +++ b/frontend/src/components/entity/product/Products.tsx @@ -3,6 +3,7 @@ import axios from 'axios'; import { useQuery } from 'react-query'; import { api } from '../../../api/config'; import { useTheme } from '../../../context/ThemeContext'; +import { useCart } from '../../../context/CartContext'; interface Product { productId: number; @@ -28,6 +29,7 @@ export default function Products() { const [showModal, setShowModal] = useState(false); const { data: products, isLoading, error } = useQuery('products', fetchProducts); const { darkMode } = useTheme(); + const { addToCart } = useCart(); const filteredProducts = products?.filter( (product) => @@ -42,14 +44,21 @@ export default function Products() { })); }; - const handleAddToCart = (productId: number) => { - const quantity = quantities[productId] || 0; + const handleAddToCart = (product: Product) => { + const quantity = quantities[product.productId] || 0; if (quantity > 0) { - // TODO: Implement cart functionality - alert(`Added ${quantity} items to cart`); + addToCart( + { + productId: product.productId, + name: product.name, + price: product.price, + discount: product.discount, + }, + quantity, + ); setQuantities((prev) => ({ ...prev, - [productId]: 0, + [product.productId]: 0, })); } }; @@ -228,7 +237,7 @@ export default function Products() {