2020-11-15 18:48:32 +00:00
|
|
|
import React from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
2020-12-03 04:22:51 +00:00
|
|
|
import { connect } from 'react-redux'
|
2020-11-15 18:48:32 +00:00
|
|
|
import { me } from '../initial_state'
|
2020-12-03 04:22:51 +00:00
|
|
|
import { openModal } from '../actions/modal'
|
2020-12-20 17:27:24 +00:00
|
|
|
import { openPopover } from '../actions/popover'
|
2020-11-15 18:48:32 +00:00
|
|
|
import {
|
|
|
|
CX,
|
|
|
|
BREAKPOINT_EXTRA_SMALL,
|
2020-12-20 17:27:24 +00:00
|
|
|
POPOVER_CHAT_SETTINGS,
|
2020-12-03 04:22:51 +00:00
|
|
|
MODAL_CHAT_CONVERSATION_CREATE,
|
2020-11-15 18:48:32 +00:00
|
|
|
} from '../constants'
|
|
|
|
import Layout from './layout'
|
|
|
|
import Responsive from '../features/ui/util/responsive_component'
|
|
|
|
import ResponsiveClassesComponent from '../features/ui/util/responsive_classes_component'
|
2020-12-04 03:27:09 +00:00
|
|
|
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'
|
|
|
|
|
2020-12-03 04:22:51 +00:00
|
|
|
class MessagesLayout extends React.PureComponent {
|
|
|
|
|
2020-12-20 17:27:24 +00:00
|
|
|
handleOpenSettingsOptionsPopover = () => {
|
|
|
|
this.props.onOpenSettingsOptionsPopover()
|
|
|
|
}
|
|
|
|
|
2020-12-03 04:22:51 +00:00
|
|
|
onClickAdd = () => {
|
|
|
|
this.props.onOpenChatConversationCreateModal()
|
|
|
|
}
|
2020-11-15 18:48:32 +00:00
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
2021-01-08 05:15:53 +00:00
|
|
|
width,
|
2020-12-03 04:22:51 +00:00
|
|
|
title,
|
2020-11-15 18:48:32 +00:00
|
|
|
children,
|
2020-12-03 04:22:51 +00:00
|
|
|
isSettings,
|
2020-11-15 18:48:32 +00:00
|
|
|
showBackBtn,
|
2020-12-03 04:22:51 +00:00
|
|
|
source,
|
|
|
|
currentConversationIsRequest,
|
2020-12-04 03:27:09 +00:00
|
|
|
selectedChatConversationId,
|
2020-11-15 18:48:32 +00:00
|
|
|
} = this.props
|
2020-12-04 03:27:09 +00:00
|
|
|
|
|
|
|
const isXS = width <= BREAKPOINT_EXTRA_SMALL
|
2020-11-15 18:48:32 +00:00
|
|
|
|
2020-12-04 03:27:09 +00:00
|
|
|
if (isXS) {
|
2020-12-04 03:31:11 +00:00
|
|
|
if (!selectedChatConversationId && !isSettings) {
|
2020-12-04 03:27:09 +00:00
|
|
|
return (
|
|
|
|
<div className={[_s.d, _s.w100PC, _s.minH100VH, _s.bgTertiary].join(' ')}>
|
|
|
|
<DefaultNavigationBar
|
|
|
|
showBackBtn
|
|
|
|
actions={[
|
|
|
|
{
|
|
|
|
icon: 'add',
|
2020-12-21 23:30:46 +00:00
|
|
|
to: '/messages/new',
|
2020-12-04 03:31:11 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: 'cog',
|
2020-12-20 17:27:24 +00:00
|
|
|
onClick: this.handleOpenSettingsOptionsPopover,
|
2020-12-04 03:27:09 +00:00
|
|
|
}
|
|
|
|
]}
|
|
|
|
title={title}
|
|
|
|
/>
|
2020-12-20 17:27:24 +00:00
|
|
|
<main role='main' className={[_s.d, _s.w100PC, _s.flexGrow1, _s.bgPrimary, _s.borderBottom1PX, _s.borderColorSecondary].join(' ')}>
|
2020-12-04 03:27:09 +00:00
|
|
|
<div className={[_s.d, _s.w100PC, _s.flexRow, _s.pb15].join(' ')}>
|
|
|
|
{
|
|
|
|
(isSettings || currentConversationIsRequest) &&
|
2020-12-04 03:31:11 +00:00
|
|
|
<ChatSettingsSidebar isXS />
|
2020-12-04 03:27:09 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
!isSettings && !currentConversationIsRequest &&
|
|
|
|
<ChatApprovedConversationsSidebar source={source} />
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
<FooterBar />
|
|
|
|
</main>
|
|
|
|
</div>
|
|
|
|
)
|
2020-12-04 03:31:11 +00:00
|
|
|
} else if (selectedChatConversationId && !isSettings) {
|
2020-12-04 03:27:09 +00:00
|
|
|
return (
|
|
|
|
<div className={[_s.d, _s.w100PC, _s.minH100VH, _s.bgTertiary].join(' ')}>
|
|
|
|
<ChatNavigationBar chatConversationId={selectedChatConversationId} />
|
2020-12-20 17:27:24 +00:00
|
|
|
<main role='main' className={[_s.d, _s.w100PC, _s.flexGrow1, _s.bgPrimary, _s.borderBottom1PX, _s.borderColorSecondary].join(' ')}>
|
2020-12-04 03:27:09 +00:00
|
|
|
<ChatMessageScrollingList chatConversationId={selectedChatConversationId} isXS={isXS} />
|
|
|
|
</main>
|
2020-12-22 20:47:02 +00:00
|
|
|
{ currentConversationIsRequest && <ChatConversationRequestApproveBar chatConversationId={selectedChatConversationId} /> }
|
2020-12-04 03:27:09 +00:00
|
|
|
{ !currentConversationIsRequest && <ChatMessageComposeForm chatConversationId={selectedChatConversationId} isXS={isXS} /> }
|
|
|
|
</div>
|
|
|
|
)
|
2020-12-04 03:31:11 +00:00
|
|
|
} else {
|
2020-12-20 17:27:24 +00:00
|
|
|
return (
|
|
|
|
<div className={[_s.d, _s.w100PC, _s.minH100VH, _s.bgTertiary].join(' ')}>
|
|
|
|
<DefaultNavigationBar showBackBtn title={title} />
|
2021-01-05 16:34:02 +00:00
|
|
|
<main role='main' className={[_s.d, _s.w100PC, _s.flexGrow1, _s.bgPrimary, _s.borderBottom1PX, _s.borderColorSecondary].join(' ')}>
|
|
|
|
<div className={[_s.d, _s.w100PC, _s.flexRow, _s.flexGrow1, _s.mb15].join(' ')}>
|
2020-12-20 17:27:24 +00:00
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
<FooterBar />
|
|
|
|
</main>
|
|
|
|
</div>
|
|
|
|
)
|
2020-12-04 03:27:09 +00:00
|
|
|
}
|
|
|
|
}
|
2020-12-03 04:22:51 +00:00
|
|
|
|
2020-11-15 18:48:32 +00:00
|
|
|
return (
|
|
|
|
<Layout
|
|
|
|
showBackBtn
|
|
|
|
noRightSidebar
|
2020-12-03 04:22:51 +00:00
|
|
|
noComposeButton
|
|
|
|
showGlobalFooter
|
2020-11-15 18:48:32 +00:00
|
|
|
showLinkFooterInSidebar
|
|
|
|
page='messages'
|
|
|
|
title='Chats'
|
|
|
|
actions={[
|
|
|
|
{
|
|
|
|
icon: 'cog',
|
2020-12-03 04:22:51 +00:00
|
|
|
to: '/messages/settings',
|
2020-11-15 18:48:32 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
icon: 'pencil',
|
2020-12-03 04:22:51 +00:00
|
|
|
onClick: () => this.onClickAdd(),
|
2020-11-15 18:48:32 +00:00
|
|
|
},
|
|
|
|
]}
|
|
|
|
>
|
2020-12-10 16:51:45 +00:00
|
|
|
<div className={[_s.d, _s.flexRow, _s.boxShadowNone, _s.w100PC, _s.calcH53PX].join(' ')}>
|
2020-11-15 18:48:32 +00:00
|
|
|
<ResponsiveClassesComponent
|
|
|
|
classNames={[_s.d, _s.flexShrink1, _s.flexGrow1].join(' ')}
|
|
|
|
classNamesSmall={[_s.d, _s.flexShrink1, _s.flexGrow1].join(' ')}
|
|
|
|
classNamesXS={[_s.d, _s.w100PC].join(' ')}
|
|
|
|
>
|
|
|
|
<ResponsiveClassesComponent
|
2020-12-04 03:27:09 +00:00
|
|
|
classNames={[_s.d, _s.w1015PX, _s.h100PC, _s.flexRow, _s.jcEnd].join(' ')}
|
|
|
|
classNamesXS={[_s.d, _s.w100PC, _s.h100PC, _s.jcEnd].join(' ')}
|
2020-11-15 18:48:32 +00:00
|
|
|
>
|
2020-12-04 03:27:09 +00:00
|
|
|
{
|
|
|
|
(isSettings || currentConversationIsRequest) &&
|
|
|
|
<ChatSettingsSidebar />
|
|
|
|
}
|
|
|
|
{
|
|
|
|
!isSettings && !currentConversationIsRequest &&
|
|
|
|
<ChatApprovedConversationsSidebar source={source} />
|
|
|
|
}
|
2020-11-15 18:48:32 +00:00
|
|
|
<div className={[_s.d, _s.flexGrow1, _s.h100PC, _s.bgPrimary, _s.borderColorSecondary, _s.borderRight1PX, _s.z1].join(' ')}>
|
|
|
|
<div className={[_s.d, _s.w100PC, _s.h100PC].join(' ')}>
|
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</ResponsiveClassesComponent>
|
|
|
|
</ResponsiveClassesComponent>
|
|
|
|
</div>
|
|
|
|
</Layout>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-03 04:22:51 +00:00
|
|
|
const mapStateToProps = (state) => {
|
2020-12-04 03:27:09 +00:00
|
|
|
const selectedChatConversationId = state.getIn(['chats', 'selectedChatConversationId'], null)
|
|
|
|
const currentConversationIsRequest = selectedChatConversationId ? !state.getIn(['chat_conversations', selectedChatConversationId, 'is_approved'], true) : false
|
2020-12-03 04:22:51 +00:00
|
|
|
|
2020-12-04 03:27:09 +00:00
|
|
|
return {
|
|
|
|
selectedChatConversationId,
|
|
|
|
currentConversationIsRequest,
|
2021-01-08 05:15:53 +00:00
|
|
|
width: state.getIn(['settings', 'window_dimensions', 'width']),
|
2020-12-04 03:27:09 +00:00
|
|
|
}
|
2020-12-03 04:22:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
|
|
onOpenChatConversationCreateModal() {
|
|
|
|
dispatch(openModal(MODAL_CHAT_CONVERSATION_CREATE))
|
2020-12-20 17:27:24 +00:00
|
|
|
},
|
|
|
|
onOpenSettingsOptionsPopover() {
|
|
|
|
dispatch(openPopover(POPOVER_CHAT_SETTINGS))
|
|
|
|
},
|
2020-12-03 04:22:51 +00:00
|
|
|
})
|
|
|
|
|
2020-11-15 18:48:32 +00:00
|
|
|
MessagesLayout.propTypes = {
|
2020-12-03 04:22:51 +00:00
|
|
|
title: PropTypes.string,
|
2020-11-15 18:48:32 +00:00
|
|
|
children: PropTypes.node,
|
2020-12-03 04:22:51 +00:00
|
|
|
isSettings: PropTypes.bool,
|
2020-11-15 18:48:32 +00:00
|
|
|
showBackBtn: PropTypes.bool,
|
2020-12-03 04:22:51 +00:00
|
|
|
source: PropTypes.string,
|
|
|
|
onOpenChatConversationCreateModal: PropTypes.func.isRequired,
|
2020-11-15 18:48:32 +00:00
|
|
|
}
|
|
|
|
|
2020-12-03 04:22:51 +00:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(MessagesLayout)
|