@@ -3,20 +3,21 @@ import { useEffect, useState } from 'react';
3
3
import {
4
4
Alert ,
5
5
AppState ,
6
+ Image ,
6
7
Linking ,
7
8
Platform ,
8
9
ScrollView ,
9
10
StatusBar ,
10
11
StyleSheet ,
11
12
Text ,
12
- TextInput ,
13
13
View ,
14
14
} from 'react-native' ;
15
15
import Intercom , {
16
16
IntercomEvents ,
17
17
Visibility ,
18
18
} from '@intercom/intercom-react-native' ;
19
19
import Button from './Button' ;
20
+ import Input from './Input' ;
20
21
import type { Registration } from '../../lib/typescript' ;
21
22
import Config from 'react-native-config' ;
22
23
@@ -42,10 +43,27 @@ export default function App() {
42
43
const [ launcherVisibility , setLauncherVisibility ] = useState < boolean > ( false ) ;
43
44
const [ user , setUser ] = useState < Registration > ( { email : '' } ) ;
44
45
46
+ const [ articleId , setArticleId ] = useState < string | undefined > ( ARTICLE_ID ) ;
47
+ const [ carouselId , setCarouselId ] = useState < string | undefined > ( CAROUSEL_ID ) ;
48
+ const [ eventName , setEventName ] = useState < string | undefined > ( EVENT_NAME ) ;
49
+ const [ collectionId , setCollectionId ] = useState < string | undefined > (
50
+ COLLECTION_ID
51
+ ) ;
52
+ const [ searchTerm , setSearchTerm ] = useState < string | undefined > ( SEARCH_TERM ) ;
53
+ const [ userName , setUserName ] = useState < string | undefined > ( USER_NAME ) ;
54
+
45
55
const showErrorAlert = ( e : Error ) => {
46
56
Alert . alert ( 'ERROR' , JSON . stringify ( e ) ) ;
47
57
} ;
48
58
59
+ const showResponseAlert = ( obj : any ) => {
60
+ Alert . alert ( 'RESPONSE' , JSON . stringify ( obj ) ) ;
61
+ } ;
62
+
63
+ const showEmptyAlertMessage = ( field : string ) => {
64
+ Alert . alert ( field , `Please provide ${ field } ` ) ;
65
+ } ;
66
+
49
67
useEffect ( ( ) => {
50
68
/**
51
69
* Handle PushNotification
@@ -92,6 +110,11 @@ export default function App() {
92
110
93
111
return (
94
112
< View style = { styles . container } accessibilityLabel = "app-root" >
113
+ < StatusBar translucent = { true } />
114
+ < View style = { [ styles . row , styles . alignCenter , styles . header ] } >
115
+ < Image source = { require ( '../assets/intercom.png' ) } style = { styles . logo } />
116
+ < Text style = { styles . title } > Intercom Example App</ Text >
117
+ </ View >
95
118
< View style = { styles . textContainer } >
96
119
< View style = { styles . row } >
97
120
< View style = { styles . visibilityContainer } >
@@ -134,9 +157,9 @@ export default function App() {
134
157
Intercom . registerUnidentifiedUser ( ) . then ( ( ) => setLoggedUser ( true ) ) ;
135
158
} }
136
159
/>
137
- < TextInput
160
+ < Input
161
+ title = "Email"
138
162
accessibilityLabel = "user-email"
139
- style = { styles . input }
140
163
value = { user . email }
141
164
onChangeText = { ( val ) => {
142
165
setUser ( ( prev ) => ( { ...prev , email : val } ) ) ;
@@ -147,18 +170,15 @@ export default function App() {
147
170
/>
148
171
< Button
149
172
accessibilityLabel = "login-identified"
150
- disabled = { loggedUser && user . email ! == '' }
173
+ disabled = { loggedUser || user . email = == '' }
151
174
title = "Login identified User"
152
175
onPress = { ( ) => {
153
176
if ( user . email ?. includes ( '@' ) ) {
154
177
Intercom . registerIdentifiedUser ( user ) . then ( ( ) =>
155
178
setLoggedUser ( true )
156
179
) ;
157
180
} else {
158
- Alert . alert (
159
- 'Not email' ,
160
- 'Provide correct email: [email protected] '
161
- ) ;
181
+ showEmptyAlertMessage ( 'Email' ) ;
162
182
}
163
183
} }
164
184
/>
@@ -170,12 +190,25 @@ export default function App() {
170
190
Intercom . displayMessenger ( ) ;
171
191
} }
172
192
/>
193
+ < Input
194
+ title = "Article Id"
195
+ accessibilityLabel = "article-id"
196
+ value = { articleId }
197
+ onChangeText = { ( val ) => {
198
+ setArticleId ( val ) ;
199
+ } }
200
+ placeholder = "Article Id"
201
+ />
173
202
< Button
174
203
accessibilityLabel = "display-article"
175
204
disabled = { ! loggedUser }
176
205
title = "Display Article"
177
206
onPress = { ( ) => {
178
- Intercom . displayArticle ( ARTICLE_ID ) ;
207
+ if ( articleId ) {
208
+ Intercom . displayArticle ( articleId ) ;
209
+ } else {
210
+ showEmptyAlertMessage ( 'Article id' ) ;
211
+ }
179
212
} }
180
213
/>
181
214
< Button
@@ -210,50 +243,91 @@ export default function App() {
210
243
Intercom . fetchHelpCenterCollections ( )
211
244
. then ( ( items ) => {
212
245
console . log ( items ) ;
246
+ showResponseAlert ( items ) ;
213
247
} )
214
248
. catch ( ( e ) => {
215
249
showErrorAlert ( e ) ;
216
250
console . error ( e ) ;
217
251
} ) ;
218
252
} }
219
253
/>
254
+ < Input
255
+ title = "Help Center Collection Id"
256
+ accessibilityLabel = "search-term"
257
+ value = { collectionId }
258
+ onChangeText = { ( val ) => {
259
+ setCollectionId ( val ) ;
260
+ } }
261
+ placeholder = "Help Center Collection Id"
262
+ />
220
263
< Button
221
264
accessibilityLabel = "fetch-help-center-collection"
222
265
disabled = { ! loggedUser }
223
266
title = "Fetch Help Center Collection"
224
267
onPress = { ( ) => {
225
- Intercom . fetchHelpCenterCollection ( COLLECTION_ID )
226
- . then ( ( item ) => {
227
- console . log ( item ) ;
228
- } )
229
- . catch ( ( e ) => {
230
- showErrorAlert ( e ) ;
231
- console . error ( e ) ;
232
- } ) ;
268
+ if ( collectionId ) {
269
+ Intercom . fetchHelpCenterCollection ( collectionId )
270
+ . then ( ( item ) => {
271
+ console . log ( item ) ;
272
+ showResponseAlert ( item ) ;
273
+ } )
274
+ . catch ( ( e ) => {
275
+ showErrorAlert ( e ) ;
276
+ console . error ( e ) ;
277
+ } ) ;
278
+ } else {
279
+ showEmptyAlertMessage ( 'Collection id' ) ;
280
+ }
281
+ } }
282
+ />
283
+ < Input
284
+ title = "Search term"
285
+ accessibilityLabel = "search-term"
286
+ value = { searchTerm }
287
+ onChangeText = { ( val ) => {
288
+ setSearchTerm ( val ) ;
233
289
} }
290
+ placeholder = "Search term"
234
291
/>
235
292
< Button
236
293
accessibilityLabel = "search-help-center"
237
294
disabled = { ! loggedUser }
238
295
title = "Search Help Center"
239
296
onPress = { ( ) => {
240
- Intercom . searchHelpCenter ( SEARCH_TERM )
241
- . then ( ( item ) => {
242
- console . log ( item ) ;
243
- } )
244
- . catch ( ( e ) => {
245
- showErrorAlert ( e ) ;
246
- console . error ( e ) ;
247
- } ) ;
297
+ if ( searchTerm ) {
298
+ Intercom . searchHelpCenter ( searchTerm )
299
+ . then ( ( item ) => {
300
+ console . log ( item ) ;
301
+ showResponseAlert ( item ) ;
302
+ } )
303
+ . catch ( ( e ) => {
304
+ showErrorAlert ( e ) ;
305
+ console . error ( e ) ;
306
+ } ) ;
307
+ } else {
308
+ showEmptyAlertMessage ( 'Search Term' ) ;
309
+ }
248
310
} }
249
311
/>
312
+ < Input
313
+ title = "Carousel Id"
314
+ accessibilityLabel = "carousel-id"
315
+ value = { carouselId }
316
+ onChangeText = { ( val ) => {
317
+ setCarouselId ( val ) ;
318
+ } }
319
+ placeholder = "Carousel Id"
320
+ />
250
321
< Button
251
322
accessibilityLabel = "display-carousel"
252
323
disabled = { ! loggedUser }
253
324
title = { 'Display Carousel' }
254
325
onPress = { ( ) => {
255
- console . log ( CAROUSEL_ID ) ;
256
- Intercom . displayCarousel ( CAROUSEL_ID ) ;
326
+ if ( carouselId ) {
327
+ Intercom . displayCarousel ( carouselId ) ;
328
+ } else {
329
+ showEmptyAlertMessage ( 'Carousel Id' ) ;
330
+ }
257
331
} }
258
332
/>
259
333
< Button
@@ -295,12 +369,25 @@ export default function App() {
295
369
) ;
296
370
} }
297
371
/>
372
+ < Input
373
+ title = "Event name"
374
+ accessibilityLabel = "event-name"
375
+ value = { eventName }
376
+ onChangeText = { ( val ) => {
377
+ setEventName ( val ) ;
378
+ } }
379
+ placeholder = "Event name"
380
+ />
298
381
< Button
299
382
accessibilityLabel = "log-event"
300
383
disabled = { ! loggedUser }
301
384
title = "Log Event"
302
385
onPress = { ( ) => {
303
- Intercom . logEvent ( EVENT_NAME ) ;
386
+ if ( eventName ) {
387
+ Intercom . logEvent ( eventName ) ;
388
+ } else {
389
+ showEmptyAlertMessage ( 'Event Name' ) ;
390
+ }
304
391
} }
305
392
/>
306
393
< Button
@@ -311,12 +398,26 @@ export default function App() {
311
398
Intercom . sendTokenToIntercom ( TOKEN ) ;
312
399
} }
313
400
/>
401
+
402
+ < Input
403
+ title = "User Name"
404
+ accessibilityLabel = "user-name"
405
+ value = { userName }
406
+ onChangeText = { ( val ) => {
407
+ setUserName ( val ) ;
408
+ } }
409
+ placeholder = "User Name"
410
+ />
314
411
< Button
315
412
accessibilityLabel = "update-user"
316
413
disabled = { ! loggedUser }
317
414
title = "Update user's name"
318
415
onPress = { ( ) => {
319
- Intercom . updateUser ( { name : USER_NAME } ) ;
416
+ if ( userName ) {
417
+ Intercom . updateUser ( { name : userName } ) ;
418
+ } else {
419
+ showEmptyAlertMessage ( 'User Name' ) ;
420
+ }
320
421
} }
321
422
/>
322
423
< Button
@@ -335,28 +436,29 @@ export default function App() {
335
436
const styles = StyleSheet . create ( {
336
437
container : {
337
438
flex : 1 ,
338
- marginHorizontal : 16 ,
439
+ marginHorizontal : 8 ,
339
440
paddingTop :
340
441
Platform . OS === 'ios'
341
- ? ( StatusBar . currentHeight ?? 0 ) + 24
342
- : StatusBar . currentHeight ?? 0 ,
442
+ ? ( StatusBar . currentHeight ?? 0 ) + 35
443
+ : ( StatusBar . currentHeight ?? 0 ) + 8 ?? 8 ,
343
444
} ,
344
445
box : {
345
446
width : 60 ,
346
447
height : 60 ,
347
448
marginVertical : 20 ,
348
449
} ,
349
- text : { marginVertical : 6 , fontSize : 18 } ,
450
+ text : { marginVertical : 4 , fontSize : 7 } ,
350
451
textCenter : { textAlign : 'center' } ,
351
452
boldText : { fontWeight : 'bold' , color : '#242d38' } ,
352
- textContainer : { justifyContent : 'center' , paddingVertical : 16 } ,
353
- input : {
354
- borderWidth : 1 ,
355
- borderColor : 'black' ,
356
- borderRadius : 8 ,
357
- paddingHorizontal : 8 ,
358
- paddingVertical : 4 ,
359
- } ,
453
+ textContainer : { justifyContent : 'center' , paddingVertical : 8 } ,
360
454
row : { flexDirection : 'row' } ,
361
455
visibilityContainer : { flex : 1 , padding : 4 } ,
456
+ logo : {
457
+ width : '10%' ,
458
+ height : undefined ,
459
+ aspectRatio : 1 ,
460
+ } ,
461
+ alignCenter : { alignItems : 'center' } ,
462
+ title : { fontWeight : 'bold' , fontSize : 17 , marginLeft : 8 } ,
463
+ header : { marginBottom : 8 } ,
362
464
} ) ;
0 commit comments