Skip to content

Commit

Permalink
fix: additional extra chars
Browse files Browse the repository at this point in the history
  • Loading branch information
emilyjablonski committed Feb 6, 2024
1 parent 39875ab commit 0589570
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 9 deletions.
17 changes: 13 additions & 4 deletions shared-helpers/src/views/multiselectQuestions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export const fieldName = (
applicationSection: ApplicationSection,
optionName?: string
) => {
return `application.${applicationSection}.${questionName?.replace(/'/g, "")}${
optionName ? `.${optionName?.replace(/'/g, "")}` : ""
return `application.${applicationSection}.${questionName?.replace(/\.|,|'/g, "")}${
optionName ? `.${optionName?.replace(/\.|,|'/g, "")}` : ""
}`
}

Expand Down Expand Up @@ -343,7 +343,7 @@ export const mapCheckboxesToApi = (
question: MultiselectQuestion,
applicationSection: ApplicationSection
): ApplicationMultiselectQuestion => {
const data = formData["application"][applicationSection][question.text.replace(/'/g, "")]
const data = formData["application"][applicationSection][question.text.replace(/\.|,|'/g, "")]
const claimed = !!Object.keys(data).filter((key) => data[key] === true).length

const addressFields = Object.keys(data).filter((option) => Object.keys(data[option]))
Expand Down Expand Up @@ -378,8 +378,17 @@ export const mapCheckboxesToApi = (
}
}

const getFinalKey = () => {
const optionKey = question?.options?.find(
(elem) => elem.text.replace(/\.|,|'/g, "") === key
)?.text
const cleanOptOutKey = question?.optOutText?.replace(/\.|,|'/g, "")
if (cleanOptOutKey === key) return question?.optOutText || key
return optionKey || key
}

return {
key,
key: getFinalKey(),
mapPinPosition: data?.[`${key}-mapPinPosition`],
checked: data[key] === true,
extraData: extraData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ const FormMultiselectQuestions = ({
questions?.forEach((listingQuestion) =>
listingQuestion?.multiselectQuestion.options.forEach((option) =>
keys.push(
fieldName(listingQuestion?.multiselectQuestion.text, applicationSection, option.text)
fieldName(
listingQuestion?.multiselectQuestion.text,
applicationSection,
option.text.replace(/\.|,|'/g, "")
)
)
)
)
Expand All @@ -68,7 +72,11 @@ const FormMultiselectQuestions = ({
const watchQuestions = watch(allOptionFieldNames)

const getCheckboxOption = (option: MultiselectOption, question: MultiselectQuestion) => {
const optionFieldName = fieldName(question.text, applicationSection, option.text)
const optionFieldName = fieldName(
question.text,
applicationSection,
option.text.replace(/\.|,|'/g, "")
)
return (
<React.Fragment key={option.text}>
<Field
Expand Down
23 changes: 22 additions & 1 deletion sites/public/src/components/shared/FormSummaryDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,27 @@ const FormSummaryDetails = ({
return `${name ? `${name}\n` : ""}${relationship ? `${relationship}\n` : ""}${helperText}`
}

const getOptionText = (
question: ApplicationMultiselectQuestion,
option: ApplicationMultiselectQuestionOption
) => {
const initialMultiselectQuestion = listing.listingMultiselectQuestions.find(
(elem) =>
elem.multiselectQuestion.text.replace(/\.|,|'/g, "") === question.key.replace(/\.|,|'/g, "")
)

const initialOption = initialMultiselectQuestion?.multiselectQuestion.options.find(
(elem) => elem.text.replace(/\.|,|'/g, "") === option.key
)

const initialOptOut = initialMultiselectQuestion?.multiselectQuestion.optOutText

const optOutOption =
option.key === initialOptOut?.replace(/\.|,|'/g, "") ? initialOptOut : undefined

return initialOption?.text || optOutOption || option.key
}

const multiselectQuestionSection = (
applicationSection: ApplicationSection,
appLink: string,
Expand Down Expand Up @@ -141,7 +162,7 @@ const FormSummaryDetails = ({
testId={"app-summary-preference"}
className={"pb-6 whitespace-pre-wrap"}
>
{option.key}
{getOptionText(question, option)}
</FieldValue>
))
)}
Expand Down
6 changes: 4 additions & 2 deletions sites/public/src/lib/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,13 @@ export const untranslateMultiselectQuestion = (
if (datum.options) {
datum.options.forEach((option) => {
const selectedOption = question.options.find((elem) => {
return elem.text.replace(/\.|,|'/g, "") === option.key
return elem.text.replace(/\.|,|'/g, "") === option.key.replace(/\.|,|'/g, "")
})
if (selectedOption) {
option.key = selectedOption.untranslatedText ?? selectedOption.text
} else if (question?.optOutText?.replace(/\.|,|'/g, "") === option.key) {
} else if (
question?.optOutText?.replace(/\.|,|'/g, "") === option.key.replace(/\.|,|'/g, "")
) {
option.key = question.untranslatedOptOutText ?? question.optOutText
}

Expand Down

0 comments on commit 0589570

Please sign in to comment.