@messenger-box/chat-ui 0.0.1-alpha.399

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 (37) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/LICENSE +21 -0
  3. package/jest.config.js +9 -0
  4. package/lib/components/CustomerSupportChat/Chat.d.ts +8 -0
  5. package/lib/components/CustomerSupportChat/Chat.d.ts.map +1 -0
  6. package/lib/components/CustomerSupportChat/Chat.js +44 -0
  7. package/lib/components/CustomerSupportChat/Chat.js.map +1 -0
  8. package/lib/components/CustomerSupportChat/CustomerSupportChat.d.ts +4 -0
  9. package/lib/components/CustomerSupportChat/CustomerSupportChat.d.ts.map +1 -0
  10. package/lib/components/CustomerSupportChat/CustomerSupportChat.js +128 -0
  11. package/lib/components/CustomerSupportChat/CustomerSupportChat.js.map +1 -0
  12. package/lib/components/CustomerSupportChat/index.d.ts +3 -0
  13. package/lib/components/CustomerSupportChat/index.d.ts.map +1 -0
  14. package/lib/components/index.d.ts +2 -0
  15. package/lib/components/index.d.ts.map +1 -0
  16. package/lib/config/env-config.d.ts +2 -0
  17. package/lib/config/env-config.d.ts.map +1 -0
  18. package/lib/config/index.d.ts +2 -0
  19. package/lib/config/index.d.ts.map +1 -0
  20. package/lib/index.d.ts +2 -0
  21. package/lib/index.d.ts.map +1 -0
  22. package/lib/index.js +1 -0
  23. package/lib/index.js.map +1 -0
  24. package/lib/module.d.ts +4 -0
  25. package/lib/module.d.ts.map +1 -0
  26. package/package.json +80 -0
  27. package/rollup.config.mjs +32 -0
  28. package/src/components/CustomerSupportChat/Chat.tsx +89 -0
  29. package/src/components/CustomerSupportChat/CustomerSupportChat.tsx +220 -0
  30. package/src/components/CustomerSupportChat/index.ts +2 -0
  31. package/src/components/index.ts +1 -0
  32. package/src/config/env-config.ts +5 -0
  33. package/src/config/index.ts +1 -0
  34. package/src/index.ts +4 -0
  35. package/src/module.tsx +7 -0
  36. package/tsconfig.json +26 -0
  37. package/webpack.config.js +92 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## [0.0.1-alpha.399](https://github.com/CDEBase/messenger-box/compare/v0.0.1-alpha.398...v0.0.1-alpha.399) (2023-10-09)
7
+
8
+ **Note:** Version bump only for package @messenger-box/chat-ui
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2017 CDMBase LLC.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/jest.config.js ADDED
@@ -0,0 +1,9 @@
1
+ const base = require('../../../jest.config.base');
2
+ const packageJson = require('./package');
3
+
4
+ module.exports = {
5
+ ...base,
6
+ testEnvironment: 'jsdom', // This is overriden, from the base testEnvironment
7
+ name: packageJson.name,
8
+ displayName: packageJson.name,
9
+ };
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ export declare const Chat: ({ user, channelId, channelMessages, setChannelMessages }: {
3
+ user: any;
4
+ channelId: any;
5
+ channelMessages: any;
6
+ setChannelMessages: any;
7
+ }) => React.JSX.Element;
8
+ //# sourceMappingURL=Chat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../../../src/components/CustomerSupportChat/Chat.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4D,MAAM,OAAO,CAAC;AAkBjF,eAAO,MAAM,IAAI;;;;;uBAsEhB,CAAC"}
@@ -0,0 +1,44 @@
1
+ import React,{useState,useRef}from'react';import {MainContainer,ChatContainer,MessageList,MessageGroup,Message,MessageInput}from'@chatscope/chat-ui-kit-react';import {useSendPublicMessageMutation,useOnPublicPostAddedSubscription}from'@messenger-box/platform-client';import {uniqBy}from'lodash';const Chat = ({ user, channelId, channelMessages, setChannelMessages }) => {
2
+ // Message input value
3
+ useState('');
4
+ const [totalCount, setTotalCount] = useState(0);
5
+ const [sendMsg] = useSendPublicMessageMutation();
6
+ const chatContainerRef = useRef(null);
7
+ const { data: newThreadMsg, loading: newThreadMsgLoading, error: newThreadMsgError, } = useOnPublicPostAddedSubscription({
8
+ variables: {
9
+ channelId: channelId === null || channelId === void 0 ? void 0 : channelId.toString(),
10
+ },
11
+ });
12
+ const handleSend = async (text) => {
13
+ if (!(text && channelId)) {
14
+ return;
15
+ }
16
+ await sendMsg({
17
+ variables: {
18
+ channelId: channelId === null || channelId === void 0 ? void 0 : channelId.toString(),
19
+ messageInput: {
20
+ content: text === null || text === void 0 ? void 0 : text.toString(),
21
+ },
22
+ },
23
+ });
24
+ };
25
+ React.useEffect(() => {
26
+ if (newThreadMsg) {
27
+ const msg = newThreadMsg === null || newThreadMsg === void 0 ? void 0 : newThreadMsg.publicPostAdded;
28
+ setTotalCount((preCount) => preCount + 1);
29
+ setChannelMessages((oldMessages) => uniqBy([...oldMessages, msg], ({ id }) => id));
30
+ // Scroll to the bottom after adding a new message
31
+ const chatContainer = chatContainerRef.current;
32
+ chatContainer.scrollToBottom();
33
+ }
34
+ }, [newThreadMsg]);
35
+ return (React.createElement(MainContainer, null,
36
+ React.createElement(ChatContainer, null,
37
+ React.createElement(MessageList, { ref: chatContainerRef }, channelMessages.map((g) => (React.createElement(MessageGroup, { key: g.id, direction: 'outgoing' },
38
+ React.createElement(MessageGroup.Messages, null,
39
+ React.createElement(Message, { key: g.id, model: {
40
+ type: 'text',
41
+ payload: g.message,
42
+ } })))))),
43
+ React.createElement(MessageInput, { placeholder: "Type message here", onSend: handleSend }))));
44
+ };export{Chat};//# sourceMappingURL=Chat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Chat.js","sources":["../../../src/components/CustomerSupportChat/Chat.tsx"],"sourcesContent":[null],"names":[],"mappings":"sSAkBO,MAAM,IAAI,GAAG,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,eAAe,EAAE,kBAAkB,EAAE,KAAI;;IAEnD,QAAQ,CAAC,EAAE,EAAE;IACvC,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;AAEhD,IAAA,MAAM,CAAC,OAAO,CAAC,GAAG,4BAA4B,EAAE,CAAC;AAEjD,IAAA,MAAM,gBAAgB,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;AAEtC,IAAA,MAAM,EACF,IAAI,EAAE,YAAY,EAClB,OAAO,EAAE,mBAAmB,EAC5B,KAAK,EAAE,iBAAiB,GAC3B,GAAG,gCAAgC,CAAC;AACjC,QAAA,SAAS,EAAE;YACP,SAAS,EAAE,SAAS,KAAT,IAAA,IAAA,SAAS,uBAAT,SAAS,CAAE,QAAQ,EAAE;AACnC,SAAA;AACJ,KAAA,CAAC,CAAC;AAEH,IAAA,MAAM,UAAU,GAAG,OAAO,IAAS,KAAI;AACnC,QAAA,IAAI,EAAE,IAAI,IAAI,SAAS,CAAC,EAAE;YACtB,OAA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A,YAAY,CAAC,QAAQ,EAAA,IAAA;oBAClB,KAAC,CAAA,aAAA,CAAA,OAAO,IACJ,GAAG,EAAE,CAAC,CAAC,EAAE,EACT,KAAK,EACD;AACI,4BAAA,IAAI,EAAE,MAAM;4BACZ,OAAO,EAAE,CAAC,CAAC,OAAO;AACd,yBAAA,EAAA,CAEd,CACkB,CACb,CAClB,CAAC,CACQ;AAEd,YAAA,KAAA,CAAA,aAAA,CAAC,YAAY,EAAA,EAAC,WAAW,EAAC,mBAAmB,EAAC,MAAM,EAAE,UAAU,EAAA,CAAI,CACxD,CACJ,EAClB;AACN"}
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import '@chatscope/chat-ui-kit-styles/dist/default/styles.min.css';
3
+ export declare const CustomerSupportChat: () => React.JSX.Element;
4
+ //# sourceMappingURL=CustomerSupportChat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CustomerSupportChat.d.ts","sourceRoot":"","sources":["../../../src/components/CustomerSupportChat/CustomerSupportChat.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAQnD,OAAO,2DAA2D,CAAC;AAKnE,eAAO,MAAM,mBAAmB,yBA8M/B,CAAC"}
@@ -0,0 +1,128 @@
1
+ import React,{useState,useEffect}from'react';import {Box,Button,Image}from'@chakra-ui/react';import {BiConversation,BiMessageDetail}from'react-icons/bi';import {MdKeyboardArrowDown,MdOutlineArticle}from'react-icons/md';import {nanoid}from'nanoid';import {BasicStorage,ChatProvider,AutoDraft}from'@chatscope/use-chat';import {ExampleChatService}from'@chatscope/use-chat/dist/examples';import'@chatscope/chat-ui-kit-styles/dist/default/styles.min.css';import {useGetNewMongooseObjectIdQuery,usePublicMessagesQuery}from'@messenger-box/platform-client';import {uniqBy}from'lodash';import {Chat}from'./Chat.js';const CustomerSupportChat = () => {
2
+ var _a;
3
+ // Check if ID exists in storage
4
+ const storeChannelId = (_a = localStorage === null || localStorage === void 0 ? void 0 : localStorage.getItem('channelId')) !== null && _a !== void 0 ? _a : null;
5
+ const [isChat, setIsChat] = useState(false);
6
+ const [isChatOpen, setIsChatOpen] = useState(false);
7
+ const [channelMessages, setChannelMessages] = useState([]);
8
+ const [channelId, setChannelId] = useState(storeChannelId);
9
+ // Storage needs to generate id for messages and groups
10
+ const messageIdGenerator = () => nanoid();
11
+ const groupIdGenerator = () => nanoid();
12
+ // Create serviceFactory
13
+ const serviceFactory = (storage, updateState) => {
14
+ return new ExampleChatService(storage, updateState);
15
+ };
16
+ const { data: mongooseObjectId } = useGetNewMongooseObjectIdQuery({
17
+ fetchPolicy: 'network-only',
18
+ });
19
+ useEffect(() => {
20
+ var _a, _b;
21
+ if (storeChannelId === 'undefined' || storeChannelId === null) {
22
+ // ID is undefined or not present in localStorage
23
+ const newId = (_a = mongooseObjectId === null || mongooseObjectId === void 0 ? void 0 : mongooseObjectId.getNewMongooseObjectId) === null || _a === void 0 ? void 0 : _a.toString();
24
+ localStorage.setItem('channelId', newId);
25
+ setChannelId((_b = mongooseObjectId === null || mongooseObjectId === void 0 ? void 0 : mongooseObjectId.getNewMongooseObjectId) === null || _b === void 0 ? void 0 : _b.toString());
26
+ }
27
+ else {
28
+ if (storeChannelId)
29
+ setChannelId(storeChannelId === null || storeChannelId === void 0 ? void 0 : storeChannelId.toString());
30
+ }
31
+ }, [mongooseObjectId, storeChannelId]);
32
+ const { data, loading, error } = usePublicMessagesQuery({
33
+ variables: {
34
+ channelId: channelId === null || channelId === void 0 ? void 0 : channelId.toString(),
35
+ },
36
+ });
37
+ React.useEffect(() => {
38
+ var _a, _b, _c;
39
+ if ((_a = data === null || data === void 0 ? void 0 : data.publicMessages) === null || _a === void 0 ? void 0 : _a.data) {
40
+ const currentConversaion = (_c = (_b = data === null || data === void 0 ? void 0 : data.publicMessages) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.slice().reverse();
41
+ currentConversaion.map((msg) => {
42
+ setChannelMessages((oldMessages) => uniqBy([...oldMessages, msg], ({ id }) => id));
43
+ });
44
+ }
45
+ }, [data, isChat]);
46
+ const handleChat = () => {
47
+ setIsChatOpen(true);
48
+ };
49
+ const handleChatClick = () => {
50
+ setIsChat(true);
51
+ };
52
+ const chatStorage = new BasicStorage({ groupIdGenerator, messageIdGenerator });
53
+ return (React.createElement(React.Fragment, null, !isChat ? (React.createElement(Box, { style: { position: 'fixed', bottom: '20px', right: '30px', zIndex: '2' } },
54
+ React.createElement(Button, { background: '#3182ce', fontSize: '38px', padding: '36px 18px', borderRadius: '50%', onClick: handleChatClick },
55
+ React.createElement(BiConversation, null)))) : (React.createElement(Box, { width: { base: '80%', md: '50%', lg: '30%', xl: '25%' }, style: { position: 'fixed', bottom: '20px', right: '30px', zIndex: '2' } },
56
+ React.createElement(Box, { textAlign: 'right', marginBottom: '20px' },
57
+ React.createElement(Button, { background: '#3182ce', fontSize: '42px', borderRadius: '50%', padding: '30px 10px', onClick: () => setIsChat(false) },
58
+ React.createElement(MdKeyboardArrowDown, null))),
59
+ React.createElement(Box, { style: { borderRadius: '20px', background: 'white' } },
60
+ React.createElement(Box, { style: {
61
+ display: 'flex',
62
+ backgroundColor: '#3182ce',
63
+ padding: '20px 30px',
64
+ lineHeight: '7vh',
65
+ alignItems: 'center',
66
+ } },
67
+ React.createElement(Box, { style: {
68
+ background: '#366c96',
69
+ padding: '10px',
70
+ borderRadius: '54px',
71
+ fontSize: '25px',
72
+ } },
73
+ React.createElement(BiMessageDetail, null)),
74
+ React.createElement(Box, { style: { fontWeight: '700', fontSize: '18px', marginLeft: '30px' } }, "Conversation(s)")),
75
+ React.createElement(Box, { style: {
76
+ height: '50vh',
77
+ background: '#fafafa',
78
+ color: 'black',
79
+ display: 'flex',
80
+ flexDirection: 'column',
81
+ alignContent: 'stretch',
82
+ justifyContent: 'space-evenly',
83
+ alignItems: 'center',
84
+ } }, !isChatOpen && !channelMessages.length ? (React.createElement(Box, { textAlign: 'center' },
85
+ React.createElement(Image, { width: '50%', margin: 'auto', src: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcThpk_KxVKIRa0_fxwaVgIFcRvTgUem0LbkaA&usqp=CAU" }),
86
+ React.createElement(Box, { textAlign: 'center' }, " No ongoing Conversation"),
87
+ React.createElement(Button, { style: {
88
+ backgroundColor: '#3182ce',
89
+ padding: '22px 26px',
90
+ marginTop: '20px',
91
+ borderRadius: '8px',
92
+ color: 'whitesmoke',
93
+ }, leftIcon: React.createElement(BiMessageDetail, { fontSize: '22px' }), onClick: handleChat }, "Chat now"))) : (React.createElement(Box, { w: '100%', h: '50vh' },
94
+ React.createElement(ChatProvider, { serviceFactory: serviceFactory, storage: chatStorage, config: {
95
+ typingThrottleTime: 250,
96
+ typingDebounceTime: 900,
97
+ debounceTyping: true,
98
+ autoDraft: AutoDraft.Save | AutoDraft.Restore,
99
+ } },
100
+ React.createElement(Chat, { user: { name: 'beeena', avatar: '' }, channelId: channelId, setChannelMessages: setChannelMessages, channelMessages: channelMessages }))))),
101
+ React.createElement(Box, { style: {
102
+ height: '7vh',
103
+ background: 'white',
104
+ color: 'black',
105
+ display: 'flex',
106
+ alignContent: 'center',
107
+ alignItems: 'center',
108
+ padding: '30px 0px',
109
+ justifyContent: 'space-evenly',
110
+ boxShadow: '0 0 5px rgba(0, 0, 0, 0.9)',
111
+ outline: '1px solid transparent',
112
+ } },
113
+ React.createElement(Box, { style: {
114
+ display: 'flex',
115
+ flexDirection: 'column',
116
+ alignItems: 'center',
117
+ } },
118
+ React.createElement(BiMessageDetail, null),
119
+ " Conversation"),
120
+ React.createElement(Box, { style: {
121
+ display: 'flex',
122
+ flexDirection: 'column',
123
+ alignItems: 'center',
124
+ } },
125
+ React.createElement(MdOutlineArticle, null),
126
+ " Articles",
127
+ ' ')))))));
128
+ };export{CustomerSupportChat};//# sourceMappingURL=CustomerSupportChat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CustomerSupportChat.js","sources":["../../../src/components/CustomerSupportChat/CustomerSupportChat.tsx"],"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;AACjB,oBAAA,eAAA,CAAA;gBACN,KAAC,CAAA,aAAA,CAAA,GAAG,EACA,EAAA,KAAK,EAAE;AACH,wBAAA,OAAO,EAAE,MAAM;AACf,wBAAA,aAAa,EAAE,QAAQ;AACvB,wBAAA,UAAU,EAAE,QAAQ;AACvB,qBAAA,EAAA;AAED,oBAAA,KAAA,CAAA,aAAA,CAAC,gBAAgB,EAAG,IAAA,CAAA;;AAAU,oBAAA,GAAG,CAC/B,CACJ,CACJ,CACJ,CACT,CACF,EACL;AACN"}
@@ -0,0 +1,3 @@
1
+ export * from './Chat';
2
+ export * from './CustomerSupportChat';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/CustomerSupportChat/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC;AACvB,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { Chat, CustomerSupportChat } from './CustomerSupportChat';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const config: Readonly<import("envalid").CleanedEnvAccessors>;
2
+ //# sourceMappingURL=env-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env-config.d.ts","sourceRoot":"","sources":["../../src/config/env-config.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,MAAM,iDAEjB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { config } from './env-config';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { Chat, CustomerSupportChat, } from './components';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,IAAI,EACJ,mBAAmB,GACtB,MAAM,cAAc,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1 @@
1
+ export{Chat}from'./components/CustomerSupportChat/Chat.js';export{CustomerSupportChat}from'./components/CustomerSupportChat/CustomerSupportChat.js';//# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import { Feature } from '@common-stack/client-react';
2
+ declare const _default: Feature;
3
+ export default _default;
4
+ //# sourceMappingURL=module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;;AAErD,wBAIG"}
package/package.json ADDED
@@ -0,0 +1,80 @@
1
+ {
2
+ "name": "@messenger-box/chat-ui",
3
+ "version": "0.0.1-alpha.399",
4
+ "description": "Account browser",
5
+ "license": "ISC",
6
+ "author": "CDMBase LLC",
7
+ "main": "lib/index.js",
8
+ "module": "lib/index.mjs",
9
+ "typings": "lib/index.d.ts",
10
+ "scripts": {
11
+ "build": "npm run build:clean && npm run build:lib",
12
+ "build:clean": "rimraf lib",
13
+ "build:lib": "rollup -c rollup.config.mjs",
14
+ "build:lib:watch": "yarn build:lib -- --watch",
15
+ "jest": "./node_modules/.bin/jest",
16
+ "prepublish": "npm run build",
17
+ "test": "cross-env ENV_FILE=../../config/test/test.env jest",
18
+ "test:debug": "npm test -- --runInBand",
19
+ "test:watch": "npm test -- --watch",
20
+ "watch": "npm run build:lib:watch"
21
+ },
22
+ "jest": {
23
+ "moduleFileExtensions": [
24
+ "ts",
25
+ "tsx",
26
+ "js",
27
+ "json"
28
+ ],
29
+ "modulePaths": [
30
+ "node_modules"
31
+ ],
32
+ "roots": [
33
+ "src"
34
+ ],
35
+ "testEnvironment": "node",
36
+ "testRegex": "/__tests__/.*test*\\.(ts|tsx|js)$",
37
+ "transform": {
38
+ "\\.(ts|tsx)$": "<rootDir>/../../node_modules/ts-jest/preprocessor.js"
39
+ }
40
+ },
41
+ "dependencies": {
42
+ "@chatscope/chat-ui-kit-react": "^1.10.1",
43
+ "@chatscope/chat-ui-kit-styles": "^1.4.0",
44
+ "@chatscope/use-chat": "^3.1.1",
45
+ "@messenger-box/core": "0.0.1-alpha.399",
46
+ "@messenger-box/platform-client": "0.0.1-alpha.399",
47
+ "date-fns": "^2.28.0",
48
+ "date-fns-tz": "^1.3.3",
49
+ "emoji-mart": "^3.0.1",
50
+ "javascript-time-ago": "^2.3.13",
51
+ "react-icons": "~4.3.1"
52
+ },
53
+ "peerDependencies": {
54
+ "@adminide-stack/chakra-design-pro": "*",
55
+ "@adminide-stack/core": "*",
56
+ "@adminide-stack/user-auth0-browser": "*",
57
+ "@cdm-logger/client": "*",
58
+ "@chakra-ui/react": "*",
59
+ "@common-stack/client-react": "*",
60
+ "@emotion/react": ">=11",
61
+ "@emotion/styled": ">=11",
62
+ "@workbench-stack/components": "*",
63
+ "lodash": "*",
64
+ "moment": "*",
65
+ "react": ">=16.14.0",
66
+ "react-redux": "*",
67
+ "react-router": "*",
68
+ "react-router-dom": "*",
69
+ "redux": ">=4.0.1",
70
+ "redux-observable": "*",
71
+ "rxjs": "*"
72
+ },
73
+ "publishConfig": {
74
+ "access": "public"
75
+ },
76
+ "typescript": {
77
+ "definition": "lib/index.d.ts"
78
+ },
79
+ "gitHead": "0813ba639b35ddbb8e75c2206f5bf2a72336f892"
80
+ }
@@ -0,0 +1,32 @@
1
+ /* eslint-disable import/no-extraneous-dependencies */
2
+ import graphql from '@rollup/plugin-graphql';
3
+ import image from '@rollup/plugin-image';
4
+ import typescript from '@rollup/plugin-typescript';
5
+
6
+ const isDev = process.env.NODE_ENV === 'development';
7
+ const bundle = (config) => ({
8
+ ...config,
9
+ input: 'src/index.ts',
10
+ // marking all node modules as external
11
+ external: (id) => !/^[./]/.test(id),
12
+ });
13
+ const globals = { react: 'React' };
14
+
15
+ export default [
16
+ bundle({
17
+ plugins: [typescript({ noEmitOnError: !isDev }), image(), graphql()],
18
+ output: [
19
+ {
20
+ dir: 'lib',
21
+ format: 'es',
22
+ name: 'Counter',
23
+ compact: true,
24
+ exports: 'named',
25
+ sourcemap: true,
26
+ preserveModules: true,
27
+ chunkFileNames: '[name]-[hash].[format].js',
28
+ globals,
29
+ },
30
+ ],
31
+ }),
32
+ ];
@@ -0,0 +1,89 @@
1
+ import React, { useState, useMemo, useEffect, useCallback, useRef } from 'react';
2
+ import {
3
+ MainContainer,
4
+ Sidebar,
5
+ ConversationList,
6
+ Conversation,
7
+ Avatar,
8
+ MessageGroup,
9
+ Message,
10
+ ChatContainer,
11
+ ConversationHeader,
12
+ MessageList,
13
+ MessageInput,
14
+ } from '@chatscope/chat-ui-kit-react';
15
+
16
+ import { useOnPublicPostAddedSubscription, useSendPublicMessageMutation } from '@messenger-box/platform-client';
17
+ import { uniqBy } from 'lodash';
18
+
19
+ export const Chat = ({ user, channelId, channelMessages, setChannelMessages }) => {
20
+ // Message input value
21
+ const [value, setValue] = useState('');
22
+ const [totalCount, setTotalCount] = useState(0);
23
+
24
+ const [sendMsg] = useSendPublicMessageMutation();
25
+
26
+ const chatContainerRef = useRef(null);
27
+
28
+ const {
29
+ data: newThreadMsg,
30
+ loading: newThreadMsgLoading,
31
+ error: newThreadMsgError,
32
+ } = useOnPublicPostAddedSubscription({
33
+ variables: {
34
+ channelId: channelId?.toString(),
35
+ },
36
+ });
37
+
38
+ const handleSend = async (text: any) => {
39
+ if (!(text && channelId)) {
40
+ return;
41
+ }
42
+
43
+ await sendMsg({
44
+ variables: {
45
+ channelId: channelId?.toString(),
46
+ messageInput: {
47
+ content: text?.toString(),
48
+ },
49
+ },
50
+ });
51
+ };
52
+ React.useEffect(() => {
53
+ if (newThreadMsg) {
54
+ const msg = newThreadMsg?.publicPostAdded;
55
+ setTotalCount((preCount: any) => preCount + 1);
56
+ setChannelMessages((oldMessages: any) => uniqBy([...oldMessages, msg], ({ id }) => id));
57
+
58
+ // Scroll to the bottom after adding a new message
59
+ const chatContainer = chatContainerRef.current;
60
+ chatContainer.scrollToBottom();
61
+ }
62
+ }, [newThreadMsg]);
63
+
64
+ return (
65
+ <MainContainer>
66
+ <ChatContainer>
67
+ <MessageList ref={chatContainerRef}>
68
+ {channelMessages.map((g) => (
69
+ <MessageGroup key={g.id} direction={'outgoing'}>
70
+ <MessageGroup.Messages>
71
+ <Message
72
+ key={g.id}
73
+ model={
74
+ {
75
+ type: 'text',
76
+ payload: g.message,
77
+ } as any
78
+ }
79
+ />
80
+ </MessageGroup.Messages>
81
+ </MessageGroup>
82
+ ))}
83
+ </MessageList>
84
+
85
+ <MessageInput placeholder="Type message here" onSend={handleSend} />
86
+ </ChatContainer>
87
+ </MainContainer>
88
+ );
89
+ };
@@ -0,0 +1,220 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import { Box, Button, Image, Text } from '@chakra-ui/react';
3
+ import { BiConversation, BiMessageDetail } from 'react-icons/bi';
4
+ import { MdKeyboardArrowDown, MdOutlineArticle } from 'react-icons/md';
5
+ import { nanoid } from 'nanoid';
6
+ import { BasicStorage, ChatProvider, AutoDraft } from '@chatscope/use-chat';
7
+ import { ExampleChatService } from '@chatscope/use-chat/dist/examples';
8
+
9
+ import '@chatscope/chat-ui-kit-styles/dist/default/styles.min.css';
10
+ import { useGetNewMongooseObjectIdQuery, usePublicMessagesQuery } from '@messenger-box/platform-client';
11
+ import { uniqBy } from 'lodash';
12
+ import { Chat } from './Chat';
13
+
14
+ export const CustomerSupportChat = () => {
15
+ // Check if ID exists in storage
16
+ const storeChannelId = localStorage?.getItem('channelId') ?? null;
17
+ const [isChat, setIsChat] = useState(false);
18
+ const [isChatOpen, setIsChatOpen] = useState(false);
19
+ const [channelMessages, setChannelMessages] = useState([]);
20
+ const [channelId, setChannelId] = useState<string>(storeChannelId);
21
+
22
+ // Storage needs to generate id for messages and groups
23
+ const messageIdGenerator = () => nanoid();
24
+ const groupIdGenerator = () => nanoid();
25
+
26
+ // Create serviceFactory
27
+ const serviceFactory = (storage, updateState) => {
28
+ return new ExampleChatService(storage, updateState);
29
+ };
30
+ const { data: mongooseObjectId } = useGetNewMongooseObjectIdQuery({
31
+ fetchPolicy: 'network-only',
32
+ });
33
+
34
+
35
+ useEffect(() => {
36
+ if (storeChannelId === 'undefined' || storeChannelId === null) {
37
+ // ID is undefined or not present in localStorage
38
+ const newId = mongooseObjectId?.getNewMongooseObjectId?.toString();
39
+ localStorage.setItem('channelId', newId);
40
+ setChannelId(mongooseObjectId?.getNewMongooseObjectId?.toString());
41
+ } else {
42
+ if (storeChannelId) setChannelId(storeChannelId?.toString());
43
+ }
44
+ }, [mongooseObjectId, storeChannelId]);
45
+
46
+ const { data, loading, error } = usePublicMessagesQuery({
47
+ variables: {
48
+ channelId: channelId?.toString(),
49
+ },
50
+ });
51
+
52
+ React.useEffect(() => {
53
+ if (data?.publicMessages?.data) {
54
+ const currentConversaion = data?.publicMessages?.data?.slice().reverse();
55
+ currentConversaion.map((msg) => {
56
+ setChannelMessages((oldMessages: any) => uniqBy([...oldMessages, msg], ({ id }) => id));
57
+ });
58
+ }
59
+ }, [data, isChat]);
60
+ const handleChat = () => {
61
+ setIsChatOpen(true);
62
+ };
63
+ const handleChatClick = () => {
64
+ setIsChat(true);
65
+ };
66
+ const chatStorage = new BasicStorage({ groupIdGenerator, messageIdGenerator });
67
+
68
+ return (
69
+ <>
70
+ {!isChat ? (
71
+ <Box style={{ position: 'fixed', bottom: '20px', right: '30px', zIndex: '2' }}>
72
+ {/* @ts-ignore */}
73
+ <Button
74
+ background={'#3182ce'}
75
+ fontSize={'38px'}
76
+ padding={'36px 18px'}
77
+ borderRadius={'50%'}
78
+ onClick={handleChatClick}
79
+ >
80
+ <BiConversation />
81
+ </Button>
82
+ </Box>
83
+ ) : (
84
+ <Box
85
+ width={{ base: '80%', md: '50%', lg: '30%', xl: '25%' }}
86
+ style={{ position: 'fixed', bottom: '20px', right: '30px', zIndex: '2' }}
87
+ >
88
+ <Box textAlign={'right'} marginBottom={'20px'}>
89
+ {/* @ts-ignore */}
90
+ <Button
91
+ background={'#3182ce'}
92
+ fontSize={'42px'}
93
+ borderRadius={'50%'}
94
+ padding={'30px 10px'}
95
+ onClick={() => setIsChat(false)}
96
+ >
97
+ <MdKeyboardArrowDown />
98
+ </Button>
99
+ </Box>
100
+ <Box style={{ borderRadius: '20px', background: 'white' }}>
101
+ <Box
102
+ style={{
103
+ display: 'flex',
104
+ backgroundColor: '#3182ce',
105
+ padding: '20px 30px',
106
+ lineHeight: '7vh',
107
+ alignItems: 'center',
108
+ }}
109
+ >
110
+ <Box
111
+ style={{
112
+ background: '#366c96',
113
+ padding: '10px',
114
+ borderRadius: '54px',
115
+ fontSize: '25px',
116
+ }}
117
+ >
118
+ <BiMessageDetail />
119
+ </Box>
120
+ <Box style={{ fontWeight: '700', fontSize: '18px', marginLeft: '30px' }}>
121
+ Conversation(s)
122
+ </Box>
123
+ </Box>
124
+ <Box
125
+ style={{
126
+ height: '50vh',
127
+ background: '#fafafa',
128
+ color: 'black',
129
+ display: 'flex',
130
+ flexDirection: 'column',
131
+ alignContent: 'stretch',
132
+ justifyContent: 'space-evenly',
133
+ alignItems: 'center',
134
+ }}
135
+ >
136
+ {!isChatOpen && !channelMessages.length ? (
137
+ <Box textAlign={'center'}>
138
+ {/* @ts-ignore */}
139
+ <Image
140
+ width={'50%'}
141
+ margin={'auto'}
142
+ src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcThpk_KxVKIRa0_fxwaVgIFcRvTgUem0LbkaA&usqp=CAU"
143
+ />
144
+ <Box textAlign={'center'}> No ongoing Conversation</Box>
145
+ {/* @ts-ignore */}
146
+ <Button
147
+ style={{
148
+ backgroundColor: '#3182ce',
149
+ padding: '22px 26px',
150
+ marginTop: '20px',
151
+ borderRadius: '8px',
152
+ color: 'whitesmoke',
153
+ }}
154
+ leftIcon={<BiMessageDetail fontSize={'22px'} />}
155
+ onClick={handleChat}
156
+ >
157
+ Chat now
158
+ </Button>
159
+ </Box>
160
+ ) : (
161
+ <Box w={'100%'} h={'50vh'}>
162
+ <ChatProvider
163
+ serviceFactory={serviceFactory}
164
+ storage={chatStorage}
165
+ config={{
166
+ typingThrottleTime: 250,
167
+ typingDebounceTime: 900,
168
+ debounceTyping: true,
169
+ autoDraft: AutoDraft.Save | AutoDraft.Restore,
170
+ }}
171
+ >
172
+ <Chat
173
+ user={{ name: 'beeena', avatar: '' }}
174
+ channelId={channelId}
175
+ setChannelMessages={setChannelMessages}
176
+ channelMessages={channelMessages}
177
+ />
178
+ </ChatProvider>
179
+ </Box>
180
+ )}
181
+ </Box>
182
+ <Box
183
+ style={{
184
+ height: '7vh',
185
+ background: 'white',
186
+ color: 'black',
187
+ display: 'flex',
188
+ alignContent: 'center',
189
+ alignItems: 'center',
190
+ padding: '30px 0px',
191
+ justifyContent: 'space-evenly',
192
+ boxShadow: '0 0 5px rgba(0, 0, 0, 0.9)',
193
+ outline: '1px solid transparent',
194
+ }}
195
+ >
196
+ <Box
197
+ style={{
198
+ display: 'flex',
199
+ flexDirection: 'column',
200
+ alignItems: 'center',
201
+ }}
202
+ >
203
+ <BiMessageDetail /> Conversation
204
+ </Box>
205
+ <Box
206
+ style={{
207
+ display: 'flex',
208
+ flexDirection: 'column',
209
+ alignItems: 'center',
210
+ }}
211
+ >
212
+ <MdOutlineArticle /> Articles{' '}
213
+ </Box>
214
+ </Box>
215
+ </Box>
216
+ </Box>
217
+ )}
218
+ </>
219
+ );
220
+ };
@@ -0,0 +1,2 @@
1
+ export * from './Chat';
2
+ export * from './CustomerSupportChat';
@@ -0,0 +1 @@
1
+ export { Chat, CustomerSupportChat } from './CustomerSupportChat';
@@ -0,0 +1,5 @@
1
+ import { cleanEnv, num, str } from 'envalid';
2
+
3
+ export const config = cleanEnv(process.env, {
4
+
5
+ });
@@ -0,0 +1 @@
1
+ export { config } from './env-config';
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export {
2
+ Chat,
3
+ CustomerSupportChat,
4
+ } from './components';
package/src/module.tsx ADDED
@@ -0,0 +1,7 @@
1
+ import { Feature } from '@common-stack/client-react';
2
+
3
+ export default new Feature({
4
+ stylesInsert: [
5
+ '@chatscope/chat-ui-kit-styles/dist/default/styles.min.css'
6
+ ],
7
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "extends": "../../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "allowSyntheticDefaultImports": true,
5
+ "experimentalDecorators": true,
6
+ "esModuleInterop": true,
7
+ "skipLibCheck": true,
8
+ "rootDir": "./src",
9
+ "outDir": "lib",
10
+ "declarationDir": "lib",
11
+ "declaration": true,
12
+ "declarationMap": true
13
+ },
14
+ "exclude": [
15
+ "../../../node_modules",
16
+ "node_modules",
17
+ "lib",
18
+ "dist",
19
+ "webpack.config.js",
20
+ "rollup.config.mjs"
21
+ ],
22
+ "include": [
23
+ "src",
24
+ "./typings/*.d.ts"
25
+ ]
26
+ }
@@ -0,0 +1,92 @@
1
+ // eslint-disable-next-line import/no-extraneous-dependencies
2
+ const nodeExternals = require('webpack-node-externals');
3
+ // eslint-disable-next-line import/no-extraneous-dependencies
4
+ const webpack = require('webpack');
5
+ const path = require('path');
6
+
7
+ const webpackOpts = {
8
+ mode: 'development',
9
+ entry: {
10
+ index: './src/index.ts',
11
+ },
12
+ target: 'node',
13
+ output: {
14
+ path: path.join(__dirname, 'lib'),
15
+ filename: '[name].js',
16
+ libraryTarget: 'commonjs2',
17
+ },
18
+ resolve: {
19
+ extensions: [
20
+ '.js',
21
+ '.jsx',
22
+ '.ts',
23
+ '.tsx',
24
+ '.graphql',
25
+ '.graphqls',
26
+ '.gql',
27
+ '.native.tsx',
28
+ '.native.ts',
29
+ '.json',
30
+ ],
31
+ },
32
+ plugins: [
33
+ new webpack.LoaderOptionsPlugin({
34
+ options: {
35
+ test: /\.tsx?$/,
36
+ ts: {
37
+ compiler: 'typescript',
38
+ configFile: 'tsconfig.json',
39
+ },
40
+ tslint: {
41
+ emitErrors: true,
42
+ failOnHint: true,
43
+ },
44
+ },
45
+ }),
46
+ ],
47
+ devtool: 'source-map',
48
+ module: {
49
+ rules: [
50
+ {
51
+ test: /\.(tsx)?$/,
52
+ use: 'ts-loader',
53
+ },
54
+ {
55
+ test: /\.mjs$/,
56
+ include: /node_modules/,
57
+ type: 'javascript/auto',
58
+ },
59
+ {
60
+ test: /\.(gql)$/,
61
+ exclude: /node_modules/,
62
+ use: ['graphql-tag/loader'],
63
+ },
64
+ {
65
+ test: /\.graphql?/,
66
+ exclude: /node_modules/,
67
+ use: 'raw-loader',
68
+ },
69
+ {
70
+ test: /\.(png|jpg|gif|webp)$/i,
71
+ use: {
72
+ loader: 'url-loader',
73
+ options: {
74
+ limit: 8192,
75
+ name: 'static/media/[name].[hash:8].[ext]',
76
+ },
77
+ },
78
+ },
79
+ {
80
+ test: /\.svg$/,
81
+ use: ['@svgr/webpack'],
82
+ },
83
+ {
84
+ test: /\.json$/,
85
+ loader: 'json-loader',
86
+ },
87
+ ],
88
+ },
89
+ externals: [nodeExternals({ modulesDir: '../../../node_modules' }), nodeExternals()],
90
+ };
91
+
92
+ module.exports = webpackOpts;