From de21c62f6ff5c646406f747334997e767fdec01b Mon Sep 17 00:00:00 2001 From: DustyD Date: Thu, 21 Nov 2024 19:35:27 -0800 Subject: [PATCH] fix: revert change of default checkbox (#1746) Co-authored-by: Xiao Peng --- .../ClientAndCodeInput/definitions.ts | 1 - .../components/ClientAndCodeInput/index.tsx | 27 +++++++------------ .../LotApplicantAndInfoForm/index.tsx | 1 - 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/frontend/src/components/ClientAndCodeInput/definitions.ts b/frontend/src/components/ClientAndCodeInput/definitions.ts index 9a1518e35..4e6063f6c 100644 --- a/frontend/src/components/ClientAndCodeInput/definitions.ts +++ b/frontend/src/components/ClientAndCodeInput/definitions.ts @@ -18,7 +18,6 @@ type ClientAndCodeInputProps = { readOnly?: boolean, maxInputColSize?: number, checkBoxInput?: BooleanInputType - shouldSelectDefaultValue?: boolean } export default ClientAndCodeInputProps; diff --git a/frontend/src/components/ClientAndCodeInput/index.tsx b/frontend/src/components/ClientAndCodeInput/index.tsx index 67eedc36c..87993883a 100644 --- a/frontend/src/components/ClientAndCodeInput/index.tsx +++ b/frontend/src/components/ClientAndCodeInput/index.tsx @@ -26,7 +26,7 @@ import './styles.scss'; const ClientAndCodeInput = ({ checkboxId, clientInput, locationCodeInput, textConfig, defaultClientNumber, defaultLocCode, setClientAndCode, readOnly, showCheckbox, maxInputColSize, - checkBoxInput, shouldSelectDefaultValue = false + checkBoxInput }: ClientAndCodeInputProps) => { const getIsDefaultVal = () => ( checkBoxInput === undefined @@ -38,16 +38,9 @@ const ClientAndCodeInput = ({ const clientInputRef = useRef(null); const locCodeInputRef = useRef(null); const [isDefault, setIsDefault] = useState( - !shouldSelectDefaultValue ? false : () => getIsDefaultVal() + () => getIsDefaultVal() ); - const [isChecked, setIsChecked] = useState(() => { - if (!shouldSelectDefaultValue) { - return false; - } - return checkBoxInput ? checkBoxInput.value : isDefault; - }); - const [showClientValidationStatus, setShowClientValidationStatus] = useState(true); const [showLocCodeValidationStatus, setShowLocCodeValidationStatus] = useState(false); @@ -66,10 +59,7 @@ const ClientAndCodeInput = ({ useEffect(() => { const areValsDefault = getIsDefaultVal(); - - if (shouldSelectDefaultValue) { - setIsDefault(areValsDefault); - } + setIsDefault(areValsDefault); // Do not show validation status if isDefault is true if (areValsDefault) { @@ -232,8 +222,9 @@ const ClientAndCodeInput = ({ } : undefined ); - setIsDefault(checked); - setIsChecked(checked); + if (!checkBoxInput) { + setIsDefault(checked); + } }; const [openAgnTooltip, setOpenAgnTooltip] = useState(false); @@ -350,7 +341,7 @@ const ClientAndCodeInput = ({ name={textConfig.useDefaultCheckbox.name} labelText={textConfig.useDefaultCheckbox.labelText} readOnly={readOnly} - checked={isChecked} + checked={checkBoxInput ? checkBoxInput.value : isDefault} onChange={(e: React.ChangeEvent) => { handleDefaultCheckBox(e.target.checked); }} @@ -370,7 +361,7 @@ const ClientAndCodeInput = ({ id={clientInput.id} autoCapitalize="on" labelText={textConfig.agencyInput.titleText} - defaultValue={shouldSelectDefaultValue ? forestClientQuery.data?.acronym : ''} + defaultValue={forestClientQuery.data?.acronym} helperText={ (readOnly || (showCheckbox && isDefault)) ? null @@ -413,7 +404,7 @@ const ClientAndCodeInput = ({ id={locationCodeInput.id} ref={locCodeInputRef} name={textConfig.locationCode.name} - defaultValue={shouldSelectDefaultValue ? locationCodeInput.value : ''} + defaultValue={locationCodeInput.value} type="number" maxCount={LOCATION_CODE_LIMIT} enableCounter diff --git a/frontend/src/components/LotApplicantAndInfoForm/index.tsx b/frontend/src/components/LotApplicantAndInfoForm/index.tsx index 03fb63185..6d81177da 100644 --- a/frontend/src/components/LotApplicantAndInfoForm/index.tsx +++ b/frontend/src/components/LotApplicantAndInfoForm/index.tsx @@ -118,7 +118,6 @@ const LotApplicantAndInfoForm = ({ } readOnly={isEdit} maxInputColSize={6} - shouldSelectDefaultValue />