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

Commit

Permalink
Listening to non-react updates to the preferences and update the reac…
Browse files Browse the repository at this point in the history
…t component (#123)

* updating the preferences when the modal opens

* update the changelog and package version
  • Loading branch information
pooyaj committed Nov 17, 2020
1 parent 9872dd2 commit e63972c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# Changelog

## 5.1.0(Nov 17, 2020)

- [#123](https://github.com/segmentio/consent-manager/pull/123) Fixed an issue where the react state wasn't being updated after the user updates the preferences via the `.savePreferences` API. This change also slightly changes how the Cancel confirmation modal is displayed.

## 5.0.2(Nov 9, 2020)

- [#111](https://github.com/segmentio/consent-manager/pull/111) Added missing TypeScript declarations in packaged output
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@segment/consent-manager",
"version": "5.0.2",
"version": "5.1.0",
"description": "Drop-in consent management plugin for analytics.js",
"keywords": [
"gdpr",
Expand Down
10 changes: 8 additions & 2 deletions src/consent-manager/container.tsx
Expand Up @@ -122,6 +122,12 @@ const Container: React.FC<ContainerProps> = props => {
}
})

React.useEffect(() => {
if (isDialogOpen) {
props.resetPreferences()
}
}, [isDialogOpen])

const onClose = () => {
if (props.closeBehavior === undefined || props.closeBehavior === CloseBehavior.DISMISS) {
return toggleBanner(false)
Expand Down Expand Up @@ -161,22 +167,22 @@ const Container: React.FC<ContainerProps> = props => {
}

const handleCancel = () => {
toggleDialog(false)
// Only show the cancel confirmation if there's unconsented destinations
if (props.newDestinations.length > 0) {
toggleCancel(true)
} else {
toggleDialog(false)
props.resetPreferences()
}
}

const handleCancelBack = () => {
toggleDialog(true)
toggleCancel(false)
}

const handleCancelConfirm = () => {
toggleCancel(false)
toggleDialog(false)
props.resetPreferences()
}

Expand Down

0 comments on commit e63972c

Please sign in to comment.