From 884e7cfc5b095e40b9e230e0fc88c85f309221d7 Mon Sep 17 00:00:00 2001 From: nasaownsky Date: Fri, 29 Nov 2024 17:00:18 +0400 Subject: [PATCH] Fix data source questions bugs --- .../CheckboxOptions.styles.tsx | 1 - .../CheckboxOptions/CheckboxOptions.tsx | 10 ++++-- .../AgencySettingsDataSource.tsx | 31 +++++++++++++------ 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/common/components/CheckboxOptions/CheckboxOptions.styles.tsx b/common/components/CheckboxOptions/CheckboxOptions.styles.tsx index 85b3ec5d4..601424772 100644 --- a/common/components/CheckboxOptions/CheckboxOptions.styles.tsx +++ b/common/components/CheckboxOptions/CheckboxOptions.styles.tsx @@ -34,7 +34,6 @@ export const CheckboxLabel = styled.div` display: flex; align-items: center; gap: 8px; - text-transform: capitalize; `; export const Checkbox = styled.input` diff --git a/common/components/CheckboxOptions/CheckboxOptions.tsx b/common/components/CheckboxOptions/CheckboxOptions.tsx index 65f67ece3..c5692ebe0 100644 --- a/common/components/CheckboxOptions/CheckboxOptions.tsx +++ b/common/components/CheckboxOptions/CheckboxOptions.tsx @@ -47,7 +47,9 @@ export const CheckboxOptions: React.FC = ({ options, onChange, }) => { - const [otherDescriptionValue, setOtherDescriptionValue] = useState(""); + const [otherDescriptionValue, setOtherDescriptionValue] = useState< + string | null + >(null); return ( @@ -88,7 +90,11 @@ export const CheckboxOptions: React.FC = ({ 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); diff --git a/publisher/src/components/AgencySettings/AgencySettingsDataSource.tsx b/publisher/src/components/AgencySettings/AgencySettingsDataSource.tsx index 08c6e4e39..1d44831c5 100644 --- a/publisher/src/components/AgencySettings/AgencySettingsDataSource.tsx +++ b/publisher/src/components/AgencySettings/AgencySettingsDataSource.tsx @@ -164,16 +164,29 @@ 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) { + setCurrentKey(""); + updatedSetting[sourceType][settingType].value = ""; + } else { + if (key !== "CURRENT_AGENCY") { + updatedSetting[sourceType].collection_method.value = ""; + if (key !== "OTHER") { + updatedSetting[sourceType].collection_method.other_description = ""; + } + } + if (key !== "OTHER_AGENCY_OR_SYSTEM") { + updatedSetting[sourceType].modification.value = ""; + if (key !== "OTHER") { + updatedSetting[sourceType].modification.other_description = ""; + } + } + if (key !== "OTHER") { + updatedSetting[sourceType][settingType].other_description = ""; + } + + setCurrentKey(key); + updatedSetting[sourceType][settingType].value = key; } - updatedSetting[sourceType][settingType].value = key; }; return (