diff --git a/backend/src/routes/cart.js b/backend/src/routes/cart.js index 97526fd..1b76eca 100644 --- a/backend/src/routes/cart.js +++ b/backend/src/routes/cart.js @@ -35,7 +35,7 @@ module.exports = (pool, query, authMiddleware) => { // Get cart items with product details const cartItemsResult = await query( `SELECT ci.id, ci.quantity, ci.added_at, - p.id AS product_id, p.name, p.description, p.price, p.image_url, + p.id AS product_id, p.name, p.description, p.price, p.category_id, pc.name AS category_name FROM cart_items ci JOIN products p ON ci.product_id = p.id @@ -69,7 +69,7 @@ module.exports = (pool, query, authMiddleware) => { if (req.user.id !== userId) { return res.status(403).json({ error: true, - message: 'You can only modify your own cart' + message: 'You can only modify your own cart' + req.user.id + " "+ userId }); } // Check if product exists @@ -125,7 +125,7 @@ module.exports = (pool, query, authMiddleware) => { // Get updated cart const updatedCartItems = await query( `SELECT ci.id, ci.quantity, ci.added_at, - p.id AS product_id, p.name, p.description, p.price, p.image_url, + p.id AS product_id, p.name, p.description, p.price, p.category_id, pc.name AS category_name FROM cart_items ci JOIN products p ON ci.product_id = p.id @@ -158,7 +158,7 @@ module.exports = (pool, query, authMiddleware) => { if (req.user.id !== userId) { return res.status(403).json({ error: true, - message: 'You can only modify your own cart' + message: 'You can only modify your own cart' + req.user.id + " "+ userId }); } // Get cart @@ -193,7 +193,7 @@ module.exports = (pool, query, authMiddleware) => { // Get updated cart const updatedCartItems = await query( `SELECT ci.id, ci.quantity, ci.added_at, - p.id AS product_id, p.name, p.description, p.price, p.image_url, + p.id AS product_id, p.name, p.description, p.price, p.category_id, pc.name AS category_name FROM cart_items ci JOIN products p ON ci.product_id = p.id @@ -226,7 +226,7 @@ module.exports = (pool, query, authMiddleware) => { if (req.user.id !== userId) { return res.status(403).json({ error: true, - message: 'You can only modify your own cart' + message: 'You can only modify your own cart' + req.user.id + " "+ userId }); } // Get cart diff --git a/frontend/src/components/Footer.jsx b/frontend/src/components/Footer.jsx index c4f2c15..70b6621 100644 --- a/frontend/src/components/Footer.jsx +++ b/frontend/src/components/Footer.jsx @@ -41,15 +41,6 @@ const Footer = () => { Shop All - - Rocks - - - Bones - - - Sticks - diff --git a/frontend/src/layouts/AdminLayout.jsx b/frontend/src/layouts/AdminLayout.jsx index 10d0078..40cf27a 100644 --- a/frontend/src/layouts/AdminLayout.jsx +++ b/frontend/src/layouts/AdminLayout.jsx @@ -60,7 +60,6 @@ const AdminLayout = () => { const mainListItems = [ { text: 'Dashboard', icon: , path: '/admin' }, { text: 'Products', icon: , path: '/admin/products' }, - { text: 'Add Product', icon: , path: '/admin/products/new' }, { text: 'Categories', icon: , path: '/admin/categories' }, { text: 'Orders', icon: , path: '/admin/orders' }, { text: 'Customers', icon: , path: '/admin/customers' }, diff --git a/frontend/src/pages/Admin/ProductEditPage.jsx b/frontend/src/pages/Admin/ProductEditPage.jsx index c18355c..5073a8f 100644 --- a/frontend/src/pages/Admin/ProductEditPage.jsx +++ b/frontend/src/pages/Admin/ProductEditPage.jsx @@ -19,7 +19,7 @@ import { Snackbar, Autocomplete } from '@mui/material'; -import { useNavigate, useParams } from 'react-router-dom'; +import { useNavigate, useParams, useLocation } from 'react-router-dom'; import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; import ArrowBackIcon from '@mui/icons-material/ArrowBack'; import SaveIcon from '@mui/icons-material/Save'; @@ -28,12 +28,12 @@ import apiClient from '@services/api'; import { useAuth } from '@hooks/reduxHooks'; const ProductEditPage = () => { - const { id } = useParams(); + const { pathname } = useLocation(); + const id = pathname.split('/').pop(); const navigate = useNavigate(); const queryClient = useQueryClient(); const { apiKey } = useAuth(); const isNewProduct = id === 'new'; - // Form state const [formData, setFormData] = useState({ name: '', @@ -92,7 +92,7 @@ const ProductEditPage = () => { const response = await apiClient.get(`/products/${id}`); return response.data; }, - enabled: !isNewProduct + enabled: !isNewProduct }); // Create product mutation diff --git a/frontend/src/pages/CartPage.jsx b/frontend/src/pages/CartPage.jsx index c0ad81d..b310d7d 100644 --- a/frontend/src/pages/CartPage.jsx +++ b/frontend/src/pages/CartPage.jsx @@ -22,7 +22,7 @@ import ShoppingCartIcon from '@mui/icons-material/ShoppingCart'; import NavigateNextIcon from '@mui/icons-material/NavigateNext'; import { Link as RouterLink, useNavigate } from 'react-router-dom'; import { useAuth } from '@hooks/reduxHooks'; -import { useGetCart, useUpdateCartItem, useClearCart } from '.@hooks/apiHooks'; +import { useGetCart, useUpdateCartItem, useClearCart } from '@hooks/apiHooks'; import imageUtils from '@utils/imageUtils'; const CartPage = () => { @@ -30,7 +30,7 @@ const CartPage = () => { const { user } = useAuth(); // Get cart data - const { data: cart, isLoading, error } = useGetCart(user?.id); + const { data: cart, isLoading, error } = useGetCart(user); // Cart mutations const updateCartItem = useUpdateCartItem(); @@ -39,7 +39,7 @@ const CartPage = () => { // Handle quantity change const handleUpdateQuantity = (productId, newQuantity) => { updateCartItem.mutate({ - userId: user.id, + userId: user, productId, quantity: newQuantity }); @@ -48,7 +48,7 @@ const CartPage = () => { // Handle remove item const handleRemoveItem = (productId) => { updateCartItem.mutate({ - userId: user.id, + userId: user, productId, quantity: 0 }); @@ -56,7 +56,7 @@ const CartPage = () => { // Handle clear cart const handleClearCart = () => { - clearCart.mutate(user.id); + clearCart.mutate(user); }; // Handle proceed to checkout diff --git a/frontend/src/pages/CheckoutPage.jsx b/frontend/src/pages/CheckoutPage.jsx index b77a55d..a3ddbf3 100644 --- a/frontend/src/pages/CheckoutPage.jsx +++ b/frontend/src/pages/CheckoutPage.jsx @@ -120,7 +120,7 @@ ${formData.country} ${formData.email}`; checkout.mutate({ - userId: user.id, + userId: user, shippingAddress }, { onSuccess: () => { diff --git a/frontend/src/pages/ProductDetailPage.jsx b/frontend/src/pages/ProductDetailPage.jsx index 7574f4d..894ef18 100644 --- a/frontend/src/pages/ProductDetailPage.jsx +++ b/frontend/src/pages/ProductDetailPage.jsx @@ -75,7 +75,7 @@ const ProductDetailPage = () => { } addToCart.mutate({ - userId: user.id, + userId: user, productId: id, quantity }); @@ -180,7 +180,6 @@ const ProductDetailPage = () => { - {console.log(product)} { } addToCart.mutate({ - userId: user.id, + userId: user, productId, quantity: 1 });