diff --git a/app/views/ProfileView/index.js b/app/views/ProfileView/index.js index c2d061615..15251a990 100644 --- a/app/views/ProfileView/index.js +++ b/app/views/ProfileView/index.js @@ -1,8 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { - View, ScrollView, Keyboard, Switch -} from 'react-native'; +import { View, ScrollView, Keyboard } from 'react-native'; import { connect } from 'react-redux'; import prompt from 'react-native-prompt-android'; import SHA256 from 'js-sha256'; @@ -21,7 +19,6 @@ import { LISTENER } from '../../containers/Toast'; import EventEmitter from '../../utils/events'; import RocketChat from '../../lib/rocketchat'; import RCTextInput from '../../containers/TextInput'; -import * as List from '../../containers/List'; import log, { logEvent, events } from '../../utils/log'; import I18n from '../../i18n'; import Button from '../../containers/Button'; @@ -30,7 +27,7 @@ import { setUser as setUserAction } from '../../actions/login'; import { CustomIcon } from '../../lib/Icons'; import * as HeaderButton from '../../containers/HeaderButton'; import StatusBar from '../../containers/StatusBar'; -import { SWITCH_TRACK_COLOR, themes } from '../../constants/colors'; +import { themes } from '../../constants/colors'; import { withTheme } from '../../theme'; import { getUserSelector } from '../../selectors/login'; import SafeAreaView from '../../containers/SafeAreaView'; @@ -64,7 +61,6 @@ class ProfileView extends React.Component { state = { saving: false, - enableMessageParser: false, name: null, username: null, email: null, @@ -113,7 +109,7 @@ class ProfileView extends React.Component { init = (user) => { const { user: userProps } = this.props; const { - name, username, emails, customFields, enableMessageParserEarlyAdoption + name, username, emails, customFields } = user || userProps; this.setState({ @@ -124,14 +120,13 @@ class ProfileView extends React.Component { currentPassword: null, avatarUrl: null, avatar: {}, - customFields: customFields || {}, - enableMessageParser: enableMessageParserEarlyAdoption || false + customFields: customFields || {} }); } formIsChanged = () => { const { - name, username, email, newPassword, avatar, customFields, enableMessageParser + name, username, email, newPassword, avatar, customFields } = this.state; const { user } = this.props; let customFieldsChanged = false; @@ -147,7 +142,6 @@ class ProfileView extends React.Component { return !(user.name === name && user.username === username - && user.enableMessageParserEarlyAdoption === enableMessageParser && !newPassword && (user.emails && user.emails[0].address === email) && !avatar.data @@ -429,22 +423,6 @@ class ProfileView extends React.Component { } } - renderMessageParserSwitch = () => { - const { enableMessageParser } = this.state; - return ( - - ); - } - - toggleEnableMessageParser = (value) => { - // logEvent(events.RI_EDIT_TOGGLE_SYSTEM_MSG); - this.setState({ enableMessageParser: value }); - } - logoutOtherLocations = () => { logEvent(events.PL_OTHER_LOCATIONS); showConfirmationAlert({ @@ -560,13 +538,6 @@ class ProfileView extends React.Component { testID='profile-view-new-password' theme={theme} /> - - this.renderMessageParserSwitch()} - /> - {this.renderCustomFields()} ({ - title: I18n.t('Preferences') - }); - static propTypes = { - navigation: PropTypes.object - } +const UserPreferencesView = ({ navigation }) => { + const user = useSelector(state => getUserSelector(state)); + const [enableParser, setEnableParser] = useState(user.enableMessageParserEarlyAdoption); - navigateToScreen = (screen, params) => { + useEffect(() => { + navigation.setOptions({ + title: I18n.t('Preferences') + }); + }, []); + + const navigateToScreen = (screen, params) => { logEvent(events[`SE_GO_${ screen.replace('View', '').toUpperCase() }`]); - const { navigation } = this.props; navigation.navigate(screen, params); - } + }; - render() { - return ( - - - - - - this.navigateToScreen('UserNotificationPrefView')} - showActionIndicator - testID='preferences-view-notifications' - /> - - - - - ); - } -} + const toggleMessageParser = async(value) => { + try { + await RocketChat.saveUserPreferences({ id: user.id, enableMessageParserEarlyAdoption: value }); + setEnableParser(value); + } catch (e) { + log(e); + } + }; + + const renderMessageParserSwitch = () => ( + + ); + + return ( + + + + + + navigateToScreen('UserNotificationPrefView')} + showActionIndicator + testID='preferences-view-notifications' + /> + + + + + renderMessageParserSwitch()} + /> + + + + + ); +}; + +UserPreferencesView.propTypes = { + navigation: PropTypes.object +}; export default UserPreferencesView; diff --git a/index.js b/index.js index 02a59df2c..bbd7a5786 100644 --- a/index.js +++ b/index.js @@ -1,13 +1,7 @@ -// import 'react-native-gesture-handler'; -// import 'react-native-console-time-polyfill'; -// import { AppRegistry } from 'react-native'; -// import { name as appName, share as shareName } from './app.json'; - -// AppRegistry.registerComponent(appName, () => require('./app/index').default); -// AppRegistry.registerComponent(shareName, () => require('./app/share').default); - -// For storybook, comment everything above and uncomment below -import './storybook'; +import 'react-native-gesture-handler'; +import 'react-native-console-time-polyfill'; +import { AppRegistry } from 'react-native'; +import { name as appName, share as shareName } from './app.json'; if (__DEV__) { require('./app/ReactotronConfig'); @@ -22,3 +16,9 @@ if (__DEV__) { console.error = () => {}; console.info = () => {}; } + +AppRegistry.registerComponent(appName, () => require('./app/index').default); +AppRegistry.registerComponent(shareName, () => require('./app/share').default); + +// For storybook, comment everything above and uncomment below +// import './storybook';