Skip to content

Commit 1a5a4b2

Browse files
new product functionality added in admin route
1 parent 22b1dab commit 1a5a4b2

File tree

9 files changed

+636
-192
lines changed

9 files changed

+636
-192
lines changed

data.json

Lines changed: 155 additions & 39 deletions
Large diffs are not rendered by default.

src/App.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ import { fetchLoggedInUserAsync } from "./features/user/userSlice";
2727
import LogOut from "./features/auth/components/LogOut";
2828
import ForgotPasswordPage from "./pages/ForgotPasswordPage";
2929
import ProtectedAdmin from "./features/auth/components/ProtectedAdmin";
30-
import AdminHome from "./pages/AdimHome";
30+
import AdminHome from "./pages/AdminHome";
3131
import AdminProductDetail from "./features/admin/components/AdminProductDetail";
32+
import ProductFormPage from "./pages/ProductFormPage";
3233
const router = createBrowserRouter([
3334
{
3435
path: "/",
@@ -88,6 +89,14 @@ const router = createBrowserRouter([
8889
</ProtectedAdmin>
8990
),
9091
},
92+
{
93+
path: "/admin/product-form",
94+
element: (
95+
<ProtectedAdmin>
96+
<ProductFormPage></ProductFormPage>
97+
</ProtectedAdmin>
98+
),
99+
},
91100
{
92101
path: "/order-success/:id",
93102
element: <OrderSuccessPage></OrderSuccessPage>,

src/features/admin/components/AdminProductList.js

Lines changed: 54 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,12 @@ export default function AdminProductList() {
199199
{/* Product grid */}
200200
<div className="lg:col-span-3">
201201
{/* This is our products list */}
202+
<Link
203+
to="/admin/product-form"
204+
className="rounded-md mx-10 bg-green-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
205+
>
206+
Add Product
207+
</Link>
202208
<ProductGrid products={products} />
203209
</div>
204210
{/* Product grid end */}
@@ -399,42 +405,58 @@ function ProductGrid({ products }) {
399405
<div className="mx-auto max-w-2xl px-4 py-0 sm:px-6 sm:py-0 lg:max-w-7xl lg:px-8">
400406
<div className="mt-6 grid grid-cols-1 gap-x-6 gap-y-10 sm:grid-cols-2 lg:grid-cols-3 xl:gap-x-8">
401407
{products.map((product) => (
402-
<Link to={`/product-detail/${product.id}`}>
403-
<div key={product.id} className="group relative p-2 border-2">
404-
<div className="min-h-60 aspect-h-1 aspect-w-1 w-full overflow-hidden rounded-md bg-gray-200 lg:aspect-none group-hover:opacity-75 lg:h-60">
405-
<img
406-
src={product.thumbnail}
407-
alt={product.title}
408-
className="h-full w-full object-cover object-center lg:h-full lg:w-full"
409-
/>
410-
</div>
411-
<div className="mt-4 flex justify-between">
412-
<div>
413-
<h3 className="text-sm text-gray-700">
414-
<div href={product.thumbnail}>
415-
<span aria-hidden="true" className="absolute inset-0" />
416-
{product.title}
408+
<div>
409+
<Link to={`/product-detail/${product.id}`}>
410+
<div>
411+
<div
412+
key={product.id}
413+
className="group relative p-2 border-2"
414+
>
415+
<div className="min-h-60 aspect-h-1 aspect-w-1 w-full overflow-hidden rounded-md bg-gray-200 lg:aspect-none group-hover:opacity-75 lg:h-60">
416+
<img
417+
src={product.thumbnail}
418+
alt={product.title}
419+
className="h-full w-full object-cover object-center lg:h-full lg:w-full"
420+
/>
421+
</div>
422+
<div className="mt-4 flex justify-between">
423+
<div>
424+
<h3 className="text-sm text-gray-700">
425+
<div href={product.thumbnail}>
426+
<span
427+
aria-hidden="true"
428+
className="absolute inset-0"
429+
/>
430+
{product.title}
431+
</div>
432+
</h3>
433+
<p className="mt-1 text-sm text-gray-500">
434+
<StarIcon className="w-6 h-6 inline"></StarIcon>
435+
<span className="align-bottom">{product.rating}</span>
436+
</p>
417437
</div>
418-
</h3>
419-
<p className="mt-1 text-sm text-gray-500">
420-
<StarIcon className="w-6 h-6 inline"></StarIcon>
421-
<span className="align-bottom">{product.rating}</span>
422-
</p>
423-
</div>
424-
<div>
425-
<p className="text-sm font-medium text-gray-900">
426-
$
427-
{Math.round(
428-
product.price * (1 - product.discountPercentage / 100)
429-
)}
430-
<p className="text-sm line-through font-medium text-gray-400">
431-
${product.price}
432-
</p>
433-
</p>
438+
<div>
439+
<p className="text-sm font-medium text-gray-900">
440+
$
441+
{Math.round(
442+
product.price *
443+
(1 - product.discountPercentage / 100)
444+
)}
445+
<p className="text-sm line-through font-medium text-gray-400">
446+
${product.price}
447+
</p>
448+
</p>
449+
</div>
450+
</div>
434451
</div>
435452
</div>
453+
</Link>
454+
<div>
455+
<button className="rounded-md my-2 bg-indigo-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600">
456+
Edit Product
457+
</button>
436458
</div>
437-
</Link>
459+
</div>
438460
))}
439461
</div>
440462
</div>

0 commit comments

Comments
 (0)