@developer_tribe/react-native-comnyx 0.4.0 → 0.4.2
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.
- package/lib/commonjs/Accumulator.js +28 -1
- package/lib/commonjs/Accumulator.js.map +1 -1
- package/lib/commonjs/api/customers.js +1 -1
- package/lib/commonjs/api/customers.js.map +1 -1
- package/lib/commonjs/components/ChatList.js +13 -11
- package/lib/commonjs/components/ChatList.js.map +1 -1
- package/lib/commonjs/components/CustomerForm.js +2 -0
- package/lib/commonjs/components/CustomerForm.js.map +1 -1
- package/lib/commonjs/components/MessageInput.js +2 -1
- package/lib/commonjs/components/MessageInput.js.map +1 -1
- package/lib/commonjs/hooks/usePolling.js +7 -7
- package/lib/commonjs/hooks/usePolling.js.map +1 -1
- package/lib/module/Accumulator.js +28 -1
- package/lib/module/Accumulator.js.map +1 -1
- package/lib/module/api/customers.js +1 -1
- package/lib/module/api/customers.js.map +1 -1
- package/lib/module/components/ChatList.js +13 -11
- package/lib/module/components/ChatList.js.map +1 -1
- package/lib/module/components/CustomerForm.js +2 -0
- package/lib/module/components/CustomerForm.js.map +1 -1
- package/lib/module/components/MessageInput.js +2 -1
- package/lib/module/components/MessageInput.js.map +1 -1
- package/lib/module/hooks/usePolling.js +7 -7
- package/lib/module/hooks/usePolling.js.map +1 -1
- package/lib/typescript/commonjs/src/Accumulator.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/ChatList.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/CustomerForm.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/components/MessageInput.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/Customer.d.ts +1 -0
- package/lib/typescript/commonjs/src/types/Customer.d.ts.map +1 -1
- package/lib/typescript/module/src/Accumulator.d.ts.map +1 -1
- package/lib/typescript/module/src/components/ChatList.d.ts.map +1 -1
- package/lib/typescript/module/src/components/CustomerForm.d.ts.map +1 -1
- package/lib/typescript/module/src/components/MessageInput.d.ts.map +1 -1
- package/lib/typescript/module/src/types/Customer.d.ts +1 -0
- package/lib/typescript/module/src/types/Customer.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Accumulator.ts +31 -4
- package/src/api/customers.ts +1 -1
- package/src/components/ChatList.tsx +14 -18
- package/src/components/CustomerForm.tsx +2 -0
- package/src/components/MessageInput.tsx +2 -1
- package/src/hooks/usePolling.ts +5 -5
- package/src/types/Customer.ts +1 -0
|
@@ -47,10 +47,11 @@ export function ChatList({ onBack }: { onBack?: () => void }) {
|
|
|
47
47
|
(windowHeight - FLATLIST_PADDING) / MESSAGE_MIN_HEIGHT
|
|
48
48
|
);
|
|
49
49
|
const [loading, setLoading] = useState(true);
|
|
50
|
-
const { customer, data, setData } = useAppStore((s) => ({
|
|
50
|
+
const { customer, data, setData, externalId } = useAppStore((s) => ({
|
|
51
51
|
customer: s.customer,
|
|
52
52
|
data: s.data,
|
|
53
53
|
setData: s.setData,
|
|
54
|
+
externalId: s.externalId,
|
|
54
55
|
}));
|
|
55
56
|
const ref = useRef<SectionList<AppConversationMessage>>(null);
|
|
56
57
|
const [page, setPage] = useState(1);
|
|
@@ -131,7 +132,7 @@ export function ChatList({ onBack }: { onBack?: () => void }) {
|
|
|
131
132
|
}, [data]);
|
|
132
133
|
|
|
133
134
|
const resendMessage = useCallback(() => {
|
|
134
|
-
if (selectedMessage &&
|
|
135
|
+
if (selectedMessage && externalId) {
|
|
135
136
|
const currentMessage = useAppStore.getState().data || [];
|
|
136
137
|
const messageIndex = currentMessage.findIndex(
|
|
137
138
|
(msg) => msg.content === selectedMessage
|
|
@@ -155,7 +156,7 @@ export function ChatList({ onBack }: { onBack?: () => void }) {
|
|
|
155
156
|
data: updatedValue,
|
|
156
157
|
});
|
|
157
158
|
|
|
158
|
-
sendCustomerMessage(
|
|
159
|
+
sendCustomerMessage(externalId, selectedMessage, {
|
|
159
160
|
fake: useAppStore.getState().fake,
|
|
160
161
|
})
|
|
161
162
|
.then((res: any) => {
|
|
@@ -221,19 +222,14 @@ export function ChatList({ onBack }: { onBack?: () => void }) {
|
|
|
221
222
|
return;
|
|
222
223
|
}
|
|
223
224
|
nextPageStatus.current = 'loading';
|
|
224
|
-
if (
|
|
225
|
+
if (externalId) {
|
|
225
226
|
const newPage = page + 1;
|
|
226
227
|
setPage(newPage);
|
|
227
228
|
const firstMessage = useAppStore.getState().firstMessage;
|
|
228
|
-
getCustomerConversation(
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
{
|
|
233
|
-
fake: useAppStore.getState().fake,
|
|
234
|
-
per_page: MESSAGES_PER_PAGE,
|
|
235
|
-
}
|
|
236
|
-
)
|
|
229
|
+
getCustomerConversation(externalId, firstMessage?.created_at, newPage, {
|
|
230
|
+
fake: useAppStore.getState().fake,
|
|
231
|
+
per_page: MESSAGES_PER_PAGE,
|
|
232
|
+
})
|
|
237
233
|
.then((newData) => {
|
|
238
234
|
listChangedRef.current = true;
|
|
239
235
|
setData((prevData) => {
|
|
@@ -282,7 +278,7 @@ export function ChatList({ onBack }: { onBack?: () => void }) {
|
|
|
282
278
|
setLoading(false);
|
|
283
279
|
});
|
|
284
280
|
}
|
|
285
|
-
}, [MESSAGES_PER_PAGE,
|
|
281
|
+
}, [MESSAGES_PER_PAGE, externalId, page, setData]);
|
|
286
282
|
|
|
287
283
|
const renderItem = useCallback(
|
|
288
284
|
({ item }: { item: AppConversationMessage }) => {
|
|
@@ -417,8 +413,8 @@ export function ChatList({ onBack }: { onBack?: () => void }) {
|
|
|
417
413
|
);
|
|
418
414
|
|
|
419
415
|
useEffect(() => {
|
|
420
|
-
if (
|
|
421
|
-
getCustomerConversation(
|
|
416
|
+
if (externalId && !initFailed) {
|
|
417
|
+
getCustomerConversation(externalId, new Date(), 1, {
|
|
422
418
|
fake: useAppStore.getState().fake,
|
|
423
419
|
per_page: MESSAGES_PER_PAGE,
|
|
424
420
|
})
|
|
@@ -468,7 +464,7 @@ export function ChatList({ onBack }: { onBack?: () => void }) {
|
|
|
468
464
|
setLoading(false);
|
|
469
465
|
});
|
|
470
466
|
}
|
|
471
|
-
}, [MESSAGES_PER_PAGE,
|
|
467
|
+
}, [MESSAGES_PER_PAGE, externalId, initFailed, setData]);
|
|
472
468
|
|
|
473
469
|
// Initialize the current section when sections are loaded
|
|
474
470
|
useEffect(() => {
|
|
@@ -747,7 +743,7 @@ const styles = ScaledSheet.create({
|
|
|
747
743
|
liveChat: {
|
|
748
744
|
fontSize: '16@vs',
|
|
749
745
|
textAlign: 'center',
|
|
750
|
-
fontWeight:
|
|
746
|
+
fontWeight: 600,
|
|
751
747
|
},
|
|
752
748
|
headerContainer: {
|
|
753
749
|
alignItems: 'center',
|
|
@@ -17,6 +17,7 @@ export function MessageInput({
|
|
|
17
17
|
}) {
|
|
18
18
|
const [value, setValue] = useState('');
|
|
19
19
|
const customer = useAppStore((s) => s.customer!);
|
|
20
|
+
const externalId = useAppStore((s) => s.externalId);
|
|
20
21
|
const themeColors = useThemeColors();
|
|
21
22
|
const localize = useLocalize();
|
|
22
23
|
|
|
@@ -36,7 +37,7 @@ export function MessageInput({
|
|
|
36
37
|
},
|
|
37
38
|
...(data ?? []),
|
|
38
39
|
]);
|
|
39
|
-
sendCustomerMessage(
|
|
40
|
+
sendCustomerMessage(externalId as string, value, {
|
|
40
41
|
fake: useAppStore.getState().fake,
|
|
41
42
|
})
|
|
42
43
|
.then((res) => {
|
package/src/hooks/usePolling.ts
CHANGED
|
@@ -5,18 +5,18 @@ import { getNewCustomerConversation } from '../api';
|
|
|
5
5
|
const NEW_MESSAGES_CHECK_INTERVAL = 10000;
|
|
6
6
|
|
|
7
7
|
export function usePolling() {
|
|
8
|
-
const {
|
|
9
|
-
customer: s.customer,
|
|
8
|
+
const { data, setData, externalId } = useAppStore((s) => ({
|
|
10
9
|
data: s.data,
|
|
11
10
|
setData: s.setData,
|
|
11
|
+
externalId: s.externalId,
|
|
12
12
|
}));
|
|
13
13
|
const lastMessage = data ? data[data.length - 1] : null;
|
|
14
14
|
useEffect(() => {
|
|
15
15
|
const created_at = lastMessage?.created_at;
|
|
16
16
|
let interval: NodeJS.Timeout | null = null;
|
|
17
|
-
if (
|
|
17
|
+
if (externalId && created_at) {
|
|
18
18
|
interval = setInterval(() => {
|
|
19
|
-
getNewCustomerConversation(
|
|
19
|
+
getNewCustomerConversation(externalId, created_at, {
|
|
20
20
|
fake: useAppStore.getState().fake,
|
|
21
21
|
}).then((newData) => {
|
|
22
22
|
setData((prevData) => {
|
|
@@ -42,5 +42,5 @@ export function usePolling() {
|
|
|
42
42
|
clearInterval(interval);
|
|
43
43
|
}
|
|
44
44
|
};
|
|
45
|
-
}, [
|
|
45
|
+
}, [externalId, lastMessage?.created_at, setData]);
|
|
46
46
|
}
|