2018-10-30 05:02:23 +00:00
|
|
|
/* @flow */
|
|
|
|
|
2018-02-13 19:46:47 +00:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
|
|
|
import { translate } from '../../../base/i18n';
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
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<string> } | Array<string>,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoked to obtain translated strings.
|
|
|
|
*/
|
|
|
|
t: Function
|
|
|
|
}
|
|
|
|
|
2018-02-13 19:46:47 +00:00
|
|
|
/**
|
|
|
|
* Displays a table with phone numbers to dial in to a conference.
|
|
|
|
*
|
|
|
|
* @extends Component
|
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
class NumbersList extends Component<Props> {
|
2018-02-13 19:46:47 +00:00
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
const { numbers, t } = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<table className = 'dial-in-numbers-list'>
|
|
|
|
<thead>
|
|
|
|
<tr>
|
2018-10-30 05:02:23 +00:00
|
|
|
{ Array.isArray(numbers)
|
2018-02-13 19:46:47 +00:00
|
|
|
? null
|
|
|
|
: <th>{ t('info.country') }</th> }
|
|
|
|
<th>{ t('info.numbers') }</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
2018-02-21 01:25:22 +00:00
|
|
|
<tbody className = 'dial-in-numbers-body'>
|
2018-10-30 05:02:23 +00:00
|
|
|
{ Array.isArray(numbers)
|
2018-02-13 19:46:47 +00:00
|
|
|
? numbers.map(this._renderNumberRow)
|
2018-10-30 05:02:23 +00:00
|
|
|
: this._renderWithCountries(numbers) }
|
2018-02-13 19:46:47 +00:00
|
|
|
</tbody>
|
|
|
|
</table>);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders rows of countries and associated phone numbers.
|
|
|
|
*
|
2019-01-01 21:46:28 +00:00
|
|
|
* @param {Object} numbersMapping - An object with country names as keys
|
|
|
|
* and values as arrays of phone numbers.
|
2018-02-13 19:46:47 +00:00
|
|
|
* @private
|
|
|
|
* @returns {ReactElement[]}
|
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
_renderWithCountries(numbersMapping: Object) {
|
2018-02-13 19:46:47 +00:00
|
|
|
const rows = [];
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
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;
|
|
|
|
});
|
2018-02-13 19:46:47 +00:00
|
|
|
|
|
|
|
rows.push(
|
|
|
|
<tr key = { country }>
|
|
|
|
<td>{ country }</td>
|
|
|
|
<td className = 'dial-in-numbers'>{ formattedNumbers }</td>
|
|
|
|
</tr>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rows;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders a table row for a phone number.
|
|
|
|
*
|
|
|
|
* @param {string} number - The phone number to display.
|
|
|
|
* @private
|
|
|
|
* @returns {ReactElement[]}
|
|
|
|
*/
|
|
|
|
_renderNumberRow(number) {
|
|
|
|
return (
|
|
|
|
<tr key = { number }>
|
|
|
|
<td className = 'dial-in-number'>
|
2018-02-21 01:25:22 +00:00
|
|
|
{ this._renderNumberLink(number) }
|
2018-02-13 19:46:47 +00:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders a div container for a phone number.
|
|
|
|
*
|
|
|
|
* @param {string} number - The phone number to display.
|
|
|
|
* @private
|
|
|
|
* @returns {ReactElement[]}
|
|
|
|
*/
|
|
|
|
_renderNumberDiv(number) {
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className = 'dial-in-number'
|
|
|
|
key = { number }>
|
2018-02-21 01:25:22 +00:00
|
|
|
{ this._renderNumberLink(number) }
|
2018-02-13 19:46:47 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2018-02-21 01:25:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 (
|
|
|
|
<a
|
2018-04-14 00:00:40 +00:00
|
|
|
href = { `tel:${number}p${this.props.conferenceID}#` }
|
2018-02-21 01:25:22 +00:00
|
|
|
key = { number } >
|
|
|
|
{ number }
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return number;
|
|
|
|
}
|
|
|
|
|
2018-02-13 19:46:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(NumbersList);
|