@messenger-box/platform-mobile 0.0.1-alpha.362 → 0.0.1-alpha.363

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 (28) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/lib/index.js +2085 -527
  3. package/lib/index.js.map +1 -1
  4. package/lib/screens/inbox/DialogThreadMessages.d.ts +7 -0
  5. package/lib/screens/inbox/DialogThreads.d.ts +6 -0
  6. package/lib/screens/inbox/components/SupportServiceDialogsListItem.d.ts +21 -0
  7. package/lib/screens/inbox/components/ThreadsViewItem.d.ts +18 -0
  8. package/lib/screens/inbox/config/config.d.ts +2 -0
  9. package/lib/screens/inbox/containers/Dialogs.d.ts +1 -0
  10. package/lib/screens/inbox/containers/SupportServiceDialogs.d.ts +6 -0
  11. package/lib/screens/inbox/containers/ThreadConversationView.d.ts +11 -0
  12. package/lib/screens/inbox/containers/ThreadsView.d.ts +8 -0
  13. package/lib/screens/index.d.ts +2 -0
  14. package/package.json +4 -4
  15. package/src/navigation/InboxNavigation.tsx +63 -0
  16. package/src/screens/inbox/DialogThreadMessages.tsx +28 -0
  17. package/src/screens/inbox/DialogThreads.tsx +107 -0
  18. package/src/screens/inbox/Inbox.tsx +5 -3
  19. package/src/screens/inbox/components/DialogsListItem.tsx +7 -3
  20. package/src/screens/inbox/components/SupportServiceDialogsListItem.tsx +295 -0
  21. package/src/screens/inbox/components/ThreadsViewItem.tsx +229 -0
  22. package/src/screens/inbox/config/config.ts +4 -0
  23. package/src/screens/inbox/containers/ConversationView.tsx +288 -95
  24. package/src/screens/inbox/containers/Dialogs.tsx +2 -1
  25. package/src/screens/inbox/containers/SupportServiceDialogs.tsx +119 -0
  26. package/src/screens/inbox/containers/ThreadConversationView.tsx +700 -0
  27. package/src/screens/inbox/containers/ThreadsView.tsx +186 -0
  28. package/src/screens/index.ts +3 -1
@@ -1,9 +1,9 @@
1
1
  import React, { useCallback, useEffect, useMemo, useState } from 'react';
2
- import { Box, Button, HStack, Icon, Image, Spinner, Text, useColorModeValue, ScrollView } from 'native-base';
2
+ import { Box, Button, HStack, Icon, Image, Spinner, Text, useColorModeValue, Avatar, ScrollView } from 'native-base';
3
3
  import { Platform, TouchableOpacity } from 'react-native';
4
- import { useNavigation, useFocusEffect } from '@react-navigation/native';
4
+ import { useNavigation, useFocusEffect, useIsFocused } from '@react-navigation/native';
5
5
  import { useSelector } from 'react-redux';
6
- import { orderBy, uniqBy } from 'lodash';
6
+ import { orderBy, uniqBy, startCase } from 'lodash';
7
7
  import * as ImagePicker from 'expo-image-picker';
8
8
  import { encode as atob } from 'base-64';
9
9
  import { Ionicons, MaterialCommunityIcons } from '@expo/vector-icons';
@@ -15,12 +15,14 @@ import {
15
15
  useSendMessagesMutation,
16
16
  useViewChannelDetailQuery,
17
17
  useUploadFilesNative,
18
+ useGetNewMongooseObjectIdQuery,
18
19
  } from '@messenger-box/platform-client';
19
20
  import { IFileInfo } from '@messenger-box/core';
20
21
  import { config } from '../config';
21
22
  import { userSelector } from '@adminide-stack/user-auth0-client';
22
23
  import { SlackMessage, ImageViewerModal } from '../components/SlackMessageContainer';
23
24
  import CachedImage from '../components/CachedImage';
25
+ import { format, isToday, isYesterday } from 'date-fns';
24
26
  const {
25
27
  MESSAGES_PER_PAGE,
26
28
  CALL_TO_ACTION_BOX_BGCOLOR,
@@ -29,9 +31,18 @@ const {
29
31
  CALL_TO_ACTION_TEXT_COLOR,
30
32
  } = config;
31
33
 
34
+ const createdAtText = (value: string) => {
35
+ if (!value) return '';
36
+ let date = new Date(value);
37
+ if (isToday(date)) return 'Today';
38
+ if (isYesterday(date)) return 'Yesterday';
39
+ return format(new Date(value), 'MMM dd, yyyy');
40
+ };
41
+
32
42
  interface IMessageProps extends IMessage {
33
43
  type: string;
34
44
  propsConfiguration?: any;
45
+ replies?: any;
35
46
  }
36
47
 
37
48
  export interface AlertMessageAttachmentsInterface {
@@ -62,6 +73,11 @@ const ConversationViewComponent = ({ channelId }: any) => {
62
73
  const [expoTokens, setExpoTokens] = useState<any[]>([]);
63
74
  const [isShowImageViewer, setImageViewer] = useState<boolean>(false);
64
75
  const [imageObject, setImageObject] = useState<any>({});
76
+ const isFocused = useIsFocused();
77
+ const { data: mongooseObjectId } = useGetNewMongooseObjectIdQuery({
78
+ fetchPolicy: 'network-only',
79
+ pollInterval: 5000,
80
+ });
65
81
 
66
82
  const { startUpload } = useUploadFilesNative();
67
83
 
@@ -74,6 +90,7 @@ const ConversationViewComponent = ({ channelId }: any) => {
74
90
  }: any = useMessagesQuery({
75
91
  variables: {
76
92
  channelId: channelId?.toString(),
93
+ parentId: null,
77
94
  limit: MESSAGES_PER_PAGE,
78
95
  },
79
96
  skip: !channelId,
@@ -106,6 +123,7 @@ const ConversationViewComponent = ({ channelId }: any) => {
106
123
  refetchChannelDetail({ id: channelId?.toString() });
107
124
  refetch({
108
125
  channelId: channelId?.toString(),
126
+ parentId: null,
109
127
  limit: MESSAGES_PER_PAGE,
110
128
  }).then(({ data }) => {
111
129
  if (!data?.messages) {
@@ -121,7 +139,7 @@ const ConversationViewComponent = ({ channelId }: any) => {
121
139
  setTotalCount(0);
122
140
  setChannelMessages([]);
123
141
  };
124
- }, []),
142
+ }, [isFocused]),
125
143
  );
126
144
 
127
145
  React.useEffect(() => {
@@ -208,6 +226,8 @@ const ConversationViewComponent = ({ channelId }: any) => {
208
226
  const numberOfNewMessages = checkForMessages?.messages?.totalCount - totalCount;
209
227
  console.log('new msg check');
210
228
  refetch({
229
+ channelId: channelId?.toString(),
230
+ parentId: null,
211
231
  limit: numberOfNewMessages,
212
232
  }).then(({ data }) => {
213
233
  if (!data?.messages) {
@@ -241,7 +261,7 @@ const ConversationViewComponent = ({ channelId }: any) => {
241
261
  const onFetchOld = useCallback(() => {
242
262
  if (data?.messages?.totalCount > channelMessages.length) {
243
263
  setLoadingOldMessages(true);
244
- refetch({ skip: channelMessages.length });
264
+ refetch({ channelId: channelId?.toString(), parentId: null, skip: channelMessages.length });
245
265
  }
246
266
  }, [data, channelMessages]);
247
267
 
@@ -420,102 +440,223 @@ const ConversationViewComponent = ({ channelId }: any) => {
420
440
  // [setChannelMessages, currentUser, channelId, images,expoTokens],
421
441
  // );
422
442
 
423
- const handleSend = async (message: string) => {
424
- if (!channelId) return;
425
- if (!message && message != ' ' && images.length == 0) return;
426
-
427
- setLoading(true);
428
- const { data } = await sendMsg({
429
- variables: {
430
- channelId,
431
- content: message,
432
- },
433
- update: (cache, { data, errors }: any) => {
434
- if (!data || errors) {
435
- setLoading(false);
436
- return;
437
- }
438
- setChannelMessages((messages: any) => [...messages, data?.sendMessage]);
439
- setTotalCount((t: any) => t + 1);
440
- setChannelToTop(channelToTop + 1);
441
- setLoading(false);
442
- setMsg('');
443
- const givenName = auth?.profile?.given_name ?? '';
444
- const familyName = auth?.profile?.family_name ?? '';
445
- const fullName = givenName ? givenName + ' ' + familyName : '';
446
- const title: String = fullName ? fullName : 'Message';
447
- const body: String = message;
448
- const notificationData: any = {
449
- url: config.INBOX_MESSEGE_PATH,
450
- params: { channelId, hideTabBar: true },
451
- screen: 'DialogMessages',
452
- };
453
- refetchChannelDetail({ id: channelId?.toString() })?.then((res: any) => {
454
- if (res?.data?.viewChannelDetail?.members?.length) {
455
- const channelData: any =
456
- res?.data?.viewChannelDetail?.members?.filter((mu: any) => mu?.user?.id != auth?.id) ?? [];
457
- const tokens: any =
458
- channelData
459
- ?.map(
460
- (u: any) =>
461
- u?.user?.tokens
462
- ?.filter((t: any) => t?.type == 'EXPO_NOTIFICATION_TOKEN')
463
- ?.map((et: any) => et?.token) ?? [],
464
- )
465
- ?.flat(1)
466
- ?.filter((t: any) => t)
467
- ?.filter((value: any, index: any, array: any) => array.indexOf(value) === index) ?? [];
468
- console.log('expo to', JSON.stringify(tokens));
469
- if (tokens?.length > 0) {
470
- const to: any = tokens?.length > 0 ? tokens : [];
471
-
472
- sendPushNotification(title, body, notificationData, to);
473
- }
474
- }
443
+ const handleSend = useCallback(
444
+ async (message: string) => {
445
+ if (!channelId) return;
446
+ if (!message && message != ' ' && images.length == 0) return;
447
+
448
+ if (images && images.length > 0) {
449
+ const postId: any = mongooseObjectId?.getNewMongooseObjectId;
450
+ setLoading(true);
451
+ const uploadResponse = await startUpload({
452
+ file: images,
453
+ saveUploadedFile: {
454
+ variables: {
455
+ postId,
456
+ },
457
+ },
458
+ createUploadLink: {
459
+ variables: {
460
+ postId,
461
+ },
462
+ },
475
463
  });
476
- },
477
- });
478
- if (images && images.length > 0 && data?.sendMessage?.id) {
479
- const { id: postId } = data.sendMessage;
480
- setLoading(true);
481
- const uploadResponse = await startUpload({
482
- file: images,
483
- saveUploadedFile: {
464
+ if (uploadResponse?.error) setLoading(false);
465
+ const uploadedFiles = uploadResponse.data as unknown as IFileInfo[];
466
+
467
+ if (uploadResponse.data) {
468
+ setImage('');
469
+ setFiles([]);
470
+ setImages([]);
471
+ //setLoading(false);
472
+ const files = uploadedFiles?.map((f: any) => f.id) ?? null;
473
+ await sendMsg({
474
+ variables: {
475
+ postId,
476
+ channelId,
477
+ content: message,
478
+ files,
479
+ },
480
+ update: (cache, { data, errors }: any) => {
481
+ if (!data || errors) {
482
+ setLoading(false);
483
+ return;
484
+ }
485
+ setChannelMessages((messages: any) => [
486
+ ...messages,
487
+ {
488
+ ...data?.sendMessage,
489
+ files: {
490
+ totalCount: uploadedFiles.length,
491
+ data: uploadedFiles,
492
+ },
493
+ },
494
+ ]);
495
+ setTotalCount((t: any) => t + 1);
496
+ setChannelToTop(channelToTop + 1);
497
+ setLoading(false);
498
+ setMsg('');
499
+ const msg = message==''?'Send a file':message;
500
+ fetchTokenAndSendPushNotification(msg, channelId);
501
+ },
502
+ });
503
+ }
504
+ } else {
505
+ setLoading(true);
506
+ const { data } = await sendMsg({
484
507
  variables: {
485
- postId,
508
+ channelId,
509
+ content: message,
486
510
  },
487
- },
488
- createUploadLink: {
489
- variables: {
490
- postId,
511
+ update: (cache, { data, errors }: any) => {
512
+ if (!data || errors) {
513
+ setLoading(false);
514
+ return;
515
+ }
516
+ setChannelMessages((messages: any) => [...messages, data?.sendMessage]);
517
+ setTotalCount((t: any) => t + 1);
518
+ setChannelToTop(channelToTop + 1);
519
+ setLoading(false);
520
+ setMsg('');
521
+ fetchTokenAndSendPushNotification(message, channelId);
491
522
  },
492
- },
493
- });
494
- if (uploadResponse?.error) setLoading(false);
495
- const uploadedFiles = uploadResponse.data as unknown as IFileInfo[];
496
- if (uploadResponse.data) {
497
- setImage('');
498
- setFiles([]);
499
- setImages([]);
500
- setLoading(false);
523
+ });
501
524
  }
502
- setChannelMessages((messages: any) =>
503
- messages.map((message: any) => {
504
- if (message.id === postId) {
505
- return {
506
- ...message,
507
- files: {
508
- totalCount: uploadedFiles.length,
509
- data: uploadedFiles,
510
- },
511
- };
512
- }
513
- return message;
514
- }),
515
- );
516
- }
525
+ },
526
+ [mongooseObjectId, setChannelMessages, channelId, images, channelToTop, expoTokens],
527
+ );
528
+
529
+ const fetchTokenAndSendPushNotification = (message: any, channelId: any) => {
530
+ const givenName = auth?.profile?.given_name ?? '';
531
+ const familyName = auth?.profile?.family_name ?? '';
532
+ const fullName = givenName ? givenName + ' ' + familyName : '';
533
+ const title: String = fullName ? fullName : 'Message';
534
+ const body: String = message;
535
+ const notificationData: any = {
536
+ url: config.INBOX_MESSEGE_PATH,
537
+ params: { channelId, hideTabBar: true },
538
+ screen: 'DialogMessages',
539
+ };
540
+ refetchChannelDetail({ id: channelId?.toString() })?.then((res: any) => {
541
+ if (res?.data?.viewChannelDetail?.members?.length) {
542
+ const channelData: any =
543
+ res?.data?.viewChannelDetail?.members?.filter((mu: any) => mu?.user?.id != auth?.id) ?? [];
544
+ const tokens: any =
545
+ channelData
546
+ ?.map(
547
+ (u: any) =>
548
+ u?.user?.tokens
549
+ ?.filter((t: any) => t?.type == 'EXPO_NOTIFICATION_TOKEN')
550
+ ?.map((et: any) => et?.token) ?? [],
551
+ )
552
+ ?.flat(1)
553
+ ?.filter((t: any) => t)
554
+ ?.filter((value: any, index: any, array: any) => array.indexOf(value) === index) ?? [];
555
+ console.log('expo to', JSON.stringify(tokens));
556
+ if (tokens?.length > 0) {
557
+ const to: any = tokens?.length > 0 ? tokens : [];
558
+ sendPushNotification(title, body, notificationData, to);
559
+ }
560
+ }
561
+ });
517
562
  };
518
563
 
564
+ // const handleSend1 = async (message: string) => {
565
+ // if (!channelId) return;
566
+ // if (!message && message != ' ' && images.length == 0) return;
567
+
568
+ // setLoading(true);
569
+ // const { data } = await sendMsg({
570
+ // variables: {
571
+ // channelId,
572
+ // content: message,
573
+ // },
574
+ // update: (cache, { data, errors }: any) => {
575
+ // if (!data || errors) {
576
+ // setLoading(false);
577
+ // return;
578
+ // }
579
+ // setChannelMessages((messages: any) => [...messages, data?.sendMessage]);
580
+ // setTotalCount((t: any) => t + 1);
581
+ // setChannelToTop(channelToTop + 1);
582
+ // setLoading(false);
583
+ // setMsg('');
584
+ // const givenName = auth?.profile?.given_name ?? '';
585
+ // const familyName = auth?.profile?.family_name ?? '';
586
+ // const fullName = givenName ? givenName + ' ' + familyName : '';
587
+ // const title: String = fullName ? fullName : 'Message';
588
+ // const body: String = message;
589
+ // const notificationData: any = {
590
+ // url: config.INBOX_MESSEGE_PATH,
591
+ // params: { channelId, hideTabBar: true },
592
+ // screen: 'DialogMessages',
593
+ // };
594
+ // refetchChannelDetail({ id: channelId?.toString() })?.then((res: any) => {
595
+ // if (res?.data?.viewChannelDetail?.members?.length) {
596
+ // const channelData: any =
597
+ // res?.data?.viewChannelDetail?.members?.filter((mu: any) => mu?.user?.id != auth?.id) ?? [];
598
+ // const tokens: any =
599
+ // channelData
600
+ // ?.map(
601
+ // (u: any) =>
602
+ // u?.user?.tokens
603
+ // ?.filter((t: any) => t?.type == 'EXPO_NOTIFICATION_TOKEN')
604
+ // ?.map((et: any) => et?.token) ?? [],
605
+ // )
606
+ // ?.flat(1)
607
+ // ?.filter((t: any) => t)
608
+ // ?.filter((value: any, index: any, array: any) => array.indexOf(value) === index) ?? [];
609
+ // console.log('expo to', JSON.stringify(tokens));
610
+ // if (tokens?.length > 0) {
611
+ // const to: any = tokens?.length > 0 ? tokens : [];
612
+
613
+ // sendPushNotification(title, body, notificationData, to);
614
+ // }
615
+ // }
616
+ // });
617
+ // },
618
+ // });
619
+ // if (images && images.length > 0 && data?.sendMessage?.id) {
620
+ // const { id: postId } = data.sendMessage;
621
+ // setLoading(true);
622
+ // const uploadResponse = await startUpload({
623
+ // file: images,
624
+ // saveUploadedFile: {
625
+ // variables: {
626
+ // postId,
627
+ // },
628
+ // },
629
+ // createUploadLink: {
630
+ // variables: {
631
+ // postId,
632
+ // },
633
+ // },
634
+ // });
635
+ // if (uploadResponse?.error) setLoading(false);
636
+ // const uploadedFiles = uploadResponse.data as unknown as IFileInfo[];
637
+ // if (uploadResponse.data) {
638
+ // setImage('');
639
+ // setFiles([]);
640
+ // setImages([]);
641
+ // setLoading(false);
642
+ // }
643
+ // setChannelMessages((messages: any) =>
644
+ // messages.map((message: any) => {
645
+ // if (message.id === postId) {
646
+ // return {
647
+ // ...message,
648
+ // files: {
649
+ // totalCount: uploadedFiles.length,
650
+ // data: uploadedFiles,
651
+ // },
652
+ // };
653
+ // }
654
+ // return message;
655
+ // }),
656
+ // );
657
+ // }
658
+ // };
659
+
519
660
  const messageList = useMemo(() => {
520
661
  let currentDate = '';
521
662
  let res: any = [];
@@ -546,6 +687,7 @@ const ConversationViewComponent = ({ channelId }: any) => {
546
687
  (message.received = msg?.isRead);
547
688
  message.type = msg?.type;
548
689
  message.propsConfiguration = msg?.propsConfiguration;
690
+ message.replies = msg?.replies ?? [];
549
691
  res.push(message);
550
692
  });
551
693
  }
@@ -569,6 +711,8 @@ const ConversationViewComponent = ({ channelId }: any) => {
569
711
 
570
712
  const renderMessageText = (props: any) => {
571
713
  const { currentMessage } = props;
714
+ const lastReply: any = currentMessage?.replies?.data?.length > 0 ? currentMessage?.replies?.data?.[0] : null;
715
+
572
716
  if (currentMessage.type === 'ALERT') {
573
717
  const attachment = currentMessage?.propsConfiguration?.contents?.attachment;
574
718
  let action: string = '';
@@ -600,7 +744,56 @@ const ConversationViewComponent = ({ channelId }: any) => {
600
744
  </Box>
601
745
  );
602
746
  } else {
603
- return <MessageText {...props} textStyle={{ left: { marginLeft: 5 } }} />;
747
+ return (
748
+ <TouchableOpacity
749
+ onPress={() =>
750
+ navigation.navigate(config.THREAD_MESSEGE_PATH, {
751
+ channelId: channelId,
752
+ title: 'Message',
753
+ postParentId: currentMessage?._id,
754
+ isPostParentIdThread: true,
755
+ })
756
+ }
757
+ >
758
+ <MessageText {...props} textStyle={{ left: { marginLeft: 5 } }} />
759
+ {currentMessage?.replies?.data?.length > 0 && (
760
+ <HStack space={1} px={1} alignItems={'center'}>
761
+ <HStack>
762
+ {currentMessage?.replies?.data
763
+ ?.filter(
764
+ (v: any, i: any, a: any) =>
765
+ a.findIndex((t: any) => t?.author?.id === v?.author?.id) === i,
766
+ )
767
+ ?.slice(0, 2)
768
+ ?.reverse()
769
+ ?.map((p: any, i: Number) => (
770
+ <Avatar
771
+ key={'key' + i}
772
+ bg={'transparent'}
773
+ size={6}
774
+ // top={i == 1 ? 4 : 0}
775
+ // right={i == 1 ? -2 : 0}
776
+ // zIndex={i == 1 ? 5 : 1}
777
+ _image={{ borderRadius: 6, borderWidth: 2, borderColor: '#fff' }}
778
+ source={{
779
+ uri: p?.author?.picture,
780
+ }}
781
+ >
782
+ {startCase(p?.author?.username?.charAt(0))}
783
+ </Avatar>
784
+ ))}
785
+ </HStack>
786
+ <Text fontSize={12} fontWeight={'bold'} color={'blue.800'}>
787
+ {currentMessage?.replies?.totalCount}{' '}
788
+ {currentMessage?.replies?.totalCount == 1 ? 'reply' : 'replies'}
789
+ </Text>
790
+ <Text fontSize={12} fontWeight={'bold'} color={'gray.500'}>
791
+ {lastReply ? createdAtText(lastReply?.createdAt) : ''}
792
+ </Text>
793
+ </HStack>
794
+ )}
795
+ </TouchableOpacity>
796
+ );
604
797
  }
605
798
  };
606
799
 
@@ -13,6 +13,7 @@ import { config } from '../config';
13
13
  export interface InboxProps {
14
14
  channelFilters?: Record<string, unknown>;
15
15
  channelRole?: string;
16
+ supportServices:boolean;
16
17
  }
17
18
 
18
19
  const DialogsComponent = (props: InboxProps) => {
@@ -119,7 +120,7 @@ const DialogsComponent = (props: InboxProps) => {
119
120
  },[])
120
121
 
121
122
  return (
122
- <Box p={2}>
123
+ <Box p={2} pt={props?.supportServices ? 0 : 2}>
123
124
  <FlatList
124
125
  data={channels && channels?.length > 0 ? channels : []}
125
126
  onRefresh={handleRefresh}
@@ -0,0 +1,119 @@
1
+ import React, { useCallback, useMemo, useEffect, useState } from 'react';
2
+ import { FlatList, Box, Heading, Input, Text, Icon, Center, Spinner } from 'native-base';
3
+ import { Ionicons } from '@expo/vector-icons';
4
+ import { useSelector, useDispatch } from 'react-redux';
5
+ import { useNavigation, useRoute, useIsFocused, useFocusEffect } from '@react-navigation/native';
6
+
7
+ import { SupportServiceDialogsListItem } from '../components/SupportServiceDialogsListItem';
8
+ import { useSupportServiceChannelsQuery } from '@messenger-box/platform-client';
9
+ import { userSelector } from '@adminide-stack/user-auth0-client';
10
+ import { CHANGE_SETTINGS_ACTION } from '@admin-layout/client';
11
+ import { config } from '../config';
12
+
13
+ export interface SupportServiceInboxProps {
14
+ channelFilters?: Record<string, unknown>;
15
+ channelRole?: string;
16
+ }
17
+
18
+ const SupportServiceDialogsComponent = (props: SupportServiceInboxProps) => {
19
+ const { channelFilters, channelRole } = props;
20
+ const { params } = useRoute<any>();
21
+ const auth = useSelector(userSelector);
22
+ const dispatch = useDispatch();
23
+ const navigation = useNavigation<any>();
24
+ const isFocused = useIsFocused();
25
+ const [refreshing, setRefresh] = useState<boolean>(false);
26
+ // const [userDirectChannel, setUserDirectChannel] = useState<any>([]);
27
+
28
+ const {
29
+ data: serviceChannels,
30
+ loading: serviceChannelsLoading,
31
+ refetch: getServiceChannelsRefetch,
32
+ } = useSupportServiceChannelsQuery({
33
+ variables: {
34
+ criteria: { type: 'SERVICE' },
35
+ },
36
+ onCompleted: (data: any) => {
37
+ //setRefresh(false);
38
+ },
39
+ });
40
+
41
+ useFocusEffect(
42
+ React.useCallback(() => {
43
+ // Do something when the screen is focused
44
+ setRefresh(false);
45
+ getServiceChannelsRefetch({ criteria: { type: 'SERVICE' } });
46
+
47
+ return () => {
48
+ // Do something when the screen is unfocused
49
+ // Useful for cleanup functions
50
+ };
51
+ }, []),
52
+ );
53
+
54
+ const channels = React.useMemo(() => {
55
+ if (!serviceChannels?.supportServiceChannels?.length) return null;
56
+ let uChannels: any =
57
+ serviceChannels?.supportServiceChannels?.filter((c: any) =>
58
+ c.members.some((u: any) => u.user.__typename == 'UserAccount'),
59
+ ) ?? [];
60
+ return uChannels || [];
61
+ }, [serviceChannels]);
62
+
63
+ const handleSelectChannel = useCallback((id: any, title: any, postParentId: any) => {
64
+ if (params?.channelId) {
65
+ navigation.navigate(
66
+ params?.postParentId || params?.postParentId == 0 ? config.THREAD_MESSEGE_PATH : (config.THREADS_PATH as any),
67
+ {
68
+ channelId: params?.channelId,
69
+ role:params?.role,
70
+ title: params?.title ?? null,
71
+ postParentId: params?.postParentId,
72
+ hideTabBar: true,
73
+ },
74
+ );
75
+ } else {
76
+ navigation.navigate(
77
+ postParentId || postParentId == 0 ? config.THREAD_MESSEGE_PATH : (config.THREADS_PATH as any),
78
+ {
79
+ channelId: id,
80
+ role:channelRole,
81
+ title: title,
82
+ postParentId: postParentId,
83
+ hideTabBar: true,
84
+ },
85
+ );
86
+ }
87
+ }, []);
88
+
89
+ const handleRefresh = useCallback(() => {
90
+ //if(userChannels?.channelsByUser?.length != channels?.length)setRefresh(true);
91
+ setRefresh(true)
92
+ getServiceChannelsRefetch({ criteria: { type: 'SERVICE' } })?.then((res:any)=>setRefresh(false));
93
+ }, []);
94
+
95
+ return (
96
+ <Box p={2} pb={0}>
97
+ <FlatList
98
+ data={channels && channels?.length > 0 ? channels : []}
99
+ onRefresh={handleRefresh}
100
+ refreshing={serviceChannelsLoading}
101
+ contentContainerStyle={{}}
102
+ ItemSeparatorComponent={() => <Box height="0.5" backgroundColor="gray.200" />}
103
+ renderItem={({ item: channel }) => (
104
+ <SupportServiceDialogsListItem
105
+ onOpen={handleSelectChannel}
106
+ currentUser={auth}
107
+ channel={channel}
108
+ refreshing={refreshing}
109
+ selectedChannelId={params?.channelId}
110
+ role={channelRole}
111
+ />
112
+ )}
113
+ keyExtractor={(item, index) => 'support-service-key' + index}
114
+ />
115
+ </Box>
116
+ );
117
+ };
118
+
119
+ export const SupportServiceDialogs = React.memo(SupportServiceDialogsComponent);