您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

AddPeopleDialog.web.js 9.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. import React, { Component } from 'react';
  2. import { Immutable } from 'nuclear-js';
  3. import { connect } from 'react-redux';
  4. import Avatar from '@atlaskit/avatar';
  5. import InlineMessage from '@atlaskit/inline-message';
  6. import { getInviteURL } from '../../base/connection';
  7. import { Dialog, hideDialog } from '../../base/dialog';
  8. import { translate } from '../../base/i18n';
  9. import MultiSelectAutocomplete
  10. from '../../base/react/components/web/MultiSelectAutocomplete';
  11. import { invitePeople, inviteRooms, searchPeople } from '../functions';
  12. declare var interfaceConfig: Object;
  13. const { PropTypes } = React;
  14. /**
  15. * The dialog that allows to invite people to the call.
  16. */
  17. class AddPeopleDialog extends Component {
  18. /**
  19. * {@code AddPeopleDialog}'s property types.
  20. *
  21. * @static
  22. */
  23. static propTypes = {
  24. /**
  25. * The {@link JitsiMeetConference} which will be used to invite "room"
  26. * participants through the SIP Jibri (Video SIP gateway).
  27. */
  28. _conference: PropTypes.object,
  29. /**
  30. * The URL pointing to the service allowing for people invite.
  31. */
  32. _inviteServiceUrl: PropTypes.string,
  33. /**
  34. * The url of the conference to invite people to.
  35. */
  36. _inviteUrl: PropTypes.string,
  37. /**
  38. * The JWT token.
  39. */
  40. _jwt: PropTypes.string,
  41. /**
  42. * The query types used when searching people.
  43. */
  44. _peopleSearchQueryTypes: PropTypes.arrayOf(PropTypes.string),
  45. /**
  46. * The URL pointing to the service allowing for people search.
  47. */
  48. _peopleSearchUrl: PropTypes.string,
  49. /**
  50. * The function closing the dialog.
  51. */
  52. hideDialog: PropTypes.func,
  53. /**
  54. * Invoked to obtain translated strings.
  55. */
  56. t: PropTypes.func
  57. };
  58. /**
  59. * Initializes a new {@code AddPeopleDialog} instance.
  60. *
  61. * @param {Object} props - The read-only properties with which the new
  62. * instance is to be initialized.
  63. */
  64. constructor(props) {
  65. super(props);
  66. this.state = {
  67. /**
  68. * Indicating that an error occurred when adding people to the call.
  69. */
  70. addToCallError: false,
  71. /**
  72. * Indicating that we're currently adding the new people to the
  73. * call.
  74. */
  75. addToCallInProgress: false,
  76. /**
  77. * The list of invite items.
  78. */
  79. inviteItems: new Immutable.List()
  80. };
  81. this._multiselect = null;
  82. this._resourceClient = {
  83. makeQuery: text => {
  84. const {
  85. _jwt,
  86. _peopleSearchQueryTypes,
  87. _peopleSearchUrl
  88. } = this.props;
  89. return searchPeople(
  90. _peopleSearchUrl,
  91. _jwt,
  92. text,
  93. _peopleSearchQueryTypes
  94. );
  95. },
  96. parseResults: response => response.map(user => {
  97. const avatar = ( // eslint-disable-line no-extra-parens
  98. <Avatar
  99. size = 'medium'
  100. src = { user.avatar } />
  101. );
  102. return {
  103. content: user.name,
  104. value: user.id,
  105. elemBefore: avatar,
  106. item: user
  107. };
  108. })
  109. };
  110. this._isAddDisabled = this._isAddDisabled.bind(this);
  111. this._onSelectionChange = this._onSelectionChange.bind(this);
  112. this._onSubmit = this._onSubmit.bind(this);
  113. this._setMultiSelectElement = this._setMultiSelectElement.bind(this);
  114. }
  115. /**
  116. * React Component method that executes once component is updated.
  117. *
  118. * @param {Object} prevState - The state object before the update.
  119. * @returns {void}
  120. */
  121. componentDidUpdate(prevState) {
  122. /**
  123. * Clears selected items from the multi select component on successful
  124. * invite.
  125. */
  126. if (prevState.addToCallError
  127. && !this.state.addToCallInProgress
  128. && !this.state.addToCallError
  129. && this._multiselect) {
  130. this._multiselect.clear();
  131. }
  132. }
  133. /**
  134. * Renders the content of this component.
  135. *
  136. * @returns {ReactElement}
  137. */
  138. render() {
  139. return (
  140. <Dialog
  141. okDisabled = { this._isAddDisabled() }
  142. okTitleKey = 'addPeople.add'
  143. onSubmit = { this._onSubmit }
  144. titleKey = 'addPeople.title'
  145. width = 'small'>
  146. { this._renderUserInputForm() }
  147. </Dialog>
  148. );
  149. }
  150. /**
  151. * Renders the input form.
  152. *
  153. * @returns {ReactElement}
  154. * @private
  155. */
  156. _renderUserInputForm() {
  157. const { t } = this.props;
  158. return (
  159. <div className = 'add-people-form-wrap'>
  160. { this._renderErrorMessage() }
  161. <MultiSelectAutocomplete
  162. isDisabled
  163. = { this.state.addToCallInProgress || false }
  164. noMatchesFound = { t('addPeople.noResults') }
  165. onSelectionChange = { this._onSelectionChange }
  166. placeholder = { t('addPeople.searchPlaceholder') }
  167. ref = { this._setMultiSelectElement }
  168. resourceClient = { this._resourceClient }
  169. shouldFitContainer = { true }
  170. shouldFocus = { true } />
  171. </div>
  172. );
  173. }
  174. /**
  175. * Indicates if the Add button should be disabled.
  176. *
  177. * @returns {boolean} - True to indicate that the Add button should
  178. * be disabled, false otherwise.
  179. * @private
  180. */
  181. _isAddDisabled() {
  182. return !this.state.inviteItems.length
  183. || this.state.addToCallInProgress;
  184. }
  185. /**
  186. * Handles a selection change.
  187. *
  188. * @param {Map} selectedItems - The list of selected items.
  189. * @private
  190. * @returns {void}
  191. */
  192. _onSelectionChange(selectedItems) {
  193. const selectedIds = selectedItems.map(o => o.item);
  194. this.setState({
  195. inviteItems: selectedIds
  196. });
  197. }
  198. /**
  199. * Handles the submit button action.
  200. *
  201. * @private
  202. * @returns {void}
  203. */
  204. _onSubmit() {
  205. if (!this._isAddDisabled()) {
  206. this.setState({
  207. addToCallInProgress: true
  208. });
  209. this.props._conference
  210. && inviteRooms(
  211. this.props._conference,
  212. this.state.inviteItems.filter(
  213. i => i.type === 'videosipgw'));
  214. invitePeople(
  215. this.props._inviteServiceUrl,
  216. this.props._inviteUrl,
  217. this.props._jwt,
  218. this.state.inviteItems.filter(i => i.type === 'user'))
  219. .then(() => {
  220. this.setState({
  221. addToCallInProgress: false
  222. });
  223. this.props.hideDialog();
  224. })
  225. .catch(() => {
  226. this.setState({
  227. addToCallInProgress: false,
  228. addToCallError: true
  229. });
  230. });
  231. }
  232. }
  233. /**
  234. * Renders the error message if the add doesn't succeed.
  235. *
  236. * @returns {ReactElement|null}
  237. * @private
  238. */
  239. _renderErrorMessage() {
  240. if (!this.state.addToCallError) {
  241. return null;
  242. }
  243. const { t } = this.props;
  244. const supportString = t('inlineDialogFailure.supportMsg');
  245. const supportLink = interfaceConfig.SUPPORT_URL;
  246. const supportLinkContent
  247. = ( // eslint-disable-line no-extra-parens
  248. <span>
  249. <span>
  250. { supportString.padEnd(supportString.length + 1) }
  251. </span>
  252. <span>
  253. <a
  254. href = { supportLink }
  255. rel = 'noopener noreferrer'
  256. target = '_blank'>
  257. { t('inlineDialogFailure.support') }
  258. </a>
  259. </span>
  260. <span>.</span>
  261. </span>
  262. );
  263. return (
  264. <div className = 'modal-dialog-form-error'>
  265. <InlineMessage
  266. title = { t('addPeople.failedToAdd') }
  267. type = 'error'>
  268. { supportLinkContent }
  269. </InlineMessage>
  270. </div>
  271. );
  272. }
  273. /**
  274. * Sets the instance variable for the multi select component
  275. * element so it can be accessed directly.
  276. *
  277. * @param {Object} element - The DOM element for the component's dialog.
  278. * @private
  279. * @returns {void}
  280. */
  281. _setMultiSelectElement(element) {
  282. this._multiselect = element;
  283. }
  284. }
  285. /**
  286. * Maps (parts of) the Redux state to the associated
  287. * {@code AddPeopleDialog}'s props.
  288. *
  289. * @param {Object} state - The Redux state.
  290. * @private
  291. * @returns {{
  292. * _peopleSearchUrl: React.PropTypes.string,
  293. * _jwt: React.PropTypes.string
  294. * }}
  295. */
  296. function _mapStateToProps(state) {
  297. const { conference } = state['features/base/conference'];
  298. const {
  299. inviteServiceUrl,
  300. peopleSearchQueryTypes,
  301. peopleSearchUrl
  302. } = state['features/base/config'];
  303. return {
  304. _conference: conference,
  305. _jwt: state['features/jwt'].jwt,
  306. _inviteUrl: getInviteURL(state),
  307. _inviteServiceUrl: inviteServiceUrl,
  308. _peopleSearchQueryTypes: peopleSearchQueryTypes,
  309. _peopleSearchUrl: peopleSearchUrl
  310. };
  311. }
  312. export default translate(
  313. connect(_mapStateToProps, { hideDialog })(AddPeopleDialog));