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.

NumbersList.web.js 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. import PropTypes from 'prop-types';
  2. import React, { Component } from 'react';
  3. import { translate } from '../../../base/i18n';
  4. /**
  5. * Displays a table with phone numbers to dial in to a conference.
  6. *
  7. * @extends Component
  8. */
  9. class NumbersList extends Component {
  10. /**
  11. * {@code NumbersList} component's property types.
  12. *
  13. * @static
  14. */
  15. static propTypes = {
  16. /**
  17. * Whether or not numbers should include links with the telephone
  18. * protocol.
  19. */
  20. clickableNumbers: PropTypes.bool,
  21. /**
  22. * The conference ID for dialing in.
  23. */
  24. conferenceID: PropTypes.number,
  25. /**
  26. * The phone numbers to display. Can be an array of numbers
  27. * or an object with countries as keys and an array of numbers
  28. * as values.
  29. */
  30. numbers: PropTypes.oneOfType([
  31. PropTypes.array,
  32. PropTypes.object
  33. ]),
  34. /**
  35. * Invoked to obtain translated strings.
  36. */
  37. t: PropTypes.func
  38. };
  39. /**
  40. * Implements React's {@link Component#render()}.
  41. *
  42. * @inheritdoc
  43. * @returns {ReactElement}
  44. */
  45. render() {
  46. const { numbers, t } = this.props;
  47. const showWithoutCountries = Array.isArray(numbers);
  48. return (
  49. <table className = 'dial-in-numbers-list'>
  50. <thead>
  51. <tr>
  52. { showWithoutCountries
  53. ? null
  54. : <th>{ t('info.country') }</th> }
  55. <th>{ t('info.numbers') }</th>
  56. </tr>
  57. </thead>
  58. <tbody className = 'dial-in-numbers-body'>
  59. { showWithoutCountries
  60. ? numbers.map(this._renderNumberRow)
  61. : this._renderWithCountries() }
  62. </tbody>
  63. </table>);
  64. }
  65. /**
  66. * Renders rows of countries and associated phone numbers.
  67. *
  68. * @private
  69. * @returns {ReactElement[]}
  70. */
  71. _renderWithCountries() {
  72. const rows = [];
  73. for (const [ country, numbers ] of Object.entries(this.props.numbers)) {
  74. const formattedNumbers = numbers.map(
  75. number => this._renderNumberDiv(number));
  76. rows.push(
  77. <tr key = { country }>
  78. <td>{ country }</td>
  79. <td className = 'dial-in-numbers'>{ formattedNumbers }</td>
  80. </tr>
  81. );
  82. }
  83. return rows;
  84. }
  85. /**
  86. * Renders a table row for a phone number.
  87. *
  88. * @param {string} number - The phone number to display.
  89. * @private
  90. * @returns {ReactElement[]}
  91. */
  92. _renderNumberRow(number) {
  93. return (
  94. <tr key = { number }>
  95. <td className = 'dial-in-number'>
  96. { this._renderNumberLink(number) }
  97. </td>
  98. </tr>
  99. );
  100. }
  101. /**
  102. * Renders a div container for a phone number.
  103. *
  104. * @param {string} number - The phone number to display.
  105. * @private
  106. * @returns {ReactElement[]}
  107. */
  108. _renderNumberDiv(number) {
  109. return (
  110. <div
  111. className = 'dial-in-number'
  112. key = { number }>
  113. { this._renderNumberLink(number) }
  114. </div>
  115. );
  116. }
  117. /**
  118. * Renders a ReactElement for displaying a telephone number. If the
  119. * component prop {@code clickableNumbers} is true, then the number will
  120. * have a link with the telephone protocol.
  121. *
  122. * @param {string} number - The phone number to display.
  123. * @private
  124. * @returns {ReactElement}
  125. */
  126. _renderNumberLink(number) {
  127. if (this.props.clickableNumbers) {
  128. return (
  129. <a
  130. href = { `tel:${number}p${this.props.conferenceID}#` }
  131. key = { number } >
  132. { number }
  133. </a>
  134. );
  135. }
  136. return number;
  137. }
  138. }
  139. export default translate(NumbersList);