From 87e289091e5396136e316d3c3f6ca76068e34670 Mon Sep 17 00:00:00 2001 From: u-e Date: Sat, 16 Mar 2019 12:51:18 +0300 Subject: [PATCH] created send feedback feature --- src/config/locales/en-US.json | 6 ++- .../settings/container/settingsContainer.js | 36 ++++++++++++++++++ src/screens/settings/screen/settingsScreen.js | 37 +++++++++++++------ src/utils/sendEmail.js | 27 ++++++++++++++ 4 files changed, 93 insertions(+), 13 deletions(-) create mode 100644 src/utils/sendEmail.js diff --git a/src/config/locales/en-US.json b/src/config/locales/en-US.json index 64408fad2..8c9c13f09 100644 --- a/src/config/locales/en-US.json +++ b/src/config/locales/en-US.json @@ -66,11 +66,15 @@ "pincode": "PIN code", "reset": "Reset", "nsfw_content": "NSFW Content", + "send_feedback": "Send Feedback", + "send": "Send", "nsfw": { "always_show": "Always show", "always_hide": "Always hide", "always_warn": "Always warn" - } + }, + "feedback_success": "Email successfully open", + "feedback_fail": "Email client could not open" }, "voters": { "voters_info": "Voters Info", diff --git a/src/screens/settings/container/settingsContainer.js b/src/screens/settings/container/settingsContainer.js index 4996886a5..69f8dc826 100644 --- a/src/screens/settings/container/settingsContainer.js +++ b/src/screens/settings/container/settingsContainer.js @@ -4,6 +4,7 @@ import { connect } from 'react-redux'; import AppCenter from 'appcenter'; import Push from 'appcenter-push'; import { Client } from 'dsteem'; +import VersionNumber from 'react-native-version-number'; // Realm import { @@ -36,6 +37,7 @@ import { VALUE as CURRENCY_VALUE } from '../../../constants/options/currency'; import { VALUE as LANGUAGE_VALUE } from '../../../constants/options/language'; // Utilities +import { sendEmail } from '../../../utils/sendEmail'; // Component import SettingsScreen from '../screen/settingsScreen'; @@ -86,6 +88,10 @@ class SettingsContainer extends Component { setNsfw2DB(action); break; + case 'feedback': + this._handleSendFeedback(); + break; + default: break; } @@ -216,6 +222,36 @@ class SettingsContainer extends Component { }); } }; + + _handleSendFeedback = async () => { + const { dispatch, intl } = this.props; + let message; + + await sendEmail( + 'bug@esteem.app', + 'Feedback/Bug report', + `Write your message here! + App version: ${VersionNumber.buildVersion} + Platform: ${Platform.OS === 'ios' ? 'IOS' : 'Android'} + Device: ${DeviceInfo.getDeviceName()}`, + ) + .then(() => { + message = 'settings.feedback_success'; + }) + .catch(() => { + message = 'settings.feedback_fail'; + }); + + if (message) { + dispatch( + toastNotification( + intl.formatMessage({ + id: message, + }), + ), + ); + } + }; render() { const { serverList } = this.state; diff --git a/src/screens/settings/screen/settingsScreen.js b/src/screens/settings/screen/settingsScreen.js index 4bda6243b..d1e446e4f 100644 --- a/src/screens/settings/screen/settingsScreen.js +++ b/src/screens/settings/screen/settingsScreen.js @@ -1,4 +1,4 @@ -import React, { PureComponent } from 'react'; +import React, { PureComponent, Fragment } from 'react'; import { ScrollView, View } from 'react-native'; import { injectIntl } from 'react-intl'; @@ -116,17 +116,30 @@ class SettingsScreen extends PureComponent { handleOnChange={handleOnChange} /> {!!isLoggedIn && ( - + + + + )} diff --git a/src/utils/sendEmail.js b/src/utils/sendEmail.js new file mode 100644 index 000000000..ca8538a68 --- /dev/null +++ b/src/utils/sendEmail.js @@ -0,0 +1,27 @@ +import { Linking } from 'react-native'; +import qs from 'qs'; + + export const sendEmail = async (to, subject, body, options = {}) => { + const { cc, bcc } = options; + + let url = `mailto:${to}`; + + const query = qs.stringify({ + subject, + body, + cc, + bcc, + }); + + if (query.length) { + url += `?${query}`; + } + + const canOpen = await Linking.canOpenURL(url); + + if (!canOpen) { + throw new Error('Provided URL can not be handled'); + } + + return Linking.openURL(url); +}; \ No newline at end of file