diff --git a/src/components/AcceptAllRejectAllToggle.tsx b/src/components/AcceptAllRejectAllToggle.tsx new file mode 100644 index 00000000..2fa86e1d --- /dev/null +++ b/src/components/AcceptAllRejectAllToggle.tsx @@ -0,0 +1,124 @@ +import { h, JSX } from 'preact'; +import { useState } from 'preact/hooks'; +import { useIntl } from 'react-intl'; +import { CONSENT_OPTIONS } from '../constants'; +import { useAirgap } from '../hooks'; +import { messages } from '../messages'; +import type { HandleSetViewState } from '../types'; +import { GPCIndicator } from './GPCIndicator'; +import { Switch } from './Switch'; + +// Timer for save state +let savingTimeout: ReturnType; + +/** + * Component showing explanatory text before offering a way + * to opt out of the sale or share of data + */ +export function DoNotSellExplainer({ + handleSetViewState, + fontColor, +}: { + /** Function to change viewState */ + handleSetViewState: HandleSetViewState; + /** Font color */ + fontColor: string; +}): JSX.Element { + const { airgap } = useAirgap(); + const { formatMessage } = useIntl(); + const [saving, setSaving] = useState(null); + const [consentLocal, setConsentLocal] = useState( + !!airgap.getConsent().purposes.SaleOfInfo, + ); + const switchId = `all-purposes-${consentLocal}`; + + const handleSwitch = ( + checked: boolean, + event: JSX.TargetedEvent, + ): void => { + if (checked) { + event.preventDefault(); + airgap.optIn(event); + } else { + event.preventDefault(); + airgap.optOut(event); + } + + setConsentLocal(checked); + setSaving(true); + + // Clear any existing timeouts still running + if (savingTimeout) { + clearTimeout(savingTimeout); + } + savingTimeout = setTimeout(() => { + setSaving(false); + }, 500); + }; + + return ( +
+ +
+
+

+ {formatMessage(messages.consentTitleAcceptAllRejectAllToggle)} +

+
+
+

+

+

+
+
+ + + +

+ {typeof saving === 'boolean' + ? formatMessage( + saving + ? messages.saving + : consentLocal + ? messages.preferencesSavedOptedIn + : messages.preferencesSaved, + ) + : '\u200b'} +

+
+
+
+ ); +} diff --git a/src/components/BottomMenu.tsx b/src/components/BottomMenu.tsx index d7c87348..255f9150 100644 --- a/src/components/BottomMenu.tsx +++ b/src/components/BottomMenu.tsx @@ -33,11 +33,11 @@ export function BottomMenu({ {viewState === 'LanguageOptions' ? (
handleSetViewState(firstSelectedViewState)} + onClick={(e) => handleSetViewState('back', e)} > - {formatMessage(bottomMenuMessages.simplerChoicesButtonPrimary)} + {formatMessage(bottomMenuMessages.backButtonText)}
) : ( diff --git a/src/messages.ts b/src/messages.ts index 555d98ec..3fde0b1a 100644 --- a/src/messages.ts +++ b/src/messages.ts @@ -2,11 +2,6 @@ import { defineMessages } from '@transcend-io/internationalization'; export const messages = defineMessages('ui.src.messages', { - backButtonLabel: { - defaultMessage: 'Go back', - description: - 'Label for the back button in the footer of the consent banner language options.', - }, consentTitle: { defaultMessage: 'What can we use data for?', description: @@ -25,7 +20,7 @@ export const messages = defineMessages('ui.src.messages', { acceptAllDescription: { defaultMessage: // eslint-disable-next-line max-len - 'BY clicking “Accept all”, you agree to the storing of cookies on your device for functional, analytics, and advertising purposes.google', + 'By clicking “Accept all”, you agree to the storing of cookies on your device for functional, analytics, and advertising purposes.', description: 'The description displayed when asking the user to accept all data processing.', }, @@ -152,6 +147,18 @@ export const messages = defineMessages('ui.src.messages', { description: 'Button text for redirecting the user to more granular consent choices.', }, + consentTitleAcceptAllRejectAllToggle: { + defaultMessage: 'Your Privacy Choices', + description: + 'The title displayed in the AcceptAllRejectAllToggle view state.', + }, + acceptAllRejectAllToggleDescription: { + defaultMessage: 'Your Privacy Choices', + description: + /* eslint-disable max-len */ + 'By opting in below, you agree to the storing of cookies on your device for functional, analytics, and advertising purposes.', + /* eslint-enable max-len */ + }, }); export const quickOptionsMessages = defineMessages('ui.src.quickOptions', { @@ -268,6 +275,16 @@ export const optOutDisclosureMessages = defineMessages( ); export const bottomMenuMessages = defineMessages('ui.src.bottomMenu', { + backButtonText: { + defaultMessage: 'Go back', + description: + 'Hover text the back button in the footer of the consent banner language options.', + }, + backButtonTooltip: { + defaultMessage: 'Go back', + description: + 'Main text for the back button in the footer of the consent banner language options.', + }, moreChoicesButtonPrimary: { defaultMessage: 'More choices', description: 'Text for selecting specific more opt out choices.', @@ -285,11 +302,11 @@ export const bottomMenuMessages = defineMessages('ui.src.bottomMenu', { description: 'Hover/alt text for selecting simpler opt out choices.', }, showPolicyButtonPrimary: { - defaultMessage: 'See Our Privacy Policy', + defaultMessage: 'See our privacy policy', description: 'Text for linking out to privacy policy.', }, showPolicyButtonCompleteOptionsInverted: { - defaultMessage: 'See Our Privacy Policy', + defaultMessage: 'See our privacy policy', description: 'Text for linking out to privacy policy in CompleteOptionsInverted UI.', },