rn-erxes-sdk 0.1.3 → 0.1.5

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 (94) hide show
  1. package/README.md +39 -20
  2. package/lib/commonjs/App.js +9 -44
  3. package/lib/commonjs/App.js.map +1 -1
  4. package/lib/commonjs/FAQ.js +175 -0
  5. package/lib/commonjs/FAQ.js.map +1 -0
  6. package/lib/commonjs/Greetings.js +57 -0
  7. package/lib/commonjs/Greetings.js.map +1 -0
  8. package/lib/commonjs/Social.js +46 -0
  9. package/lib/commonjs/Social.js.map +1 -0
  10. package/lib/commonjs/Support.js +93 -0
  11. package/lib/commonjs/Support.js.map +1 -0
  12. package/lib/commonjs/Supporters.js +73 -0
  13. package/lib/commonjs/Supporters.js.map +1 -0
  14. package/lib/commonjs/Widget.js +132 -0
  15. package/lib/commonjs/Widget.js.map +1 -0
  16. package/lib/commonjs/apolloClient.js +55 -0
  17. package/lib/commonjs/apolloClient.js.map +1 -0
  18. package/lib/commonjs/assets/images/Facebook.png +0 -0
  19. package/lib/commonjs/assets/images/Twitter.png +0 -0
  20. package/lib/commonjs/assets/images/Youtube.png +0 -0
  21. package/lib/commonjs/assets/images/avatar.png +0 -0
  22. package/lib/commonjs/assets/images/index.js +15 -0
  23. package/lib/commonjs/assets/images/index.js.map +1 -0
  24. package/lib/commonjs/graphql/graphql.js +108 -0
  25. package/lib/commonjs/graphql/graphql.js.map +1 -0
  26. package/lib/commonjs/graphql/mutation.js +47 -0
  27. package/lib/commonjs/graphql/mutation.js.map +1 -0
  28. package/lib/module/App.js +9 -44
  29. package/lib/module/App.js.map +1 -1
  30. package/lib/module/FAQ.js +165 -0
  31. package/lib/module/FAQ.js.map +1 -0
  32. package/lib/module/Greetings.js +48 -0
  33. package/lib/module/Greetings.js.map +1 -0
  34. package/lib/module/Social.js +37 -0
  35. package/lib/module/Social.js.map +1 -0
  36. package/lib/module/Support.js +84 -0
  37. package/lib/module/Support.js.map +1 -0
  38. package/lib/module/Supporters.js +64 -0
  39. package/lib/module/Supporters.js.map +1 -0
  40. package/lib/module/Widget.js +123 -0
  41. package/lib/module/Widget.js.map +1 -0
  42. package/lib/module/apolloClient.js +46 -0
  43. package/lib/module/apolloClient.js.map +1 -0
  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/assets/images/avatar.png +0 -0
  48. package/lib/module/assets/images/index.js +8 -0
  49. package/lib/module/assets/images/index.js.map +1 -0
  50. package/lib/module/graphql/graphql.js +99 -0
  51. package/lib/module/graphql/graphql.js.map +1 -0
  52. package/lib/module/graphql/mutation.js +41 -0
  53. package/lib/module/graphql/mutation.js.map +1 -0
  54. package/lib/typescript/App.d.ts +1 -1
  55. package/lib/typescript/App.d.ts.map +1 -1
  56. package/lib/typescript/FAQ.d.ts +4 -0
  57. package/lib/typescript/FAQ.d.ts.map +1 -0
  58. package/lib/typescript/Greetings.d.ts +4 -0
  59. package/lib/typescript/Greetings.d.ts.map +1 -0
  60. package/lib/typescript/Social.d.ts +4 -0
  61. package/lib/typescript/Social.d.ts.map +1 -0
  62. package/lib/typescript/Support.d.ts +4 -0
  63. package/lib/typescript/Support.d.ts.map +1 -0
  64. package/lib/typescript/Supporters.d.ts +4 -0
  65. package/lib/typescript/Supporters.d.ts.map +1 -0
  66. package/lib/typescript/Widget.d.ts +4 -0
  67. package/lib/typescript/Widget.d.ts.map +1 -0
  68. package/lib/typescript/apolloClient.d.ts +6 -0
  69. package/lib/typescript/apolloClient.d.ts.map +1 -0
  70. package/lib/typescript/assets/images/index.d.ts +8 -0
  71. package/lib/typescript/assets/images/index.d.ts.map +1 -0
  72. package/lib/typescript/graphql/graphql.d.ts +6 -0
  73. package/lib/typescript/graphql/graphql.d.ts.map +1 -0
  74. package/lib/typescript/graphql/mutation.d.ts +3 -0
  75. package/lib/typescript/graphql/mutation.d.ts.map +1 -0
  76. package/package.json +9 -5
  77. package/src/App.tsx +8 -42
  78. package/src/FAQ.tsx +166 -0
  79. package/src/Greetings.tsx +37 -0
  80. package/src/Social.tsx +46 -0
  81. package/src/Support.tsx +74 -0
  82. package/src/Supporters.tsx +63 -0
  83. package/src/Widget.tsx +138 -0
  84. package/src/apolloClient.ts +57 -0
  85. package/src/assets/images/Facebook.png +0 -0
  86. package/src/assets/images/Twitter.png +0 -0
  87. package/src/assets/images/Youtube.png +0 -0
  88. package/src/assets/images/avatar.png +0 -0
  89. package/src/assets/images/index.ts +8 -0
  90. package/src/graphql/graphql.ts +108 -0
  91. package/src/graphql/mutation.ts +42 -0
  92. package/lib/commonjs/index.html +0 -114
  93. package/lib/module/index.html +0 -114
  94. package/src/index.html +0 -114
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Greetings.d.ts","sourceRoot":"","sources":["../../src/Greetings.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,QAAA,MAAM,SAAS,UAAW,GAAG,sBAmB5B,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ declare const Social: (props: any) => React.JSX.Element;
3
+ export default Social;
4
+ //# sourceMappingURL=Social.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Social.d.ts","sourceRoot":"","sources":["../../src/Social.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,QAAA,MAAM,MAAM,UAAW,GAAG,sBAyBzB,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ declare const Support: (props: any) => React.JSX.Element | null;
3
+ export default Support;
4
+ //# sourceMappingURL=Support.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Support.d.ts","sourceRoot":"","sources":["../../src/Support.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAC;AAM1B,QAAA,MAAM,OAAO,UAAW,GAAG,6BAiD1B,CAAC;AAEF,eAAe,OAAO,CAAC"}
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ declare const Supporters: (props: any) => React.JSX.Element | null;
3
+ export default Supporters;
4
+ //# sourceMappingURL=Supporters.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Supporters.d.ts","sourceRoot":"","sources":["../../src/Supporters.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,QAAA,MAAM,UAAU,UAAW,GAAG,6BAsC7B,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ declare const Widget: (props: any) => React.JSX.Element;
3
+ export default Widget;
4
+ //# sourceMappingURL=Widget.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Widget.d.ts","sourceRoot":"","sources":["../../src/Widget.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAO1B,QAAA,MAAM,MAAM,UAAW,GAAG,sBAiDzB,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { ApolloClient } from '@apollo/client/core';
2
+ export declare const apiUrl: string;
3
+ export declare const wsLink: any;
4
+ declare const ClientProvider: () => ApolloClient<import("@apollo/client/core").NormalizedCacheObject>;
5
+ export default ClientProvider;
6
+ //# sourceMappingURL=apolloClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apolloClient.d.ts","sourceRoot":"","sources":["../../src/apolloClient.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EAKb,MAAM,qBAAqB,CAAC;AAQ7B,eAAO,MAAM,MAAM,QAAuB,CAAC;AAG3C,eAAO,MAAM,MAAM,EAAE,GAQpB,CAAC;AAwBF,QAAA,MAAM,cAAc,yEAKhB,CAAC;AAEL,eAAe,cAAc,CAAC"}
@@ -0,0 +1,8 @@
1
+ declare const images: {
2
+ facebook: any;
3
+ youtube: any;
4
+ twitter: any;
5
+ avatar: any;
6
+ };
7
+ export default images;
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/assets/images/index.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,MAAM;;;;;CAKX,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -0,0 +1,6 @@
1
+ declare const widgetsMessengerSupporters: DocumentNode;
2
+ declare const widgetsConversations: DocumentNode;
3
+ declare const knowledgeBaseTopicDetail: DocumentNode;
4
+ declare const knowledgeBaseCategoryDetail: DocumentNode;
5
+ export { widgetsMessengerSupporters, widgetsConversations, knowledgeBaseTopicDetail, knowledgeBaseCategoryDetail, };
6
+ //# sourceMappingURL=graphql.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../../src/graphql/graphql.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,0BAA0B,cAoB/B,CAAC;AAEF,QAAA,MAAM,oBAAoB,cAyBzB,CAAC;AAEF,QAAA,MAAM,wBAAwB,cA0B7B,CAAC;AAEF,QAAA,MAAM,2BAA2B,cAqBhC,CAAC;AAEF,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,EACpB,wBAAwB,EACxB,2BAA2B,GAC5B,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const connect: DocumentNode;
2
+ export { connect };
3
+ //# sourceMappingURL=mutation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mutation.d.ts","sourceRoot":"","sources":["../../../src/graphql/mutation.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,OAAO,cAqCZ,CAAC;AAEF,OAAO,EAAE,OAAO,EAAE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rn-erxes-sdk",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "react-native erxes sdk",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -40,13 +40,13 @@
40
40
  "ios",
41
41
  "android"
42
42
  ],
43
- "repository": "https://github.com/Munkhorgilb/rn-erxes-sdk",
43
+ "repository": "https://github.com/erxes/rn-erxes-sdk",
44
44
  "author": "Munkh-orgil <monkhorgilbayarbaatar@gmail.com> (https://github.com/Munkhorgilb)",
45
45
  "license": "MIT",
46
46
  "bugs": {
47
- "url": "https://github.com/Munkhorgilb/rn-erxes-sdk/issues"
47
+ "url": "https://github.com/erxes/rn-erxes-sdk/issues"
48
48
  },
49
- "homepage": "https://github.com/Munkhorgilb/rn-erxes-sdk#readme",
49
+ "homepage": "https://github.com/erxes/rn-erxes-sdk#readme",
50
50
  "publishConfig": {
51
51
  "registry": "https://registry.npmjs.org/"
52
52
  },
@@ -157,6 +157,10 @@
157
157
  ]
158
158
  },
159
159
  "dependencies": {
160
- "react-native-webview": "^12.2.0"
160
+ "@apollo/client": "^3.7.15",
161
+ "dayjs": "^1.11.8",
162
+ "react-native-webview": "11.26.0",
163
+ "graphql-ws": "^5.13.1",
164
+ "react-apollo": "^3.1.5"
161
165
  }
162
166
  }
package/src/App.tsx CHANGED
@@ -1,51 +1,17 @@
1
1
  import React from 'react';
2
- import { WebView } from 'react-native-webview';
3
- import { Platform } from 'react-native';
2
+ import { ApolloProvider } from '@apollo/client';
3
+ import ClientProvider from './apolloClient';
4
+ import Widget from './Widget';
4
5
 
5
6
  export type PropTypes = {
6
- script: string;
7
+ brandCode: string;
7
8
  };
8
9
 
9
- const ErxesSDK: React.FC<PropTypes> = ({ script }) => {
10
- const onMessage = (data: any) => {
11
- const { notificationCount } = JSON.parse(data.nativeEvent.data);
12
-
13
- console.log('****************** ', notificationCount);
14
- };
15
-
10
+ const ErxesSDK: React.FC<PropTypes> = ({ brandCode }) => {
16
11
  return (
17
- <WebView
18
- ref={() => {}}
19
- source={
20
- Platform.OS === 'ios'
21
- ? require('./index.html')
22
- : { uri: 'file:///android_asset/index.html' }
23
- }
24
- originWhitelist={['*']}
25
- sharedCookiesEnabled={true}
26
- cacheEnabled={true}
27
- allowFileAccess={true}
28
- domStorageEnabled={true}
29
- thirdPartyCookiesEnabled={true}
30
- // allowingReadAccessToURL
31
- // style={{ width: 200 }}
32
- onLoadEnd={(syntheticEvent) => {
33
- // update component to be aware of loading status
34
- const { nativeEvent } = syntheticEvent;
35
- console.log(nativeEvent.loading);
36
- }}
37
- javaScriptEnabled={true}
38
- onError={(er) => {
39
- console.log(er);
40
- }}
41
- startInLoadingState={true}
42
- // renderLoading={() => <Loader />}
43
- injectedJavaScript={script}
44
- // injectedJavaScriptBeforeContentLoaded={runFirst}
45
-
46
- // onNavigationStateChange={this.handleWebViewNavigationStateChange}
47
- onMessage={onMessage}
48
- />
12
+ <ApolloProvider client={ClientProvider()}>
13
+ <Widget brandCode={brandCode} />
14
+ </ApolloProvider>
49
15
  );
50
16
  };
51
17
 
package/src/FAQ.tsx ADDED
@@ -0,0 +1,166 @@
1
+ /* eslint-disable react-native/no-inline-styles */
2
+ import {
3
+ View,
4
+ Text,
5
+ StyleSheet,
6
+ FlatList,
7
+ TouchableOpacity,
8
+ ActivityIndicator,
9
+ } from 'react-native';
10
+ import React, { useState } from 'react';
11
+ import { useQuery } from '@apollo/client';
12
+ import {
13
+ knowledgeBaseCategoryDetail,
14
+ knowledgeBaseTopicDetail,
15
+ } from './graphql/graphql';
16
+
17
+ const FAQ = (props: any) => {
18
+ const { knowledgeBaseTopicId } = props;
19
+
20
+ const [selectedParent, setSelectedParent] = useState<any>('');
21
+ const [selectedCategory, setSelectedCategory] = useState<any>('');
22
+
23
+ const { data, loading } = useQuery(knowledgeBaseTopicDetail, {
24
+ variables: {
25
+ _id: knowledgeBaseTopicId,
26
+ },
27
+ });
28
+
29
+ const { data: dataCategory, loading: loadingCategory } = useQuery(
30
+ knowledgeBaseCategoryDetail,
31
+ {
32
+ variables: {
33
+ _id: selectedCategory?._id,
34
+ },
35
+ skip: !selectedCategory,
36
+ }
37
+ );
38
+
39
+ if (loading) {
40
+ return null;
41
+ }
42
+
43
+ const renderItem = ({ item, index }: any) => {
44
+ const isParent = item?.parentCategoryId === null;
45
+ const childrenCount = isParent
46
+ ? data?.knowledgeBaseTopicDetail?.categories?.filter(
47
+ (e: any) => e?.parentCategoryId === item?._id
48
+ )?.length
49
+ : item?.numOfArticles;
50
+ return (
51
+ <TouchableOpacity
52
+ key={index}
53
+ onPress={() => {
54
+ if (item?.parentCategoryId === null) {
55
+ return setSelectedParent(item);
56
+ }
57
+ return setSelectedCategory(item);
58
+ }}
59
+ style={styles.container}
60
+ >
61
+ <Text>
62
+ {item?.title} ({childrenCount})
63
+ </Text>
64
+ <Text style={{ color: '#393C40', marginTop: 5 }}>
65
+ {item?.description}
66
+ </Text>
67
+ </TouchableOpacity>
68
+ );
69
+ };
70
+
71
+ const renderArticles = ({ item, index }: any) => {
72
+ return (
73
+ <TouchableOpacity key={index} style={styles.container}>
74
+ <Text>{item?.title}</Text>
75
+ <Text style={{ marginTop: 5, color: '#393C40' }}>{item?.summary}</Text>
76
+ </TouchableOpacity>
77
+ );
78
+ };
79
+
80
+ const renderCategoryDetail = () => {
81
+ if (loadingCategory) {
82
+ return (
83
+ <View style={{ marginTop: 20, alignItems: 'center' }}>
84
+ <ActivityIndicator />
85
+ </View>
86
+ );
87
+ }
88
+ return (
89
+ <FlatList
90
+ data={dataCategory?.knowledgeBaseCategoryDetail?.articles}
91
+ renderItem={renderArticles}
92
+ keyExtractor={(item) => item.id}
93
+ contentContainerStyle={{ gap: 10, paddingBottom: 60 }}
94
+ ItemSeparatorComponent={seperator}
95
+ // eslint-disable-next-line react/no-unstable-nested-components
96
+ ListHeaderComponent={() => {
97
+ return (
98
+ <TouchableOpacity
99
+ style={{ backgroundColor: '#f7f6f9', padding: 5 }}
100
+ onPress={() => {
101
+ setSelectedCategory('');
102
+ }}
103
+ >
104
+ <Text style={{ marginLeft: 5 }}>Back to Categories</Text>
105
+ </TouchableOpacity>
106
+ );
107
+ }}
108
+ />
109
+ );
110
+ };
111
+
112
+ const header = () => {
113
+ return (
114
+ <TouchableOpacity
115
+ style={{ backgroundColor: '#f7f6f9', padding: 5 }}
116
+ onPress={() => {
117
+ setSelectedParent('');
118
+ }}
119
+ >
120
+ <Text style={{ marginLeft: 5 }}>Back to FAQ</Text>
121
+ </TouchableOpacity>
122
+ );
123
+ };
124
+
125
+ const seperator = () => {
126
+ return (
127
+ <View style={{ height: 1, backgroundColor: '#000', marginTop: 10 }} />
128
+ );
129
+ };
130
+
131
+ return (
132
+ <View style={{ flex: 1 }}>
133
+ {selectedCategory ? (
134
+ renderCategoryDetail()
135
+ ) : selectedParent ? (
136
+ <FlatList
137
+ data={data?.knowledgeBaseTopicDetail?.categories?.filter(
138
+ (e: any) => e?.parentCategoryId === selectedParent?._id
139
+ )}
140
+ renderItem={renderItem}
141
+ keyExtractor={(item) => item.id}
142
+ contentContainerStyle={{ gap: 10, paddingBottom: 60 }}
143
+ ItemSeparatorComponent={seperator}
144
+ ListHeaderComponent={header}
145
+ />
146
+ ) : (
147
+ <FlatList
148
+ data={data?.knowledgeBaseTopicDetail?.parentCategories}
149
+ renderItem={renderItem}
150
+ keyExtractor={(item) => item.id}
151
+ contentContainerStyle={{ gap: 10 }}
152
+ ItemSeparatorComponent={seperator}
153
+ />
154
+ )}
155
+ </View>
156
+ );
157
+ };
158
+
159
+ export default FAQ;
160
+
161
+ const styles = StyleSheet.create({
162
+ container: {
163
+ marginTop: 10,
164
+ marginHorizontal: 10,
165
+ },
166
+ });
@@ -0,0 +1,37 @@
1
+ /* eslint-disable react-native/no-inline-styles */
2
+ import { View, Text, StyleSheet, SafeAreaView } from 'react-native';
3
+ import React from 'react';
4
+ import Social from './Social';
5
+ import Supporters from './Supporters';
6
+
7
+ const Greetings = (props: any) => {
8
+ const { greetings, bgColor, integrationId } = props;
9
+
10
+ return (
11
+ <SafeAreaView style={{ backgroundColor: bgColor || 'green' }}>
12
+ <View style={[styles.title]}>
13
+ <Social links={greetings?.links} />
14
+ <View style={{ marginTop: 20 }}>
15
+ <Text style={{ fontWeight: '600', fontSize: 18 }}>
16
+ {greetings?.messages?.greetings?.title}
17
+ </Text>
18
+ <Text style={{ marginTop: 20, color: '#393C40' }}>
19
+ {greetings?.messages?.greetings?.message}
20
+ </Text>
21
+ </View>
22
+ <Supporters integrationId={integrationId} />
23
+ </View>
24
+ </SafeAreaView>
25
+ );
26
+ };
27
+
28
+ export default Greetings;
29
+
30
+ const styles = StyleSheet.create({
31
+ title: {
32
+ paddingVertical: 10,
33
+ paddingHorizontal: 10,
34
+ borderTopLeftRadius: 8,
35
+ borderTopRightRadius: 8,
36
+ },
37
+ });
package/src/Social.tsx ADDED
@@ -0,0 +1,46 @@
1
+ /* eslint-disable react-native/no-inline-styles */
2
+ import {
3
+ View,
4
+ StyleSheet,
5
+ TouchableOpacity,
6
+ Image,
7
+ Linking,
8
+ } from 'react-native';
9
+ import React from 'react';
10
+ import images from './assets/images';
11
+
12
+ const Social = (props: any) => {
13
+ const { links } = props;
14
+
15
+ const renderSocial = (link: any, imageUrl: any, index: number) => {
16
+ return (
17
+ <TouchableOpacity
18
+ style={{ marginLeft: index !== 0 ? 10 : 0 }}
19
+ onPress={() => {
20
+ Linking.openURL(link);
21
+ }}
22
+ >
23
+ <Image source={imageUrl} style={styles.image} />
24
+ </TouchableOpacity>
25
+ );
26
+ };
27
+
28
+ return (
29
+ <View style={styles.container}>
30
+ {links?.facebook
31
+ ? renderSocial(links.facebook, images.facebook, 0)
32
+ : null}
33
+ {links?.twitter ? renderSocial(links.twitter, images.twitter, 1) : null}
34
+ {links?.youtube ? renderSocial(links.youtube, images.youtube, 2) : null}
35
+ </View>
36
+ );
37
+ };
38
+
39
+ export default Social;
40
+
41
+ const styles = StyleSheet.create({
42
+ container: {
43
+ flexDirection: 'row',
44
+ },
45
+ image: { width: 30, height: 30, borderRadius: 90 },
46
+ });
@@ -0,0 +1,74 @@
1
+ /* eslint-disable react/no-unstable-nested-components */
2
+ /* eslint-disable react-native/no-inline-styles */
3
+ import { View, Text, StyleSheet, FlatList, Image } from 'react-native';
4
+ import React from 'react';
5
+ import { useQuery } from '@apollo/client';
6
+ import { widgetsConversations } from './graphql/graphql';
7
+ import dayjs from 'dayjs';
8
+ import images from './assets/images';
9
+
10
+ const Support = (props: any) => {
11
+ const { integrationId, customerId } = props;
12
+
13
+ const { data, loading } = useQuery(widgetsConversations, {
14
+ variables: {
15
+ integrationId,
16
+ customerId,
17
+ },
18
+ });
19
+
20
+ if (loading) {
21
+ return null;
22
+ }
23
+
24
+ const renderItem = ({ item, index }: any) => {
25
+ return (
26
+ <View style={{ flexDirection: 'row', alignItems: 'center' }} key={index}>
27
+ <Image source={images.avatar} style={styles.image} />
28
+ <View style={{ marginLeft: 10, flex: 1 }}>
29
+ <Text>Support Staff</Text>
30
+ <Text>{item?.content}</Text>
31
+ </View>
32
+ <Text>{dayjs(item?.createdAt).format('h:mm A')}</Text>
33
+ </View>
34
+ );
35
+ };
36
+
37
+ const renderHeader = () => {
38
+ return <Text>Recent Conversations</Text>;
39
+ };
40
+
41
+ return (
42
+ <View style={styles.container}>
43
+ <FlatList
44
+ data={data?.widgetsConversations}
45
+ renderItem={renderItem}
46
+ keyExtractor={(item) => item.id}
47
+ contentContainerStyle={{ gap: 10 }}
48
+ ItemSeparatorComponent={() => {
49
+ return (
50
+ <View
51
+ style={{ height: 1, backgroundColor: '#000', marginTop: 10 }}
52
+ />
53
+ );
54
+ }}
55
+ ListHeaderComponent={renderHeader()}
56
+ />
57
+ </View>
58
+ );
59
+ };
60
+
61
+ export default Support;
62
+
63
+ const styles = StyleSheet.create({
64
+ container: {
65
+ padding: 10,
66
+ borderRadius: 6,
67
+ flex: 1,
68
+ },
69
+ image: {
70
+ width: 40,
71
+ height: 40,
72
+ borderRadius: 90,
73
+ },
74
+ });
@@ -0,0 +1,63 @@
1
+ /* eslint-disable react-native/no-inline-styles */
2
+ import { View, Image, StyleSheet } from 'react-native';
3
+ import React from 'react';
4
+ import { useQuery } from '@apollo/client';
5
+ import { widgetsMessengerSupporters } from './graphql/graphql';
6
+
7
+ const Supporters = (props: any) => {
8
+ const { integrationId } = props;
9
+
10
+ const { data, loading } = useQuery(widgetsMessengerSupporters, {
11
+ variables: {
12
+ integrationId,
13
+ },
14
+ });
15
+
16
+ if (loading) {
17
+ return null;
18
+ }
19
+
20
+ const supporters = data?.widgetsMessengerSupporters?.supporters;
21
+
22
+ const renderSupporter = (supporter: any, index: number) => {
23
+ const color = supporter?.isOnline ? 'green' : 'white';
24
+ return (
25
+ <View key={index}>
26
+ <Image
27
+ source={{ uri: supporter?.details?.avatar }}
28
+ style={styles.image}
29
+ resizeMode="center"
30
+ />
31
+ <View style={[{ backgroundColor: color }, styles.activeStatus]} />
32
+ </View>
33
+ );
34
+ };
35
+
36
+ return (
37
+ <View style={{ marginTop: 10 }}>
38
+ {supporters
39
+ ?.filter((supporter: any) => supporter?.isActive)
40
+ ?.map((supporter: any, index: number) => {
41
+ return renderSupporter(supporter, index);
42
+ })}
43
+ </View>
44
+ );
45
+ };
46
+
47
+ export default Supporters;
48
+
49
+ const styles = StyleSheet.create({
50
+ image: {
51
+ width: 50,
52
+ height: 50,
53
+ borderRadius: 90,
54
+ },
55
+ activeStatus: {
56
+ width: 15,
57
+ height: 15,
58
+ borderRadius: 90,
59
+ position: 'absolute',
60
+ bottom: 0,
61
+ left: 35,
62
+ },
63
+ });