Updated the Input.jsx state
This commit is contained in:
parent
bfd78c0f52
commit
80cc61170a
@ -4,7 +4,7 @@ import {useEffect, useState} from "react";
|
|||||||
import {socket} from "@/common/utils/socket.js";
|
import {socket} from "@/common/utils/socket.js";
|
||||||
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
|
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
|
||||||
|
|
||||||
export const Input = ({setState, capital, setCost, setWin}) => {
|
export const Input = ({setState, capital, setCost, setWin, settings}) => {
|
||||||
|
|
||||||
const [price, setPrice] = useState(1000);
|
const [price, setPrice] = useState(1000);
|
||||||
const [amount, setAmount] = useState(10);
|
const [amount, setAmount] = useState(10);
|
||||||
@ -12,7 +12,7 @@ export const Input = ({setState, capital, setCost, setWin}) => {
|
|||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
|
|
||||||
const submit = () => {
|
const submit = () => {
|
||||||
if ((1000 * amount + 4000) > capital) {
|
if ((settings.costPerCake * amount + settings.costPerRound) > capital) {
|
||||||
setError("Zu wenig Kapital");
|
setError("Zu wenig Kapital");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -36,10 +36,12 @@ export const Input = ({setState, capital, setCost, setWin}) => {
|
|||||||
}, [error]);
|
}, [error]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setCost(1000 * amount + 4000);
|
setCost(settings.costPerCake * amount + settings.costPerRound);
|
||||||
setWin((price * amount) - (1000 * amount + 4000));
|
setWin((price * amount) - (settings.costPerCake * amount + settings.costPerRound));
|
||||||
}, [price, amount]);
|
}, [price, amount]);
|
||||||
|
|
||||||
|
if (!settings || Object.keys(settings).length === 0) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{error && <div className="error">
|
{error && <div className="error">
|
||||||
@ -48,13 +50,13 @@ export const Input = ({setState, capital, setCost, setWin}) => {
|
|||||||
</div>}
|
</div>}
|
||||||
<div className="input-area">
|
<div className="input-area">
|
||||||
<h3>Preis</h3>
|
<h3>Preis</h3>
|
||||||
<input type="number" placeholder="Preis" className="glassy" min={0} max={10000}
|
<input type="number" placeholder="Preis" className="glassy" min={0} max={settings.maxPrice}
|
||||||
onChange={(e) => e.target.value <= 10000 && setPrice(e.target.value)} value={price}/>
|
onChange={(e) => e.target.value <= settings.maxPrice && setPrice(e.target.value)} value={price}/>
|
||||||
</div>
|
</div>
|
||||||
<div className="input-area">
|
<div className="input-area">
|
||||||
<h3>Absatzmenge</h3>
|
<h3>Absatzmenge</h3>
|
||||||
<input type="number" placeholder="Menge" className="glassy" min={1} max={20}
|
<input type="number" placeholder="Menge" className="glassy" min={1} max={settings.maxProduction}
|
||||||
onChange={(e) => e.target.value <= 20 && setAmount(e.target.value)} value={amount}/>
|
onChange={(e) => e.target.value <= settings.maxProduction && setAmount(e.target.value)} value={amount}/>
|
||||||
</div>
|
</div>
|
||||||
<Button text="Abgeben" onClick={submit} icon={faPaperPlane} />
|
<Button text="Abgeben" onClick={submit} icon={faPaperPlane} />
|
||||||
</>
|
</>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user