From 18ee5b18dc3a8639987e67721c757ad8a0c5de22 Mon Sep 17 00:00:00 2001 From: Sayaka Ono Date: Mon, 29 Jul 2024 10:12:43 -0700 Subject: [PATCH 1/2] LF-4351 Set OTHER_PURPOSE_ID in useEffect --- .../ProductCard/index.tsx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/webapp/src/components/Task/AddSoilAmendmentProducts/ProductCard/index.tsx b/packages/webapp/src/components/Task/AddSoilAmendmentProducts/ProductCard/index.tsx index 9475b3bd73..d49b83ec01 100644 --- a/packages/webapp/src/components/Task/AddSoilAmendmentProducts/ProductCard/index.tsx +++ b/packages/webapp/src/components/Task/AddSoilAmendmentProducts/ProductCard/index.tsx @@ -13,7 +13,7 @@ * GNU General Public License for more details, see . */ -import { ReactNode, useRef } from 'react'; +import { ReactNode, useEffect, useRef } from 'react'; import { Controller, useFormContext } from 'react-hook-form'; import { useTranslation } from 'react-i18next'; import { GroupBase, SelectInstance } from 'react-select'; @@ -101,6 +101,7 @@ const SoilAmendmentProductCard = ({ register, watch, setValue, + getValues, formState: { errors }, } = useFormContext(); @@ -120,6 +121,12 @@ const SoilAmendmentProductCard = ({ selectRef?.current?.clearValue(); }; + useEffect(() => { + if (otherPurposeId && !getValues(OTHER_PURPOSE_ID)) { + setValue(OTHER_PURPOSE_ID, otherPurposeId); + } + }, [otherPurposeId]); + return (
{!isReadOnly && onRemove && ( @@ -185,12 +192,7 @@ const SoilAmendmentProductCard = ({ /> )} /> - + {purposes?.includes(otherPurposeId) && ( <> From 4d47fe12a0919c928c5410fc47066f23c7cef4f4 Mon Sep 17 00:00:00 2001 From: Sayaka Ono Date: Mon, 29 Jul 2024 10:17:25 -0700 Subject: [PATCH 2/2] LF-4351 Remove out-dated comment --- .../Task/AddSoilAmendmentProducts/ProductCard/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/webapp/src/components/Task/AddSoilAmendmentProducts/ProductCard/index.tsx b/packages/webapp/src/components/Task/AddSoilAmendmentProducts/ProductCard/index.tsx index d49b83ec01..00fd3ed2f0 100644 --- a/packages/webapp/src/components/Task/AddSoilAmendmentProducts/ProductCard/index.tsx +++ b/packages/webapp/src/components/Task/AddSoilAmendmentProducts/ProductCard/index.tsx @@ -188,7 +188,7 @@ const SoilAmendmentProductCard = ({ const newPurposes = e.map(({ value }) => value); setValue(PURPOSES, newPurposes, { shouldValidate: true }); }} - style={{ paddingBottom: '12px' }} // TODO: remove after adding + style={{ paddingBottom: '12px' }} /> )} />