|
| 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