Skip to content

Commit 5bfdab0

Browse files
committed
Add handlers to RiskQuestionForm
1 parent 96ec205 commit 5bfdab0

File tree

4 files changed

+32
-42
lines changed

4 files changed

+32
-42
lines changed

src/__SEED__/risk_questions.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,7 @@
4545
]
4646
},
4747
"warnings": [],
48-
"validation": [
49-
{
50-
"required": true,
51-
"message": "You must select an option"
52-
}
53-
],
48+
"validation": [],
5449
"next": [
5550
{
5651
"equals": "YES",

src/components/QuestionForm/formik-v2/types/index.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
FunctionComponent,
3-
HTMLAttributeAnchorTarget,
4-
ReactElement,
5-
} from "react";
1+
import { FunctionComponent, HTMLAttributeAnchorTarget } from "react";
62
import { Rule } from "async-validator";
73

84
import { DynamicTextParagraph } from "../../../DynamicText/DynamicText.types";
@@ -96,10 +92,7 @@ export enum SupportedFormField {
9692
export type QuestionFormSubmission = Record<string, string | undefined>;
9793

9894
export interface QuestionFormProps extends QuestionSchema {
99-
fields: Record<
100-
SupportedFormField,
101-
FunctionComponent<QuestionFieldWrapperProps<any>>
102-
>;
95+
fields: Record<SupportedFormField, FunctionComponent<QuestionFieldWrapperProps<any>>>;
10396
questionFieldUI?: FunctionComponent<any>;
10497
initialValues?: QuestionFormSubmission;
10598
className?: string;
@@ -131,8 +124,9 @@ export type QuestionFieldManagerProps = {
131124
export type QuestionFieldProps = {
132125
fields: QuestionFormProps["fields"];
133126
question: Question<QuestionFieldProperties>;
134-
previousQuestion: Question<QuestionFieldProperties> | undefined;
135-
nextQuestion: Question<QuestionFieldProperties> | undefined;
127+
questions: Question<QuestionFieldProperties>[];
128+
previousQuestion: Question<QuestionFieldProperties> | undefined; // TODO: determine if this prop is necessary?
129+
nextQuestion: Question<QuestionFieldProperties> | undefined; // TODO: determine if this prop is necessary?
136130
questionFieldUI: QuestionFormProps["questionFieldUI"];
137131
onSubmitFormCallback: () => void;
138132
onEndFormCallback: () => void;
@@ -173,9 +167,7 @@ export type NextQuestionButtonProperties = {
173167
};
174168

175169
export type ButtonGroupProperties = {
176-
buttons: Question<
177-
LinkButtonProperties | NextQuestionButtonProperties | SubmitButtonProperties
178-
>[];
170+
buttons: Question<LinkButtonProperties | NextQuestionButtonProperties | SubmitButtonProperties>[];
179171
};
180172

181173
export type PromptProperties = {

src/components/RiskQuestionForm/RiskQuestionForm.component.tsx

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import SubmitButtonFieldWrapper from "../fields/v2/field-wrappers/SubmitButton";
1717
import SectionBlockFieldWrapper from "components/fields/v2/field-wrappers/SectionBlock";
1818

1919
/* Types */
20-
import { QuestionFormProps } from "../QuestionForm/formik-v2/types";
20+
import { QuestionFormProps, QuestionFormSubmission } from "../QuestionForm/formik-v2/types";
2121

2222
import { RiskQuestionFormProps } from "./RiskQuestionForm.types";
2323

@@ -33,36 +33,39 @@ const fields: QuestionFormProps["fields"] = {
3333
SectionBlock: SectionBlockFieldWrapper,
3434
};
3535

36-
const QuestionFieldUI: FC<{ children: ReactElement | ReactElement[] }> = ({
37-
children,
38-
}) => (
39-
<Box
40-
bg="white"
41-
borderWidth="1px"
42-
borderRadius="lg"
43-
boxShadow="xl"
44-
padding={6}
45-
margin={6}
46-
width={800}
47-
>
36+
const QuestionFieldUI: FC<{ children: ReactElement | ReactElement[] }> = ({ children }) => (
37+
<Box bg="white" borderWidth="1px" borderRadius="lg" boxShadow="xl" padding={6} margin={6} width={800}>
4838
{children}
4939
</Box>
5040
);
5141

52-
export const RiskQuestionForm: FC<RiskQuestionFormProps> = ({
53-
initialValues,
54-
schema,
55-
onSubmitCallback,
56-
onEndFormCallback,
57-
}) => {
42+
export const RiskQuestionForm: FC<RiskQuestionFormProps> = ({ initialValues, schema, onSubmitCallback, onEndFormCallback }) => {
43+
const handleSubmit = (values: QuestionFormSubmission) => {
44+
console.log("*** SUBMITTED ***", {
45+
source: "ONLINE",
46+
guided_question: schema.miscellaneous.guided_question,
47+
answers: Object.entries(values).map(([k, v]: [string, string | undefined]) => ({ name: k, answer: v })),
48+
});
49+
onSubmitCallback({
50+
source: "ONLINE",
51+
guided_question: schema.miscellaneous.guided_question,
52+
answers: Object.entries(values).map(([k, v]: [string, string | undefined]) => ({ name: k, answer: v })),
53+
});
54+
};
55+
56+
const handleEndForm = () => {
57+
console.log("*** ENDED ***");
58+
onEndFormCallback();
59+
};
60+
5861
return (
5962
<Flex flex={1} flexDir="column" alignItems="center">
6063
<QuestionForm
6164
fields={fields}
6265
questionFieldUI={QuestionFieldUI}
6366
initialValues={initialValues}
64-
onSubmitCallback={console.log}
65-
onEndFormCallback={console.log}
67+
onSubmitCallback={handleSubmit}
68+
onEndFormCallback={handleEndForm}
6669
{...schema}
6770
questions={schema.questions.map((q) => ({ ...q, ui: true }))}
6871
/>

src/components/RiskQuestionForm/RiskQuestionForm.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface RiskQuestionFormProps {
99
schema: RiskQuestionFormSchema;
1010
initialValues?: Record<string, string | undefined>;
1111
onSubmitCallback: (results: RiskQuestionFormPayload) => void;
12-
onEndFormCallback: (results: Record<string, string | undefined>) => void;
12+
onEndFormCallback: () => void;
1313
}
1414

1515
export type RiskQuestionFormPayload = {

0 commit comments

Comments
 (0)