Skip to content

Commit

Permalink
Marketing consent form: Allow null values from the api and sanitize H…
Browse files Browse the repository at this point in the history
…TML for custom texts
  • Loading branch information
nygrenh committed Dec 13, 2024
1 parent 1b62ba6 commit c0d83d6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import ErrorBanner from "@/shared-module/common/components/ErrorBanner"
import CheckBox from "@/shared-module/common/components/InputFields/CheckBox"
import Spinner from "@/shared-module/common/components/Spinner"
import { assertNotNullOrUndefined } from "@/shared-module/common/utils/nullability"
import { sanitizeCourseMaterialHtml } from "@/utils/sanitizeCourseMaterialHtml"

interface SelectMarketingConsentFormProps {
courseId: string
Expand All @@ -34,6 +35,7 @@ const SelectMarketingConsentForm: React.FC<SelectMarketingConsentFormProps> = ({
const customPrivacyPolicyCheckboxTextsQuery = useQuery({
queryKey: ["customPrivacyPolicyCheckboxTexts", courseId],
queryFn: () => fetchCustomPrivacyPolicyCheckboxTexts(courseId),
enabled: courseId !== undefined,
})

const handleEmailSubscriptionConsentChange = (event: React.ChangeEvent<HTMLInputElement>) => {
Expand All @@ -50,9 +52,9 @@ const SelectMarketingConsentForm: React.FC<SelectMarketingConsentFormProps> = ({

useEffect(() => {
if (initialMarketingConsentQuery.isSuccess) {
setMarketingConsent(initialMarketingConsentQuery.data.consent)
setMarketingConsent(initialMarketingConsentQuery.data?.consent ?? false)
const emailSub =
initialMarketingConsentQuery.data.email_subscription_in_mailchimp === "subscribed"
initialMarketingConsentQuery.data?.email_subscription_in_mailchimp === "subscribed"
setEmailSubscriptionConsent(emailSub)
}
}, [initialMarketingConsentQuery.data, initialMarketingConsentQuery.isSuccess])
Expand All @@ -63,7 +65,7 @@ const SelectMarketingConsentForm: React.FC<SelectMarketingConsentFormProps> = ({
(text) => text.text_slug === "marketing-consent",
)
if (customText) {
return customText.text_html
return sanitizeCourseMaterialHtml(customText.text_html)
}
}
return t("marketing-consent-checkbox-text")
Expand All @@ -75,7 +77,7 @@ const SelectMarketingConsentForm: React.FC<SelectMarketingConsentFormProps> = ({
(text) => text.text_slug === "privacy-policy",
)
if (customText) {
return customText.text_html
return sanitizeCourseMaterialHtml(customText.text_html)
}
}
return t("marketing-consent-privacy-policy-checkbox-text")
Expand Down
4 changes: 2 additions & 2 deletions services/course-material/src/services/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -774,9 +774,9 @@ export const updateMarketingConsent = async (

export const fetchUserMarketingConsent = async (
courseId: string,
): Promise<UserMarketingConsent> => {
): Promise<UserMarketingConsent | null> => {
const res = await courseMaterialClient.get(`/courses/${courseId}/fetch-user-marketing-consent`)
return validateResponse(res, isUserMarketingConsent)
return validateResponse(res, isUnion(isUserMarketingConsent, isNull))
}

export const fetchPartnersBlock = async (courseId: string): Promise<PartnersBlock> => {
Expand Down

0 comments on commit c0d83d6

Please sign in to comment.