2021-11-10 18:43:35 +00:00
|
|
|
import { StackNavigationProp } from '@react-navigation/stack';
|
2022-01-12 14:05:30 +00:00
|
|
|
import React, { useEffect } from 'react';
|
2021-10-20 16:32:58 +00:00
|
|
|
import { Switch } from 'react-native';
|
2022-05-13 15:01:34 +00:00
|
|
|
import { useDispatch } from 'react-redux';
|
2020-08-21 13:30:11 +00:00
|
|
|
|
2022-01-12 14:05:30 +00:00
|
|
|
import { setUser } from '../../actions/login';
|
2020-08-21 13:30:11 +00:00
|
|
|
import I18n from '../../i18n';
|
2022-06-06 14:17:51 +00:00
|
|
|
import log, { logEvent, events } from '../../lib/methods/helpers/log';
|
2022-07-06 15:43:50 +00:00
|
|
|
import { compareServerVersion } from '../../lib/methods/helpers';
|
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';
|
2022-04-07 14:10:03 +00:00
|
|
|
import { SWITCH_TRACK_COLOR } from '../../lib/constants';
|
2021-10-20 16:32:58 +00:00
|
|
|
import { getUserSelector } from '../../selectors/login';
|
2021-12-03 19:27:57 +00:00
|
|
|
import { ProfileStackParamList } from '../../stacks/types';
|
2022-04-28 20:37:25 +00:00
|
|
|
import { Services } from '../../lib/services';
|
2022-05-13 15:01:34 +00:00
|
|
|
import { useAppSelector } from '../../lib/hooks';
|
2020-08-21 13:30:11 +00:00
|
|
|
|
2021-11-10 18:43:35 +00:00
|
|
|
interface IUserPreferencesViewProps {
|
2021-12-03 19:27:57 +00:00
|
|
|
navigation: StackNavigationProp<ProfileStackParamList, 'UserPreferencesView'>;
|
2021-11-10 18:43:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const UserPreferencesView = ({ navigation }: IUserPreferencesViewProps): JSX.Element => {
|
2022-05-13 15:01:34 +00:00
|
|
|
const { enableMessageParserEarlyAdoption, id } = useAppSelector(state => getUserSelector(state));
|
2022-07-06 15:43:50 +00:00
|
|
|
const serverVersion = useAppSelector(state => state.server.version);
|
2022-01-12 14:05:30 +00:00
|
|
|
const dispatch = useDispatch();
|
2020-08-21 13:30:11 +00:00
|
|
|
|
2021-10-20 16:32:58 +00:00
|
|
|
useEffect(() => {
|
|
|
|
navigation.setOptions({
|
|
|
|
title: I18n.t('Preferences')
|
|
|
|
});
|
2022-05-03 01:34:56 +00:00
|
|
|
}, [navigation]);
|
2020-08-21 13:30:11 +00:00
|
|
|
|
2021-12-03 19:27:57 +00:00
|
|
|
const navigateToScreen = (screen: keyof ProfileStackParamList) => {
|
2021-11-10 18:43:35 +00:00
|
|
|
logEvent(events.UP_GO_USER_NOTIFICATION_PREF);
|
|
|
|
navigation.navigate(screen);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-08-21 13:30:11 +00:00
|
|
|
|
2021-11-10 18:43:35 +00:00
|
|
|
const toggleMessageParser = async (value: boolean) => {
|
2021-10-20 16:32:58 +00:00
|
|
|
try {
|
2022-01-12 14:05:30 +00:00
|
|
|
dispatch(setUser({ enableMessageParserEarlyAdoption: value }));
|
2022-04-28 20:37:25 +00:00
|
|
|
await Services.saveUserPreferences({ id, enableMessageParserEarlyAdoption: value });
|
2021-10-20 16:32:58 +00:00
|
|
|
} catch (e) {
|
|
|
|
log(e);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-01-12 14:05:30 +00:00
|
|
|
const renderMessageParserSwitch = (value: boolean) => (
|
|
|
|
<Switch value={value} trackColor={SWITCH_TRACK_COLOR} onValueChange={toggleMessageParser} />
|
2021-10-20 16:32:58 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
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>
|
2022-07-06 15:43:50 +00:00
|
|
|
{compareServerVersion(serverVersion, 'lowerThan', '5.0.0') ? (
|
|
|
|
<List.Section>
|
|
|
|
<List.Separator />
|
|
|
|
<List.Item
|
|
|
|
title='Enable_Message_Parser'
|
|
|
|
testID='preferences-view-enable-message-parser'
|
|
|
|
right={() => renderMessageParserSwitch(enableMessageParserEarlyAdoption)}
|
|
|
|
/>
|
|
|
|
<List.Separator />
|
|
|
|
</List.Section>
|
|
|
|
) : null}
|
2021-10-20 16:32:58 +00:00
|
|
|
</List.Container>
|
|
|
|
</SafeAreaView>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-10-30 13:59:44 +00:00
|
|
|
export default UserPreferencesView;
|