* feat(invite): be able to call numbers from the invite dialog The major changes: - Remove DialOutDialog, its views, redux hooks, css, and images. Its main functionality has been moved into AddPeopleDialog. - Modify the AppPeopleDialog styling a bit so it is wider. - Add phone numbers to AddPeopleDialog search results. Phone numbers are validated in parallel with the request for people and then appended to the result. The validation includes an ajax to validate the number is recognized as dialable by the server. The trigger for the validation is essentially if the entered input is numbers only. - AddPeopleDialog holds onto the full object representation of an item selected in MultiSelectAutocomplete. This is so selected items can be removed on successful invite, leaving only unsuccessful items. - More granular error handling on invite so individual invitees can be removed from the selected items list. * squash: change load state, new regex for numbers * squash: change strings, auto prepend 1 if no country code, add reminders
117 lines
3.6 KiB
JavaScript
117 lines
3.6 KiB
JavaScript
// @flow
|
|
|
|
declare var $: Function;
|
|
declare var interfaceConfig: Object;
|
|
|
|
/**
|
|
* Get the position of the invite option in the interfaceConfig.INVITE_OPTIONS
|
|
* list.
|
|
*
|
|
* @param {string} name - The invite option name.
|
|
* @private
|
|
* @returns {number} - The position of the option in the list.
|
|
*/
|
|
export function getInviteOptionPosition(name: string): number {
|
|
return interfaceConfig.INVITE_OPTIONS.indexOf(name);
|
|
}
|
|
|
|
/**
|
|
* Sends a post request to an invite service.
|
|
*
|
|
* @param {string} inviteServiceUrl - The invite service that generates the
|
|
* invitation.
|
|
* @param {string} inviteUrl - The url to the conference.
|
|
* @param {string} jwt - The jwt token to pass to the search service.
|
|
* @param {Immutable.List} inviteItems - The list of the "user" or "room"
|
|
* type items to invite.
|
|
* @returns {Promise} - The promise created by the request.
|
|
*/
|
|
export function invitePeopleAndChatRooms( // eslint-disable-line max-params
|
|
inviteServiceUrl: string,
|
|
inviteUrl: string,
|
|
jwt: string,
|
|
inviteItems: Object): Promise<void> {
|
|
if (!inviteItems || inviteItems.length === 0) {
|
|
return Promise.resolve();
|
|
}
|
|
|
|
return new Promise((resolve, reject) => {
|
|
$.post(
|
|
`${inviteServiceUrl}?token=${jwt}`,
|
|
JSON.stringify({
|
|
'invited': inviteItems,
|
|
'url': inviteUrl
|
|
}),
|
|
resolve,
|
|
'json')
|
|
.fail((jqxhr, textStatus, error) => reject(error));
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Indicates if an invite option is enabled in the configuration.
|
|
*
|
|
* @param {string} name - The name of the option defined in
|
|
* interfaceConfig.INVITE_OPTIONS.
|
|
* @returns {boolean} - True to indicate that the given invite option is
|
|
* enabled, false - otherwise.
|
|
*/
|
|
export function isInviteOptionEnabled(name: string) {
|
|
return getInviteOptionPosition(name) !== -1;
|
|
}
|
|
|
|
/**
|
|
* Sends an ajax request to a directory service.
|
|
*
|
|
* @param {string} serviceUrl - The service to query.
|
|
* @param {string} jwt - The jwt token to pass to the search service.
|
|
* @param {string} text - Text to search.
|
|
* @param {Array<string>} queryTypes - Array with the query types that will be
|
|
* executed - "conferenceRooms" | "user" | "room".
|
|
* @returns {Promise} - The promise created by the request.
|
|
*/
|
|
export function searchDirectory( // eslint-disable-line max-params
|
|
serviceUrl: string,
|
|
jwt: string,
|
|
text: string,
|
|
queryTypes: Array<string> = [ 'conferenceRooms', 'user', 'room' ]
|
|
): Promise<Array<Object>> {
|
|
const queryTypesString = JSON.stringify(queryTypes);
|
|
|
|
return new Promise((resolve, reject) => {
|
|
$.getJSON(
|
|
`${serviceUrl}?query=${encodeURIComponent(text)}&queryTypes=${
|
|
queryTypesString}&jwt=${jwt}`,
|
|
resolve)
|
|
.catch((jqxhr, textStatus, error) => reject(error));
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Sends an ajax request to check if the phone number can be called.
|
|
*
|
|
* @param {string} dialNumber - The dial number to check for validity.
|
|
* @param {string} dialOutAuthUrl - The endpoint to use for checking validity.
|
|
* @returns {Promise} - The promise created by the request.
|
|
*/
|
|
export function checkDialNumber(
|
|
dialNumber: string, dialOutAuthUrl: string): Promise<Object> {
|
|
if (!dialOutAuthUrl) {
|
|
// no auth url, let's say it is valid
|
|
const response = {
|
|
allow: true,
|
|
phone: dialNumber
|
|
};
|
|
|
|
return Promise.resolve(response);
|
|
}
|
|
|
|
const fullUrl = `${dialOutAuthUrl}?phone=${dialNumber}`;
|
|
|
|
return new Promise((resolve, reject) => {
|
|
$.getJSON(fullUrl)
|
|
.then(resolve)
|
|
.catch(reject);
|
|
});
|
|
}
|