import { StackNavigationProp } from '@react-navigation/stack'; import React, { useEffect } from 'react'; import { Switch } from 'react-native'; import { useDispatch } from 'react-redux'; import { setUser } from '../../actions/login'; import I18n from '../../i18n'; import log, { logEvent, events } from '../../lib/methods/helpers/log'; import { compareServerVersion } from '../../lib/methods/helpers'; import SafeAreaView from '../../containers/SafeAreaView'; import StatusBar from '../../containers/StatusBar'; import * as List from '../../containers/List'; import { SWITCH_TRACK_COLOR } from '../../lib/constants'; import { getUserSelector } from '../../selectors/login'; import { ProfileStackParamList } from '../../stacks/types'; import { Services } from '../../lib/services'; import { useAppSelector } from '../../lib/hooks'; import ListPicker from './ListPicker'; interface IUserPreferencesViewProps { navigation: StackNavigationProp; } const UserPreferencesView = ({ navigation }: IUserPreferencesViewProps): JSX.Element => { const { enableMessageParserEarlyAdoption, id, alsoSendThreadToChannel } = useAppSelector(state => getUserSelector(state)); const serverVersion = useAppSelector(state => state.server.version); const dispatch = useDispatch(); useEffect(() => { navigation.setOptions({ title: I18n.t('Preferences') }); }, [navigation]); const navigateToScreen = () => { logEvent(events.UP_GO_USER_NOTIFICATION_PREF); navigation.navigate('UserNotificationPrefView'); }; const toggleMessageParser = async (value: boolean) => { try { dispatch(setUser({ enableMessageParserEarlyAdoption: value })); await Services.saveUserPreferences({ id, enableMessageParserEarlyAdoption: value }); } catch (e) { log(e); } }; const setAlsoSendThreadToChannel = async (param: { [key: string]: string }, onError: () => void) => { try { await Services.saveUserPreferences(param); dispatch(setUser(param)); } catch (e) { log(e); onError(); } }; const renderMessageParserSwitch = (value: boolean) => ( ); return ( navigateToScreen()} showActionIndicator testID='preferences-view-notifications' /> {compareServerVersion(serverVersion, 'lowerThan', '5.0.0') ? ( renderMessageParserSwitch(enableMessageParserEarlyAdoption)} /> ) : null} {compareServerVersion(serverVersion, 'greaterThanOrEqualTo', '5.0.0') ? ( ) : null} ); }; export default UserPreferencesView;