Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Commit

Permalink
Fix onAcceptAll, onDenyAll and load preferences to let 'N/A' value
Browse files Browse the repository at this point in the history
  • Loading branch information
edsonjab committed Jul 19, 2023
1 parent 0670b5f commit 46a45a4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
27 changes: 19 additions & 8 deletions src/consent-manager/container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,30 @@ const Container: React.FC<ContainerProps> = props => {
} = normalizeDestinations(props.destinations)

const onAcceptAll = () => {
const truePreferences = Object.keys(props.preferences).reduce((acc, category) => {
acc[category] = true
return acc
}, {})
const truePreferences: CategoryPreferences = props.preferences
for (const preferenceName of Object.keys(props.preferences)) {
const value = props.preferences[preferenceName]
if (typeof value === 'string') {
truePreferences[preferenceName] = value
} else {
truePreferences[preferenceName] = true
}
}

props.setPreferences(truePreferences)
return props.saveConsent()
}

const onDenyAll = () => {
const falsePreferences = Object.keys(props.preferences).reduce((acc, category) => {
acc[category] = false
return acc
}, {})
const falsePreferences: CategoryPreferences = props.preferences
for (const preferenceName of Object.keys(props.preferences)) {
const value = props.preferences[preferenceName]
if (typeof value === 'string') {
falsePreferences[preferenceName] = value
} else {
falsePreferences[preferenceName] = false
}
}

props.setPreferences(falsePreferences)
return props.saveConsent()
Expand Down
2 changes: 1 addition & 1 deletion src/consent-manager/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export default class ConsentManager extends PureComponent<ConsentManagerProps, {
if (customCategories) {
for (const preferenceName of Object.keys(customCategories)) {
const value = preferences[preferenceName]
if (typeof value === 'boolean') {
if (typeof value === 'boolean' || typeof value === 'string') {
customPreferences[preferenceName] = value
} else {
customPreferences[preferenceName] = true
Expand Down

0 comments on commit 46a45a4

Please sign in to comment.