diff --git a/package.json b/package.json index 149dd4f..1f39b63 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rn-erxes-sdk", - "version": "0.1.20", + "version": "0.1.23", "description": "react-native erxes sdk", "main": "lib/commonjs/index", "module": "lib/module/index", diff --git a/src/App.tsx b/src/App.tsx index a167372..65eb3df 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -32,37 +32,19 @@ const ErxesSDK: React.FC = ({ data, properties, }) => { + const [loading, setLoading] = React.useState(false); const [connection, setConnection] = React.useState({ cachedCustomerId: null, visitorId: null, }); - + const [cachedConversationId, setCachedConversationId] = + React.useState(null); const [show, setShow] = React.useState(showWidget); - const props = { - brandCode, - subDomain, - email, - onBack, - connection, - setConnection, - showWidget, - // icons - backIcon, - newChatIcon, - sendIcon, - // tracking - phone, - data, - properties, - // launcherOptions - show, - setShow, - }; - useEffect(() => { let visitorId: any; let tempCustomerId = ''; + setLoading(true); AsyncStorage.getItem('cachedCustomerId') .then((value) => { if (value !== null) { @@ -76,9 +58,25 @@ const ErxesSDK: React.FC = ({ cachedCustomerId: tempCustomerId ? tempCustomerId : null, visitorId: visitorId?.toString(), }); + AsyncStorage.getItem('conversationId') + .then((v) => { + if (v !== null) { + setCachedConversationId(v); + } + setLoading(false); + }) + .catch((e) => { + setLoading(false); + console.log('Failed on cachedConversationId', e.message); + }); }) .catch((e) => { - console.log('checkIntro', e.message); + setConnection({ + cachedCustomerId: null, + visitorId: new ObjectId(), + }); + setLoading(false); + console.log('Failed on cachedCustomerId', e.message); }); }, []); @@ -86,6 +84,33 @@ const ErxesSDK: React.FC = ({ return null; } + if (loading) { + return null; + } + + const props = { + brandCode, + subDomain, + email, + onBack, + connection, + setConnection, + showWidget, + // icons + backIcon, + newChatIcon, + sendIcon, + // tracking + phone, + data, + properties, + // launcherOptions + show, + setShow, + // + cachedConversationId, + }; + return ( diff --git a/src/Widget.tsx b/src/Widget.tsx index a6e46ff..5d24cbf 100644 --- a/src/Widget.tsx +++ b/src/Widget.tsx @@ -36,12 +36,14 @@ const Widget = (props: any) => { setShow, //domain subDomain, + // + cachedConversationId, } = props; const [visibleLauncher, setVisibleLauncher] = React.useState(false); const [response, setResponse] = React.useState(null); const [conversationId, setConversationId] = React.useState( - null + cachedConversationId ); const { data: dataUnreadCount } = useQuery(widgetsTotalUnreadCount, { diff --git a/src/components/InputTools.tsx b/src/components/InputTools.tsx index 6fefd80..9349733 100644 --- a/src/components/InputTools.tsx +++ b/src/components/InputTools.tsx @@ -27,6 +27,7 @@ const InputTools: React.FC = (props: any) => { onChangeText={(text) => { onInput(text); }} + autoCorrect={false} multiline={true} numberOfLines={5} // returnKeyType="send" diff --git a/src/screen/conversation/ConversationDetail.tsx b/src/screen/conversation/ConversationDetail.tsx index ab6e0a9..ad34731 100644 --- a/src/screen/conversation/ConversationDetail.tsx +++ b/src/screen/conversation/ConversationDetail.tsx @@ -22,6 +22,7 @@ import { widgetsInsertMessage } from '../../graphql/mutation'; import { conversationMessageInserted } from '../../graphql/subscription'; import { getAttachmentUrl } from '../../utils/utils'; import AppContext from '../../context/Context'; +import AsyncStorage from '@react-native-async-storage/async-storage'; const ConversationDetail = () => { const value = useContext(AppContext); @@ -220,6 +221,7 @@ const Header = (props: any) => { > { + AsyncStorage.removeItem('conversationId'); setConversationId(null); }} style={[ @@ -268,6 +270,7 @@ const Header = (props: any) => { > { + AsyncStorage.removeItem('conversationId'); setConversationId(null); }} style={[ diff --git a/src/screen/conversation/Conversations.tsx b/src/screen/conversation/Conversations.tsx index 8edb4af..a38963c 100644 --- a/src/screen/conversation/Conversations.tsx +++ b/src/screen/conversation/Conversations.tsx @@ -14,6 +14,7 @@ import dayjs from 'dayjs'; import FAB from '../../components/FAB'; import AppContext from '../../context/Context'; import Avatar from '../../components/Avatar'; +import AsyncStorage from '@react-native-async-storage/async-storage'; const Conversations = () => { const value = useContext(AppContext); @@ -59,6 +60,7 @@ const Conversations = () => { { + AsyncStorage.setItem('conversationId', item._id); setConversationId(item._id); }} >