Input Form Connected with Backend

This commit is contained in:
brausjonas
2023-05-16 22:47:45 +02:00
parent b1ede8005d
commit ce38765fe1
3 changed files with 39364 additions and 4 deletions
+30 -4
View File
@@ -11,11 +11,37 @@ export default function InputForm() {
const [endDate, setEndDate] = useState("");
const [courseName, setCourseName] = useState("");
function onCreateClicked()
async function onCreateClicked()
{
console.log(startDate)
console.log(endDate)
console.log(courseName)
let startSplit = startDate.split("-");
let endSplit = endDate.split("-");
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 (
Binary file not shown.
File diff suppressed because it is too large Load Diff