airbridge-react-native-sdk
Version:
Airbridge SDK for React Native
188 lines (168 loc) • 5.21 kB
JavaScript
import React, { useRef } from 'react'
import { View } from 'react-native'
import { Styles } from '../common/Styles'
import { Colors } from '../common/Colors'
import CustomButton from '../component/CustomButton'
import ValueInputDialog from '../component/ValueInputDialog'
import AttributeEntryInputDialog from '../component/AttributeEntryInputDialog'
import EntryInputDialog from '../component/EntryInputDialog'
import { Airbridge } from 'airbridge-react-native-sdk'
export default function UserInfoPage() {
const idRef = useRef();
const emailRef = useRef();
const phoneRef = useRef();
const attrEntryRef = useRef();
const attrKeyRef = useRef();
const aliasEntryRef = useRef();
const aliasKeyRef = useRef();
return (
<View style={Styles.container}>
<CustomButton
buttonColor={Colors.red}
title={'SET ID'}
accessibilityLabel={'setId'}
arrow={true}
onPress={() => idRef.current.show()} />
<CustomButton
buttonColor={Colors.red}
title={'CLEAR ID'}
accessibilityLabel={'clearId'}
onPress={() => {
Airbridge.clearUserID()
}} />
<CustomButton
buttonColor={Colors.pink}
title={'SET EMAIL'}
accessibilityLabel={'setEmail'}
arrow={true}
onPress={() => emailRef.current.show()} />
<CustomButton
buttonColor={Colors.pink}
title={'CLEAR EMAIL'}
accessibilityLabel={'clearEmail'}
onPress={() => {
Airbridge.clearUserEmail()
}} />
<CustomButton
buttonColor={Colors.purple}
title={'SET PHONE'}
accessibilityLabel={'setPhone'}
arrow={true}
onPress={() => phoneRef.current.show()} />
<CustomButton
buttonColor={Colors.purple}
title={'CLEAR PHONE'}
accessibilityLabel={'clearPhone'}
onPress={() => {
Airbridge.clearUserPhone()
}} />
<CustomButton
buttonColor={Colors.deepPurple}
title={'ADD ATTRIBUTE'}
accessibilityLabel={'addAttribute'}
arrow={true}
onPress={() => attrEntryRef.current.show()} />
<CustomButton
buttonColor={Colors.indigo}
title={'REMOVE ATTRIBUTE'}
accessibilityLabel={'removeAttribute'}
arrow={true}
onPress={() => attrKeyRef.current.show()} />
<CustomButton
buttonColor={Colors.blue}
title={'CLEAR ATTRIBUTE'}
accessibilityLabel={'clearAttributes'}
onPress={() => {
Airbridge.clearUserAttributes()
}} />
<CustomButton
buttonColor={Colors.lightBlue}
title={'ADD ALIAS'}
accessibilityLabel={'addAlias'}
arrow={true}
onPress={() => aliasEntryRef.current.show()} />
<CustomButton
buttonColor={Colors.cyan}
title={'REMOVE ALIAS'}
accessibilityLabel={'removeAlias'}
arrow={true}
onPress={() => aliasKeyRef.current.show()} />
<CustomButton
buttonColor={Colors.teal}
title={'CLEAR ALIAS'}
accessibilityLabel={'clearAlias'}
onPress={() => {
Airbridge.clearUserAlias()
}} />
<CustomButton
buttonColor={Colors.green}
title={'CLEAR ALL'}
accessibilityLabel={'clearAll'}
onPress={() => {
Airbridge.clearUser()
}} />
<View style={{ margin: 16}} />
<CustomButton
buttonColor={Colors.lime}
title={'SEND DUMMY EVENT'}
accessibilityLabel={'dummyEvent'}
onPress={() => {
Airbridge.trackEvent('dummy_event')
}} />
<ValueInputDialog
ref={idRef}
onConfirm={(value) => {
Airbridge.setUserID(value)
}} />
<ValueInputDialog
ref={emailRef}
onConfirm={(value) => {
Airbridge.setUserEmail(value)
}} />
<ValueInputDialog
ref={phoneRef}
onConfirm={(value) => {
Airbridge.setUserPhone(value)
}} />
<AttributeEntryInputDialog
ref={attrEntryRef}
onConfirm={(key, value, type) => {
let parsedValue
switch (type.toLowerCase()) {
case 'int':
case 'long':
parsedValue = parseInt(value)
break;
case 'float':
case 'double':
parsedValue = parseFloat(value)
break;
case 'boolean':
parsedValue = value == "true" ? true : false
break
case 'string':
parsedValue = value
break;
default:
break;
}
Airbridge.setUserAttribute(key, parsedValue)
}} />
<ValueInputDialog
ref={attrKeyRef}
onConfirm={(key) => {
Airbridge.removeUserAttribute(key)
} } />
<EntryInputDialog
ref={aliasEntryRef}
onConfirm={(key, value) => {
Airbridge.setUserAlias(key, value)
} } />
<ValueInputDialog
ref={aliasKeyRef}
onConfirm={(key) => {
Airbridge.removeUserAlias(key)
} } />
</View>
)
}