rn-erxes-sdk 0.1.9 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/lib/commonjs/App.js +75 -6
  2. package/lib/commonjs/App.js.map +1 -1
  3. package/lib/commonjs/Widget.js +96 -88
  4. package/lib/commonjs/Widget.js.map +1 -1
  5. package/lib/commonjs/assets/images/Facebook.png +0 -0
  6. package/lib/commonjs/assets/images/Twitter.png +0 -0
  7. package/lib/commonjs/assets/images/Youtube.png +0 -0
  8. package/lib/commonjs/components/FAB.js +60 -0
  9. package/lib/commonjs/components/FAB.js.map +1 -0
  10. package/lib/commonjs/components/InputTools.js +79 -0
  11. package/lib/commonjs/components/InputTools.js.map +1 -0
  12. package/lib/commonjs/{apolloClient.js → graphql/apolloClient.js} +8 -1
  13. package/lib/commonjs/graphql/apolloClient.js.map +1 -0
  14. package/lib/commonjs/graphql/mutation.js +82 -1
  15. package/lib/commonjs/graphql/mutation.js.map +1 -1
  16. package/lib/commonjs/graphql/query.js +68 -1
  17. package/lib/commonjs/graphql/query.js.map +1 -1
  18. package/lib/commonjs/graphql/subscription.js +91 -0
  19. package/lib/commonjs/graphql/subscription.js.map +1 -0
  20. package/lib/commonjs/icons/MaterialCommunityIcons.js +2 -2
  21. package/lib/commonjs/icons/MaterialCommunityIcons.js.map +1 -1
  22. package/lib/commonjs/screen/conversation/Attachment.js +128 -0
  23. package/lib/commonjs/screen/conversation/Attachment.js.map +1 -0
  24. package/lib/commonjs/screen/conversation/ConversationDetail.js +290 -0
  25. package/lib/commonjs/screen/conversation/ConversationDetail.js.map +1 -0
  26. package/lib/commonjs/screen/conversation/Conversations.js +161 -0
  27. package/lib/commonjs/screen/conversation/Conversations.js.map +1 -0
  28. package/lib/commonjs/screen/conversation/Message.js +151 -0
  29. package/lib/commonjs/screen/conversation/Message.js.map +1 -0
  30. package/lib/commonjs/{Greetings.js → screen/greetings/Greetings.js} +35 -7
  31. package/lib/commonjs/screen/greetings/Greetings.js.map +1 -0
  32. package/lib/commonjs/{Social.js → screen/greetings/Social.js} +1 -1
  33. package/lib/commonjs/screen/greetings/Social.js.map +1 -0
  34. package/lib/commonjs/{Supporters.js → screen/greetings/Supporters.js} +2 -2
  35. package/lib/commonjs/screen/greetings/Supporters.js.map +1 -0
  36. package/lib/commonjs/utils/common.js +24 -0
  37. package/lib/commonjs/utils/common.js.map +1 -0
  38. package/lib/commonjs/utils/utils.js +42 -0
  39. package/lib/commonjs/utils/utils.js.map +1 -0
  40. package/lib/module/App.js +73 -6
  41. package/lib/module/App.js.map +1 -1
  42. package/lib/module/Widget.js +99 -87
  43. package/lib/module/Widget.js.map +1 -1
  44. package/lib/module/assets/images/Facebook.png +0 -0
  45. package/lib/module/assets/images/Twitter.png +0 -0
  46. package/lib/module/assets/images/Youtube.png +0 -0
  47. package/lib/module/components/FAB.js +51 -0
  48. package/lib/module/components/FAB.js.map +1 -0
  49. package/lib/module/components/InputTools.js +68 -0
  50. package/lib/module/components/InputTools.js.map +1 -0
  51. package/lib/module/{apolloClient.js → graphql/apolloClient.js} +8 -1
  52. package/lib/module/graphql/apolloClient.js.map +1 -0
  53. package/lib/module/graphql/mutation.js +80 -1
  54. package/lib/module/graphql/mutation.js.map +1 -1
  55. package/lib/module/graphql/query.js +67 -1
  56. package/lib/module/graphql/query.js.map +1 -1
  57. package/lib/module/graphql/subscription.js +81 -0
  58. package/lib/module/graphql/subscription.js.map +1 -0
  59. package/lib/module/icons/MaterialCommunityIcons.js +2 -2
  60. package/lib/module/icons/MaterialCommunityIcons.js.map +1 -1
  61. package/lib/module/screen/conversation/Attachment.js +119 -0
  62. package/lib/module/screen/conversation/Attachment.js.map +1 -0
  63. package/lib/module/screen/conversation/ConversationDetail.js +279 -0
  64. package/lib/module/screen/conversation/ConversationDetail.js.map +1 -0
  65. package/lib/module/screen/conversation/Conversations.js +152 -0
  66. package/lib/module/screen/conversation/Conversations.js.map +1 -0
  67. package/lib/module/screen/conversation/Message.js +142 -0
  68. package/lib/module/screen/conversation/Message.js.map +1 -0
  69. package/lib/module/{Greetings.js → screen/greetings/Greetings.js} +36 -8
  70. package/lib/module/screen/greetings/Greetings.js.map +1 -0
  71. package/lib/module/{Social.js → screen/greetings/Social.js} +1 -1
  72. package/lib/module/screen/greetings/Social.js.map +1 -0
  73. package/lib/module/{Supporters.js → screen/greetings/Supporters.js} +2 -2
  74. package/lib/module/screen/greetings/Supporters.js.map +1 -0
  75. package/lib/module/utils/common.js +15 -0
  76. package/lib/module/utils/common.js.map +1 -0
  77. package/lib/module/utils/utils.js +32 -0
  78. package/lib/module/utils/utils.js.map +1 -0
  79. package/lib/typescript/App.d.ts +3 -0
  80. package/lib/typescript/App.d.ts.map +1 -1
  81. package/lib/typescript/Widget.d.ts +1 -1
  82. package/lib/typescript/Widget.d.ts.map +1 -1
  83. package/lib/typescript/components/FAB.d.ts +18 -0
  84. package/lib/typescript/components/FAB.d.ts.map +1 -0
  85. package/lib/typescript/components/InputTools.d.ts +4 -0
  86. package/lib/typescript/components/InputTools.d.ts.map +1 -0
  87. package/lib/typescript/graphql/apolloClient.d.ts.map +1 -0
  88. package/lib/typescript/graphql/mutation.d.ts +3 -1
  89. package/lib/typescript/graphql/mutation.d.ts.map +1 -1
  90. package/lib/typescript/graphql/query.d.ts +2 -1
  91. package/lib/typescript/graphql/query.d.ts.map +1 -1
  92. package/lib/typescript/graphql/subscription.d.ts +7 -0
  93. package/lib/typescript/graphql/subscription.d.ts.map +1 -0
  94. package/lib/typescript/icons/MaterialCommunityIcons.d.ts.map +1 -1
  95. package/lib/typescript/screen/conversation/Attachment.d.ts +4 -0
  96. package/lib/typescript/screen/conversation/Attachment.d.ts.map +1 -0
  97. package/lib/typescript/screen/conversation/ConversationDetail.d.ts +4 -0
  98. package/lib/typescript/screen/conversation/ConversationDetail.d.ts.map +1 -0
  99. package/lib/typescript/screen/conversation/Conversations.d.ts +4 -0
  100. package/lib/typescript/screen/conversation/Conversations.d.ts.map +1 -0
  101. package/lib/typescript/screen/conversation/Message.d.ts +4 -0
  102. package/lib/typescript/screen/conversation/Message.d.ts.map +1 -0
  103. package/lib/typescript/screen/greetings/Greetings.d.ts.map +1 -0
  104. package/lib/typescript/screen/greetings/Social.d.ts.map +1 -0
  105. package/lib/typescript/screen/greetings/Supporters.d.ts.map +1 -0
  106. package/lib/typescript/utils/common.d.ts +4 -0
  107. package/lib/typescript/utils/common.d.ts.map +1 -0
  108. package/lib/typescript/utils/utils.d.ts +4 -0
  109. package/lib/typescript/utils/utils.d.ts.map +1 -0
  110. package/package.json +10 -1
  111. package/src/App.tsx +79 -4
  112. package/src/Widget.tsx +98 -92
  113. package/src/assets/images/Facebook.png +0 -0
  114. package/src/assets/images/Twitter.png +0 -0
  115. package/src/assets/images/Youtube.png +0 -0
  116. package/src/components/FAB.tsx +80 -0
  117. package/src/components/InputTools.tsx +74 -0
  118. package/src/{apolloClient.ts → graphql/apolloClient.ts} +8 -1
  119. package/src/graphql/mutation.ts +82 -1
  120. package/src/graphql/query.ts +68 -0
  121. package/src/graphql/subscription.ts +91 -0
  122. package/src/icons/MaterialCommunityIcons.tsx +2 -6
  123. package/src/screen/conversation/Attachment.tsx +136 -0
  124. package/src/screen/conversation/ConversationDetail.tsx +293 -0
  125. package/src/screen/conversation/Conversations.tsx +146 -0
  126. package/src/screen/conversation/Message.tsx +152 -0
  127. package/src/screen/greetings/Greetings.tsx +76 -0
  128. package/src/{Social.tsx → screen/greetings/Social.tsx} +1 -1
  129. package/src/{Supporters.tsx → screen/greetings/Supporters.tsx} +2 -2
  130. package/src/utils/common.ts +17 -0
  131. package/src/utils/utils.tsx +35 -0
  132. package/lib/commonjs/Greetings.js.map +0 -1
  133. package/lib/commonjs/Social.js.map +0 -1
  134. package/lib/commonjs/Support.js +0 -93
  135. package/lib/commonjs/Support.js.map +0 -1
  136. package/lib/commonjs/Supporters.js.map +0 -1
  137. package/lib/commonjs/apolloClient.js.map +0 -1
  138. package/lib/module/Greetings.js.map +0 -1
  139. package/lib/module/Social.js.map +0 -1
  140. package/lib/module/Support.js +0 -84
  141. package/lib/module/Support.js.map +0 -1
  142. package/lib/module/Supporters.js.map +0 -1
  143. package/lib/module/apolloClient.js.map +0 -1
  144. package/lib/typescript/Greetings.d.ts.map +0 -1
  145. package/lib/typescript/Social.d.ts.map +0 -1
  146. package/lib/typescript/Support.d.ts +0 -4
  147. package/lib/typescript/Support.d.ts.map +0 -1
  148. package/lib/typescript/Supporters.d.ts.map +0 -1
  149. package/lib/typescript/apolloClient.d.ts.map +0 -1
  150. package/src/Greetings.tsx +0 -37
  151. package/src/Support.tsx +0 -74
  152. /package/lib/typescript/{apolloClient.d.ts → graphql/apolloClient.d.ts} +0 -0
  153. /package/lib/typescript/{Greetings.d.ts → screen/greetings/Greetings.d.ts} +0 -0
  154. /package/lib/typescript/{Social.d.ts → screen/greetings/Social.d.ts} +0 -0
  155. /package/lib/typescript/{Supporters.d.ts → screen/greetings/Supporters.d.ts} +0 -0
@@ -39,4 +39,85 @@ const connect = gql`
39
39
  }
40
40
  `;
41
41
 
42
- export { connect };
42
+ const widgetsInsertMessage = gql`
43
+ mutation widgetsInsertMessage(
44
+ $integrationId: String!
45
+ $customerId: String
46
+ $visitorId: String
47
+ $message: String
48
+ $contentType: String
49
+ $conversationId: String
50
+ $attachments: [AttachmentInput]
51
+ $skillId: String
52
+ ) {
53
+ widgetsInsertMessage(
54
+ integrationId: $integrationId
55
+ customerId: $customerId
56
+ visitorId: $visitorId
57
+ contentType: $contentType
58
+ message: $message
59
+ conversationId: $conversationId
60
+ attachments: $attachments
61
+ skillId: $skillId
62
+ ) {
63
+ _id
64
+ conversationId
65
+ customerId
66
+ user {
67
+ _id
68
+ details {
69
+ avatar
70
+ fullName
71
+ __typename
72
+ }
73
+ __typename
74
+ }
75
+ content
76
+ createdAt
77
+ internal
78
+ fromBot
79
+ contentType
80
+ videoCallData {
81
+ url
82
+ status
83
+ __typename
84
+ }
85
+ engageData {
86
+ content
87
+ kind
88
+ sentAs
89
+ messageId
90
+ brandId
91
+ __typename
92
+ }
93
+ botData
94
+ messengerAppData
95
+ attachments {
96
+ url
97
+ name
98
+ size
99
+ type
100
+ __typename
101
+ }
102
+ __typename
103
+ }
104
+ }
105
+ `;
106
+
107
+ const widgetsSaveCustomerGetNotified = gql`
108
+ mutation widgetsSaveCustomerGetNotified(
109
+ $customerId: String
110
+ $visitorId: String
111
+ $type: String!
112
+ $value: String!
113
+ ) {
114
+ widgetsSaveCustomerGetNotified(
115
+ customerId: $customerId
116
+ visitorId: $visitorId
117
+ type: $type
118
+ value: $value
119
+ )
120
+ }
121
+ `;
122
+
123
+ export { connect, widgetsInsertMessage, widgetsSaveCustomerGetNotified };
@@ -100,9 +100,77 @@ const knowledgeBaseCategoryDetail = gql`
100
100
  }
101
101
  `;
102
102
 
103
+ const widgetsConversationDetail = gql`
104
+ query widgetsConversationDetail($_id: String, $integrationId: String!) {
105
+ widgetsConversationDetail(_id: $_id, integrationId: $integrationId) {
106
+ _id
107
+ messages {
108
+ _id
109
+ conversationId
110
+ customerId
111
+ user {
112
+ _id
113
+ details {
114
+ avatar
115
+ fullName
116
+ __typename
117
+ }
118
+ __typename
119
+ }
120
+ content
121
+ createdAt
122
+ internal
123
+ fromBot
124
+ contentType
125
+ videoCallData {
126
+ url
127
+ status
128
+ __typename
129
+ }
130
+ engageData {
131
+ content
132
+ kind
133
+ sentAs
134
+ messageId
135
+ brandId
136
+ __typename
137
+ }
138
+ botData
139
+ messengerAppData
140
+ attachments {
141
+ url
142
+ name
143
+ size
144
+ type
145
+ __typename
146
+ }
147
+ __typename
148
+ }
149
+ operatorStatus
150
+ isOnline
151
+ participatedUsers {
152
+ _id
153
+ details {
154
+ avatar
155
+ fullName
156
+ shortName
157
+ description
158
+ position
159
+ location
160
+ __typename
161
+ }
162
+ links
163
+ __typename
164
+ }
165
+ __typename
166
+ }
167
+ }
168
+ `;
169
+
103
170
  export {
104
171
  widgetsMessengerSupporters,
105
172
  widgetsConversations,
173
+ widgetsConversationDetail,
106
174
  knowledgeBaseTopicDetail,
107
175
  knowledgeBaseCategoryDetail,
108
176
  };
@@ -0,0 +1,91 @@
1
+ import { gql } from '@apollo/client';
2
+
3
+ const conversationMessageInserted = gql`
4
+ subscription conversationMessageInserted($_id: String!) {
5
+ conversationMessageInserted(_id: $_id) {
6
+ _id
7
+ attachments {
8
+ url
9
+ name
10
+ type
11
+ size
12
+ }
13
+ botData
14
+ content
15
+ contentType
16
+ conversationId
17
+ createdAt
18
+ customer {
19
+ avatar
20
+ firstName
21
+ lastName
22
+ primaryEmail
23
+ primaryPhone
24
+ _id
25
+ state
26
+ }
27
+ customerId
28
+ internal
29
+ fromBot
30
+ user {
31
+ _id
32
+ username
33
+ details {
34
+ avatar
35
+ fullName
36
+ position
37
+ }
38
+ }
39
+ userId
40
+ videoCallData {
41
+ url
42
+ name
43
+ status
44
+ recordingLinks
45
+ }
46
+ mentionedUserIds
47
+ }
48
+ }
49
+ `;
50
+
51
+ const conversationClientMessageInserted = gql`
52
+ subscription conversationClientMessageInserted(
53
+ $subdomain: String!
54
+ $userId: String!
55
+ ) {
56
+ conversationClientMessageInserted(subdomain: $subdomain, userId: $userId) {
57
+ _id
58
+ content
59
+ }
60
+ }
61
+ `;
62
+
63
+ const conversationChanged = gql`
64
+ subscription conversationChanged($_id: String!) {
65
+ conversationChanged(_id: $_id) {
66
+ conversationId
67
+ type
68
+ }
69
+ }
70
+ `;
71
+ const conversationExternalIntegrationMessageInserted = gql`
72
+ subscription conversationExternalIntegrationMessageInserted {
73
+ conversationExternalIntegrationMessageInserted
74
+ }
75
+ `;
76
+
77
+ const adminMessageInserted = gql`
78
+ subscription conversationAdminMessageInserted($customerId: String) {
79
+ conversationAdminMessageInserted(customerId: $customerId) {
80
+ unreadCount
81
+ }
82
+ }
83
+ `;
84
+
85
+ export {
86
+ conversationMessageInserted,
87
+ conversationClientMessageInserted,
88
+ conversationChanged,
89
+ conversationExternalIntegrationMessageInserted,
90
+ adminMessageInserted,
91
+ };
@@ -21,12 +21,8 @@ try {
21
21
  // Fallback component for icons
22
22
  MaterialCommunityIcons = ({ color, size, ...rest }: any) => {
23
23
  if (!isErrorLogged) {
24
- if (
25
- !/(Cannot find module|Module not found|Cannot resolve module)/.test(
26
- (e as any).message
27
- )
28
- ) {
29
- console.error(e);
24
+ if (!/(Cannot find module|Module not found|Cannot resolve module)/) {
25
+ console.error('Error');
30
26
  }
31
27
 
32
28
  console.warn(
@@ -0,0 +1,136 @@
1
+ /* eslint-disable react-native/no-inline-styles */
2
+ import React from 'react';
3
+ import { Dimensions, Image, Text, View } from 'react-native';
4
+ import { getAttachmentUrl } from '../../utils/utils';
5
+
6
+ const fullWidth = Dimensions.get('window');
7
+ const width = fullWidth.width / 2;
8
+
9
+ const Attachment: React.FC<any> = ({ images }) => {
10
+ if (!images || images.length === 0) {
11
+ return null;
12
+ }
13
+
14
+ const renderImage = (
15
+ mWidth: number | string | undefined,
16
+ uri: string,
17
+ index: number
18
+ ) => {
19
+ const url = getAttachmentUrl(uri);
20
+ return (
21
+ <View key={index}>
22
+ <Image
23
+ style={{
24
+ // flex: 1,
25
+ width: mWidth,
26
+ height: mWidth,
27
+ borderRadius: 6,
28
+ backgroundColor: 'transparent',
29
+ marginVertical: 8,
30
+ }}
31
+ source={{ uri: url }}
32
+ />
33
+ </View>
34
+ );
35
+ };
36
+
37
+ if (images.length === 1) {
38
+ return <View marginT-10>{renderImage(width, images[0].url, 0)}</View>;
39
+ }
40
+
41
+ if (images.length === 2) {
42
+ return (
43
+ <View
44
+ style={{
45
+ alignItems: 'center',
46
+ justifyContent: 'space-between',
47
+ flexDirection: 'row',
48
+ marginTop: 10,
49
+ }}
50
+ >
51
+ {renderImage(width / 2 - 2, images[0].url, 0)}
52
+ <View paddingL-8>{renderImage(width / 2 - 2, images[1].url, 1)}</View>
53
+ </View>
54
+ );
55
+ }
56
+
57
+ if (images.length === 3) {
58
+ return (
59
+ <View
60
+ style={{
61
+ alignItems: 'center',
62
+ justifyContent: 'space-between',
63
+ flexDirection: 'row',
64
+ marginTop: 10,
65
+ }}
66
+ >
67
+ {renderImage(width / 3 - 2, images[0].url, 0)}
68
+ <View paddingL-8>{renderImage(width / 3 - 2, images[1].url, 1)}</View>
69
+ <View paddingL-8>{renderImage(width / 3 - 2, images[2].url, 2)}</View>
70
+ </View>
71
+ );
72
+ }
73
+
74
+ if (images.length === 4) {
75
+ return (
76
+ <View>
77
+ <View
78
+ style={{
79
+ alignItems: 'center',
80
+ justifyContent: 'space-between',
81
+ flexDirection: 'row',
82
+ marginTop: 10,
83
+ }}
84
+ >
85
+ {renderImage(width / 3 - 2, images[0].url, 0)}
86
+ <View paddingL-8>{renderImage(width / 3 - 2, images[1].url, 1)}</View>
87
+ <View paddingL-8>{renderImage(width / 3 - 2, images[2].url, 2)}</View>
88
+ <View paddingL-8>{renderImage(width / 3 - 2, images[3].url, 3)}</View>
89
+ </View>
90
+ </View>
91
+ );
92
+ }
93
+
94
+ return (
95
+ <View>
96
+ <View
97
+ style={{
98
+ alignItems: 'center',
99
+ flexDirection: 'row',
100
+ marginTop: 10,
101
+ }}
102
+ >
103
+ {renderImage(width / 3 - 2, images[0].url, 0)}
104
+ <View style={{ paddingLeft: 8 }}>
105
+ {renderImage(width / 3 - 2, images[1].url, 1)}
106
+ </View>
107
+ <View style={{ paddingLeft: 8 }}>
108
+ {renderImage(width / 3 - 2, images[2].url, 2)}
109
+ </View>
110
+ <View style={{ paddingLeft: 8 }}>
111
+ {renderImage(width / 3 - 2, images[3].url, 3)}
112
+ <View
113
+ style={{
114
+ position: 'absolute',
115
+ right: 0,
116
+ left: 0,
117
+ top: 0,
118
+ bottom: 0,
119
+ backgroundColor: 'rgba(255,255,255,0.5)',
120
+ marginLeft: 8,
121
+ alignItems: 'center',
122
+ justifyContent: 'center',
123
+ borderRadius: 6,
124
+ }}
125
+ >
126
+ <Text style={{ color: '#686868', fontSize: 16, fontWeight: '500' }}>
127
+ {'+ ' + `${images.length - 4}`}
128
+ </Text>
129
+ </View>
130
+ </View>
131
+ </View>
132
+ </View>
133
+ );
134
+ };
135
+
136
+ export default Attachment;
@@ -0,0 +1,293 @@
1
+ /* eslint-disable react-native/no-inline-styles */
2
+ import {
3
+ View,
4
+ Text,
5
+ ActivityIndicator,
6
+ TouchableOpacity,
7
+ StyleSheet,
8
+ FlatList,
9
+ KeyboardAvoidingView,
10
+ Platform,
11
+ TouchableWithoutFeedback,
12
+ Keyboard,
13
+ Image,
14
+ } from 'react-native';
15
+ import React, { useEffect } from 'react';
16
+ import { useMutation, useQuery, useSubscription } from '@apollo/client';
17
+ import { widgetsConversationDetail } from '../../graphql/query';
18
+ import MaterialCommunityIcons from '../../icons/MaterialCommunityIcons';
19
+ import { useSafeAreaInsets } from 'react-native-safe-area-context';
20
+ import Message from './Message';
21
+ import InputTools from '../../components/InputTools';
22
+ import { widgetsInsertMessage } from '../../graphql/mutation';
23
+ import { conversationMessageInserted } from '../../graphql/subscription';
24
+ import { getAttachmentUrl } from '../../utils/utils';
25
+ import { getLocalStorageItem, setLocalStorageItem } from '../../utils/common';
26
+
27
+ const ConversationDetail = (props: any) => {
28
+ const { route, navigation } = props;
29
+ const { _id, integrationId, bgColor, brand, customerId, visitorId } =
30
+ route.params;
31
+
32
+ const [messages, setMessages] = React.useState<any>([]);
33
+
34
+ const { data, loading } = useQuery(widgetsConversationDetail, {
35
+ variables: {
36
+ _id,
37
+ integrationId,
38
+ },
39
+ fetchPolicy: 'network-only',
40
+ skip: !_id,
41
+ });
42
+
43
+ const { data: subscriptionData } = useSubscription(
44
+ conversationMessageInserted,
45
+ {
46
+ variables: { _id },
47
+ fetchPolicy: 'network-only',
48
+ skip: !_id,
49
+ }
50
+ );
51
+
52
+ useEffect(() => {
53
+ let shouldAdd = subscriptionData && data;
54
+ if (data?.length > 0) {
55
+ shouldAdd =
56
+ subscriptionData?.conversationMessageInserted?._id !== data[0]._id;
57
+ }
58
+ if (shouldAdd) {
59
+ setMessages((prev: any) => [
60
+ subscriptionData?.conversationMessageInserted,
61
+ ...prev,
62
+ ]);
63
+ }
64
+ // eslint-disable-next-line react-hooks/exhaustive-deps
65
+ }, [subscriptionData]);
66
+
67
+ useEffect(() => {
68
+ if (data?.widgetsConversationDetail?.messages) {
69
+ let reversed = data?.widgetsConversationDetail?.messages
70
+ ?.slice()
71
+ ?.reverse();
72
+ setMessages(reversed);
73
+ }
74
+ }, [data]);
75
+
76
+ const [sendMutation] = useMutation(widgetsInsertMessage);
77
+
78
+ const onSend = (text: string) => {
79
+ sendMutation({
80
+ variables: {
81
+ integrationId,
82
+ customerId,
83
+ visitorId,
84
+ conversationId: _id,
85
+ contentType: 'text',
86
+ message: text,
87
+ },
88
+ })
89
+ .then((res: any) => {
90
+ if (res.errors) {
91
+ return console.log(res.errors);
92
+ }
93
+ if (res.data.widgetsInsertMessage) {
94
+ const cachedCustomerId = getLocalStorageItem('customerId');
95
+ if (!cachedCustomerId) {
96
+ const tempCustomerId = res.data.widgetsInsertMessage.customerId;
97
+ setLocalStorageItem('customerId', tempCustomerId);
98
+ }
99
+ let shouldAdd = messages?.length === 0;
100
+ if (!shouldAdd) {
101
+ shouldAdd = res.data.widgetsInsertMessage._id !== data[0]._id;
102
+ }
103
+ if (shouldAdd) {
104
+ const newArray = [res.data.widgetsInsertMessage, ...data];
105
+ setMessages(newArray);
106
+ }
107
+ }
108
+ })
109
+ .catch((err: any) => {
110
+ console.log(err);
111
+ });
112
+ };
113
+
114
+ if (loading) {
115
+ return (
116
+ <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
117
+ <ActivityIndicator color={'#686868'} size={'large'} />
118
+ </View>
119
+ );
120
+ }
121
+
122
+ const renderItem = ({ item }: any) => {
123
+ return <Message item={item} bgColor={bgColor} />;
124
+ };
125
+
126
+ const renderContent = () => {
127
+ return (
128
+ <View style={{ flex: 1 }}>
129
+ <FlatList
130
+ contentContainerStyle={styles.contentStyle}
131
+ showsVerticalScrollIndicator={false}
132
+ data={messages}
133
+ keyExtractor={(item: any) => item._id}
134
+ onEndReachedThreshold={0.2}
135
+ renderItem={renderItem}
136
+ ItemSeparatorComponent={() => null}
137
+ inverted
138
+ />
139
+ </View>
140
+ );
141
+ };
142
+
143
+ return (
144
+ <View style={{ flex: 1 }}>
145
+ <Header
146
+ navigation={navigation}
147
+ brand={brand}
148
+ bgColor={bgColor}
149
+ users={data?.widgetsConversationDetail?.participatedUsers}
150
+ />
151
+ <View style={{ backgroundColor: 'rgba(215,215,215,.7)', flex: 1 }}>
152
+ {renderContent()}
153
+ <KeyboardAvoidingView
154
+ behavior={Platform.OS === 'ios' ? 'padding' : undefined}
155
+ keyboardVerticalOffset={100}
156
+ >
157
+ <TouchableWithoutFeedback onPress={() => Keyboard.dismiss()}>
158
+ <InputTools onSend={onSend} bgColor={bgColor} />
159
+ </TouchableWithoutFeedback>
160
+ </KeyboardAvoidingView>
161
+ </View>
162
+ </View>
163
+ );
164
+ };
165
+
166
+ export default ConversationDetail;
167
+
168
+ const Header = (props: any) => {
169
+ const { navigation, brand, bgColor, users } = props;
170
+
171
+ const insets = useSafeAreaInsets();
172
+
173
+ if (users?.length > 0) {
174
+ const url = getAttachmentUrl(users[0]?.details?.avatar);
175
+ return (
176
+ <View
177
+ style={{
178
+ flexDirection: 'row',
179
+ alignItems: 'center',
180
+ paddingBottom: 20,
181
+ backgroundColor: bgColor || 'green',
182
+ paddingTop: insets.top,
183
+ }}
184
+ >
185
+ <TouchableOpacity
186
+ onPress={() => {
187
+ navigation.goBack();
188
+ }}
189
+ style={[
190
+ styles.backStyle,
191
+ {
192
+ backgroundColor: '#2F1F69',
193
+ },
194
+ ]}
195
+ >
196
+ <MaterialCommunityIcons
197
+ allowFontScaling={false}
198
+ name={'chevron-left'}
199
+ size={24}
200
+ color={'white'}
201
+ direction="ltr"
202
+ />
203
+ </TouchableOpacity>
204
+ <View
205
+ style={[
206
+ styles.title,
207
+ {
208
+ marginLeft: 10,
209
+ alignItems: 'center',
210
+ flex: 1,
211
+ },
212
+ ]}
213
+ >
214
+ <Image
215
+ source={{ uri: url, cache: 'force-cache' }}
216
+ style={styles.avatar}
217
+ resizeMode="stretch"
218
+ />
219
+ <View style={{ marginLeft: 10 }}>
220
+ <Text style={{ fontWeight: '600' }}>
221
+ {users[0]?.details?.fullName}
222
+ </Text>
223
+ <Text style={{ color: '#686868' }}>
224
+ {users[0]?.details?.position}
225
+ </Text>
226
+ </View>
227
+ </View>
228
+ </View>
229
+ );
230
+ }
231
+
232
+ return (
233
+ <View
234
+ style={{
235
+ flexDirection: 'row',
236
+ alignItems: 'center',
237
+ paddingBottom: 20,
238
+ backgroundColor: bgColor || 'green',
239
+ paddingTop: insets.top,
240
+ }}
241
+ >
242
+ <TouchableOpacity
243
+ onPress={() => {
244
+ navigation.goBack();
245
+ }}
246
+ style={[
247
+ styles.backStyle,
248
+ {
249
+ backgroundColor: '#2F1F69',
250
+ },
251
+ ]}
252
+ >
253
+ <MaterialCommunityIcons
254
+ allowFontScaling={false}
255
+ name={'chevron-left'}
256
+ size={24}
257
+ color={'white'}
258
+ direction="ltr"
259
+ />
260
+ </TouchableOpacity>
261
+ <View style={[styles.title]}>
262
+ <Text style={{ fontWeight: '600', fontSize: 16 }}>{brand?.name}</Text>
263
+ </View>
264
+ </View>
265
+ );
266
+ };
267
+
268
+ const styles = StyleSheet.create({
269
+ backStyle: {
270
+ width: 40,
271
+ height: 40,
272
+ marginLeft: 15,
273
+ borderRadius: 90,
274
+ justifyContent: 'center',
275
+ alignItems: 'center',
276
+ },
277
+ title: {
278
+ paddingVertical: 10,
279
+ paddingHorizontal: 15,
280
+ borderTopLeftRadius: 8,
281
+ borderTopRightRadius: 8,
282
+ flexDirection: 'row',
283
+ },
284
+ contentStyle: {
285
+ flexGrow: 1,
286
+ padding: 20,
287
+ },
288
+ avatar: {
289
+ width: 40,
290
+ height: 40,
291
+ borderRadius: 90,
292
+ },
293
+ });