Skip to content
Snippets Groups Projects
Unverified Commit f2feb9d0 authored by meskio's avatar meskio :tent:
Browse files

Display correctly new inventary entries

parent 058ad779
No related branches found
No related tags found
No related merge requests found
import React, { useState } from "react";
import { Redirect } from "react-router-dom";
import { Form, Row, Col, Button } from "react-bootstrap";
import ProductPicker from "../product/ProductPicker";
import Fetcher from "../Fetcher";
......@@ -13,16 +12,18 @@ function supplierNameToId(suppliers, name) {
return null;
}
function CreateInventary() {
function CreateInventary(props) {
const [suppliers, setSuppliers] = useState([]);
const [comment, setComment] = useState("");
const [supplier, setSupplier] = useState(null);
const [picks, setPicks] = useState([]);
const [redirect, setRedirect] = useState(null);
if (redirect !== null) {
return <Redirect to={"/inventary/" + redirect.ID} />;
}
const onSuccess = (entry) => {
setComment("");
setSupplier(null);
setPicks([]);
props.setEntry(entry);
};
const body = () => {
return {
......@@ -38,14 +39,14 @@ function CreateInventary() {
};
};
const disabled = picks.length == 0;
const disabled = picks.length === 0;
const supplierOptions = [<option key=""></option>].concat(
suppliers.map((s) => <option key={s.ID}>{s.name}</option>)
);
return (
<Sender url="/api/inventary" body={body} onSuccess={setRedirect}>
<Sender url="/api/inventary" body={body} onSuccess={onSuccess}>
<Form.Group as={Row}>
<Form.Label as="legend" column sm={3}>
Proveedor
......
......@@ -6,16 +6,10 @@ import Fetcher from "../Fetcher";
function Inventary() {
const [inventary, setInventary] = useState([]);
const setEntry = (entry) => {
let i = inventary;
i.push(entry);
setInventary(i);
};
return (
<div>
<h2 className="text-center">Entradas de Almacén</h2>
<CreateInventary setEntry={setEntry} />
<CreateInventary setEntry={(e) => setInventary([e, ...inventary])} />
<hr />
<Fetcher url="/api/inventary" onFetch={setInventary}>
......
......@@ -40,7 +40,7 @@ function InventaryList(props) {
<tr>
<td>{printInventaryID(i)}</td>
<td>{printDate(i.date)}</td>
<td>{i.member.name}</td>
<td>{i.member && i.member.name}</td>
<td>{supplier(i)}</td>
</tr>
</LinkContainer>
......
......@@ -15,13 +15,13 @@ class ProductPicker extends React.Component {
}
delPick(index) {
let picks = this.props.picks;
let picks = [...this.props.picks];
picks.splice(index, 1);
this.props.setPicks(picks);
}
setAmount(index, amount) {
let picks = this.props.picks;
let picks = [...this.props.picks];
picks[index].amount = parseInt(amount);
this.props.setPicks(picks);
// trick it to redraw on each change
......@@ -29,7 +29,7 @@ class ProductPicker extends React.Component {
}
setPrice(index, price) {
let picks = this.props.picks;
let picks = [...this.props.picks];
picks[index].price = price;
this.props.setPicks(picks);
}
......@@ -45,7 +45,7 @@ class ProductPicker extends React.Component {
}
pickProduct(product) {
let picks = this.props.picks;
let picks = [...this.props.picks];
if (picks.find((p) => product.code === p.code)) {
return;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment