1- import React , { useEffect } from 'react' ;
2- import { StatusBar } from 'expo-status-bar' ;
1+ import React , { useEffect , useState , useCallback } from 'react' ;
32import {
4- StyleSheet ,
53 AppState ,
64 Text ,
75 TextInput ,
86 TouchableOpacity ,
97 View ,
8+ ScrollView ,
109} from 'react-native' ;
1110import Intercom , { Visibility } from '@intercom/intercom-react-native' ;
1211import { useIntercom } from './useIntercom' ;
@@ -27,43 +26,200 @@ export default function App() {
2726 } ) ( ) ;
2827 } , [ ] ) ;
2928
29+ const [ conversationId , setConversationId ] = useState ( null ) ;
30+ const [ articleId , setArticleId ] = useState ( null ) ;
31+ const [ carouselId , setCarouselId ] = useState ( null ) ;
32+ const [ surveyId , setSurveyId ] = useState ( null ) ;
33+ const [ collectionId , setCollectionId ] = useState ( null ) ;
34+ const [ launcherVisibility , setLauncherVisibility ] = useState ( false ) ;
35+
36+ const showConversation = useCallback ( ( ) => {
37+ openConversation ( conversationId ) ;
38+ } , [ conversationId ] ) ;
39+
40+ const showCarousel = useCallback ( ( ) => {
41+ openCarousel ( carouselId ) ;
42+ } ) ;
43+
44+ const showArticle = useCallback ( ( ) => {
45+ openArticle ( articleId ) ;
46+ } , [ articleId ] ) ;
47+
48+ const showSurvey = useCallback ( ( ) => {
49+ openSurvey ( surveyId ) ;
50+ } , [ articleId ] ) ;
51+
52+ const showHelpCenterCollection = useCallback ( ( ) => {
53+ openHelpCenterCollection ( collectionId ) ;
54+ } , [ articleId ] ) ;
55+
56+ const toggleLauncherVisibility = useCallback ( ( ) => {
57+ Intercom . setLauncherVisibility (
58+ launcherVisibility ? Visibility . GONE : Visibility . VISIBLE
59+ ) . then ( ( ) => setLauncherVisibility ( ( v ) => ! v ) ) ;
60+ } ) ;
61+
3062 const {
3163 handleLoginIdentifiedUser,
3264 handleLoginUnidentifiedUser,
3365 handleLogout,
3466 setUserIdentifier,
35- isLoggedIn,
67+ openHelpCenter,
68+ openMessages,
69+ openTicketsSpace,
70+ openConversation,
71+ openHelpCenterCollection,
72+ openArticle,
73+ openCarousel,
74+ openSurvey,
75+ openMessageComposer,
3676 } = useIntercom ( ) ;
3777
3878 return (
3979 < View style = { styles . screenWrapper } >
40- < Text style = { styles . title } > Push Notifications Sandbox </ Text >
41- < View style = { styles . wrapper } >
42- { ! isLoggedIn ? (
80+ < ScrollView >
81+ < Text style = { styles . title } > Push Notifications Sandbox </ Text >
82+ < View style = { styles . wrapper } >
4383 < >
44- < TextInput style = { styles . input } onChangeText = { setUserIdentifier } />
84+ < TextInput
85+ style = { styles . emailInput }
86+ onChangeText = { setUserIdentifier }
87+ placeholder = "Enter email"
88+ />
4589 < TouchableOpacity
4690 style = { styles . button }
4791 onPress = { handleLoginIdentifiedUser }
4892 >
49- < Text style = { styles . buttonText } > Login Identified User </ Text >
93+ < Text style = { styles . buttonText } > REGISTER IDENTIFIED </ Text >
5094 </ TouchableOpacity >
95+ < View style = { styles . rowWrapper } >
96+ < TouchableOpacity
97+ style = { styles . button }
98+ onPress = { handleLoginUnidentifiedUser }
99+ >
100+ < Text style = { styles . buttonText } > REGISTER UNIDENTIFIED</ Text >
101+ </ TouchableOpacity >
51102
52- < View style = { styles . divider } />
103+ < TouchableOpacity style = { styles . button } onPress = { handleLogout } >
104+ < Text style = { styles . buttonText } > RESET</ Text >
105+ </ TouchableOpacity >
106+ </ View >
107+ < View style = { styles . rowWrapper } >
108+ < TouchableOpacity style = { styles . button } onPress = { openMessages } >
109+ < Text style = { styles . buttonText } > OPEN MESSAGES</ Text >
110+ </ TouchableOpacity >
53111
54- < TouchableOpacity
55- style = { styles . button }
56- onPress = { handleLoginUnidentifiedUser }
57- >
58- < Text style = { styles . buttonText } > Login Unidentified User</ Text >
59- </ TouchableOpacity >
112+ < TouchableOpacity style = { styles . button } onPress = { openHelpCenter } >
113+ < Text style = { styles . buttonText } > HELP CENTER</ Text >
114+ </ TouchableOpacity >
115+ </ View >
116+ < View style = { styles . rowWrapper } >
117+ < TouchableOpacity
118+ style = { styles . button }
119+ onPress = { openTicketsSpace }
120+ >
121+ < Text style = { styles . buttonText } > TICKETS</ Text >
122+ </ TouchableOpacity >
123+
124+ < TouchableOpacity
125+ style = { styles . button }
126+ onPress = { openTicketsSpace }
127+ >
128+ < Text style = { styles . buttonText } > MESSENGER</ Text >
129+ </ TouchableOpacity >
130+ </ View >
131+ < View style = { styles . rowWrapper } >
132+ < TextInput
133+ style = { styles . input }
134+ onChangeText = { setCollectionId }
135+ placeholder = "Collection Id"
136+ />
137+ < TouchableOpacity
138+ style = { styles . button }
139+ onPress = { showHelpCenterCollection }
140+ disabled = { ! collectionId }
141+ >
142+ < Text style = { styles . buttonText } > HELP CENTER COLLECTION</ Text >
143+ </ TouchableOpacity >
144+ </ View >
145+ < View style = { styles . rowWrapper } >
146+ < TextInput
147+ style = { styles . input }
148+ onChangeText = { setConversationId }
149+ placeholder = "Conversation Id..."
150+ />
151+ < TouchableOpacity
152+ style = { styles . button }
153+ onPress = { showConversation }
154+ disabled = { ! conversationId }
155+ >
156+ < Text style = { styles . buttonText } > SHOW CONVERSATION</ Text >
157+ </ TouchableOpacity >
158+ </ View >
159+
160+ < View style = { styles . rowWrapper } >
161+ < TextInput
162+ style = { styles . input }
163+ onChangeText = { setArticleId }
164+ placeholder = "Article Id..."
165+ />
166+ < TouchableOpacity
167+ style = { styles . button }
168+ onPress = { showArticle }
169+ disabled = { ! articleId }
170+ >
171+ < Text style = { styles . buttonText } > SHOW ARTICLE</ Text >
172+ </ TouchableOpacity >
173+ </ View >
174+
175+ < View style = { styles . rowWrapper } >
176+ < TextInput
177+ style = { styles . input }
178+ onChangeText = { setCarouselId }
179+ placeholder = "Carousel Id..."
180+ />
181+ < TouchableOpacity
182+ style = { styles . button }
183+ onPress = { showCarousel }
184+ disabled = { ! carouselId }
185+ >
186+ < Text style = { styles . buttonText } > SHOW CAROUSEL</ Text >
187+ </ TouchableOpacity >
188+ </ View >
189+
190+ < View style = { styles . rowWrapper } >
191+ < TextInput
192+ style = { styles . input }
193+ onChangeText = { setSurveyId }
194+ placeholder = "Survey Id..."
195+ />
196+ < TouchableOpacity
197+ style = { styles . button }
198+ onPress = { showSurvey }
199+ disabled = { ! surveyId }
200+ >
201+ < Text style = { styles . buttonText } > SHOW SURVEY</ Text >
202+ </ TouchableOpacity >
203+ </ View >
204+
205+ < View style = { styles . rowWrapper } >
206+ < TouchableOpacity
207+ style = { styles . button }
208+ onPress = { openMessageComposer }
209+ >
210+ < Text style = { styles . buttonText } > SHOW COMPOSER</ Text >
211+ </ TouchableOpacity >
212+
213+ < TouchableOpacity
214+ style = { styles . button }
215+ onPress = { toggleLauncherVisibility }
216+ >
217+ < Text style = { styles . buttonText } > TOGGLE MESSENGER</ Text >
218+ </ TouchableOpacity >
219+ </ View >
60220 </ >
61- ) : (
62- < TouchableOpacity style = { styles . button } onPress = { handleLogout } >
63- < Text style = { styles . buttonText } > Logout</ Text >
64- </ TouchableOpacity >
65- ) }
66- </ View >
221+ </ View >
222+ </ ScrollView >
67223 </ View >
68224 ) ;
69225}
0 commit comments