Skip to content

Commit

Permalink
last conversation navigate
Browse files Browse the repository at this point in the history
  • Loading branch information
Munkhorgilb committed Sep 1, 2023
1 parent 3446b8e commit 487e1ff
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
71 changes: 48 additions & 23 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,19 @@ const ErxesSDK: React.FC<PropTypes> = ({
data,
properties,
}) => {
const [loading, setLoading] = React.useState<boolean>(false);
const [connection, setConnection] = React.useState<any>({
cachedCustomerId: null,
visitorId: null,
});

const [cachedConversationId, setCachedConversationId] =
React.useState<any>(null);
const [show, setShow] = React.useState<boolean>(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) {
Expand All @@ -76,16 +58,59 @@ const ErxesSDK: React.FC<PropTypes> = ({
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);
});
}, []);

if (!connection?.cachedCustomerId && !connection?.visitorId) {
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 (
<ApolloContainer subDomain={subDomain}>
<Widget {...props} />
Expand Down
4 changes: 3 additions & 1 deletion src/Widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ const Widget = (props: any) => {
setShow,
//domain
subDomain,
//
cachedConversationId,
} = props;

const [visibleLauncher, setVisibleLauncher] = React.useState<boolean>(false);
const [response, setResponse] = React.useState<any>(null);
const [conversationId, setConversationId] = React.useState<string | null>(
null
cachedConversationId
);

const { data: dataUnreadCount } = useQuery(widgetsTotalUnreadCount, {
Expand Down
1 change: 1 addition & 0 deletions src/components/InputTools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const InputTools: React.FC<any> = (props: any) => {
onChangeText={(text) => {
onInput(text);
}}
autoCorrect={false}
multiline={true}
numberOfLines={5}
// returnKeyType="send"
Expand Down
3 changes: 3 additions & 0 deletions src/screen/conversation/ConversationDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -220,6 +221,7 @@ const Header = (props: any) => {
>
<TouchableOpacity
onPress={() => {
AsyncStorage.removeItem('conversationId');
setConversationId(null);
}}
style={[
Expand Down Expand Up @@ -268,6 +270,7 @@ const Header = (props: any) => {
>
<TouchableOpacity
onPress={() => {
AsyncStorage.removeItem('conversationId');
setConversationId(null);
}}
style={[
Expand Down
2 changes: 2 additions & 0 deletions src/screen/conversation/Conversations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -59,6 +60,7 @@ const Conversations = () => {
<TouchableOpacity
style={styles.itemContainer}
onPress={() => {
AsyncStorage.setItem('conversationId', item._id);
setConversationId(item._id);
}}
>
Expand Down

0 comments on commit 487e1ff

Please sign in to comment.