fixed chechout and product add
This commit is contained in:
parent
af0608ed43
commit
37f7cc23b7
8 changed files with 18 additions and 29 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -41,15 +41,6 @@ const Footer = () => {
|
|||
<Link component={RouterLink} to="/products" color="inherit" display="block">
|
||||
Shop All
|
||||
</Link>
|
||||
<Link component={RouterLink} to="/products?category=Rock" color="inherit" display="block">
|
||||
Rocks
|
||||
</Link>
|
||||
<Link component={RouterLink} to="/products?category=Bone" color="inherit" display="block">
|
||||
Bones
|
||||
</Link>
|
||||
<Link component={RouterLink} to="/products?category=Stick" color="inherit" display="block">
|
||||
Sticks
|
||||
</Link>
|
||||
</Grid>
|
||||
|
||||
<Grid item xs={12} sm={4}>
|
||||
|
|
|
|||
|
|
@ -60,7 +60,6 @@ const AdminLayout = () => {
|
|||
const mainListItems = [
|
||||
{ text: 'Dashboard', icon: <DashboardIcon />, path: '/admin' },
|
||||
{ text: 'Products', icon: <CategoryIcon />, path: '/admin/products' },
|
||||
{ text: 'Add Product', icon: <AddCircleIcon />, path: '/admin/products/new' },
|
||||
{ text: 'Categories', icon: <ClassIcon />, path: '/admin/categories' },
|
||||
{ text: 'Orders', icon: <ShoppingCartIcon />, path: '/admin/orders' },
|
||||
{ text: 'Customers', icon: <PeopleIcon />, path: '/admin/customers' },
|
||||
|
|
|
|||
|
|
@ -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: '',
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ ${formData.country}
|
|||
${formData.email}`;
|
||||
|
||||
checkout.mutate({
|
||||
userId: user.id,
|
||||
userId: user,
|
||||
shippingAddress
|
||||
}, {
|
||||
onSuccess: () => {
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ const ProductDetailPage = () => {
|
|||
}
|
||||
|
||||
addToCart.mutate({
|
||||
userId: user.id,
|
||||
userId: user,
|
||||
productId: id,
|
||||
quantity
|
||||
});
|
||||
|
|
@ -180,7 +180,6 @@ const ProductDetailPage = () => {
|
|||
<Grid item xs={12} md={6}>
|
||||
<Box sx={{ mb: 2 }}>
|
||||
<Card>
|
||||
{console.log(product)}
|
||||
<CardMedia
|
||||
component="img"
|
||||
image={
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ const ProductsPage = () => {
|
|||
}
|
||||
|
||||
addToCart.mutate({
|
||||
userId: user.id,
|
||||
userId: user,
|
||||
productId,
|
||||
quantity: 1
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue