Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5064 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
5038 stevensc 1
/* eslint-disable react/display-name */
5035 stevensc 2
/* eslint-disable react/prop-types */
3
import React, { useEffect, useState } from 'react'
5041 stevensc 4
import SearchIcon from '@mui/icons-material/Search'
5043 stevensc 5
import ContactsList from './ContactsList'
5048 stevensc 6
import AddIcon from '@mui/icons-material/Add'
7
import CreateGroupModal from './CreateGroupModal'
5035 stevensc 8
 
5043 stevensc 9
const ContactsFilters = ({ dataset, selectConversation }) => {
5206 stevensc 10
  const [search, setSearch] = useState('')
11
  const [contacts, setContacts] = useState([])
12
  const [addGroup, setAddGroup] = useState(false)
13
  const [groups, setGroups] = useState([])
14
  const [activeTab, setActiveTab] = useState('user')
5035 stevensc 15
 
5206 stevensc 16
  const filtredContacts = contacts.filter(({ name }) => name.toLowerCase().includes(search.toLowerCase()))
17
  const filtredGroups = groups.filter(({ name }) => name.toLowerCase().includes(search.toLowerCase()))
5035 stevensc 18
 
5206 stevensc 19
  const handleChangeTab = (tab) => setActiveTab(tab)
5035 stevensc 20
 
5206 stevensc 21
  const handleEntities = () => {
22
    let newUserContacts = []
23
    let newGroups = []
24
    dataset.map((entity) => {
25
      switch (entity.type) {
26
        case 'user':
27
          newUserContacts = [...newUserContacts, entity]
28
          break
29
        case 'group':
30
          newGroups = [...newGroups, entity]
31
          break
32
        default:
33
          break
34
      }
35
    })
36
    setContacts(newUserContacts)
37
    setGroups(newGroups)
38
  }
5038 stevensc 39
 
5206 stevensc 40
  useEffect(() => {
41
    handleEntities()
42
  }, [dataset])
5043 stevensc 43
 
5206 stevensc 44
  return (
5043 stevensc 45
        <>
5045 stevensc 46
            <div className="search-input mx-2">
5206 stevensc 47
                <input type="text" name='search' value={search} onChange={(e) => setSearch(e.target.value)}/>
5043 stevensc 48
                <SearchIcon />
49
            </div>
5048 stevensc 50
            {activeTab === 'group' &&
5049 stevensc 51
                <button className="action-btn ml-2" onClick={() => setAddGroup(true)}>
5048 stevensc 52
                    <AddIcon />
5206 stevensc 53
                    {CHAT_LABELS.CREATE_GROUP}
5048 stevensc 54
                </button>
55
            }
5043 stevensc 56
            <div className="actions-container">
5206 stevensc 57
                <button className={`action-btn ${activeTab === 'user' && 'active'}`} onClick={() => handleChangeTab('user')}>
58
                    {CHAT_LABELS.CONTACTS}
5043 stevensc 59
                </button>
5206 stevensc 60
                <button className={`action-btn ${activeTab === 'group' && 'active'}`} onClick={() => handleChangeTab('group')}>
61
                    {CHAT_LABELS.GROUPS}
5043 stevensc 62
                </button>
63
            </div>
64
            <ContactsList contacts={activeTab === 'user' ? filtredContacts : filtredGroups} selectConversation={selectConversation} />
5048 stevensc 65
            <CreateGroupModal show={addGroup} closeModal={() => setAddGroup(false)} />
5043 stevensc 66
        </>
5206 stevensc 67
  )
5035 stevensc 68
}
69
 
5206 stevensc 70
export default ContactsFilters