diff --git a/src/App.tsx b/src/App.tsx index d37fc07..05c0033 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -7,6 +7,7 @@ import { createBrowserRouter, RouterProvider } from "react-router-dom"; 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"; const router = createBrowserRouter([ { @@ -38,6 +39,14 @@ const router = createBrowserRouter([ ), }, + { + path: "/Products/AddProduct", + element: ( + + + + ), + }, ]); export default function App() { diff --git a/src/components/InventoryInfo/InventoryInfo.tsx b/src/components/InventoryInfo/InventoryInfo.tsx index d301cc9..0e15968 100644 --- a/src/components/InventoryInfo/InventoryInfo.tsx +++ b/src/components/InventoryInfo/InventoryInfo.tsx @@ -1,14 +1,8 @@ import { Table, TableBody, TableCell, TableContainer, TableHead, TableRow } from '@mui/material'; - -type Product = { - id: number; - name: string; - stocks: number; - lastModified: string; -}; +import { ProductType } from '../ProductType/ProductType'; type ProductInfoProps = { - products: Product[]; + products: ProductType[]; }; export default function InventoryInfo(props: ProductInfoProps) { diff --git a/src/components/ProductInfo/ProductInfo.tsx b/src/components/ProductInfo/ProductInfo.tsx index 6afacda..fa04efd 100644 --- a/src/components/ProductInfo/ProductInfo.tsx +++ b/src/components/ProductInfo/ProductInfo.tsx @@ -1,14 +1,8 @@ import { Table, TableBody, TableCell, TableContainer, TableHead, TableRow } from '@mui/material'; - -type Product = { - id: number; - name: string; - stocks: number; - lastModified: string; -}; +import { ProductType } from '../ProductType/ProductType'; type ProductInfoProps = { - products: Product[]; + products: ProductType[]; }; export default function ProductInfo(props: ProductInfoProps) { diff --git a/src/components/ProductType/ProductType.tsx b/src/components/ProductType/ProductType.tsx new file mode 100644 index 0000000..2ceafc8 --- /dev/null +++ b/src/components/ProductType/ProductType.tsx @@ -0,0 +1,7 @@ +export type ProductType = { + id: number; + name: string; + stocks: number; + lastModified: string; + }; + diff --git a/src/routes/Products/AddProduct/AddProduct.tsx b/src/routes/Products/AddProduct/AddProduct.tsx new file mode 100644 index 0000000..15b5297 --- /dev/null +++ b/src/routes/Products/AddProduct/AddProduct.tsx @@ -0,0 +1,61 @@ +import React, { useState } from "react"; +import ProductsLists from "../../../Components/ProductsLists/ProductsLists"; +import { ProductType } from "../../../Components/ProductType/ProductType"; +import styles from "../../../styles"; +import ProductsIcon from "../../../Components/Icons/ProductsIcon/ProductsIcon"; +import ProductInfo from "../../../Components/ProductInfo/ProductInfo"; + + +export default function AddProduct() { + const [name, setName] = useState(""); + const [stocks, setStocks] = useState(""); + + const handleNameChange = (event: React.ChangeEvent) => { + setName(event.target.value); + }; + + const handleStocksChange = (event: React.ChangeEvent) => { + setStocks(event.target.value); + }; + + const handleAddProduct = () => { + if (name && stocks) { + const newProduct: ProductType = { + id: ProductsLists.length + 1, + name: name, + stocks: parseInt(stocks), + lastModified: new Date().toLocaleString(), + }; + ProductsLists.push(newProduct); + } + //window.location.href = "/Products"; + }; + + const handleCancel = () => { + window.location.href = "/Products"; + }; + + return ( +
+
+ +

Products

+
+

Add Product

+ + +
+ + +
+ + + +
+ ); +} diff --git a/src/routes/Products/Products.tsx b/src/routes/Products/Products.tsx index 2f456c6..8db92ee 100644 --- a/src/routes/Products/Products.tsx +++ b/src/routes/Products/Products.tsx @@ -5,6 +5,10 @@ import ProductInfo from "../../Components/ProductInfo/ProductInfo"; import ProductsLists from "../../Components/ProductsLists/ProductsLists"; export default function Products() { + const handleAddProduct = () => { + window.location.href = "/Products/AddProduct"; + }; + return (
@@ -12,6 +16,7 @@ export default function Products() {

Products

+
); }