1import * as Chat2Gen from '../../../actions/chat2-gen'
2import * as Constants from '../../../constants/chat2'
3import * as Container from '../../../util/container'
4import * as React from 'react'
5import * as Types from '../../../constants/types/chat2'
6import * as TeamConstants from '../../../constants/teams'
7import {InfoPanel, Panel} from '.'
8
9type Props = {
10  conversationIDKey?: Types.ConversationIDKey
11  navigation?: any
12}
13
14const InfoPanelConnector = (props: Props) => {
15  const storeSelectedTab = Container.useSelector(state => state.chat2.infoPanelSelectedTab)
16  const initialTab =
17    // @ts-ignore
18    typeof props.navigation !== 'undefined' ? Container.getRouteProps(props, 'tab', null) : storeSelectedTab
19
20  const conversationIDKey: Types.ConversationIDKey =
21    props.conversationIDKey ??
22    Container.getRouteProps(props as any, 'conversationIDKey', Constants.noConversationIDKey)
23
24  const meta = Container.useSelector(state => Constants.getMeta(state, conversationIDKey))
25  const shouldNavigateOut = meta.conversationIDKey === Constants.noConversationIDKey
26  const yourRole = Container.useSelector(state => TeamConstants.getRole(state, meta.teamID))
27  const isPreview = meta.membershipType === 'youArePreviewing'
28  const channelname = meta.channelname
29  const smallTeam = meta.teamType !== 'big'
30  const teamname = meta.teamname
31
32  const prevShouldNavigateOut = Container.usePrevious(shouldNavigateOut)
33  const [selectedTab, onSelectTab] = React.useState<Panel | null>(initialTab)
34
35  const dispatch = Container.useDispatch()
36  const onCancel = () => {
37    dispatch(Chat2Gen.createShowInfoPanel({show: false}))
38    dispatch(Chat2Gen.createClearAttachmentView({conversationIDKey}))
39  }
40  const onGoToInbox = React.useCallback(() => dispatch(Chat2Gen.createNavigateToInbox()), [dispatch])
41
42  React.useEffect(() => {
43    !prevShouldNavigateOut && shouldNavigateOut && onGoToInbox()
44  }, [prevShouldNavigateOut, shouldNavigateOut, onGoToInbox])
45
46  return (
47    <InfoPanel
48      onCancel={onCancel}
49      onSelectTab={onSelectTab}
50      channelname={channelname}
51      isPreview={isPreview}
52      selectedConversationIDKey={conversationIDKey}
53      selectedTab={selectedTab ?? 'members'}
54      smallTeam={smallTeam}
55      teamname={teamname}
56      yourRole={yourRole}
57    />
58  )
59}
60
61export default InfoPanelConnector
62