diff --git a/src/EditableCell.js b/src/EditableCell.js index d54c93783de80170b8f68a49e802a69093e4ef82..3c084f37da6accd0b1333b928b686f1777be54bb 100644 --- a/src/EditableCell.js +++ b/src/EditableCell.js @@ -1,12 +1,18 @@ import React, { useState } from "react"; import { Form } from "react-bootstrap"; +import { printMoney } from "./util"; +import PriceEditor from "./PriceEditor"; function EditableCell(props) { const [data, setData] = useState(props.value); const [editing, setEditing] = useState(false); + let value = props.value; + if (props.price) { + value = printMoney(props.value); + } if (props.ro || !editing) { - return <td onClick={() => setEditing(true)}>{props.value}</td>; + return <td onClick={() => setEditing(true)}>{value}</td>; } const submit = (e) => { @@ -18,11 +24,15 @@ function EditableCell(props) { return ( <td> <Form onSubmit={submit}> - <Form.Control - value={data} - onChange={(e) => setData(e.target.value)} - onBlur={() => setEditing(false)} - /> + {props.price ? ( + <PriceEditor value={data} onChange={(price) => setData(price)} /> + ) : ( + <Form.Control + value={data} + onChange={(e) => setData(e.target.value)} + onBlur={() => setEditing(false)} + /> + )} </Form> </td> ); diff --git a/src/ProductList.js b/src/ProductList.js index e184d6d2355ed7743655f84dd9e2ec69e3746c39..ea872c3cc9243c53497b871337adf36058079e67 100644 --- a/src/ProductList.js +++ b/src/ProductList.js @@ -4,7 +4,7 @@ import Fetcher from "./Fetcher"; import EditableCell from "./EditableCell"; import ProductAdder from "./ProductAdder"; import AuthContext from "./AuthContext"; -import { printMoney, url } from "./util"; +import { url } from "./util"; class ProductList extends React.Component { static contextType = AuthContext; @@ -34,9 +34,6 @@ class ProductList extends React.Component { case "stock": value = parseInt(value); break; - case "price": - value = value * 100; - break; default: break; } @@ -127,8 +124,9 @@ class ProductList extends React.Component { /> <EditableCell onChange={(v) => this.update(row, "price", v)} - value={printMoney(product.price)} + value={product.price} ro={!isAdmin} + price /> <EditableCell onChange={(v) => this.update(row, "stock", v)}