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", "pincode": "PIN code",
"reset": "Reset", "reset": "Reset",
"nsfw_content": "NSFW Content", "nsfw_content": "NSFW Content",
"send_feedback": "Send Feedback",
"send": "Send",
"nsfw": { "nsfw": {
"always_show": "Always show", "always_show": "Always show",
"always_hide": "Always hide", "always_hide": "Always hide",
"always_warn": "Always warn" "always_warn": "Always warn"
} },
"feedback_success": "Email successfully open",
"feedback_fail": "Email client could not open"
}, },
"voters": { "voters": {
"voters_info": "Voters Info", "voters_info": "Voters Info",

View File

@ -4,6 +4,7 @@ import { connect } from 'react-redux';
import AppCenter from 'appcenter'; import AppCenter from 'appcenter';
import Push from 'appcenter-push'; import Push from 'appcenter-push';
import { Client } from 'dsteem'; import { Client } from 'dsteem';
import VersionNumber from 'react-native-version-number';
// Realm // Realm
import { import {
@ -36,6 +37,7 @@ import { VALUE as CURRENCY_VALUE } from '../../../constants/options/currency';
import { VALUE as LANGUAGE_VALUE } from '../../../constants/options/language'; import { VALUE as LANGUAGE_VALUE } from '../../../constants/options/language';
// Utilities // Utilities
import { sendEmail } from '../../../utils/sendEmail';
// Component // Component
import SettingsScreen from '../screen/settingsScreen'; import SettingsScreen from '../screen/settingsScreen';
@ -86,6 +88,10 @@ class SettingsContainer extends Component {
setNsfw2DB(action); setNsfw2DB(action);
break; break;
case 'feedback':
this._handleSendFeedback();
break;
default: default:
break; 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() { render() {
const { serverList } = this.state; 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 { ScrollView, View } from 'react-native';
import { injectIntl } from 'react-intl'; import { injectIntl } from 'react-intl';
@ -116,17 +116,30 @@ class SettingsScreen extends PureComponent {
handleOnChange={handleOnChange} handleOnChange={handleOnChange}
/> />
{!!isLoggedIn && ( {!!isLoggedIn && (
<SettingsItem <Fragment>
title={intl.formatMessage({ <SettingsItem
id: 'settings.pincode', title={intl.formatMessage({
})} id: 'settings.pincode',
text={intl.formatMessage({ })}
id: 'settings.reset', text={intl.formatMessage({
})} id: 'settings.reset',
type="button" })}
actionType="pincode" type="button"
handleOnChange={handleOnChange} 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> </ScrollView>
</View> </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);
};