Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Publisher][Agency Settings] Fix data source questions bugs #1600

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading