@@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react';
2
2
import {
3
3
StyleSheet ,
4
4
SafeAreaView ,
5
+ ScrollView ,
5
6
View ,
6
7
Text ,
7
8
TextInput ,
@@ -22,11 +23,12 @@ const LoadingView = () => (
22
23
23
24
const App = ( ) => {
24
25
const [ token , setToken ] = useState ( '' ) ;
26
+ const [ fieldId , setFieldId ] = useState ( '' ) ;
27
+ const [ tag , setTag ] = useState ( '' ) ;
25
28
const [ isLoading , setIsLoading ] = useState ( true ) ;
26
29
27
30
useEffect ( ( ) => {
28
31
Zendesk . initialize ( { channelKey : CHANNEL_KEY } )
29
-
30
32
. then ( ( ) => {
31
33
console . log ( 'zendesk initialized' ) ;
32
34
@@ -44,6 +46,8 @@ const App = () => {
44
46
} , [ ] ) ;
45
47
46
48
const handleChangeToken = ( text : string ) => setToken ( text ) ;
49
+ const handleChangeFieldId = ( id : string ) => setFieldId ( id ) ;
50
+ const handleChangeTag = ( tag : string ) => setTag ( tag ) ;
47
51
48
52
const runner = async ( fn : ( ) => Promise < any > ) => {
49
53
if ( isLoading ) return ;
@@ -70,33 +74,83 @@ const App = () => {
70
74
)
71
75
) ;
72
76
} ;
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
+ }
73
101
74
102
return (
75
103
< 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 >
100
154
{ isLoading ? < LoadingView /> : null }
101
155
</ SafeAreaView >
102
156
) ;
0 commit comments