# All files / components/ConversationListBox index.js

87.5% Statements 7/8
100% Branches 2/2
50% Functions 1/2
87.5% Lines 7/8

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152

    1x

    1x

    2x

    2x

    1x

    1x

    1x

     import React from 'react';
    import PropTypes from 'prop-types';
    import styled from 'styled-components';

    import Header from '../Header';
    import ConversationList from '../ConversationList/Loadable';
    import Button from '../Button';

    const ConversationListBoxContainer = styled.div`
      border-radius: 10px 10px 0px 0px;
      box-shadow: ${(props) => props.theme.shadows['2p']};
      height: 100%;
      width: 100%;
      margin: 0;
      max-width: none;
      padding-bottom: 10px;
    `;

    const ConversationListBox = (props) => {
      const {
        conversations,
        title,
        subtitle,
        person,
        className,
        toggleChat,
        newConversationHandler,
        clickConversationHandler,
        openMenu,
        showMinimizeButton,
        showMenuButton,
        showAddConversationButton,
        noMoreDataText,
        emptyStateText,
        newConversationText,
      } = props;

      return (
        <ConversationListBoxContainer className={className}>
          <Header
            title={title}
            subtitle={subtitle}
            person={person}
            toggleChat={toggleChat}
            openMenu={openMenu}
            showMinimizeButton={showMinimizeButton}
            showMenuButton={showMenuButton}
          />
          <ConversationList
            conversations={conversations}
            clickItem={clickConversationHandler}
            noMoreDataText={noMoreDataText}
            emptyStateText={emptyStateText}
          />
          {showAddConversationButton &&
            <Button
              type="submit"
              clickHandler={newConversationHandler}
              value={newConversationText}
            />
          }
        </ConversationListBoxContainer>
      );
    };

    ConversationListBox.propTypes = {
      /**
       * conversations: Conversation list to be displayed
       */
      conversations: PropTypes.array.isRequired,
      /**
       * title: Title to show on the header
       */
      title: PropTypes.string,
      /**
       * subtitle: Title to show on the header
       */
      subtitle: PropTypes.string,
      /**
       * persona: Avatar image to display on the header of the component
       */
      person: PropTypes.object,
      /**
       * toggleChat: Callback function called when user clicks on the toggle button
       */
      toggleChat: PropTypes.func,
      /**
       * openMenu: Callback function called when user clicks on open menu button
       */
      openMenu: PropTypes.func,
      /**
       * clickConversationHandler: Callback function called when user clicks on a conversation item
       * This callback recieves the conversation object, the index, and the pure dom event
       * So it should be of the form callback = (conversation, index, e) =>
       */
      clickConversationHandler: PropTypes.func,
      /**
       * clickConversationHandler: Callback function called when user clicks on a new conversation button
       * This only applies when showAddConversationButton is true
       */
      newConversationHandler: PropTypes.func,
      /**
       * showMinimizeButton: Boolean indicates wheter or not to display the minimize button on the header
       */
      showMinimizeButton: PropTypes.bool,
      /**
       * showMenuButton: Boolean indicates wheter or not to display the menu button on the header
       */
      showMenuButton: PropTypes.bool,
      /**
       * showMenuButton: Boolean indicates wheter or not to display the add conversation button
       */
      showAddConversationButton: PropTypes.bool,
      /**
       * noMoreDataText: Text to be displayed when there is no more conversation items (at the end of the conversation list)
       */
      noMoreDataText: PropTypes.string,
      /**
       * newConversationText: Text to be displayed inside the Add Conversation Button
       */
      newConversationText: PropTypes.string,
      /**
       * emptyStateText: Text to be displayed when there are no conversations to display
       */
      emptyStateText: PropTypes.string,
      /**
       * className: Extra className to provide to the component in order to style it when used in different contexts.
       */
      className: PropTypes.string,
    };

    ConversationListBox.defaultProps = {
      title: '',
      subtitle: '',
      person: {},
      toggleChat: null,
      openMenu: null,
      clickConversationHandler: null,
      newConversationHandler: null,
      showMinimizeButton: false,
      showMenuButton: false,
      showAddConversationButton: true,
      noMoreDataText: '',
      newConversationText: '',
      emptyStateText: '',
      className: 'LT-ConversationListBox-Container',
    };

    ConversationListBox.displayName = 'ConversationListBox';

    export default ConversationListBox;