You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

InviteButton.native.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. // @flow
  2. import { connect } from 'react-redux';
  3. import type { Dispatch } from 'redux';
  4. import { translate } from '../../base/i18n';
  5. import { AbstractButton } from '../../base/toolbox';
  6. import type { AbstractButtonProps } from '../../base/toolbox';
  7. import { beginShareRoom } from '../../share-room';
  8. import { beginAddPeople } from '../actions';
  9. import { isAddPeopleEnabled, isDialOutEnabled } from '../functions';
  10. type Props = AbstractButtonProps & {
  11. /**
  12. * Whether or not the feature to directly invite people into the
  13. * conference is available.
  14. */
  15. _addPeopleEnabled: boolean,
  16. /**
  17. * Whether or not the feature to dial out to number to join the
  18. * conference is available.
  19. */
  20. _dialOutEnabled: boolean,
  21. /**
  22. * Launches native invite dialog.
  23. *
  24. * @protected
  25. */
  26. _onAddPeople: Function,
  27. /**
  28. * Begins the UI procedure to share the conference/room URL.
  29. */
  30. _onShareRoom: Function
  31. };
  32. /**
  33. * The indicator which determines (at bundle time) whether there should be a
  34. * button in {@code Toolbox} to expose the functionality of the feature
  35. * share-room in the user interface of the app.
  36. *
  37. * @private
  38. * @type {boolean}
  39. */
  40. const _SHARE_ROOM_TOOLBAR_BUTTON = true;
  41. /**
  42. * Implements an {@link AbstractButton} to enter add/invite people to the
  43. * current call/conference/meeting.
  44. */
  45. class InviteButton extends AbstractButton<Props, *> {
  46. accessibilityLabel = 'toolbar.accessibilityLabel.shareRoom';
  47. iconName = 'icon-link';
  48. label = 'toolbar.shareRoom';
  49. /**
  50. * Handles clicking / pressing the button, and opens the appropriate dialog.
  51. *
  52. * @private
  53. * @returns {void}
  54. */
  55. _handleClick() {
  56. const {
  57. _addPeopleEnabled,
  58. _dialOutEnabled,
  59. _onAddPeople,
  60. _onShareRoom
  61. } = this.props;
  62. if (_addPeopleEnabled || _dialOutEnabled) {
  63. _onAddPeople();
  64. } else if (_SHARE_ROOM_TOOLBAR_BUTTON) {
  65. _onShareRoom();
  66. }
  67. }
  68. /**
  69. * Implements React's {@link Component#render()}.
  70. *
  71. * @inheritdoc
  72. * @returns {React$Node}
  73. */
  74. render() {
  75. const { _addPeopleEnabled, _dialOutEnabled } = this.props;
  76. return (
  77. _SHARE_ROOM_TOOLBAR_BUTTON
  78. || _addPeopleEnabled
  79. || _dialOutEnabled
  80. ? super.render()
  81. : null);
  82. }
  83. }
  84. /**
  85. * Maps redux actions to {@link InviteButton}'s React
  86. * {@code Component} props.
  87. *
  88. * @param {Function} dispatch - The redux action {@code dispatch} function.
  89. * @returns {{
  90. * _onAddPeople,
  91. * _onShareRoom
  92. * }}
  93. * @private
  94. */
  95. function _mapDispatchToProps(dispatch: Dispatch<*>) {
  96. return {
  97. /**
  98. * Launches native invite dialog.
  99. *
  100. * @private
  101. * @returns {void}
  102. * @type {Function}
  103. */
  104. _onAddPeople() {
  105. dispatch(beginAddPeople());
  106. },
  107. /**
  108. * Begins the UI procedure to share the conference/room URL.
  109. *
  110. * @private
  111. * @returns {void}
  112. * @type {Function}
  113. */
  114. _onShareRoom() {
  115. dispatch(beginShareRoom());
  116. }
  117. };
  118. }
  119. /**
  120. * Maps (parts of) the redux state to {@link Toolbox}'s React {@code Component}
  121. * props.
  122. *
  123. * @param {Object} state - The redux store/state.
  124. * @private
  125. * @returns {{
  126. * }}
  127. */
  128. function _mapStateToProps(state) {
  129. return {
  130. /**
  131. * Whether or not the feature to directly invite people into the
  132. * conference is available.
  133. *
  134. * @type {boolean}
  135. */
  136. _addPeopleEnabled: isAddPeopleEnabled(state),
  137. /**
  138. * Whether or not the feature to dial out to number to join the
  139. * conference is available.
  140. *
  141. * @type {boolean}
  142. */
  143. _dialOutEnabled: isDialOutEnabled(state)
  144. };
  145. }
  146. export default translate(
  147. connect(_mapStateToProps, _mapDispatchToProps)(InviteButton));