| 6340 |
stevensc |
1 |
import React, { useEffect, useState } from 'react'
|
|
|
2 |
import Contacts from '../components/contacts/Contacts'
|
|
|
3 |
import Chat from '../components/chat/Chat'
|
|
|
4 |
import GroupMembers from '../components/group-members/GroupMembers'
|
|
|
5 |
import AddMember from '../components/add-member/AddMember'
|
|
|
6 |
|
|
|
7 |
const CHAT_TABS = {
|
|
|
8 |
CHAT: 'CHAT',
|
|
|
9 |
DEFAULT: 'DEFAULT',
|
|
|
10 |
GROUP_MEMBERS: 'GROUP_MEMBERS',
|
|
|
11 |
ADD_GROUP_MEMBER: 'ADD_GROUP_MEMBER',
|
|
|
12 |
}
|
|
|
13 |
|
|
|
14 |
const MobileChat = ({ chatUsers = [], chatGroups = [], timezones = {} }) => {
|
|
|
15 |
const [selectedConversation, setSelectedConversation] = useState(null)
|
|
|
16 |
const [activeTab, setActiveTab] = useState(CHAT_TABS.DEFAULT)
|
|
|
17 |
|
|
|
18 |
const openChat = (entity) => {
|
|
|
19 |
setSelectedConversation(entity)
|
|
|
20 |
setActiveTab(CHAT_TABS.CHAT)
|
|
|
21 |
}
|
|
|
22 |
|
|
|
23 |
const changeTab = (tab) => {
|
|
|
24 |
setActiveTab(tab)
|
|
|
25 |
}
|
|
|
26 |
|
|
|
27 |
useEffect(() => {
|
|
|
28 |
activeTab === CHAT_TABS.DEFAULT && setSelectedConversation(null)
|
|
|
29 |
}, [activeTab])
|
|
|
30 |
|
|
|
31 |
return (
|
|
|
32 |
<>
|
|
|
33 |
{activeTab === CHAT_TABS.DEFAULT && (
|
|
|
34 |
<Contacts
|
|
|
35 |
persons={chatUsers}
|
|
|
36 |
groups={chatGroups}
|
|
|
37 |
selectedConversation={selectedConversation}
|
|
|
38 |
changeConversation={(conversation) => openChat(conversation)}
|
|
|
39 |
/>
|
|
|
40 |
)}
|
|
|
41 |
{activeTab === CHAT_TABS.CHAT && (
|
|
|
42 |
<Chat
|
|
|
43 |
entity={selectedConversation}
|
|
|
44 |
timezones={timezones}
|
|
|
45 |
changeTab={changeTab}
|
|
|
46 |
/>
|
|
|
47 |
)}
|
|
|
48 |
{activeTab === CHAT_TABS.ADD_GROUP_MEMBER && (
|
|
|
49 |
<AddMember group={selectedConversation} />
|
|
|
50 |
)}
|
|
|
51 |
{activeTab === CHAT_TABS.GROUP_MEMBERS && (
|
|
|
52 |
<GroupMembers group={selectedConversation} />
|
|
|
53 |
)}
|
|
|
54 |
</>
|
|
|
55 |
)
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
export default MobileChat
|