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 3.9KB

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