import React from 'react' import PropTypes from 'prop-types' import { connect } from 'react-redux' import { me } from '../initial_state' import { openModal } from '../actions/modal' import { openPopover } from '../actions/popover' import { CX, BREAKPOINT_EXTRA_SMALL, POPOVER_CHAT_SETTINGS, MODAL_CHAT_CONVERSATION_CREATE, } from '../constants' import Layout from './layout' import Responsive from '../features/ui/util/responsive_component' import ResponsiveClassesComponent from '../features/ui/util/responsive_classes_component' import ChatSettingsSidebar from '../features/messages/components/chat_settings_sidebar' import ChatApprovedConversationsSidebar from '../features/messages/components/chat_approved_conversations_sidebar' import FooterBar from '../components/footer_bar' import DefaultNavigationBar from '../components/navigation_bar/default_navigation_bar' import ChatNavigationBar from '../components/navigation_bar/chat_navigation_bar_xs' import ChatMessageScrollingList from '../features/messages/components/chat_message_scrolling_list' import ChatMessageComposeForm from '../features/messages/components/chat_message_compose_form' import ChatConversationRequestApproveBar from '../features/messages/components/chat_conversation_request_approve_bar' class MessagesLayout extends React.PureComponent { handleOpenSettingsOptionsPopover = () => { this.props.onOpenSettingsOptionsPopover() } onClickAdd = () => { this.props.onOpenChatConversationCreateModal() } render() { const { width, title, children, isSettings, showBackBtn, source, currentConversationIsRequest, selectedChatConversationId, } = this.props const isXS = width <= BREAKPOINT_EXTRA_SMALL if (isXS) { if (!selectedChatConversationId && !isSettings) { return (
{ (isSettings || currentConversationIsRequest) && } { !isSettings && !currentConversationIsRequest && }
) } else if (selectedChatConversationId && !isSettings) { return (
{ currentConversationIsRequest && } { !currentConversationIsRequest && }
) } else { return (
{children}
) } } return ( this.onClickAdd(), }, ]} >
{ (isSettings || currentConversationIsRequest) && } { !isSettings && !currentConversationIsRequest && }
{children}
) } } const mapStateToProps = (state) => { const selectedChatConversationId = state.getIn(['chats', 'selectedChatConversationId'], null) const currentConversationIsRequest = selectedChatConversationId ? !state.getIn(['chat_conversations', selectedChatConversationId, 'is_approved'], true) : false return { selectedChatConversationId, currentConversationIsRequest, width: state.getIn(['settings', 'window_dimensions', 'width']), } } const mapDispatchToProps = (dispatch) => ({ onOpenChatConversationCreateModal() { dispatch(openModal(MODAL_CHAT_CONVERSATION_CREATE)) }, onOpenSettingsOptionsPopover() { dispatch(openPopover(POPOVER_CHAT_SETTINGS)) }, }) MessagesLayout.propTypes = { title: PropTypes.string, children: PropTypes.node, isSettings: PropTypes.bool, showBackBtn: PropTypes.bool, source: PropTypes.string, onOpenChatConversationCreateModal: PropTypes.func.isRequired, } export default connect(mapStateToProps, mapDispatchToProps)(MessagesLayout)