Skip to content

Commit 74c0f99

Browse files
committed
feat: add User Consent screen and update navigation
- Introduced `UserConsentScreen` for managing user consent details, including key, description, mandatory status, checked status, and action type. - Updated `HomeStack` to include the new `UserConsent` route. - Enhanced `BugReportingScreen` with a new option to navigate to the `UserConsentScreen`. - Added test IDs for improved testing integration.
1 parent d46a941 commit 74c0f99

File tree

3 files changed

+159
-0
lines changed

3 files changed

+159
-0
lines changed

examples/default/src/navigation/HomeStack.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
RepliesStateScreen,
3232
type RepliesStateScreenProp,
3333
} from '../screens/bug-reporting/RepliesStateScreen';
34+
import { UserConsentScreen } from '../screens/bug-reporting/UserConsentScreen';
3435
import { CrashReportingScreen } from '../screens/CrashReportingScreen';
3536
import {
3637
CrashReportingStateScreen,
@@ -92,6 +93,7 @@ export type HomeStackParamList = {
9293
InvocationOptions: InvocationOptionsScreenProp;
9394
ViewHierarchy: ViewHierarchyScreenProp;
9495
RepliesState: RepliesStateScreenProp;
96+
UserConsent: undefined;
9597

9698
// Crash Reporting //
9799
CrashReporting: undefined;
@@ -185,6 +187,11 @@ export const HomeStackNavigator: React.FC = () => {
185187
component={RepliesStateScreen}
186188
options={{ title: 'Replies State' }}
187189
/>
190+
<HomeStack.Screen
191+
name="UserConsent"
192+
component={UserConsentScreen}
193+
options={{ title: 'User Consent' }}
194+
/>
188195

189196
{/* Crash Reporting */}
190197
<HomeStack.Screen

examples/default/src/screens/bug-reporting/BugReportingScreen.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,13 @@ export const BugReportingScreen: React.FC<
228228
testID="id_replies"
229229
/>
230230

231+
232+
<ListTile
233+
title="User Consent"
234+
onPress={() => navigation.navigate('UserConsent')}
235+
testID="id_user_consent"
236+
/>
237+
231238
<Divider my={5} />
232239

233240
<ListTile title="Show" onPress={() => Instabug.show()} testID="id_show_button" />
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
import React, { useState } from 'react';
2+
import { ScrollView, StyleSheet, View, Text, Alert } from 'react-native';
3+
import { BugReporting, userConsentActionType } from 'instabug-reactnative';
4+
import { Screen } from '../../components/Screen';
5+
import { Section } from '../../components/Section';
6+
import { Button, VStack } from 'native-base';
7+
import { InputField } from '../../components/InputField';
8+
import { Select } from '../../components/Select';
9+
import type { NativeStackScreenProps } from '@react-navigation/native-stack';
10+
import type { HomeStackParamList } from '../../navigation/HomeStack';
11+
12+
const styles = StyleSheet.create({
13+
inputWrapper: {
14+
padding: 4,
15+
flex: 1,
16+
},
17+
inputTitle: {
18+
fontSize: 12,
19+
fontWeight: 'bold',
20+
color: 'black',
21+
paddingLeft: 4,
22+
paddingBottom: 4,
23+
},
24+
});
25+
26+
export const UserConsentScreen: React.FC<
27+
NativeStackScreenProps<HomeStackParamList, 'UserConsent'>
28+
> = ({ navigation }) => {
29+
const [key, setKey] = useState<string>('');
30+
const [description, setDescription] = useState<string>('');
31+
const [mandatory, setMandatory] = useState<boolean>(false);
32+
const [checked, setChecked] = useState<boolean>(false);
33+
const [actionType, setActionType] = useState<userConsentActionType | undefined>(undefined);
34+
35+
const handleSubmit = () => {
36+
BugReporting.addUserConsent(key, description, mandatory, checked, actionType);
37+
Alert.alert('User Consent Added', 'User consent added successfully');
38+
navigation.goBack();
39+
};
40+
41+
return (
42+
<ScrollView>
43+
<Screen>
44+
<Section title="User Consent">
45+
<VStack>
46+
<View style={styles.inputWrapper}>
47+
<Text style={styles.inputTitle}>Key</Text>
48+
<InputField
49+
placeholder="Key"
50+
onChangeText={setKey}
51+
value={key}
52+
testID="id_consent_key"
53+
/>
54+
</View>
55+
<View style={styles.inputWrapper}>
56+
<Text style={styles.inputTitle}>Description</Text>
57+
<InputField
58+
placeholder="Description"
59+
onChangeText={setDescription}
60+
value={description}
61+
testID="id_consent_description"
62+
/>
63+
</View>
64+
<View style={styles.inputWrapper}>
65+
<Text style={styles.inputTitle}>Mandatory</Text>
66+
<Select
67+
label="Mandatory"
68+
testID="id_consent_mandatory"
69+
items={[
70+
{
71+
label: 'Yes',
72+
value: 'true',
73+
isInitial: true,
74+
testID: 'id_consent_mandatory_yes',
75+
},
76+
{
77+
label: 'No',
78+
value: 'false',
79+
testID: 'id_consent_mandatory_no',
80+
},
81+
]}
82+
onValueChange={(value) => setMandatory(value === 'true')}
83+
/>
84+
</View>
85+
<View style={styles.inputWrapper}>
86+
<Text style={styles.inputTitle}>Checked</Text>
87+
<Select
88+
label="Checked"
89+
testID="id_consent_checked"
90+
items={[
91+
{
92+
label: 'Yes',
93+
value: 'true',
94+
isInitial: true,
95+
testID: 'id_consent_checked_yes',
96+
},
97+
{
98+
label: 'No',
99+
value: 'false',
100+
testID: 'id_consent_checked_no',
101+
},
102+
]}
103+
onValueChange={(value) => setChecked(value === 'true')}
104+
/>
105+
</View>
106+
<View style={styles.inputWrapper}>
107+
<Text style={styles.inputTitle}>Action Type</Text>
108+
<Select
109+
label="Action Type"
110+
testID="id_consent_action_type"
111+
items={[
112+
{
113+
value: userConsentActionType.dropAutoCapturedMedia,
114+
label: 'Drop Auto Captured Media',
115+
testID: 'id_consent_action_type_dropAutoCapturedMedia',
116+
},
117+
{
118+
value: userConsentActionType.dropLogs,
119+
label: 'Drop Logs',
120+
testID: 'id_consent_action_type_dropLogs',
121+
},
122+
{
123+
value: userConsentActionType.noChat,
124+
label: 'No Chat',
125+
testID: 'id_consent_action_type_noChat',
126+
},
127+
{
128+
value: undefined,
129+
label: 'None',
130+
testID: 'id_consent_action_type_none',
131+
isInitial: true,
132+
},
133+
]}
134+
onValueChange={setActionType}
135+
/>
136+
</View>
137+
<Button mt="4" onPress={handleSubmit} testID="id_submit_consent">
138+
Add User Consent
139+
</Button>
140+
</VStack>
141+
</Section>
142+
</Screen>
143+
</ScrollView>
144+
);
145+
};

0 commit comments

Comments
 (0)