import React, { FunctionComponent, useEffect, useState } from 'react'; import { StyleSheet, Text, TextStyle, TouchableOpacity, View, ViewStyle, } from 'react-native'; import { Strings } from '../../resources/localization/Strings'; import { IStyledProps } from '../common/types'; import { IConversation } from '../../store/conversations/types'; import { ParticipantsListView } from '../common/ParticipantsListView'; import { getConversations, getConversationsResult } from '../../store/conversations/conversationSlice'; import { eventEmitter, EventType } from '../../services/EventEmitter'; import { Header } from '../common/Header'; import { ForwardedViewNavigationProp, ForwardedViewRouteProp } from '../../RootStackParamList'; import { useAppDispatch, useAppSelector } from '../../store/hooks'; import { forwardMessage } from '../../store/messages/messagesSlice'; import { TextInput } from 'react-native-paper'; interface IForwardingActionsProps extends IStyledProps { navigation: ForwardedViewNavigationProp; route: ForwardedViewRouteProp customView?: React.ReactNode, } interface IForwardingStyleProps { forwardingBody?: ViewStyle; headerTitle?: TextStyle; errorText?: TextStyle; forwardActiveButton?: ViewStyle; forwardInActiveButton?: ViewStyle; msgView?: ViewStyle; forwardText?: TextStyle messageTabStyle?: ViewStyle; participantsTabStyle?: ViewStyle; container?: ViewStyle; tabText?: ViewStyle; tab?: ViewStyle; input?: ViewStyle; } const MessageForwardedView: FunctionComponent = ({ customView, style, route, navigation }) => { const selectedMessage = route.params.message; const mergedStyle = { ...defaultStyle, ...style }; const [msgText, setMsgText] = useState(''); const [ConversationsID, setConversationsID] = useState([]); const [selectedTab, setSelectedTab] = React.useState(1); const dispatch = useAppDispatch(); const conversations = useAppSelector((state) => state.conversations.conversations); useEffect(() => { getConversations(); eventEmitter.addListener( EventType.ConversationsUpdated, (eventData: IConversation[]) => { dispatch(getConversationsResult(eventData)); } ); }, [getConversations, getConversationsResult]); const onTextChange = (name: string) => { setMsgText(name); }; const updateConversations = (selectedConversationsID: string[]) => { setConversationsID(selectedConversationsID); }; const onForwardingClick = () => { dispatch(forwardMessage({ text: msgText, message: selectedMessage, conversationsIds: ConversationsID })) navigation.pop(); } const renderForwardingBody = () => { return ( {selectedMessage.text} {ConversationsID.length === 0 && {Strings.forwardError}} 0 ? false : true} style={ConversationsID.length > 0 ? mergedStyle.forwardActiveButton : mergedStyle.forwardInActiveButton} onPress={onForwardingClick}> {Strings.forward} ); }; const renderCenterHeader = () => { return {'Forwarding Message'} } const renderTab = () => { switch (selectedTab) { case 1: return renderForwardingBody() case 2: return default: return null } } if (customView) { return <>{customView} } else { return ( <>
setSelectedTab(1)} > Message setSelectedTab(2)} > Conversations {renderTab()} ); } }; export const ForwardedView = MessageForwardedView; const defaultStyle: IForwardingStyleProps = StyleSheet.create({ errorText: { color: 'red', fontSize: 14, margin: 10 }, container: { flex: 1, backgroundColor: '#ffffff', height: 'auto', }, headerTitle: { textAlign: 'center', alignSelf: 'center', color: '#ffffff', fontSize: 16 }, forwardingBody: { flexDirection: 'column', flex: 1, paddingStart: 10, paddingEnd: 10, paddingTop: 20 }, forwardActiveButton: { alignSelf: 'stretch', height: 50, justifyContent: 'center', alignItems: 'center', backgroundColor: '#3786c9' }, forwardInActiveButton: { alignSelf: 'stretch', height: 50, justifyContent: 'center', alignItems: 'center', backgroundColor: '#8bb8df' }, msgView: { height: 200, backgroundColor: '#f2f2f2', marginTop: 10, marginBottom: 20, padding: 10 }, forwardText: { color: 'white' }, input: { marginTop: 20, }, });