/* @flow */ import React, { Component } from 'react'; import { translate } from '../../../base/i18n'; type Props = { /** * Whether or not numbers should include links with the telephone protocol. */ clickableNumbers: boolean, /** * The conference ID for dialing in. */ conferenceID: number, /** * The phone numbers to display. Can be an array of numbers or an object * with countries as keys and an array of numbers as values. */ numbers: { [string]: Array } | Array, /** * Invoked to obtain translated strings. */ t: Function } /** * Displays a table with phone numbers to dial in to a conference. * * @extends Component */ class NumbersList extends Component { /** * Implements React's {@link Component#render()}. * * @inheritdoc * @returns {ReactElement} */ render() { const { numbers, t } = this.props; return ( { Array.isArray(numbers) ? null : } { Array.isArray(numbers) ? numbers.map(this._renderNumberRow) : this._renderWithCountries(numbers) }
{ t('info.country') }{ t('info.numbers') }
); } /** * Renders rows of countries and associated phone numbers. * * @param {Object} numbersMapping - An object with country names as keys * and values as arrays of phone numbers. * @private * @returns {ReactElement[]} */ _renderWithCountries(numbersMapping: Object) { const rows = []; for (const [ country, numbers ] of Object.entries(numbersMapping)) { if (!Array.isArray(numbers)) { return; } const formattedNumbers = numbers.map(number => { if (typeof number === 'string') { return this._renderNumberDiv(number); } return null; }); rows.push( { country } { formattedNumbers } ); } return rows; } /** * Renders a table row for a phone number. * * @param {string} number - The phone number to display. * @private * @returns {ReactElement[]} */ _renderNumberRow(number) { return ( { this._renderNumberLink(number) } ); } /** * Renders a div container for a phone number. * * @param {string} number - The phone number to display. * @private * @returns {ReactElement[]} */ _renderNumberDiv(number) { return (
{ this._renderNumberLink(number) }
); } /** * Renders a ReactElement for displaying a telephone number. If the * component prop {@code clickableNumbers} is true, then the number will * have a link with the telephone protocol. * * @param {string} number - The phone number to display. * @private * @returns {ReactElement} */ _renderNumberLink(number) { if (this.props.clickableNumbers) { return ( { number } ); } return number; } } export default translate(NumbersList);