Created the Input.jsx
This commit is contained in:
parent
ede28e3251
commit
00adf52682
52
client/src/pages/Join/states/Input/Input.jsx
Normal file
52
client/src/pages/Join/states/Input/Input.jsx
Normal 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} />
|
||||
</>
|
||||
)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user