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.

AddPeopleDialog.js 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. // @flow
  2. import React, { useState, useEffect } from 'react';
  3. import { createInviteDialogEvent, sendAnalytics } from '../../../../analytics';
  4. import { getRoomName } from '../../../../base/conference';
  5. import { getInviteURL } from '../../../../base/connection';
  6. import { Dialog } from '../../../../base/dialog';
  7. import { translate } from '../../../../base/i18n';
  8. import { JitsiRecordingConstants } from '../../../../base/lib-jitsi-meet';
  9. import { getLocalParticipant } from '../../../../base/participants';
  10. import { connect } from '../../../../base/redux';
  11. import { getActiveSession } from '../../../../recording';
  12. import { updateDialInNumbers } from '../../../actions';
  13. import { _getDefaultPhoneNumber, getInviteText, isAddPeopleEnabled, isDialOutEnabled } from '../../../functions';
  14. import CopyMeetingLinkSection from './CopyMeetingLinkSection';
  15. import DialInSection from './DialInSection';
  16. import Header from './Header';
  17. import InviteByEmailSection from './InviteByEmailSection';
  18. import InviteContactsSection from './InviteContactsSection';
  19. import LiveStreamSection from './LiveStreamSection';
  20. declare var interfaceConfig: Object;
  21. type Props = {
  22. /**
  23. * The name of the current conference. Used as part of inviting users.
  24. */
  25. _conferenceName: string,
  26. /**
  27. * The object representing the dialIn feature.
  28. */
  29. _dialIn: Object,
  30. /**
  31. * Whether or not invite contacts should be visible.
  32. */
  33. _inviteContactsVisible: boolean,
  34. /**
  35. * The current url of the conference to be copied onto the clipboard.
  36. */
  37. _inviteUrl: string,
  38. /**
  39. * The current known URL for a live stream in progress.
  40. */
  41. _liveStreamViewURL: string,
  42. /**
  43. * The redux representation of the local participant.
  44. */
  45. _localParticipantName: ?string,
  46. /**
  47. * The current location url of the conference.
  48. */
  49. _locationUrl: Object,
  50. /**
  51. * Invoked to obtain translated strings.
  52. */
  53. t: Function,
  54. /**
  55. * Method to update the dial in numbers.
  56. */
  57. updateNumbers: Function
  58. };
  59. /**
  60. * Invite More component.
  61. *
  62. * @returns {React$Element<any>}
  63. */
  64. function AddPeopleDialog({
  65. _conferenceName,
  66. _dialIn,
  67. _inviteContactsVisible,
  68. _inviteUrl,
  69. _liveStreamViewURL,
  70. _localParticipantName,
  71. _locationUrl,
  72. t,
  73. updateNumbers }: Props) {
  74. const [ phoneNumber, setPhoneNumber ] = useState(undefined);
  75. /**
  76. * Updates the dial-in numbers.
  77. */
  78. useEffect(() => {
  79. if (!_dialIn.numbers) {
  80. updateNumbers();
  81. }
  82. }, []);
  83. /**
  84. * Sends analytics events when the dialog opens/closes.
  85. *
  86. * @returns {void}
  87. */
  88. useEffect(() => {
  89. sendAnalytics(createInviteDialogEvent(
  90. 'invite.dialog.opened', 'dialog'));
  91. return () => {
  92. sendAnalytics(createInviteDialogEvent(
  93. 'invite.dialog.closed', 'dialog'));
  94. };
  95. }, []);
  96. /**
  97. * Updates the phone number in the state once the dial-in numbers are fetched.
  98. *
  99. * @returns {void}
  100. */
  101. useEffect(() => {
  102. if (!phoneNumber && _dialIn && _dialIn.numbers) {
  103. setPhoneNumber(_getDefaultPhoneNumber(_dialIn.numbers));
  104. }
  105. }, [ _dialIn ]);
  106. const invite = getInviteText({
  107. _conferenceName,
  108. _localParticipantName,
  109. _inviteUrl,
  110. _locationUrl,
  111. _dialIn,
  112. _liveStreamViewURL,
  113. phoneNumber,
  114. t
  115. });
  116. const inviteSubject = t('addPeople.inviteMoreMailSubject', {
  117. appName: interfaceConfig.APP_NAME
  118. });
  119. return (
  120. <Dialog
  121. cancelKey = { 'dialog.close' }
  122. customHeader = { Header }
  123. hideCancelButton = { true }
  124. submitDisabled = { true }
  125. titleKey = 'addPeople.inviteMorePrompt'
  126. width = { 'small' }>
  127. <div className = 'invite-more-dialog'>
  128. { _inviteContactsVisible && <InviteContactsSection /> }
  129. <CopyMeetingLinkSection url = { _inviteUrl } />
  130. <InviteByEmailSection
  131. inviteSubject = { inviteSubject }
  132. inviteText = { invite } />
  133. {
  134. _liveStreamViewURL
  135. && <LiveStreamSection liveStreamViewURL = { _liveStreamViewURL } />
  136. }
  137. {
  138. _dialIn.numbers
  139. && <DialInSection
  140. conferenceName = { _conferenceName }
  141. dialIn = { _dialIn }
  142. locationUrl = { _locationUrl }
  143. phoneNumber = { phoneNumber } />
  144. }
  145. </div>
  146. </Dialog>
  147. );
  148. }
  149. /**
  150. * Maps (parts of) the Redux state to the associated props for the
  151. * {@code AddPeopleDialog} component.
  152. *
  153. * @param {Object} state - The Redux state.
  154. * @private
  155. * @returns {Props}
  156. */
  157. function mapStateToProps(state) {
  158. const localParticipant = getLocalParticipant(state);
  159. const currentLiveStreamingSession
  160. = getActiveSession(state, JitsiRecordingConstants.mode.STREAM);
  161. const { iAmRecorder } = state['features/base/config'];
  162. const addPeopleEnabled = isAddPeopleEnabled(state);
  163. const dialOutEnabled = isDialOutEnabled(state);
  164. const hideInviteContacts = iAmRecorder || (!addPeopleEnabled && !dialOutEnabled);
  165. return {
  166. _conferenceName: getRoomName(state),
  167. _dialIn: state['features/invite'],
  168. _inviteContactsVisible: interfaceConfig.ENABLE_DIAL_OUT && !hideInviteContacts,
  169. _inviteUrl: getInviteURL(state),
  170. _liveStreamViewURL:
  171. currentLiveStreamingSession
  172. && currentLiveStreamingSession.liveStreamViewURL,
  173. _localParticipantName: localParticipant?.name,
  174. _locationUrl: state['features/base/connection'].locationURL
  175. };
  176. }
  177. /**
  178. * Maps dispatching of some action to React component props.
  179. *
  180. * @param {Function} dispatch - Redux action dispatcher.
  181. * @returns {Props}
  182. */
  183. const mapDispatchToProps = {
  184. updateNumbers: () => updateDialInNumbers()
  185. };
  186. export default translate(
  187. connect(mapStateToProps, mapDispatchToProps)(AddPeopleDialog)
  188. );