diff --git a/src/screens/SupportChat.tsx b/src/screens/SupportChat.tsx index edd9623..f5ec6c3 100644 --- a/src/screens/SupportChat.tsx +++ b/src/screens/SupportChat.tsx @@ -9,94 +9,69 @@ import { StyleSheet, } from 'react-native'; -const SupportChat = () => { - const [loading, setLoading] = useState(true); - const [error, setError] = useState(null); - const [chatReady, setChatReady] = useState(false); - const webViewRef = useRef(null); +const CHATWOOT_HTML = ` + + + + + + Flash Support + + + +
Connecting to support...
- const chatUrl = 'https://getflash.io/app/tidio.html'; - - const handleLoadStart = () => { - console.log('WebView started loading'); - setLoading(true); - setError(null); - setChatReady(false); - }; + + + +`; + +const SupportChat = () => { + const [loading, setLoading] = useState(true); + const [error, setError] = useState(null); + const webViewRef = useRef(null); - webViewRef.current?.injectJavaScript(injectJS); + const handleLoadEnd = () => { + // WebView loaded, Chatwoot SDK will initialize + setTimeout(() => setLoading(false), 3000); // Fallback timeout }; const handleError = (syntheticEvent: any) => { @@ -111,28 +86,8 @@ const SupportChat = () => { const data = JSON.parse(event.nativeEvent?.data); console.log('Message from WebView:', data); - switch (data.type) { - case 'chatOpened': - setChatReady(true); - console.log('Chat opened successfully'); - break; - case 'chatReady': - setChatReady(true); - console.log('Chat is ready'); - break; - case 'chatError': - console.error('Chat error:', data.error); - setError(`Chat error: ${data.error}`); - break; - case 'chatTimeout': - console.error('Chat timeout after', data.attempts, 'attempts'); - setError('Chat failed to load. Please try refreshing.'); - break; - case 'scriptInjected': - console.log('Script injected at:', data.timestamp); - break; - default: - console.log('Unknown message type:', data.type); + if (data.type === 'chatReady') { + setLoading(false); } } catch (e) { console.log('Raw WebView message:', event.nativeEvent.data); @@ -142,13 +97,11 @@ const SupportChat = () => { const handleRefresh = () => { setError(null); setLoading(true); - setChatReady(false); webViewRef.current?.reload(); }; return ( - {/* Error display */} {error && ( {error} @@ -158,35 +111,29 @@ const SupportChat = () => { )} - {/* Loading overlay */} {loading && ( - Loading Tidio Chat... + Loading Support Chat... )} - {/* WebView */}