diff --git a/src/CONST.js b/src/CONST.js index c91b3e5b5736..08eeaf68234d 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -334,6 +334,7 @@ const CONST = { POLICY: { TYPE: { FREE: 'free', + PERSONAL: 'personal', }, ROLE: { ADMIN: 'admin', diff --git a/src/languages/en.js b/src/languages/en.js index 989b8091bcf7..d50fb421e816 100755 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -489,5 +489,6 @@ export default { growlMessageOnSave: 'Call requested.', growlMessageInvalidPhone: 'That doesn’t look like a valid phone number. Try again with the country code.\ne.g. +15005550006', growlMessageEmptyName: 'Please provide both a first and last name so our Guides know how to address you!', + growlMessageNoPersonalPolicy: 'I wasn’t able to find a personal policy to associate this Guides call with, please check your connection and try again.', }, }; diff --git a/src/languages/es.js b/src/languages/es.js index 8779ff802b2f..5048f802c3f3 100644 --- a/src/languages/es.js +++ b/src/languages/es.js @@ -451,5 +451,6 @@ export default { growlMessageOnSave: 'Llamada solicitada.', growlMessageInvalidPhone: 'El teléfono no es valido. Intentalo de nuevo agregando el código de país. P. ej.: +15005550006', growlMessageEmptyName: 'Por favor ingresa tu nombre completo', + growlMessageNoPersonalPolicy: 'No he podido encontrar una póliza personal con la que asociar esta llamada a las Guías, compruebe su conexión e inténtelo de nuevo.', }, }; diff --git a/src/libs/Growl.js b/src/libs/Growl.js index d16038480692..15d46c3402ec 100644 --- a/src/libs/Growl.js +++ b/src/libs/Growl.js @@ -24,7 +24,18 @@ function error(bodyText, duration = CONST.GROWL.DURATION) { show(bodyText, CONST.GROWL.ERROR, duration); } +/** + * Show success growl + * + * @param {String} bodyText + * @param {Number} [duration] + */ +function success(bodyText, duration = CONST.GROWL.DURATION) { + show(bodyText, CONST.GROWL.SUCCESS, duration); +} + export default { show, error, + success, }; diff --git a/src/pages/RequestCallPage.js b/src/pages/RequestCallPage.js index eb6d5c52427b..fe52c29fd32f 100644 --- a/src/pages/RequestCallPage.js +++ b/src/pages/RequestCallPage.js @@ -40,6 +40,15 @@ const propTypes = { partnerUserID: PropTypes.string, })), }).isRequired, + + /** The policies which the user has access to */ + policies: PropTypes.shape({ + /** ID of the policy */ + policyID: PropTypes.string, + + /** The type of the policy */ + type: PropTypes.string, + }).isRequired, }; class RequestCallPage extends Component { @@ -61,22 +70,27 @@ class RequestCallPage extends Component { onSubmit() { this.setState({isLoading: true}); if (!this.state.firstName.length || !this.state.lastName.length) { - Growl.show(this.props.translate('requestCallPage.growlMessageEmptyName'), CONST.GROWL.ERROR); + Growl.success(this.props.translate('requestCallPage.growlMessageEmptyName')); this.setState({isLoading: false}); return; } - requestConciergeDMCall('', this.state.firstName, this.state.lastName, this.state.phoneNumber) + const personalPolicy = _.find(this.props.policies, policy => policy.type === CONST.POLICY.TYPE.PERSONAL); + if (!personalPolicy) { + Growl.error(this.props.translate('requestCallPage.growlMessageNoPersonalPolicy'), 3000); + return; + } + requestConciergeDMCall(personalPolicy.id, this.state.firstName, this.state.lastName, this.state.phoneNumber) .then((result) => { this.setState({isLoading: false}); if (result.jsonCode === 200) { - Growl.show(this.props.translate('requestCallPage.growlMessageOnSave'), CONST.GROWL.SUCCESS); + Growl.success(this.props.translate('requestCallPage.growlMessageOnSave')); fetchOrCreateChatReport([this.props.session.email, CONST.EMAIL.CONCIERGE], true); return; } // Phone number validation is handled by the API - Growl.show(result.message, CONST.GROWL.ERROR, 3000); + Growl.error(result.message, 3000); }); } @@ -195,5 +209,8 @@ export default compose( user: { key: ONYXKEYS.USER, }, + policies: { + key: ONYXKEYS.COLLECTION.POLICY, + }, }), )(RequestCallPage);