Input Form Connected with Backend
This commit is contained in:
@@ -11,11 +11,37 @@ export default function InputForm() {
|
|||||||
const [endDate, setEndDate] = useState("");
|
const [endDate, setEndDate] = useState("");
|
||||||
const [courseName, setCourseName] = useState("");
|
const [courseName, setCourseName] = useState("");
|
||||||
|
|
||||||
function onCreateClicked()
|
async function onCreateClicked()
|
||||||
{
|
{
|
||||||
console.log(startDate)
|
let startSplit = startDate.split("-");
|
||||||
console.log(endDate)
|
let endSplit = endDate.split("-");
|
||||||
console.log(courseName)
|
let startYear = parseInt(startSplit[0]);
|
||||||
|
let endYear = parseInt(endSplit[0]);
|
||||||
|
|
||||||
|
let startInternalDate = new Date(startYear, parseInt(startSplit[1]) - 1, parseInt(startSplit[2]) - 1)
|
||||||
|
let endInternalDate = new Date(endYear, parseInt(endSplit[1]) - 1, parseInt(endSplit[2]) - 1)
|
||||||
|
|
||||||
|
let startDayInYear = Math.floor( (startInternalDate - new Date(startYear, 0, 0)) / (1000 * 60 * 60 * 24));
|
||||||
|
let endDayInYear = Math.floor((endInternalDate - new Date(endYear, 0, 0)) / (1000 * 60 * 60 * 24));
|
||||||
|
|
||||||
|
let json = {
|
||||||
|
"id": 0,
|
||||||
|
"startday": startDayInYear,
|
||||||
|
"endday": endDayInYear,
|
||||||
|
"name": courseName,
|
||||||
|
"startyear": startYear,
|
||||||
|
"endyear": endYear
|
||||||
|
}
|
||||||
|
|
||||||
|
let url = "http://localhost:8080/semester?sessionid=" + localStorage.getItem("sessionid");
|
||||||
|
|
||||||
|
await fetch(url, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {"Content-Type": "application/json"},
|
||||||
|
body: JSON.stringify(json)
|
||||||
|
}).then(response => response.json()).then(semester => console.log(semester));
|
||||||
|
|
||||||
|
router.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user