From 62c7c4c84871ff9c22a8321422bfdd1d9dacbc66 Mon Sep 17 00:00:00 2001 From: vishnu R <157986076+vishnu-R2005@users.noreply.github.com> Date: Mon, 15 Jun 2026 22:23:14 +0530 Subject: [PATCH 1/4] feat: add product image upload and admin product management --- frontend/src/components/layout/Navbar.jsx | 83 +++++++++++++++++------ frontend/src/pages/AdminDashboard.jsx | 43 ++++++++++++ 2 files changed, 105 insertions(+), 21 deletions(-) diff --git a/frontend/src/components/layout/Navbar.jsx b/frontend/src/components/layout/Navbar.jsx index df17b48..4d7d791 100644 --- a/frontend/src/components/layout/Navbar.jsx +++ b/frontend/src/components/layout/Navbar.jsx @@ -40,27 +40,68 @@ export default function Navbar() { {darkMode ? '☀️' : '🌙'} - {isAuthenticated ? ( - <> - {user?.role === 'admin' && ( - Admin - )} - Orders - Wishlist - Profile - - 🛒 - {itemCount > 0 && ( - - {itemCount} - - )} - - - - ) : ( + {isAuthenticated ? ( + user?.role === 'admin' ? ( + <> + + Admin + + + + + ) : ( + <> + + Orders + + + + Wishlist + + + + Profile + + + + 🛒 + + {itemCount > 0 && ( + + {itemCount} + + )} + + + + + ) +) : ( <> Login Sign Up diff --git a/frontend/src/pages/AdminDashboard.jsx b/frontend/src/pages/AdminDashboard.jsx index 3dcb890..ae5debc 100644 --- a/frontend/src/pages/AdminDashboard.jsx +++ b/frontend/src/pages/AdminDashboard.jsx @@ -1,6 +1,7 @@ import { useEffect, useState } from 'react' import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer, LineChart, Line } from 'recharts' import { analyticsAPI } from '../services/api' +import { Link } from 'react-router-dom' export default function AdminDashboard() { const [stats, setStats] = useState(null) @@ -30,6 +31,48 @@ export default function AdminDashboard() {

GoCart Admin Dashboard

Shop Smarter. Shop Faster.

+
+ + +

+ 📦 Manage Products +

+ +

+ View, edit and delete products +

+ + + +

+ ➕ Add Product +

+ +

+ Create a new product +

+ + + +

+ 📊 Inventory +

+ +

+ Check stock levels and pricing +

+ + +
{statCards.map((s) => ( From 9ee6c08d5df46ab0b68776964ad598daa8571081 Mon Sep 17 00:00:00 2001 From: vishnu R <157986076+vishnu-R2005@users.noreply.github.com> Date: Mon, 15 Jun 2026 23:03:44 +0530 Subject: [PATCH 2/4] fix: display product images using absolute media URL --- frontend/src/components/products/ProductCard.jsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/products/ProductCard.jsx b/frontend/src/components/products/ProductCard.jsx index 85a5d44..ca2dbfd 100644 --- a/frontend/src/components/products/ProductCard.jsx +++ b/frontend/src/components/products/ProductCard.jsx @@ -40,7 +40,11 @@ export default function ProductCard({ product }) {
{product.primary_image ? ( - {product.name} Date: Mon, 15 Jun 2026 23:04:06 +0530 Subject: [PATCH 3/4] fix: support product image upload and update --- frontend/src/pages/admin/EditProduct.jsx | 34 +++++++++++++++++------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/frontend/src/pages/admin/EditProduct.jsx b/frontend/src/pages/admin/EditProduct.jsx index f2dd649..c1bf347 100644 --- a/frontend/src/pages/admin/EditProduct.jsx +++ b/frontend/src/pages/admin/EditProduct.jsx @@ -79,19 +79,33 @@ export default function EditProduct() { ...formData, category: Number(formData.category), }) - if (selectedImage) { - const { data: product } = await productsAPI.get(slug) + if (selectedImage) { + const { data: product } = await productsAPI.get(slug) - const imageData = new FormData() + console.log("EDIT PRODUCT:", product) + console.log("PRODUCT ID:", product.id) + console.log("PRODUCT IMAGES:", product.images) - imageData.append('product', product.id) - imageData.append('image', selectedImage) - imageData.append('alt_text', formData.name) - imageData.append('is_primary', true) - imageData.append('order', 1) + const imageData = new FormData() - await productImagesAPI.upload(imageData) - } + imageData.append('image', selectedImage) + imageData.append('alt_text', formData.name) + imageData.append('is_primary', true) + imageData.append('order', 1) + + if (product.images?.length > 0) { + console.log("Updating image:", product.images[0].id) + + await productImagesAPI.update( + product.images[0].id, + imageData + ) + } else { + imageData.append('product', product.id) + + await productImagesAPI.upload(imageData) + } +} toast.success('Product updated successfully') From 975b45337efbef9bc6582264dbe4351387855e2b Mon Sep 17 00:00:00 2001 From: vishnu R <157986076+vishnu-R2005@users.noreply.github.com> Date: Mon, 15 Jun 2026 23:04:59 +0530 Subject: [PATCH 4/4] fix: resolve product image loading issues --- frontend/src/services/api.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/frontend/src/services/api.js b/frontend/src/services/api.js index 0dbe528..e2ed13d 100644 --- a/frontend/src/services/api.js +++ b/frontend/src/services/api.js @@ -97,6 +97,13 @@ export const productImagesAPI = { 'Content-Type': 'multipart/form-data', }, }), + + update: (imageId, formData) => + api.patch(`/products/images/${imageId}/`, formData, { + headers: { + 'Content-Type': 'multipart/form-data', + }, + }), remove: (imageId) => api.delete(`/products/images/${imageId}/`),