Feature für die Umfrage #58

Merged
cami merged 5 commits from feature/umfrage into main 2021-06-26 22:42:00 +00:00
2 changed files with 42 additions and 14 deletions

View file

@ -150,6 +150,17 @@ def register():
)} )}
return ret, 200 return ret, 200
@app.route('/umfrage', methods=['POST'])
@flask_praetorian.auth_required
def survey():
req = flask.request.get_json(force=True)
gender = req.get('gender', None)
print(req)
ret = {'message': 'Umfrage freigestellt'}
return ret, 200
@app.route('/time') @app.route('/time')
def get_current_time(): def get_current_time():
return {'time': time.time()} return {'time': time.time()}

View file

@ -5,6 +5,7 @@ import "../Input.css";
import Footer from "../../Footer"; import Footer from "../../Footer";
import InputField from "../InputField"; import InputField from "../InputField";
import SubmitField from "../SubmitField"; import SubmitField from "../SubmitField";
import { authFetch } from "../../auth/AuthProvider";
export default function Umfrage() { export default function Umfrage() {
const [age, setAge] = useState(""); const [age, setAge] = useState("");
@ -12,6 +13,8 @@ export default function Umfrage() {
const [education, setEducation] = useState(""); const [education, setEducation] = useState("");
const [skills, setSkills] = useState(""); const [skills, setSkills] = useState("");
let surveyIsValid = true;
const onSubmitClick = (e) => { const onSubmitClick = (e) => {
e.preventDefault(); e.preventDefault();
let opts = { let opts = {
@ -20,20 +23,32 @@ export default function Umfrage() {
education: education, education: education,
skills: skills, skills: skills,
}; };
console.log(opts);
/*fetch("/api/login", { if (!Number(age)) {
console.log("age is not a number");
surveyIsValid = false;
}
if (gender === "DEFAULT" || gender === "") {
console.log("choose gender");
surveyIsValid = false;
}
if (education === "DEFAULT" || education === "") {
console.log("choose edu");
surveyIsValid = false;
}
if (skills === "DEFAULT" || skills === "") {
console.log("choose skills");
surveyIsValid = false;
}
if (surveyIsValid === true) {
console.log(opts);
}
authFetch("/umfrage", {
method: "post", method: "post",
body: JSON.stringify(opts), body: JSON.stringify(opts),
}) });
.then((r) => r.json())
.then((token) => {
if (token.access_token) {
login(token);
} else {
console.log("Please type in the correct username / password");
}
});
*/
}; };
const handleAgeChange = (e) => { const handleAgeChange = (e) => {
@ -71,10 +86,11 @@ export default function Umfrage() {
So kann es für mich beispielsweise relevant sein, wenn sämtliche So kann es für mich beispielsweise relevant sein, wenn sämtliche
Teilnehmenden ein sehr gutes Informatikverständnis haben. Teilnehmenden ein sehr gutes Informatikverständnis haben.
</p> </p>
<form id="umfrage" onClick={onSubmitClick}> <form id="umfrage">
<InputField <InputField
InputType="number" InputType="number"
onChange={handleAgeChange} onChange={handleAgeChange}
className="input-field"
LabelName="Wie alt bist du? (Alter in Jahren)" LabelName="Wie alt bist du? (Alter in Jahren)"
/> />
<div className="input-field"> <div className="input-field">
@ -143,6 +159,7 @@ export default function Umfrage() {
InputName="Umfrage abschicken" InputName="Umfrage abschicken"
InputValue="Umfrage abschicken" InputValue="Umfrage abschicken"
LabelName="Umfrage abschicken" LabelName="Umfrage abschicken"
onClick={onSubmitClick}
/> />
</form> </form>
</div> </div>