Proyectos de Subversion LeadersLinked - SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
5 stevensc 1
import React from 'react'
2
import { useSelector } from 'react-redux'
3
import styled, { css } from 'styled-components'
4
import Avatar from '@mui/material/Avatar'
5
 
6
import Options from '../UI/Option'
7
import EmptySection from '../UI/EmptySection'
8
 
9
const ContactsContainer = styled.div`
10
  background-color: var(--bg-color);
11
  border-radius: var(--border-radius);
12
  border: 1px solid var(--border-primary);
13
  display: flex;
14
  flex-direction: column;
15
  height: 100%;
16
  gap: 0.5rem;
17
  padding: 1rem 0.5rem;
18
  max-height: 80vh;
19
  flex-grow: 1;
20
`
21
 
22
const ContactHeader = styled.div`
23
  position: relative;
24
 
25
  h1 {
26
    font-weight: 600;
27
    font-size: 1.3rem;
28
  }
29
`
30
 
31
const ContactList = styled.ul`
32
  display: flex;
33
  flex-direction: column;
34
  overflow: auto;
35
`
36
 
37
const ContactItem = styled.div`
38
  align-items: center;
39
  display: flex;
40
  height: auto;
41
  padding: 0.5rem 1rem;
42
  gap: 0.5rem;
43
  cursor: pointer;
44
  border-radius: var(--border-radius);
45
 
46
  ${(props) =>
47
    props.current &&
48
    css`
49
      background-color: #42b72a21;
50
    `}
51
`
52
 
53
const ContactInfo = styled.div`
54
  display: flex;
55
  flex-direction: column;
56
 
57
  span {
58
    font-size: 0.9rem;
59
    font-weight: bold;
60
    white-space: nowrap;
61
    overflow: hidden;
62
    text-overflow: ellipsis;
63
    max-width: 20ch;
64
  }
65
`
66
 
67
const Contacts = ({ children }) => {
68
  return <ContactsContainer>{children}</ContactsContainer>
69
}
70
 
71
const Header = ({ options = [], children }) => {
72
  return (
73
    <ContactHeader>
74
      {children}
75
      {!!options.length && <Options options={options} />}
76
    </ContactHeader>
77
  )
78
}
79
 
80
const List = ({
81
  contacts = [],
82
  onChange = () => null,
83
  currentConversation,
84
}) => {
85
  const labels = useSelector(({ intl }) => intl.labels)
86
 
87
  return (
88
    <ContactList>
89
      {!contacts.length ? (
90
        <EmptySection message={labels.datatable_szerorecords} />
91
      ) : (
92
        contacts.map((contact) => {
93
          return (
94
            <li key={contact.id || contact.uuid}>
95
              <List.Item contact={contact} onClick={onChange} />
96
            </li>
97
          )
98
        })
99
      )}
100
    </ContactList>
101
  )
102
}
103
 
104
const Item = ({ contact, onClick, isCurrent }) => {
105
  const labels = useSelector(({ intl }) => intl.labels)
106
 
107
  return (
108
    <ContactItem onClick={() => onClick(contact)} current={isCurrent}>
109
      <Avatar
110
        src={contact.image || '/images/users-group.png'}
111
        alt="image-image"
112
        sx={{ width: 32, height: 32 }}
113
      />
114
      <ContactInfo>
115
        <span>{contact.name}</span>
116
        {contact.last_message && (
117
          <p>
118
            {`${
119
              contact.count_not_seen_messages || contact.count_unread || ''
120
            } ${labels.new_messages} |
121
              ${contact.last_message}`}
122
          </p>
123
        )}
124
      </ContactInfo>
125
    </ContactItem>
126
  )
127
}
128
 
129
List.Item = Item
130
Contacts.List = List
131
Contacts.Header = Header
132
 
133
export default Contacts