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.

DialInNumber.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { translate } from '../../../../base/i18n';
  4. import { Icon, IconCopy } from '../../../../base/icons';
  5. import { copyText } from '../../../../base/util';
  6. import { _formatConferenceIDPin } from '../../../_utils';
  7. /**
  8. * The type of the React {@code Component} props of {@link DialInNumber}.
  9. */
  10. type Props = {
  11. /**
  12. * The numeric identifier for the current conference, used after dialing a
  13. * the number to join the conference.
  14. */
  15. conferenceID: number,
  16. /**
  17. * The phone number to dial to begin the process of dialing into a
  18. * conference.
  19. */
  20. phoneNumber: string,
  21. /**
  22. * Invoked to obtain translated strings.
  23. */
  24. t: Function
  25. };
  26. /**
  27. * React {@code Component} responsible for displaying a telephone number and
  28. * conference ID for dialing into a conference.
  29. *
  30. * @extends Component
  31. */
  32. class DialInNumber extends Component<Props> {
  33. /**
  34. * Initializes a new DialInNumber instance.
  35. *
  36. * @param {Object} props - The read-only properties with which the new
  37. * instance is to be initialized.
  38. */
  39. constructor(props) {
  40. super(props);
  41. // Bind event handler so it is only bound once for every instance.
  42. this._onCopyText = this._onCopyText.bind(this);
  43. this._onCopyTextKeyPress = this._onCopyTextKeyPress.bind(this);
  44. }
  45. _onCopyText: () => void;
  46. /**
  47. * Copies the dial-in information to the clipboard.
  48. *
  49. * @returns {void}
  50. */
  51. _onCopyText() {
  52. const { conferenceID, phoneNumber, t } = this.props;
  53. const dialInLabel = t('info.dialInNumber');
  54. const passcode = t('info.dialInConferenceID');
  55. const conferenceIDPin = `${_formatConferenceIDPin(conferenceID)}#`;
  56. const textToCopy = `${dialInLabel} ${phoneNumber} ${passcode} ${conferenceIDPin}`;
  57. copyText(textToCopy);
  58. }
  59. _onCopyTextKeyPress: (Object) => void;
  60. /**
  61. * KeyPress handler for accessibility.
  62. *
  63. * @param {Object} e - The key event to handle.
  64. *
  65. * @returns {void}
  66. */
  67. _onCopyTextKeyPress(e) {
  68. if (e.key === ' ' || e.key === 'Enter') {
  69. e.preventDefault();
  70. this._onCopyText();
  71. }
  72. }
  73. /**
  74. * Implements React's {@link Component#render()}.
  75. *
  76. * @inheritdoc
  77. * @returns {ReactElement}
  78. */
  79. render() {
  80. const { conferenceID, phoneNumber, t } = this.props;
  81. return (
  82. <div className = 'dial-in-number'>
  83. <div>
  84. <span className = 'phone-number'>
  85. <span className = 'info-label'>
  86. { t('info.dialInNumber') }
  87. </span>
  88. <span className = 'spacer'>&nbsp;</span>
  89. <span className = 'info-value'>
  90. { phoneNumber }
  91. </span>
  92. </span>
  93. <span className = 'spacer'>&nbsp;</span>
  94. <span className = 'conference-id'>
  95. <span className = 'info-label'>
  96. { t('info.dialInConferenceID') }
  97. </span>
  98. <span className = 'spacer'>&nbsp;</span>
  99. <span className = 'info-value'>
  100. { `${_formatConferenceIDPin(conferenceID)}#` }
  101. </span>
  102. </span>
  103. </div>
  104. <a
  105. aria-label = { t('info.copyNumber') }
  106. className = 'dial-in-copy'
  107. onClick = { this._onCopyText }
  108. onKeyPress = { this._onCopyTextKeyPress }
  109. role = 'button'
  110. tabIndex = { 0 }>
  111. <Icon src = { IconCopy } />
  112. </a>
  113. </div>
  114. );
  115. }
  116. }
  117. export default translate(DialInNumber);