created send feedback feature

This commit is contained in:
u-e 2019-03-16 12:51:18 +03:00
parent 9d35e81a37
commit fab90fe312
4 changed files with 93 additions and 13 deletions

View File

@ -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",

View File

@ -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;
}
@ -217,6 +223,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;

View File

@ -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,6 +116,7 @@ class SettingsScreen extends PureComponent {
handleOnChange={handleOnChange}
/>
{!!isLoggedIn && (
<Fragment>
<SettingsItem
title={intl.formatMessage({
id: 'settings.pincode',
@ -127,6 +128,18 @@ class SettingsScreen extends PureComponent {
actionType="pincode"
handleOnChange={handleOnChange}
/>
<SettingsItem
title={intl.formatMessage({
id: 'settings.send_feedback',
})}
text={intl.formatMessage({
id: 'settings.send',
})}
type="button"
actionType="feedback"
handleOnChange={handleOnChange}
/>
</Fragment>
)}
</ScrollView>
</View>

27
src/utils/sendEmail.js Normal file
View File

@ -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);
};