import React, { useEffect, useState } from 'react'; import { FlatList, ImageBackground, ImageStyle, TextStyle, ViewStyle, Alert, View, StyleSheet } from 'react-native'; import { Platform } from 'react-native'; import { Strings } from '../../resources/localization/Strings'; import { contactsService } from '../../services/contacts-service'; import { eventEmitter, EventType } from '../../services/EventEmitter'; import { IContact, IEmail, IPhoneNumber, Presence, } from '../../store/contacts/types'; import { callPBX } from '../../store/pbx/pbxSlice'; import { Logger } from '../../utils/Log'; import { IStyledProps } from '../common/types'; import { removeContact } from '../../store/contacts/contactsSlice'; import { Header } from '../common/Header'; import Icon from 'react-native-vector-icons/Ionicons'; import { AvatarPresenceBadge } from '../presence/AvatarPresenceBadge'; import { ContactInformationNavigationProp, ContactInformationRouteProp } from '../../RootStackParamList'; import { useAppDispatch, useAppSelector } from '../../store/hooks'; import { CallButton } from '../common/callButton'; import { Button,Text } from 'react-native-paper'; export interface IProps extends IStyledProps { route: ContactInformationRouteProp; navigation: ContactInformationNavigationProp; } export interface IContactInfoStyleProps { backgroundImg?: ImageStyle; itemTextContainer?: TextStyle; headerTitle?: TextStyle; itemContainer?:ViewStyle; } export const ContactInformation: React.FunctionComponent = ({ route, style, }) => { const logger = new Logger('ContactInformation'); const contact = route.params.contact; const dispatch = useAppDispatch(); const user = useAppSelector((state) => state.authReducer.user); const { makeCallButtonProps } = route.params; const [presence, setPresence] = useState(contact.presence); const [updatedContact, setUpdatedContact] = useState(contact); const [InvitationSent, setInvitationSent] = useState(contact.isInvited); const [addRoster, setAddRoster] = useState(!updatedContact.isRoster && !updatedContact.isInvited) const [removeRoster, setRemoveRoster] = useState(updatedContact.isRoster); const mergedStyle = { ...styles, ...style }; useEffect(() => { if ( Platform.OS === 'ios' && !updatedContact.isRoster && updatedContact.companyName === user?.contact.companyName ) { contactsService.fetchContactDetails(updatedContact.jId); } eventEmitter.addListener( EventType.PresenceUpdated, (eventData: { presence: Presence; contactJId: string }) => { if (eventData.contactJId === updatedContact.jId) { logger.info(`onPresenceUpdated : ${updatedContact.name}`); setPresence(eventData.presence); } } ); eventEmitter.addListener( EventType.ContactsDetailUpdated, (eventData: IContact) => { if (eventData.jId === updatedContact.jId) { logger.info(`onContactsDetailsUpdated : ${updatedContact.name}`); setUpdatedContact(eventData); } } ); eventEmitter.addListener( EventType.RemoveContact, (eventData: string) => { if (eventData === 'success') { logger.info(`removeContact listener`); setAddRoster(true); setRemoveRoster(false); } } ); eventEmitter.addListener( EventType.AddContactToRoster, (eventData: string) => { if (eventData === "success") setInvitationSent(true); Alert.alert('Invite contact to my network', eventData); } ) }, []); const renderEmailItem = ({ item }: {item :IEmail}) => { return ( {Strings.emailStrings[item.type]} {item.value} ); }; const renderPhoneItem = ({ item }: { item: IPhoneNumber }) => { return ( {Strings.phoneStrings[item.type]} {item.value} ); }; const makeCall = (item: IPhoneNumber) => { dispatch(callPBX(item.value)); }; const setKeyExtractor = (item: any) => { return item.value; }; const removeContactFromNetwork = () => { dispatch(removeContact(updatedContact.jId)); } const addToRoster = () => { contactsService.addContactToRoster(updatedContact.jId); } const renderCenterHeader = () => { return {Strings.contactDetails} ; } const renderRightHeader = () => { if (makeCallButtonProps) { return ; } else return null; } return (
{updatedContact.name} {updatedContact.jobTitle} {updatedContact.companyName} {Strings[updatedContact.presence]} {addToRoster && ( )} {InvitationSent && ( {Strings.invitationSent} )} {removeRoster && ( )} ); }; const styles = StyleSheet.create({ text: { color: '#FFFFFF', fontSize: 12, }, headerTitle: { textAlign: 'center', alignSelf: 'center', fontSize: 16, color: '#0086CF', }, itemContainer: { flexDirection: 'row', padding: 12, alignItems: 'center', }, itemTextContainer: { marginLeft: 12, }, itemTypeText: { color: '#0086CF', // Use a hex code for a consistent color }, phoneNumberText: { color: 'black', }, container: { flex: 1, paddingHorizontal: 16, }, backgroundImg: { width: '100%', height: 150, justifyContent: 'center', }, imageOpacity: { opacity: 0.2, }, contactHeader: { flexDirection: 'row', padding: 16, alignItems: 'center', }, contactInfo: { marginLeft: 16, }, actionsContainer: { padding: 16, }, rosterButton: { marginVertical: 8, }, buttonContent: { flexDirection: 'row-reverse', }, invitationContainer: { flexDirection: 'row', alignItems: 'center', marginVertical: 8, }, invitationText: { color: '#0086CF', marginLeft: 8, }, removeButton: { marginVertical: 8, }, listsContainer: { padding: 16, } });