🚧 started on question-form

Co-authored-by: haraldnilsen <harald_998@hotmail.com>
Signed-off-by: Sindre Kjelsrud <kjelsrudsindre@gmail.com>
This commit is contained in:
Sindre Kjelsrud 2024-01-04 18:23:45 +01:00
parent 8e4e7aa5fc
commit 7e00f24fbd
Signed by: sidski
GPG key ID: D2BBDF3EDE6BA9A6
3 changed files with 17 additions and 5 deletions

View file

@ -0,0 +1,38 @@
interface postUserformDataReponse {
respondentID: number;
}
export const postUserformData = (
age: string,
education: string,
healthcare_personnel: string,
gender: string
): postUserformDataReponse => {
let url = "http://localhost:8080/submitform";
let personnel = healthcare_personnel == "Ja" ? true : false;
const response = fetch(url, {
method: "POST",
body: JSON.stringify({
age: age,
education: education,
healthcare_personnel: personnel,
gender: gender,
}),
})
.then((response) => {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
return response.json();
})
.then((data) => {
console.log(data);
localStorage.setItem("RespondentId", data);
return data;
})
.catch((error) => {
console.log(error);
});
return response;
};