From 8b2a30254b81fdf25da1cb25c0e865a42e0e83a3 Mon Sep 17 00:00:00 2001 From: Dave Armstrong Date: Fri, 22 Jul 2022 13:27:07 -0500 Subject: [PATCH 1/3] PROD-2441 #comment clearing bug hunt form on new form #time 1h --- .../intake-forms/bug-hunt/BugHuntIntakeForm.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src-ts/tools/work/work-self-service/intake-forms/bug-hunt/BugHuntIntakeForm.tsx b/src-ts/tools/work/work-self-service/intake-forms/bug-hunt/BugHuntIntakeForm.tsx index 8910c8c3b..066a695b0 100644 --- a/src-ts/tools/work/work-self-service/intake-forms/bug-hunt/BugHuntIntakeForm.tsx +++ b/src-ts/tools/work/work-self-service/intake-forms/bug-hunt/BugHuntIntakeForm.tsx @@ -5,8 +5,10 @@ import { Form, FormAction, FormDefinition, + formGetInputFields, formGetInputModel, FormInputModel, + formOnReset, IconOutline, InfoCard, LoadingSpinner, @@ -66,6 +68,11 @@ const BugHuntIntakeForm: React.FC = () => { const [selectedPackage, setSelectedPackage]: [PricePackageName, Dispatch>] = useState(formValues.packageType) + const formInputs: Array = formGetInputFields(formDef.groups) + if (!workId && !challenge) { + formOnReset(formInputs, formValues) + } + useEffect(() => { const useEffectAsync: () => Promise = async () => { if (!workId) { From 88b6b86e89de138095ed09402a1f1f1ba10a41bf Mon Sep 17 00:00:00 2001 From: Dave Armstrong Date: Fri, 22 Jul 2022 13:39:00 -0500 Subject: [PATCH 2/3] validation bugfix --- src-ts/lib/form/Form.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src-ts/lib/form/Form.tsx b/src-ts/lib/form/Form.tsx index 7def56566..b648ec492 100644 --- a/src-ts/lib/form/Form.tsx +++ b/src-ts/lib/form/Form.tsx @@ -57,13 +57,22 @@ const Form: (props: FormProps, Dispatch>>] = useState>(formGetInputFields(formDef.groups || [])) const [isFormInvalid, setFormInvalid]: [boolean, Dispatch] = useState(inputs.filter(item => !!item.error).length > 0) + + useEffect(() => { + if (!formRef.current?.elements) { + return + } + + validateForm(formRef.current?.elements, 'initial', inputs) + checkIfFormIsValid(inputs) + }, []) + useEffect(() => { if (!formRef.current?.elements) { return } - // validators do not clear errors on the 'initial' event, - // so we call validateForm as a change here, to support the parent component sending props.formValues updates due to async data loading + // so we repeat the validation when formValues changes, to support the parent component's async data loading validateForm(formRef.current?.elements, 'change', inputs) checkIfFormIsValid(inputs) }, [props.formValues]) From 56f434aceddab7b014c9350d6b74008ba8aa967a Mon Sep 17 00:00:00 2001 From: Dave Armstrong Date: Fri, 22 Jul 2022 13:40:39 -0500 Subject: [PATCH 3/3] linter fix --- src-ts/lib/form/Form.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src-ts/lib/form/Form.tsx b/src-ts/lib/form/Form.tsx index b648ec492..fa7445cb1 100644 --- a/src-ts/lib/form/Form.tsx +++ b/src-ts/lib/form/Form.tsx @@ -57,7 +57,6 @@ const Form: (props: FormProps, Dispatch>>] = useState>(formGetInputFields(formDef.groups || [])) const [isFormInvalid, setFormInvalid]: [boolean, Dispatch] = useState(inputs.filter(item => !!item.error).length > 0) - useEffect(() => { if (!formRef.current?.elements) { return