🚧 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:
parent
8e4e7aa5fc
commit
7e00f24fbd
3 changed files with 17 additions and 5 deletions
38
frontend/src/api/postUserformData.ts
Normal file
38
frontend/src/api/postUserformData.ts
Normal 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;
|
||||
};
|
||||
Reference in a new issue