-
Notifications
You must be signed in to change notification settings - Fork 122
Expand file tree
/
Copy pathindex.js
More file actions
140 lines (124 loc) · 3.71 KB
/
Copy pathindex.js
File metadata and controls
140 lines (124 loc) · 3.71 KB
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
import React from 'react';
import PropTypes from 'prop-types';
import isEmail from 'validator/lib/isEmail';
import classNames from 'classnames';
import PeopleList from '@webex/react-component-people-list';
import {Button, Icon, Input, Spinner} from '@momentum-ui/react';
import { FormattedMessage } from 'react-intl';
import messages from '../../messages';
import styles from './styles.css';
const propTypes = {
noResultsMessage: PropTypes.string.isRequired,
onAddPerson: PropTypes.func.isRequired,
onChange: PropTypes.func.isRequired,
onDismiss: PropTypes.func.isRequired,
placeholder: PropTypes.string.isRequired,
searchResults: PropTypes.shape({
inProgress: PropTypes.bool,
date: PropTypes.number,
results: PropTypes.array
}),
searchTerm: PropTypes.string
};
const defaultProps = {
searchResults: undefined,
searchTerm: ''
};
function AddParticipant({
noResultsMessage,
onChange,
onDismiss,
onAddPerson,
placeholder,
searchResults,
searchTerm
}) {
const baseClassPrefix = 'webex-roster-add-participant';
function handleChange(e) {
onChange(e.target.value);
}
function handleClose() {
onChange('');
onDismiss();
}
function handleClick(person) {
onAddPerson(person);
}
function handleInvite() {
onAddPerson(searchTerm);
}
function handleKeyPressInvite(e) {
if (e.key === 'Enter' || e.key === ' ') {
onAddPerson(searchTerm);
}
}
let results;
if (searchResults) {
if (searchResults.inProgress) {
results = (
<div className={classNames(`${baseClassPrefix}-results-loading`, styles.resultsLoading)}>
<Spinner />
</div>
);
}
else if (searchResults.results && searchResults.results.length) {
results = (
<div className={classNames(`${baseClassPrefix}-results`, styles.results, styles.fullHeight)}>
<PeopleList
items={[{people: searchResults.results}]}
onItemClick={handleClick}
/>
</div>
);
}
else if (searchResults.results && searchResults.results.length === 0 && isEmail(searchTerm)) {
results = (
<div
className={classNames(`${baseClassPrefix}-results-invite`, styles.resultsInvite)}
onClick={handleInvite}
onKeyPress={handleKeyPressInvite}
role="button"
tabIndex="0"
>
<div className={classNames(`${baseClassPrefix}-results-invite-icon`, styles.resultsInviteIcon)}><Icon name="icon-email-invite_24" /></div>
<FormattedMessage {...messages.inviteParticipantMessage} values={{ value: searchTerm }} />
</div>
);
}
else if (searchTerm) {
results = (
<div className={classNames(`${baseClassPrefix}-results-none`, styles.resultsNone)}>
<div>{noResultsMessage}</div>
</div>
);
}
}
return (
<div className={classNames(`${baseClassPrefix}`, styles.addPartipicant)}>
<div className={classNames(styles.searchBar)}>
<div className={classNames(`${baseClassPrefix}-close-button-container`, styles.closeButton)}>
<Button
ariaLabel="Close Search"
circle
onClick={handleClose}
size={28}
>
<Icon name="icon-arrow-left_12" />
</Button>
</div>
<Input
name="addParticipantSearchInput"
htmlId="addParticipantSearchInput"
onChange={handleChange}
placeholder={placeholder}
className={classNames(styles.searchInput, 'md-input--filled')}
value={searchTerm}
/>
</div>
{results}
</div>
);
}
AddParticipant.propTypes = propTypes;
AddParticipant.defaultProps = defaultProps;
export default AddParticipant;