diff --git a/src/App.tsx b/src/App.tsx
index 05c0033..591c26a 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -8,6 +8,7 @@ import Store from "./Plugins/Redux/Store/Store";
import { Provider } from "react-redux";
import Inventory from "./Routes/Inventory/Inventory";
import AddProduct from "./Routes/Products/AddProduct/AddProduct";
+import EditProduct from "./Routes/Products/EditProduct/EditProduct";
const router = createBrowserRouter([
{
@@ -47,6 +48,14 @@ const router = createBrowserRouter([
),
},
+ {
+ path: "/Products/EditProduct/:id", // Updated route with dynamic id parameter
+ element: (
+
+
+
+ ),
+ },
]);
export default function App() {
diff --git a/src/components/InventoryInfo/InventoryInfo.tsx b/src/components/InventoryInfo/InventoryInfo.tsx
index 0e15968..43e3915 100644
--- a/src/components/InventoryInfo/InventoryInfo.tsx
+++ b/src/components/InventoryInfo/InventoryInfo.tsx
@@ -22,7 +22,7 @@ export default function InventoryInfo(props: ProductInfoProps) {
{products.map((product) => (
- {product.id}
+ {product.id.toString().padStart(3, '0')}
{product.name}
{product.stocks}
{product.lastModified}
diff --git a/src/components/ProductInfo/ProductInfo.tsx b/src/components/ProductInfo/ProductInfo.tsx
index fa04efd..348f5db 100644
--- a/src/components/ProductInfo/ProductInfo.tsx
+++ b/src/components/ProductInfo/ProductInfo.tsx
@@ -1,5 +1,6 @@
import { Table, TableBody, TableCell, TableContainer, TableHead, TableRow } from '@mui/material';
import { ProductType } from '../ProductType/ProductType';
+import { useNavigate } from 'react-router-dom';
type ProductInfoProps = {
products: ProductType[];
@@ -7,6 +8,15 @@ type ProductInfoProps = {
export default function ProductInfo(props: ProductInfoProps) {
const { products } = props;
+ const navigate = useNavigate();
+
+ const handleEdit = (id: number) => {
+ navigate(`/Products/EditProduct/${id.toString().padStart(3, '0')}`);
+ };
+
+ const handleDelete = (id: number) => {
+ console.log(`Deleting product with ID ${id}`);
+ };
return (
@@ -16,14 +26,19 @@ export default function ProductInfo(props: ProductInfoProps) {
Product ID
Product Name
Last Modified
+ Actions
{products.map((product) => (
- {product.id}
+ {product.id.toString().padStart(3, '0')}
{product.name}
{product.lastModified}
+
+
+
+
))}
diff --git a/src/routes/Products/AddProduct/AddProduct.tsx b/src/routes/Products/AddProduct/AddProduct.tsx
index 525083b..8f67675 100644
--- a/src/routes/Products/AddProduct/AddProduct.tsx
+++ b/src/routes/Products/AddProduct/AddProduct.tsx
@@ -1,10 +1,17 @@
import React, { useState } from "react";
import { useNavigate } from "react-router-dom";
-import ProductsLists from "../../../Components/ProductsLists/ProductsLists";
import { ProductType } from "../../../Components/ProductType/ProductType";
+import ProductsLists from "../../../Components/ProductsLists/ProductsLists";
import styles from "../../../styles";
import ProductsIcon from "../../../Components/Icons/ProductsIcon/ProductsIcon";
-import ProductInfo from "../../../Components/ProductInfo/ProductInfo";
+
+import {
+ Table,
+ TableBody,
+ TableCell,
+ TableContainer,
+ TableRow,
+} from "@mui/material";
export default function AddProduct() {
const [name, setName] = useState("");
@@ -43,16 +50,24 @@ export default function AddProduct() {
Products
Add Product
-
-
-
-
-
+
+
+
diff --git a/src/routes/Products/EditProduct/EditProduct.tsx b/src/routes/Products/EditProduct/EditProduct.tsx
new file mode 100644
index 0000000..614c2dd
--- /dev/null
+++ b/src/routes/Products/EditProduct/EditProduct.tsx
@@ -0,0 +1,99 @@
+import React, { useState, useEffect } from "react";
+import { useParams, useNavigate } from "react-router-dom";
+import {
+ Table,
+ TableBody,
+ TableCell,
+ TableContainer,
+ TableHead,
+ TableRow,
+ TextField,
+ IconButton,
+} from "@mui/material";
+import { ProductType } from "../../../Components/ProductType/ProductType";
+import ProductsLists from "../../../Components/ProductsLists/ProductsLists";
+import styles from "../../../styles";
+
+type EditProductParams = {
+ id?: string;
+};
+
+export default function EditProduct() {
+ const { id } = useParams();
+ const navigate = useNavigate();
+
+ const [name, setName] = useState("");
+ const [stocks, setStocks] = useState("");
+
+ useEffect(() => {
+ const product = ProductsLists.find((product) => product.id.toString() === id);
+ if (product) {
+ setName(product.name);
+ setStocks(product.stocks.toString());
+ }
+ }, [id]);
+
+ const handleNameChange = (event: React.ChangeEvent) => {
+ setName(event.target.value);
+ };
+
+ const handleStocksChange = (event: React.ChangeEvent) => {
+ setStocks(event.target.value);
+ };
+
+ const handleUpdateProduct = () => {
+ const updatedProduct: ProductType = {
+ id: parseInt(id || "0"), // add a default value of "0" for id if it's undefined
+ name: name,
+ stocks: parseInt(stocks),
+ lastModified: new Date().toLocaleString(),
+ };
+
+ const index = ProductsLists.findIndex((product) => product.id.toString() === id);
+ ProductsLists.splice(index, 1, updatedProduct);
+
+ navigate("/Products");
+ };
+
+ const handleCancel = () => {
+ navigate("/Products");
+ };
+
+ return (
+
+
+
Edit Product
+
+
+
+
+
+ Product ID
+ Product Name
+ Stocks
+
+
+
+
+ {id}
+ {name}
+
+
+
+
+
+
+
+
+
+
+
+ );
+}