/* eslint-disable react-native/no-inline-styles */ import { View, Text, FlatList, StyleSheet, TouchableOpacity, RefreshControl, } from 'react-native'; import React, { useContext } from 'react'; import { widgetsConversations } from '../../graphql/query'; import { useQuery } from '@apollo/client'; import dayjs from 'dayjs'; import FAB from '../../components/FAB'; import AppContext from '../../context/Context'; import Avatar from '../../components/Avatar'; import AsyncStorage from '@react-native-async-storage/async-storage'; const Conversations = () => { const value = useContext(AppContext); const { customerId, visitorId, bgColor, integrationId, setConversationId, // newChatIcon, } = value; const { data, loading, refetch } = useQuery(widgetsConversations, { variables: { integrationId, customerId: customerId || null, visitorId: customerId ? null : visitorId, }, }); const [refreshing, setRefreshing] = React.useState(false); const onRefresh = React.useCallback(() => { setRefreshing(true); refetch(); setTimeout(() => { setRefreshing(false); }, 1000); }, [refetch]); if (loading) { return null; } const renderItem = ({ item }: any) => { let name = 'Support Staff'; if (item?.participatedUsers?.length > 0) { name = item?.participatedUsers[0]?.details?.fullName; } return ( { AsyncStorage.setItem('conversationId', item._id); setConversationId(item._id); }} > {name} {item?.content} {dayjs(item?.createdAt).format('hh:mm A')} ); }; const renderHeader = () => { return ( Recent conversations ); }; const seperator = () => { return ; }; const emptyComponent = () => { return ( There is no chat currently right now ); }; return ( item._id} onEndReachedThreshold={0.2} renderItem={renderItem} ListHeaderComponent={renderHeader} refreshControl={ } ListEmptyComponent={emptyComponent} ItemSeparatorComponent={seperator} /> { setConversationId(''); }} backgroundColor={bgColor} icon={newChatIcon} /> ); }; export default Conversations; const styles = StyleSheet.create({ contentStyle: { flexGrow: 1, padding: 20, }, itemContainer: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', }, image: { width: 40, height: 40, borderRadius: 90, }, });