diff --git a/src/routes/Inventory/Inventory.tsx b/src/routes/Inventory/Inventory.tsx index 205d551..d9112c5 100644 --- a/src/routes/Inventory/Inventory.tsx +++ b/src/routes/Inventory/Inventory.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useState } from "react"; import styles from "../../styles"; import InventoryIcon from "../../Components/Icons/InventoryIcon/InventoryIcon"; import { @@ -13,13 +13,67 @@ import { import { SampleInventoryData } from "../../Components/SampleData/SampleData"; export default function Inventory() { - function change_color(in_stock: number) { - if (in_stock > 0 && in_stock < 3) { - return {in_stock}; - } else if (in_stock > 3 && in_stock < 9) { - return {in_stock}; + function is_number(number: string) { + const re = /^[0-9\b]+$/; + if (re.test(number)) { + return true; } else { - return {in_stock}; + return false; + } + } + function StockRender(in_stock: number) { + const [stock, setStock] = useState("" + in_stock); + if (in_stock > 0 && in_stock < 3) { + return ( + + ) => { + if (is_number(e.target.value) === true) { + setStock(e.target.value); + } + }} + /> + + ); + } else if (in_stock > 3 && in_stock < 9) { + return ( + + ) => { + if (is_number(e.target.value) === true) { + setStock(e.target.value); + } + }} + /> + + ); + } else { + return ( + + ) => { + if (is_number(e.target.value) === true) { + setStock(e.target.value); + } + }} + /> + + ); } } return ( @@ -50,7 +104,7 @@ export default function Inventory() { > {row.id} {row.name} - {change_color(row.in_stock)} + {StockRender(row.in_stock)} ))}