Skip to content

Commit dc0c19f

Browse files
committed
feat: update example
- add conversation fields - add conversation tags refs #25
1 parent eee1703 commit dc0c19f

File tree

1 file changed

+79
-25
lines changed

1 file changed

+79
-25
lines changed

example/src/App.tsx

Lines changed: 79 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react';
22
import {
33
StyleSheet,
44
SafeAreaView,
5+
ScrollView,
56
View,
67
Text,
78
TextInput,
@@ -22,11 +23,12 @@ const LoadingView = () => (
2223

2324
const App = () => {
2425
const [token, setToken] = useState('');
26+
const [fieldId, setFieldId] = useState('');
27+
const [tag, setTag] = useState('');
2528
const [isLoading, setIsLoading] = useState(true);
2629

2730
useEffect(() => {
2831
Zendesk.initialize({ channelKey: CHANNEL_KEY })
29-
3032
.then(() => {
3133
console.log('zendesk initialized');
3234

@@ -44,6 +46,8 @@ const App = () => {
4446
}, []);
4547

4648
const handleChangeToken = (text: string) => setToken(text);
49+
const handleChangeFieldId = (id: string) => setFieldId(id);
50+
const handleChangeTag = (tag: string) => setTag(tag);
4751

4852
const runner = async (fn: () => Promise<any>) => {
4953
if (isLoading) return;
@@ -70,33 +74,83 @@ const App = () => {
7074
)
7175
);
7276
};
77+
const handlePressSetFields = () => {
78+
if (!fieldId) {
79+
console.warn('field id is empty');
80+
return
81+
}
82+
Zendesk.setConversationFields({ [fieldId]: 'react-native-zendesk-messaging' });
83+
Alert.alert('setConversationFields: ' + fieldId);
84+
};
85+
const handlePressClearFields = () => {
86+
Zendesk.clearConversationFields();
87+
Alert.alert('clearConversationFields');
88+
}
89+
const handlePressSetTags = () => {
90+
if (!tag) {
91+
console.warn('tag is empty');
92+
return;
93+
}
94+
Zendesk.setConversationTags([tag]);
95+
Alert.alert('setConversationTags: ' + JSON.stringify([tag]));
96+
};
97+
const handlePressClearTags = () => {
98+
Zendesk.clearConversationTags();
99+
Alert.alert('clearConversationTags');
100+
}
73101

74102
return (
75103
<SafeAreaView style={styles.container}>
76-
<Text style={styles.heading}>Zendesk</Text>
77-
<Section title="User Authentication">
78-
<TextInput
79-
value={token}
80-
onChangeText={handleChangeToken}
81-
style={styles.textInput}
82-
placeholder="User token"
83-
/>
84-
<View style={styles.gap} />
85-
<Text style={styles.text}>
86-
{'User token: '}
87-
<EmptyText>{token}</EmptyText>
88-
</Text>
89-
<View style={styles.gap} />
90-
<Button label="Login" onPress={handlePressLogin} />
91-
<View style={styles.gap} />
92-
<Button label="Logout" onPress={handlePressLogout} />
93-
</Section>
94-
<Section title="Chat" hideSeparator>
95-
<Button label="Open Messaging" onPress={handlePressOpen} />
96-
</Section>
97-
<Section title="Notifications" hideSeparator>
98-
<Button label="Get unread count" onPress={handlePressCount} />
99-
</Section>
104+
<ScrollView>
105+
<Text style={styles.heading}>Zendesk</Text>
106+
<Section title="User Authentication">
107+
<TextInput
108+
value={token}
109+
onChangeText={handleChangeToken}
110+
style={styles.textInput}
111+
placeholder="User token"
112+
/>
113+
<View style={styles.gap} />
114+
<Text style={styles.text}>
115+
{'User token: '}
116+
<EmptyText>{token}</EmptyText>
117+
</Text>
118+
<View style={styles.gap} />
119+
<Button label="Login" onPress={handlePressLogin} />
120+
<View style={styles.gap} />
121+
<Button label="Logout" onPress={handlePressLogout} />
122+
</Section>
123+
<Section title="Chat">
124+
<Button label="Open Messaging" onPress={handlePressOpen} />
125+
</Section>
126+
<Section title="Fields">
127+
<TextInput
128+
value={fieldId}
129+
onChangeText={handleChangeFieldId}
130+
style={styles.textInput}
131+
placeholder="Field id"
132+
/>
133+
<View style={styles.gap} />
134+
<Button label="Set Fields" onPress={handlePressSetFields} />
135+
<View style={styles.gap} />
136+
<Button label="Clear Fields" onPress={handlePressClearFields} />
137+
</Section>
138+
<Section title="Tags">
139+
<TextInput
140+
value={tag}
141+
onChangeText={handleChangeTag}
142+
style={styles.textInput}
143+
placeholder="Tag"
144+
/>
145+
<View style={styles.gap} />
146+
<Button label="Set Tags" onPress={handlePressSetTags} />
147+
<View style={styles.gap} />
148+
<Button label="Clear Tags" onPress={handlePressClearTags} />
149+
</Section>
150+
<Section title="Notifications" hideSeparator>
151+
<Button label="Get unread count" onPress={handlePressCount} />
152+
</Section>
153+
</ScrollView>
100154
{isLoading ? <LoadingView /> : null}
101155
</SafeAreaView>
102156
);

0 commit comments

Comments
 (0)