From ee94923ffbe84361d1b8d219a8ed2e1d7a08e6a2 Mon Sep 17 00:00:00 2001 From: ks129 <45097959+ks129@users.noreply.github.com> Date: Mon, 8 Feb 2021 17:55:46 +0200 Subject: Improve submit data gathering --- src/pages/FormPage.tsx | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/pages/FormPage.tsx b/src/pages/FormPage.tsx index e8d1a4b..ab74be9 100644 --- a/src/pages/FormPage.tsx +++ b/src/pages/FormPage.tsx @@ -229,10 +229,9 @@ function FormPage(): JSX.Element { setSending(true); - const answers = {}; + const answers: { [key: string]: unknown } = {}; questions.forEach(prop => { - const question = prop.props.question; - const options: string | string[] = prop.props.question.data["options"]; + const question: Question = prop.props.question; // TODO: Parse input from each question, and submit switch (question.type) { @@ -240,16 +239,12 @@ function FormPage(): JSX.Element { answers[question.id] = false; break; - case QuestionType.Code: - answers[question.id] = ""; - break; - case QuestionType.Checkbox: { - const parsed = new Map(); + const parsed: { [key: string]: unknown } = {}; - prop.props.public_state.forEach((value, key) => { + prop.props.public_state.forEach((value: unknown, key: string) => { if (key !== "valid" && key !== "error") { - answers.set(key.slice(6), value); + parsed[key.slice(6)] = value; } }); @@ -257,6 +252,7 @@ function FormPage(): JSX.Element { break; } + case QuestionType.Code: default: answers[question.id] = prop.props.public_state.get("value"); } -- cgit v1.2.3