Új adat felvitele
This commit is contained in:
1 parent
eb79e3557e
commit
55ccd302a9
2 files changed
+41
-1
No files matched your search
@@ -95,6 +95,12 @@
|
||||
"name": "Green Eye",
|
||||
"roast": "Light",
|
||||
"price": 810
|
||||
},
|
||||
{
|
||||
"id": "sm_VqzuyNpM",
|
||||
"name": "kotyogós",
|
||||
"roast": "dark",
|
||||
"price": "720"
|
||||
}
|
||||
],
|
||||
"$schema": "./node_modules/json-server/schema.json"
|
||||
|
||||
@@ -1,8 +1,42 @@
|
||||
|
||||
import { useState } from "react"
|
||||
|
||||
function CoffeeForm() {
|
||||
const[id,setId]=useState("");
|
||||
const[name,setName]=useState("");
|
||||
const[roast,setRoast]=useState("");
|
||||
const[price,setPrice]=useState("");
|
||||
|
||||
const adatkuldes=(adatok)=>{
|
||||
fetch('http://localhost:3000/coffees',{
|
||||
method:'POST',
|
||||
headers:{
|
||||
"Content-type":"application/json"
|
||||
},
|
||||
body:JSON.stringify(adatok)
|
||||
})
|
||||
.then(res=>res.text())
|
||||
.then(adat=>alert(adat))
|
||||
.catch(err=>alert(err));
|
||||
|
||||
}
|
||||
|
||||
const onSubmit=(e)=>{
|
||||
e.preventDefault();
|
||||
adatkuldes({id,name,roast,price});
|
||||
}
|
||||
|
||||
return (
|
||||
<div>CoffeeForm</div>
|
||||
<div>
|
||||
<h1 className="text-2xl text-center font-bold">Új kávé rögzítése</h1>
|
||||
<form className="flex flex-col items-center justify-center" onSubmit={onSubmit}>
|
||||
<input type="text" required value={id} onChange={(e)=>setId(e.target.value)} placeholder="Id" className="input m-2" />
|
||||
<input type="text" required value={name} onChange={(e)=>setName(e.target.value)} placeholder="Name" className="input m-2" />
|
||||
<input type="text" required value={roast} onChange={(e)=>setRoast(e.target.value)} placeholder="Roast" className="input m-2" />
|
||||
<input type="text" required value={price} onChange={(e)=>setPrice(e.target.value)} placeholder="Price" className="input m-2" />
|
||||
<button className="btn btn-primary">Küldés</button>
|
||||
</form>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user