Skip to content

Commit

Permalink
fix: revert change of default checkbox (#1746)
Browse files Browse the repository at this point in the history
Co-authored-by: Xiao Peng <[email protected]>
  • Loading branch information
xiaopeng0202 and Xiao Peng authored Nov 22, 2024
1 parent c4026c2 commit de21c62
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
1 change: 0 additions & 1 deletion frontend/src/components/ClientAndCodeInput/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ type ClientAndCodeInputProps = {
readOnly?: boolean,
maxInputColSize?: number,
checkBoxInput?: BooleanInputType
shouldSelectDefaultValue?: boolean
}

export default ClientAndCodeInputProps;
27 changes: 9 additions & 18 deletions frontend/src/components/ClientAndCodeInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -38,16 +38,9 @@ const ClientAndCodeInput = ({
const clientInputRef = useRef<HTMLInputElement>(null);
const locCodeInputRef = useRef<HTMLInputElement>(null);
const [isDefault, setIsDefault] = useState<boolean>(
!shouldSelectDefaultValue ? false : () => getIsDefaultVal()
() => getIsDefaultVal()
);

const [isChecked, setIsChecked] = useState<boolean>(() => {
if (!shouldSelectDefaultValue) {
return false;
}
return checkBoxInput ? checkBoxInput.value : isDefault;
});

const [showClientValidationStatus, setShowClientValidationStatus] = useState<boolean>(true);

const [showLocCodeValidationStatus, setShowLocCodeValidationStatus] = useState<boolean>(false);
Expand All @@ -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) {
Expand Down Expand Up @@ -232,8 +222,9 @@ const ClientAndCodeInput = ({
}
: undefined
);
setIsDefault(checked);
setIsChecked(checked);
if (!checkBoxInput) {
setIsDefault(checked);
}
};

const [openAgnTooltip, setOpenAgnTooltip] = useState<boolean>(false);
Expand Down Expand Up @@ -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<HTMLInputElement>) => {
handleDefaultCheckBox(e.target.checked);
}}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/LotApplicantAndInfoForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ const LotApplicantAndInfoForm = ({
}
readOnly={isEdit}
maxInputColSize={6}
shouldSelectDefaultValue
/>
<Row className="agency-email-row">
<Column sm={4} md={8} lg={16} xlg={12}>
Expand Down

0 comments on commit de21c62

Please sign in to comment.