1
0

Created the Input.jsx

This commit is contained in:
Mathias Wagner 2023-11-19 00:20:49 +01:00
parent ede28e3251
commit 00adf52682
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44

View File

@ -0,0 +1,52 @@
import Button from "@/common/components/Button";
import {faPaperPlane, faRightToBracket, faWarning} from "@fortawesome/free-solid-svg-icons";
import {useEffect, useState} from "react";
import {socket} from "@/common/utils/socket.js";
import "./styles.sass";
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
export const Input = ({setState}) => {
const [price, setPrice] = useState(1000);
const [amount, setAmount] = useState(10);
const [error, setError] = useState("");
const submit = () => {
socket.emit("SUBMIT", {price, amount}, (data) => {
if (data) {
setState("waiting");
} else {
setError("Inkorrekte Eingabe");
}
});
}
useEffect(() => {
const timeout = setTimeout(() => {
setError("");
}, 30000);
return () => clearTimeout(timeout);
}, [error]);
return (
<>
{error && <div className="error">
<FontAwesomeIcon icon={faWarning} />
<p>{error}</p>
</div>}
<div className="input-area">
<h3>Preis</h3>
<input type="text" placeholder="Preis" className="glassy"
onChange={(e) => setPrice(e.target.value)} value={price}/>
</div>
<div className="input-area">
<h3>Absatzmenge</h3>
<input type="text" placeholder="Menge" className="glassy"
onChange={(e) => setAmount(e.target.value)} value={amount}/>
</div>
<Button text="Abgeben" onClick={submit} icon={faPaperPlane} />
</>
)
}