Skip to content

Commit 165a260

Browse files
feat: implement authId common interface
1 parent f5f69d8 commit 165a260

File tree

6 files changed

+49
-14
lines changed

6 files changed

+49
-14
lines changed

example/src/App.tsx

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import React, { useState, useEffect, useCallback, useRef } from 'react';
2-
import { View, Text, SafeAreaView, Button, StyleSheet } from 'react-native';
2+
import {
3+
View,
4+
Text,
5+
SafeAreaView,
6+
Button,
7+
StyleSheet,
8+
TextInput,
9+
} from 'react-native';
310
import { LaunchArguments } from 'react-native-launch-arguments';
411

512
import {
@@ -38,6 +45,7 @@ const config = {
3845
export default function App() {
3946
const [userData, setUserData] = useState<SPUserData>({});
4047
const [sdkStatus, setSDKStatus] = useState<SDKStatus>(SDKStatus.NotStarted);
48+
const [authId, setAuthId] = useState<string | undefined>(launchArgs.authId);
4149
const consentManager = useRef<SPConsentManager | null>();
4250

4351
useEffect(() => {
@@ -75,7 +83,7 @@ export default function App() {
7583

7684
consentManager.current?.getUserData().then(setUserData);
7785

78-
consentManager.current?.loadMessage();
86+
consentManager.current?.loadMessage({ authId });
7987

8088
setSDKStatus(SDKStatus.Networking);
8189

@@ -85,9 +93,9 @@ export default function App() {
8593
}, []);
8694

8795
const onLoadMessagePress = useCallback(() => {
88-
consentManager.current?.loadMessage();
96+
consentManager.current?.loadMessage({ authId });
8997
setSDKStatus(SDKStatus.Networking);
90-
}, []);
98+
}, [authId]);
9199

92100
const onGDPRPMPress = useCallback(() => {
93101
setSDKStatus(SDKStatus.Networking);
@@ -111,8 +119,18 @@ export default function App() {
111119
<SafeAreaView style={styles.container}>
112120
<View>
113121
<Text style={styles.title}>Sourcepoint CMP</Text>
122+
<TextInput
123+
value={authId}
124+
placeholder="(optional) authId"
125+
onChangeText={setAuthId}
126+
style={styles.authIdInput}
127+
autoCapitalize="none"
128+
autoCorrect={false}
129+
autoComplete="off"
130+
clearButtonMode="always"
131+
/>
114132
<Button
115-
title="Load Messages"
133+
title={authId ? `Load Messages (${authId})` : 'Load Messages'}
116134
onPress={onLoadMessagePress}
117135
disabled={disable}
118136
/>
@@ -131,7 +149,7 @@ export default function App() {
131149
{sdkStatus}
132150
</Text>
133151
</View>
134-
<UserDataView data={userData} />
152+
<UserDataView data={userData} authId={authId} />
135153
</SafeAreaView>
136154
);
137155
}
@@ -146,4 +164,13 @@ const styles = StyleSheet.create({
146164
textAlign: 'center',
147165
color: '#999',
148166
},
167+
authIdInput: {
168+
marginVertical: 12,
169+
marginHorizontal: 'auto',
170+
width: '70%',
171+
padding: 8,
172+
fontSize: 18,
173+
textAlign: 'center',
174+
borderWidth: 1,
175+
},
149176
});

example/src/LaunchArgs.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import type { SPCampaigns } from '@sourcepoint/react-native-cmp';
22

33
export type LaunchArgs = {
4-
config: {
4+
config?: {
55
accountId?: number;
66
propertyId?: number;
77
propertyName?: string;
88
gdprPMId?: string;
99
usnatPMId?: string;
1010
campaigns?: SPCampaigns;
1111
};
12+
authId?: string;
1213
clearData?: boolean;
1314
};

example/src/TestableText.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from 'react';
22
import { Text, StyleSheet } from 'react-native';
33

44
export type TestableTextProps = {
5-
testID: string | undefined;
5+
testID?: string;
66
} & React.PropsWithChildren;
77

88
export const TestableText = ({ testID, children }: TestableTextProps) => (

example/src/UserDataView.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import { ScrollView, View, Text, StyleSheet } from 'react-native';
44
import { TestableText } from './TestableText';
55
import type { SPUserData } from '@sourcepoint/react-native-cmp';
66

7-
export default ({ data }: UserDataViewProps) => (
7+
export default ({ data, authId }: UserDataViewProps) => (
88
<View style={styles.container}>
9-
<Text style={styles.header}>Local User Data</Text>
9+
<Text style={styles.header}>
10+
{authId ? `User Data (${authId})` : `User Data`}
11+
</Text>
1012
<TestableText testID="gdpr.uuid">{data?.gdpr?.consents?.uuid}</TestableText>
1113
<TestableText testID="gdpr.consentStatus">
1214
{data?.gdpr?.consents?.statuses?.consentedAll
@@ -31,6 +33,7 @@ export default ({ data }: UserDataViewProps) => (
3133

3234
type UserDataViewProps = {
3335
data: SPUserData;
36+
authId?: string;
3437
};
3538

3639
const styles = StyleSheet.create({

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { NativeModules, Platform, NativeEventEmitter } from 'react-native';
2-
import type { Spec, SPCampaigns, SPUserData } from './types';
2+
import type { Spec, SPCampaigns, SPUserData, LoadMessageParams } from './types';
33

44
const LINKING_ERROR =
55
`The package '@sourcepoint/react-native-cmp' doesn't seem to be linked. Make sure: \n\n` +
@@ -45,8 +45,8 @@ export class SPConsentManager implements Spec {
4545
return RNSourcepointCmp.getUserData();
4646
}
4747

48-
loadMessage() {
49-
RNSourcepointCmp.loadMessage();
48+
loadMessage(params?: LoadMessageParams) {
49+
RNSourcepointCmp.loadMessage(params);
5050
}
5151

5252
clearLocalData() {

src/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ export type SPUserData = {
8686
usnat?: CampaignConsent<USNatConsent>;
8787
};
8888

89+
export type LoadMessageParams = {
90+
authId?: string;
91+
};
92+
8993
export interface Spec extends TurboModule {
9094
build(
9195
accountId: number,
@@ -94,7 +98,7 @@ export interface Spec extends TurboModule {
9498
campaigns: SPCampaigns
9599
): void;
96100
getUserData(): Promise<SPUserData>;
97-
loadMessage(): void;
101+
loadMessage(params?: LoadMessageParams): void;
98102
clearLocalData(): void;
99103
loadGDPRPrivacyManager(pmId: string): void;
100104
loadUSNatPrivacyManager(pmId: string): void;

0 commit comments

Comments
 (0)