Use const for survey validity and change smaller things
This commit is contained in:
parent
6e9219fa7c
commit
0ecb73cbe7
1 changed files with 12 additions and 11 deletions
|
@ -27,7 +27,8 @@ export default function Umfrage() {
|
|||
const [isEducationOk, setIsEducationOk] = useState("");
|
||||
const [isSkillsOk, setIsSkillsOk] = useState("");
|
||||
|
||||
let surveyIsValid = true;
|
||||
/* genereal check if survey is valid */
|
||||
const [isSurveyValid, setIsSurveyValid] = useState("");
|
||||
|
||||
const onSubmitClick = (e) => {
|
||||
e.preventDefault();
|
||||
|
@ -38,39 +39,39 @@ export default function Umfrage() {
|
|||
skills: skills,
|
||||
};
|
||||
|
||||
setIsAgeOk(true)
|
||||
setIsGenderOk(true)
|
||||
setIsEducationOk(true)
|
||||
setIsSkillsOk(true)
|
||||
setIsAgeOk(true);
|
||||
setIsGenderOk(true);
|
||||
setIsEducationOk(true);
|
||||
setIsSkillsOk(true);
|
||||
|
||||
if (!Number(age)) {
|
||||
setAgeErrorMessage("Das Alter muss als Zahl angegeben werden.");
|
||||
surveyIsValid = false;
|
||||
setIsSurveyValid(false);
|
||||
setIsAgeOk(false);
|
||||
}
|
||||
if (gender === "DEFAULT" || gender === "") {
|
||||
setGenderErrorMessage(
|
||||
"Bitte wähle eine der Optionen für dein Geschlecht aus."
|
||||
);
|
||||
surveyIsValid = false;
|
||||
setIsSurveyValid(false);
|
||||
setIsGenderOk(false);
|
||||
}
|
||||
if (education === "DEFAULT" || education === "") {
|
||||
setEducationErrorMessage(
|
||||
"Bitte wähle eine der Optionen zu deiner Ausbildung aus."
|
||||
);
|
||||
surveyIsValid = false;
|
||||
setIsSurveyValid(false);
|
||||
setIsEducationOk(false);
|
||||
}
|
||||
if (skills === "DEFAULT" || skills === "") {
|
||||
setSkillsErrorMessage(
|
||||
"Bitte wähle eine der Optionen zu den Fähigkeiten aus"
|
||||
);
|
||||
surveyIsValid = false;
|
||||
setIsSurveyValid(false);
|
||||
setIsSkillsOk(false);
|
||||
}
|
||||
|
||||
if (surveyIsValid === true) {
|
||||
if (isSurveyValid === true) {
|
||||
authFetch("/api/protected/umfrage", {
|
||||
method: "post",
|
||||
body: JSON.stringify(opts),
|
||||
|
@ -164,7 +165,7 @@ export default function Umfrage() {
|
|||
<option>Keine Angabe</option>
|
||||
</select>
|
||||
</div>
|
||||
{!isEducationOk && <ErrorMessage message={genderErrorMessage} />}
|
||||
{!isEducationOk && <ErrorMessage message={educationErrorMessage} />}
|
||||
<div className="input-field">
|
||||
<label htmlFor="itskills">
|
||||
Wie schätzt du deine Kompetenzen im Bereich der Informatik als
|
||||
|
|
Loading…
Reference in a new issue