import React, { FunctionComponent, useEffect } from 'react'; import { Strings } from '../../resources/localization/Strings'; import { eventEmitter, EventType } from '../../services/EventEmitter'; import { getCallLogs, getCallLogsResult, getMissedCall, getMissedCallResult, getVoiceMailCapabilities, getVoiceMailCapabilitiesResult, markMissedCallsAsRead, updateCallLogsPresence, } from '../../store/callLogs/callLogSlice'; import { ICallLog } from '../../store/callLogs/types'; import { Presence } from '../../store/contacts/types'; import { forwardCallToVoiceMail } from '../../store/pbx/pbxSlice'; import { Logger } from '../../utils/Log'; import { CallLogsView } from './CallLogsView'; import { VoiceMailsView } from './VoiceMailsView'; import { useAppDispatch, useAppSelector } from '../../store/hooks'; import { Text, Button, Surface, useTheme, Badge } from 'react-native-paper'; import { StyleSheet, View } from 'react-native'; interface ICallLogsProps { onClickCallLogAction?: (callLog: ICallLog) => void; } /** * @module * @name CallLogs * @version SDKVERSION * @public * @description * * This module for managing Call history for the Webrtc and PBX and you can use it for showing the 'all call history','missed calls' and 'voice messages' * */ const CallLogsContainer: FunctionComponent = ({onClickCallLogAction}) => { const logger = new Logger('CallLogsContainer'); const theme = useTheme(); const [selectedTab, setSelectedTab] = React.useState(1); const dispatch = useAppDispatch(); const callLogs = useAppSelector((state) => state.callLogs.callLogs); const missedCallLogs = useAppSelector((state) => state.callLogs.missedCallLogs); const loading = useAppSelector((state) => state.callLogs.loading); const isVoiceMailAllowed = useAppSelector((state) => state.callLogs.isVoiceMailAllowed); const voiceMailNumber = useAppSelector((state) => state.callLogs.voiceMailNumber); const voiceMailCounter = useAppSelector((state) => state.callLogs.voiceMailCounter); useEffect(() => { dispatch(getCallLogs()); dispatch(getMissedCall()); dispatch( getVoiceMailCapabilities()); eventEmitter.addListener( EventType.CallLogsUpdated, (allCalls: ICallLog[]) => { dispatch(getCallLogsResult(allCalls)) } ); eventEmitter.addListener( EventType.MissedCallLogsUpdated, (missedCalls: ICallLog[]) => { dispatch(getMissedCallResult(missedCalls)) } ); eventEmitter.addListener( EventType.PresenceUpdated, (eventData: { presence: Presence; contactJId: string }) => { dispatch(updateCallLogsPresence(eventData)) } ); eventEmitter.addListener( EventType.VoiceMailCapabilityUpdate, (eventData: { isVoiceMailAllowed: boolean; voiceMailNumber: string }) => { dispatch(getVoiceMailCapabilitiesResult(eventData)) } ); return () => { }; }, []); const onRefreshData = () => { if (selectedTab === 0) { logger.info(`refresh Call Logs in active Tab :${selectedTab}`); dispatch(getCallLogs()); } else { logger.info(`refresh missed Call Logs in active Tab :${selectedTab}`); dispatch(getMissedCall()); } }; const onCallVoiceMail = () => { forwardCallToVoiceMail(voiceMailNumber); }; const renderTab = () => { switch (selectedTab) { case 1: return case 2: return case 3: return default: return null } } return ( <> {isVoiceMailAllowed && voiceMailCounter > 0 && ( <> {voiceMailCounter} )} {renderTab()} ); }; export const CallLogs = CallLogsContainer; const styles = StyleSheet.create({ container: { width: 300, alignSelf: 'center', paddingVertical: 10, elevation: 6, borderRadius: 8, backgroundColor: 'white', }, tabRow: { flexDirection: 'row', alignItems: 'center', justifyContent: 'center', }, tabButton: { flex: 1, marginHorizontal: 4, borderRadius: 20, }, selectedTabButton: { backgroundColor: '#0086CF', }, buttonText: { color: '#FFFFFF', fontWeight: 'bold', }, unselectedButtonText: { color: '#0086CF', }, badge: { position: 'absolute', right: 15, top: -5, backgroundColor: 'red', color: 'white', fontSize: 10, paddingHorizontal: 5, }, });