Skip to content

Commit

Permalink
[Publisher][Agency Settings] Fix data source questions bugs (#1600)
Browse files Browse the repository at this point in the history
* Fix data source questions bugs

* Add comments describing checkbox check/uncheck handling
  • Loading branch information
nasaownsky authored Dec 3, 2024
1 parent 92fa396 commit d281bb5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export const CheckboxLabel = styled.div`
display: flex;
align-items: center;
gap: 8px;
text-transform: capitalize;
`;

export const Checkbox = styled.input`
Expand Down
10 changes: 8 additions & 2 deletions common/components/CheckboxOptions/CheckboxOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ export const CheckboxOptions: React.FC<CheckboxOptionsProps> = ({
options,
onChange,
}) => {
const [otherDescriptionValue, setOtherDescriptionValue] = useState("");
const [otherDescriptionValue, setOtherDescriptionValue] = useState<
string | null
>(null);

return (
<Styled.CheckboxContainer>
Expand Down Expand Up @@ -88,7 +90,11 @@ export const CheckboxOptions: React.FC<CheckboxOptionsProps> = ({
otherDescription.placeholder ||
"Please provide additional information..."
}
value={otherDescriptionValue || otherDescription.value}
value={
otherDescriptionValue !== null
? otherDescriptionValue
: otherDescription.value || ""
}
onChange={(e) => {
setOtherDescriptionValue(e.target.value);
otherDescription.onChange(e.target.value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,36 @@ const QuestionCheckboxBlock: React.FC<{
};

const handleChange = (key: string) => {
if (key !== "CURRENT_AGENCY") {
updatedSetting[sourceType].collection_method.value = "";
}
if (key !== "OTHER_AGENCY_OR_SYSTEM") {
updatedSetting[sourceType].modification.value = "";
}
if (key !== "OTHER") {
updatedSetting[sourceType][settingType].other_description = "";
if (currentKey === key) {
// this handles checkbox unchecking
setCurrentKey("");
updatedSetting[sourceType][settingType].value = "";
} else {
// this handles unchecking collection method checkbox & removing other description value of collection method
// if we uncheck "Data is collected directly by the agency" question
if (key !== "CURRENT_AGENCY") {
updatedSetting[sourceType].collection_method.value = "";
if (key !== "OTHER") {
updatedSetting[sourceType].collection_method.other_description = "";
}
}
// this handles unchecking modification checkbox & removing other description value of modification
// if we uncheck "Data is received from another agency or data system" question
if (key !== "OTHER_AGENCY_OR_SYSTEM") {
updatedSetting[sourceType].modification.value = "";
if (key !== "OTHER") {
updatedSetting[sourceType].modification.other_description = "";
}
}
// this handles removing general other description value if we unckeck Other checkbox
if (key !== "OTHER") {
updatedSetting[sourceType][settingType].other_description = "";
}

// this handles checkbox checking
setCurrentKey(key);
updatedSetting[sourceType][settingType].value = key;
}
updatedSetting[sourceType][settingType].value = key;
};

return (
Expand Down

0 comments on commit d281bb5

Please sign in to comment.