From f7d169be5afd333be572c802414b8d6eba185d9b Mon Sep 17 00:00:00 2001 From: BeritJanssen Date: Tue, 15 Oct 2024 16:04:26 +0200 Subject: [PATCH] fix #1310: FeedbackForm calls makeResult --- .../components/FeedbackForm/FeedbackForm.tsx | 32 ++++--------------- frontend/src/components/Trial/Trial.test.tsx | 5 +-- frontend/src/components/Trial/Trial.tsx | 3 +- 3 files changed, 11 insertions(+), 29 deletions(-) diff --git a/frontend/src/components/FeedbackForm/FeedbackForm.tsx b/frontend/src/components/FeedbackForm/FeedbackForm.tsx index 8dab41173..6d45bc750 100644 --- a/frontend/src/components/FeedbackForm/FeedbackForm.tsx +++ b/frontend/src/components/FeedbackForm/FeedbackForm.tsx @@ -1,9 +1,9 @@ -import { useState, useRef } from "react"; +import { useState } from "react"; import Question from "../Question/Question"; import Button from "../Button/Button"; import IQuestion from "@/types/Question"; -import { OnResultType } from "@/hooks/useResultHandler"; +import { submitResultType } from "@/hooks/useResultHandler"; interface FeedbackFormProps { formActive: boolean; @@ -11,8 +11,7 @@ interface FeedbackFormProps { buttonLabel: string; skipLabel: string; isSkippable: boolean; - onResult: OnResultType - onNext: () => void; + submitResult: submitResultType emphasizeTitle?: boolean; } @@ -23,35 +22,18 @@ const FeedbackForm = ({ buttonLabel, skipLabel, isSkippable, - onResult, - onNext, + submitResult, emphasizeTitle = false, }: FeedbackFormProps) => { - const isSubmitted = useRef(false); const showSubmitButtons = form.filter((formElement) => formElement.submits).length === 0; const [formValid, setFormValid] = useState(false); - const onSubmit = async () => { - // Prevent double submit - if (isSubmitted.current) { - return; - } - isSubmitted.current = true; - - // Callback onResult with question data - await onResult({ - form, - }); - - onNext(); - }; - const onChange = (value: string | number | boolean, question_index: number) => { form[question_index].value = value; if (form[question_index].submits) { - onSubmit(); + submitResult(); } // for every non-skippable question, check that we have a value const validFormElements = form.filter(formElement => { @@ -93,7 +75,7 @@ const FeedbackForm = ({ // skip button