Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Reject All GDPR #2423

Merged
merged 2 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions projects/Mallard/src/components/Spacer/Spacer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from 'react';
import { StyleSheet, View } from 'react-native';

const styles = (unit: number) =>
StyleSheet.create({
spacer: {
marginRight: unit,
marginTop: unit,
},
});
export const Spacer = ({ unit = 8 }: { unit?: number }) => (
<View style={styles(unit).spacer} />
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import TestRenderer from 'react-test-renderer';
import { Spacer } from '../Spacer';

describe('<Spacer />', () => {
it('should render with default props', () => {
const wrapper = TestRenderer.create(<Spacer />).toJSON();
expect(wrapper).toMatchSnapshot();
});

it('should render with given props', () => {
const wrapper = TestRenderer.create(<Spacer unit={30} />).toJSON();
expect(wrapper).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<Spacer /> should render with default props 1`] = `
<View
style={
{
"marginRight": 8,
"marginTop": 8,
}
}
/>
`;

exports[`<Spacer /> should render with given props 1`] = `
<View
style={
{
"marginRight": 30,
"marginTop": 30,
}
}
/>
`;
7 changes: 7 additions & 0 deletions projects/Mallard/src/helpers/words.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,16 +246,23 @@ const externalSubscription = {
cancel: 'Cancel',
};

const enableAll = 'Enable all';
const rejectAll = 'Reject all';
const andContinue = 'and continue';

export const copy = {
alreadySubscribed,
andContinue,
authSwitcherScreen,
consentOnboarding,
enableAll,
externalSubscription,
failedSignIn,
homeScreen,
issueListFooter,
manageDownloads,
newEditionWords,
rejectAll,
settings,
signIn,
subFound,
Expand Down
39 changes: 12 additions & 27 deletions projects/Mallard/src/hooks/use-gdpr.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,13 @@ export enum OnboardingStatus {
}

interface GdprSettings extends GdprCoreSettings {
gdprAllowGoogleLogin: GdprSwitchSetting;
gdprAllowAppleLogin: GdprSwitchSetting;
setGdprFunctionalityBucket: (setting: GdprSwitchSetting) => void;
setGdprPerformanceBucket: (setting: GdprSwitchSetting) => void;
enableAllSettings: () => void;
rejectAllSettings: () => void;
resetAllSettings: () => void;
hasSetGdpr: () => OnboardingStatus;
isCorrectConsentVersion: () => boolean;
loading: boolean;
}

export type GdprSwitches = {
Expand All @@ -64,15 +62,13 @@ const defaultState: GdprSettings = {
gdprAllowPerformance: null,
gdprAllowFunctionality: null,
gdprConsentVersion: null,
gdprAllowGoogleLogin: null,
gdprAllowAppleLogin: null,
setGdprFunctionalityBucket: () => {},
setGdprPerformanceBucket: () => {},
enableAllSettings: () => {},
rejectAllSettings: () => {},
resetAllSettings: () => {},
hasSetGdpr: () => OnboardingStatus.Unknown,
isCorrectConsentVersion: () => false,
loading: true,
};

const GDPRContext = createContext<GdprSettings>(defaultState);
Expand All @@ -87,12 +83,6 @@ export const GDPRProvider = ({ children }: { children: React.ReactNode }) => {
const [gdprConsentVersion, setGdprConsentVersion] = useState<
GdprSettings['gdprConsentVersion']
>(defaultState.gdprConsentVersion);
const [gdprAllowGoogleLogin, setGdprAllowGoogleLogin] = useState<
GdprSettings['gdprAllowGoogleLogin']
>(defaultState.gdprAllowGoogleLogin);
const [gdprAllowAppleLogin, setGdprAllowAppleLogin] = useState<
GdprSettings['gdprAllowAppleLogin']
>(defaultState.gdprAllowAppleLogin);

const [loading, setLoading] = useState<boolean>(true);

Expand Down Expand Up @@ -153,8 +143,6 @@ export const GDPRProvider = ({ children }: { children: React.ReactNode }) => {
const setGdprFunctionalityBucket = (setting: GdprSwitchSetting) => {
// Local state modifier
setGdprAllowFunctionality(setting);
setGdprAllowGoogleLogin(setting);
setGdprAllowAppleLogin(setting);
setGdprConsentVersion(CURRENT_CONSENT_VERSION);
// Persisted state modifier
setting === null
Expand All @@ -163,26 +151,26 @@ export const GDPRProvider = ({ children }: { children: React.ReactNode }) => {
gdprConsentVersionCache.set(CURRENT_CONSENT_VERSION);
};

const enableAllSettings = () => {
const allSettings = (modifier: boolean) => {
// Local state modifier
setGdprAllowPerformance(true);
setGdprAllowFunctionality(true);
setGdprAllowPerformance(modifier);
setGdprAllowFunctionality(modifier);
setGdprConsentVersion(CURRENT_CONSENT_VERSION);
setGdprAllowGoogleLogin(true);
setGdprAllowAppleLogin(true);
// Persisted state modifier
gdprAllowPerformanceCache.set(true);
gdprAllowFunctionalityCache.set(true);
gdprAllowPerformanceCache.set(modifier);
gdprAllowFunctionalityCache.set(modifier);
gdprConsentVersionCache.set(CURRENT_CONSENT_VERSION);
};

const enableAllSettings = () => allSettings(true);

const rejectAllSettings = () => allSettings(false);

const resetAllSettings = () => {
// Local state modifier
setGdprAllowPerformance(defaultState.gdprAllowPerformance);
setGdprAllowFunctionality(defaultState.gdprAllowFunctionality);
setGdprConsentVersion(defaultState.gdprConsentVersion);
setGdprAllowGoogleLogin(defaultState.gdprAllowGoogleLogin);
setGdprAllowAppleLogin(defaultState.gdprAllowAppleLogin);
// Persisted state modifier
gdprAllowPerformanceCache.reset();
gdprAllowFunctionalityCache.reset();
Expand All @@ -202,13 +190,10 @@ export const GDPRProvider = ({ children }: { children: React.ReactNode }) => {
setGdprFunctionalityBucket,
setGdprPerformanceBucket,
enableAllSettings,
rejectAllSettings,
resetAllSettings,
hasSetGdpr,
isCorrectConsentVersion,
// The following are not used anywhere as things stand and are therefore not persisted
gdprAllowGoogleLogin,
gdprAllowAppleLogin,
loading,
}}
>
{children}
Expand Down
66 changes: 49 additions & 17 deletions projects/Mallard/src/screens/settings/gdpr-consent-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import type { ThreeWaySwitchValue } from 'src/components/layout/ui/switch';
import { ThreeWaySwitch } from 'src/components/layout/ui/switch';
import { LinkNav } from 'src/components/link';
import { LoginHeader } from 'src/components/login/login-layout';
import { Spacer } from 'src/components/Spacer/Spacer';
import { UiBodyCopy } from 'src/components/styled-text';
import { logEvent } from 'src/helpers/analytics';
import {
copy,
PREFS_SAVED_MSG,
PRIVACY_SETTINGS_HEADER_TITLE,
} from 'src/helpers/words';
Expand Down Expand Up @@ -41,10 +43,10 @@ const essentials: EssentialGdprSwitch = {

const GdprConsent = ({
shouldShowDismissableHeader = false,
continueText,
withContinue = false,
}: {
shouldShowDismissableHeader?: boolean;
continueText: string;
withContinue?: boolean;
}) => {
const navigation =
useNavigation<NativeStackNavigationProp<MainStackParamList>>();
Expand All @@ -56,6 +58,7 @@ const GdprConsent = ({

const {
enableAllSettings,
rejectAllSettings,
resetAllSettings,
gdprAllowPerformance,
gdprAllowFunctionality,
Expand Down Expand Up @@ -86,10 +89,24 @@ const GdprConsent = ({

const onEnableAllAndContinue = () => {
enableAllSettings();
navigation.navigate(RouteNames.Issue);
showToast(PREFS_SAVED_MSG);
withContinue && navigation.navigate(RouteNames.Issue);
};

const onRejectAllAndContinue = () => {
rejectAllSettings();
showToast(PREFS_SAVED_MSG);
withContinue && navigation.navigate(RouteNames.Issue);
};

const continueText = withContinue
? `${copy.enableAll} ${copy.andContinue}`
: copy.enableAll;

const rejectText = withContinue
? `${copy.rejectAll} ${copy.andContinue}`
: copy.rejectAll;

const onDismiss = () => {
if (hasSetGdpr() === OnboardingStatus.Complete) {
navigation.navigate(RouteNames.Issue);
Expand Down Expand Up @@ -145,18 +162,33 @@ const GdprConsent = ({
</Text>
}
proxy={
<Button
appearance={ButtonAppearance.Skeleton}
onPress={() => {
onEnableAllAndContinue();
logEvent({
name: 'gdpr_enable_all',
value: 'gdpr_enable_all',
});
}}
>
{continueText}
</Button>
<>
<Button
appearance={ButtonAppearance.Skeleton}
onPress={() => {
onEnableAllAndContinue();
logEvent({
name: 'gdpr_enable_all',
value: 'gdpr_enable_all',
});
}}
>
{continueText}
</Button>
<Spacer />
<Button
appearance={ButtonAppearance.Skeleton}
onPress={() => {
onRejectAllAndContinue();
logEvent({
name: 'gdpr_reject_all',
value: 'gdpr_reject_all',
});
}}
>
{rejectText}
</Button>
</>
}
></TallRow>
<Separator></Separator>
Expand Down Expand Up @@ -241,7 +273,7 @@ const GdprConsentScreen = () => (
actionLeft={true}
>
<WithAppAppearance value={'settings'}>
<GdprConsent continueText={'Enable all'}></GdprConsent>
<GdprConsent />
</WithAppAppearance>
</HeaderScreenContainer>
);
Expand All @@ -250,7 +282,7 @@ const GdprConsentScreenForOnboarding = () => (
<WithAppAppearance value={'settings'}>
<GdprConsent
shouldShowDismissableHeader={true}
continueText={'Enable all and continue'}
withContinue
></GdprConsent>
</WithAppAppearance>
);
Expand Down
Loading