From d168b0c87ea84adcb290a62b8a644f8bc24ce6f3 Mon Sep 17 00:00:00 2001 From: cami Date: Fri, 23 Jul 2021 01:00:14 +0200 Subject: [PATCH] Add errormessage if username or password are not correct --- frontend/src/components/pages/Study.jsx | 42 +++++++++++++++++++------ 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/frontend/src/components/pages/Study.jsx b/frontend/src/components/pages/Study.jsx index dec7bc3..2694809 100644 --- a/frontend/src/components/pages/Study.jsx +++ b/frontend/src/components/pages/Study.jsx @@ -3,6 +3,7 @@ import "../../App.css"; import Footer from "../../Footer"; import InputField from "../InputField"; import SubmitField from "../SubmitField"; +import ErrorMessage from "../ErrorMessage"; import { Logger } from "@behametrics/logger-web"; import { Button } from "../Button"; import BehaviorStudyInfo from "../BehaviorStudyInfo"; @@ -24,6 +25,10 @@ export default function Study() { END: "end", }; const [state, setState] = useState(STATES.START); + const [isInputCorrect, setIsInputCorrect] = useState(true); + + const errorText = + "Das Passwort und der Benutzername stimmen nicht überein. Bitte prüfen Sie, dass Sie das Passwort richtig abgetippt und den Benutzernamen richtig eingegeben haben."; useEffect(() => { _logger.current = new Logger({ @@ -109,28 +114,44 @@ export default function Study() { handleLoggerOn(); }; + const resetInputValues = () => { + let inputElements = document.querySelectorAll('div input:not([type="submit"])'); + for (let i=0; i < inputElements.length; i++){ + inputElements[i].value = "" + + } + }; + const handleClickAtStepNormal = () => { if (checkIfValuesAreCorrect()) { receiveRandomPassword(); + setIsInputCorrect(true); setState(STATES.PHONE); + } else { + setIsInputCorrect(false); + resetInputValues(); } }; const handleClickAtStepPhone = () => { if (checkIfValuesAreCorrect()) { receiveRandomPassword(); + setIsInputCorrect(true); setState(STATES.STANDING); } else { - console.log("Passwort und Benutzername stimmen nicht."); + setIsInputCorrect(false); + resetInputValues(); } }; const handleClickAtStepStanding = () => { if (checkIfValuesAreCorrect()) { + setIsInputCorrect(true); setState(STATES.END); handleLoggerOff(); } else { - console.log("Passwort und Benutzername stimmen nicht."); + setIsInputCorrect(false); + resetInputValues(); } }; @@ -151,8 +172,9 @@ export default function Study() { const study_normal = ( <> - -
+ + {!isInputCorrect && } +
- +
); const study_phone = ( <> -
+ {!isInputCorrect && } +
- +
); const study_standing = ( <> -
+ {!isInputCorrect && } +
- +
);