Skip to content

Commit

Permalink
chore(packages/sui-consents): fix deps
Browse files Browse the repository at this point in the history
kikoruiz committed Nov 13, 2023
1 parent 7fea970 commit 95153a8
Showing 2 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/sui-consents/package.json
Original file line number Diff line number Diff line change
@@ -12,13 +12,13 @@
"author": "",
"license": "MIT",
"devDependencies": {
"@s-ui/react-context": "1",
"@s-ui/react-context": "typescript",
"@testing-library/react": "11.2.5",
"react": "17",
"react-dom": "17"
},
"peerDependencies": {
"@s-ui/react-context": "1",
"@s-ui/react-context": "typescript",
"react": "16 || 17"
}
}
20 changes: 13 additions & 7 deletions packages/sui-consents/src/useUserConsents.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { useContext, useEffect, useState } from 'react'
import {useContext, useEffect, useState} from 'react'

import SUIContext from '@s-ui/react-context'

import { TCF_VERSION, TCF_WINDOW_API } from './config'
import {TCF_VERSION, TCF_WINDOW_API} from './config'
import hasUserConsents from './hasUserConsents'
import { EventStatus, Purpose } from './types'
import {EventStatus, Purpose} from './types'

export default function useUserConsents (requiredConsents: number[]): boolean {
export default function useUserConsents(requiredConsents: number[]): boolean {
/**
* Consents acceptance state is inited based on the cookies from the
* context, so we know the state of consents from the beginning, even
* in SSR.
*/
const { cookies } = useContext(SUIContext)
const {cookies} = useContext(SUIContext)
const [areConsentsAccepted, setAreConsentsAccepted] = useState(() =>
hasUserConsents({ requiredConsents, cookies })
hasUserConsents({requiredConsents, cookies})
)

/**
@@ -25,7 +25,13 @@ export default function useUserConsents (requiredConsents: number[]): boolean {
useEffect(() => {
const tcfApi = window[TCF_WINDOW_API]
if (tcfApi !== undefined) {
const consentsListener = ({ eventStatus, purpose }: { eventStatus: EventStatus, purpose: Purpose}): void => {
const consentsListener = ({
eventStatus,
purpose
}: {
eventStatus: EventStatus
purpose: Purpose
}): void => {
if (eventStatus !== EventStatus.USER_ACTION_COMPLETE) return

setAreConsentsAccepted(

0 comments on commit 95153a8

Please sign in to comment.