2021-11-25 14:25:11 +00:00
|
|
|
import { StackNavigationProp } from '@react-navigation/stack';
|
2021-10-28 17:49:08 +00:00
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
import { Switch } from 'react-native';
|
|
|
|
import { useSelector } from 'react-redux';
|
2020-08-21 13:30:11 +00:00
|
|
|
|
|
|
|
import I18n from '../../i18n';
|
2021-10-28 17:49:08 +00:00
|
|
|
import log, { logEvent, events } from '../../utils/log';
|
2020-08-21 13:30:11 +00:00
|
|
|
import SafeAreaView from '../../containers/SafeAreaView';
|
|
|
|
import StatusBar from '../../containers/StatusBar';
|
2020-10-30 13:59:44 +00:00
|
|
|
import * as List from '../../containers/List';
|
2021-10-28 17:49:08 +00:00
|
|
|
import { SWITCH_TRACK_COLOR } from '../../constants/colors';
|
|
|
|
import { getUserSelector } from '../../selectors/login';
|
|
|
|
import RocketChat from '../../lib/rocketchat';
|
2021-12-24 13:12:49 +00:00
|
|
|
import { ProfileStackParamList } from '../../stacks/types';
|
2020-08-21 13:30:11 +00:00
|
|
|
|
2021-11-25 14:25:11 +00:00
|
|
|
interface IUserPreferencesViewProps {
|
2021-12-24 13:12:49 +00:00
|
|
|
navigation: StackNavigationProp<ProfileStackParamList, 'UserPreferencesView'>;
|
2021-11-25 14:25:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const UserPreferencesView = ({ navigation }: IUserPreferencesViewProps): JSX.Element => {
|
2021-10-28 17:49:08 +00:00
|
|
|
const user = useSelector(state => getUserSelector(state));
|
|
|
|
const [enableParser, setEnableParser] = useState(user.enableMessageParserEarlyAdoption);
|
2020-08-21 13:30:11 +00:00
|
|
|
|
2021-10-28 17:49:08 +00:00
|
|
|
useEffect(() => {
|
|
|
|
navigation.setOptions({
|
|
|
|
title: I18n.t('Preferences')
|
|
|
|
});
|
|
|
|
}, []);
|
2020-08-21 13:30:11 +00:00
|
|
|
|
2021-12-24 13:12:49 +00:00
|
|
|
const navigateToScreen = (screen: keyof ProfileStackParamList) => {
|
2021-11-25 14:25:11 +00:00
|
|
|
logEvent(events.UP_GO_USER_NOTIFICATION_PREF);
|
|
|
|
navigation.navigate(screen);
|
2021-10-01 18:12:19 +00:00
|
|
|
};
|
2020-08-21 13:30:11 +00:00
|
|
|
|
2021-11-25 14:25:11 +00:00
|
|
|
const toggleMessageParser = async (value: boolean) => {
|
2021-10-28 17:49:08 +00:00
|
|
|
try {
|
|
|
|
await RocketChat.saveUserPreferences({ id: user.id, enableMessageParserEarlyAdoption: value });
|
|
|
|
setEnableParser(value);
|
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const renderMessageParserSwitch = () => (
|
|
|
|
<Switch value={enableParser} trackColor={SWITCH_TRACK_COLOR} onValueChange={toggleMessageParser} />
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<SafeAreaView testID='preferences-view'>
|
|
|
|
<StatusBar />
|
|
|
|
<List.Container>
|
|
|
|
<List.Section>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
title='Notifications'
|
|
|
|
onPress={() => navigateToScreen('UserNotificationPrefView')}
|
|
|
|
showActionIndicator
|
|
|
|
testID='preferences-view-notifications'
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
</List.Section>
|
|
|
|
<List.Section>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
title='Enable_Message_Parser'
|
|
|
|
testID='preferences-view-enable-message-parser'
|
|
|
|
right={() => renderMessageParserSwitch()}
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
</List.Section>
|
|
|
|
</List.Container>
|
|
|
|
</SafeAreaView>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-10-30 13:59:44 +00:00
|
|
|
export default UserPreferencesView;
|