Rocket.Chat.ReactNative/app/views/SecurityPrivacyView.tsx

124 lines
3.8 KiB
TypeScript
Raw Normal View History

import AsyncStorage from '@react-native-async-storage/async-storage';
import { StackNavigationProp } from '@react-navigation/stack';
import React, { useEffect, useState } from 'react';
import * as List from '../containers/List';
import SafeAreaView from '../containers/SafeAreaView';
import StatusBar from '../containers/StatusBar';
import I18n from '../i18n';
feat: mobile color normalization (#5616) * chore: remove auxiliaryText color * chore: remove titleText * chore: password colors change * chore: use fontDefault on ActionSheet item * wip: type * chore: set custom icon default color * remove tintActive color * only set color when checked * remove icon color * remove tintActive * chore: remove STATUS_COLORS * chore: remove mentions colors * chore: remove switch color * chore: background color * chore: auxiliaryBackground * chore: one local colors * wip: some colors * wip: colors * wip: colors * wip: end colors * test: update * chore: fix some colors * chore: fix lint * chore: back to text props * chore: fix ts errors * revert * chore: fix lint * test: update snapshot * update storybook * cocoapods * fix app theme color * remove unused color * fix login service button color * remove unused color * unused backgroundColor * fix background color * fix transparent color * fix background color * wip: key * fix color * chore: revert to 1 tick * test: update * chore: use same color as front end * test: update * fix radius * fix background color * fix wrong color * change some colors * chore: update stories * chore: fix button style * chore: fix item color * lint * update snapshot * link * remove background color * change send to channel color * call icons * video conf colors * fix app default color * bottom sheet * remove background * two factor color * update tests * feat: add force-logout stream listener * remove icon colors * improve badge color * update tests * fix header colors * fix collapsible icon color * imagePreview color * wip * update test * lint --------- Co-authored-by: Diego Mello <diegolmello@gmail.com>
2024-04-18 10:19:54 +00:00
import { ANALYTICS_EVENTS_KEY, CRASH_REPORT_KEY, isFDroidBuild } from '../lib/constants';
import { useAppSelector } from '../lib/hooks';
import useServer from '../lib/methods/useServer';
import { SettingsStackParamList } from '../stacks/types';
import { handleLocalAuthentication } from '../lib/methods/helpers/localAuthentication';
import {
events,
getReportAnalyticsEventsValue,
getReportCrashErrorsValue,
logEvent,
toggleAnalyticsEventsReport,
toggleCrashErrorsReport
} from '../lib/methods/helpers/log';
feat: mobile color normalization (#5616) * chore: remove auxiliaryText color * chore: remove titleText * chore: password colors change * chore: use fontDefault on ActionSheet item * wip: type * chore: set custom icon default color * remove tintActive color * only set color when checked * remove icon color * remove tintActive * chore: remove STATUS_COLORS * chore: remove mentions colors * chore: remove switch color * chore: background color * chore: auxiliaryBackground * chore: one local colors * wip: some colors * wip: colors * wip: colors * wip: end colors * test: update * chore: fix some colors * chore: fix lint * chore: back to text props * chore: fix ts errors * revert * chore: fix lint * test: update snapshot * update storybook * cocoapods * fix app theme color * remove unused color * fix login service button color * remove unused color * unused backgroundColor * fix background color * fix transparent color * fix background color * wip: key * fix color * chore: revert to 1 tick * test: update * chore: use same color as front end * test: update * fix radius * fix background color * fix wrong color * change some colors * chore: update stories * chore: fix button style * chore: fix item color * lint * update snapshot * link * remove background color * change send to channel color * call icons * video conf colors * fix app default color * bottom sheet * remove background * two factor color * update tests * feat: add force-logout stream listener * remove icon colors * improve badge color * update tests * fix header colors * fix collapsible icon color * imagePreview color * wip * update test * lint --------- Co-authored-by: Diego Mello <diegolmello@gmail.com>
2024-04-18 10:19:54 +00:00
import Switch from '../containers/Switch';
interface ISecurityPrivacyViewProps {
navigation: StackNavigationProp<SettingsStackParamList, 'SecurityPrivacyView'>;
}
const SecurityPrivacyView = ({ navigation }: ISecurityPrivacyViewProps): JSX.Element => {
const [crashReportState, setCrashReportState] = useState(getReportCrashErrorsValue());
const [analyticsEventsState, setAnalyticsEventsState] = useState(getReportAnalyticsEventsValue());
const [server] = useServer();
const e2eEnabled = useAppSelector(state => state.settings.E2E_Enable);
useEffect(() => {
navigation.setOptions({
title: I18n.t('Security_and_privacy')
});
}, [navigation]);
const toggleCrashReport = (value: boolean) => {
logEvent(events.SP_TOGGLE_CRASH_REPORT);
AsyncStorage.setItem(CRASH_REPORT_KEY, JSON.stringify(value));
setCrashReportState(value);
toggleCrashErrorsReport(value);
};
const toggleAnalyticsEvents = (value: boolean) => {
logEvent(events.SP_TOGGLE_ANALYTICS_EVENTS);
AsyncStorage.setItem(ANALYTICS_EVENTS_KEY, JSON.stringify(value));
setAnalyticsEventsState(value);
toggleAnalyticsEventsReport(value);
};
const navigateToScreen = (screen: 'E2EEncryptionSecurityView' | 'ScreenLockConfigView') => {
// @ts-ignore
logEvent(events[`SP_GO_${screen.replace('View', '').toUpperCase()}`]);
navigation.navigate(screen);
};
const navigateToScreenLockConfigView = async () => {
if (server?.autoLock) {
await handleLocalAuthentication(true);
}
navigateToScreen('ScreenLockConfigView');
};
return (
<SafeAreaView testID='security-privacy-view'>
<StatusBar />
<List.Container testID='security-privacy-view-list'>
<List.Section>
<List.Separator />
{e2eEnabled ? (
<>
<List.Item
title='E2E_Encryption'
showActionIndicator
onPress={() => navigateToScreen('E2EEncryptionSecurityView')}
testID='security-privacy-view-e2e-encryption'
/>
<List.Separator />
</>
) : null}
<List.Item
title='Screen_lock'
showActionIndicator
onPress={navigateToScreenLockConfigView}
testID='security-privacy-view-screen-lock'
/>
<List.Separator />
</List.Section>
{!isFDroidBuild ? (
<>
<List.Section>
<List.Separator />
<List.Item
title='Log_analytics_events'
testID='security-privacy-view-analytics-events'
right={() => (
feat: mobile color normalization (#5616) * chore: remove auxiliaryText color * chore: remove titleText * chore: password colors change * chore: use fontDefault on ActionSheet item * wip: type * chore: set custom icon default color * remove tintActive color * only set color when checked * remove icon color * remove tintActive * chore: remove STATUS_COLORS * chore: remove mentions colors * chore: remove switch color * chore: background color * chore: auxiliaryBackground * chore: one local colors * wip: some colors * wip: colors * wip: colors * wip: end colors * test: update * chore: fix some colors * chore: fix lint * chore: back to text props * chore: fix ts errors * revert * chore: fix lint * test: update snapshot * update storybook * cocoapods * fix app theme color * remove unused color * fix login service button color * remove unused color * unused backgroundColor * fix background color * fix transparent color * fix background color * wip: key * fix color * chore: revert to 1 tick * test: update * chore: use same color as front end * test: update * fix radius * fix background color * fix wrong color * change some colors * chore: update stories * chore: fix button style * chore: fix item color * lint * update snapshot * link * remove background color * change send to channel color * call icons * video conf colors * fix app default color * bottom sheet * remove background * two factor color * update tests * feat: add force-logout stream listener * remove icon colors * improve badge color * update tests * fix header colors * fix collapsible icon color * imagePreview color * wip * update test * lint --------- Co-authored-by: Diego Mello <diegolmello@gmail.com>
2024-04-18 10:19:54 +00:00
<Switch value={analyticsEventsState} onValueChange={toggleAnalyticsEvents} />
)}
/>
<List.Separator />
<List.Item
title='Send_crash_report'
testID='security-privacy-view-crash-report'
right={() => (
feat: mobile color normalization (#5616) * chore: remove auxiliaryText color * chore: remove titleText * chore: password colors change * chore: use fontDefault on ActionSheet item * wip: type * chore: set custom icon default color * remove tintActive color * only set color when checked * remove icon color * remove tintActive * chore: remove STATUS_COLORS * chore: remove mentions colors * chore: remove switch color * chore: background color * chore: auxiliaryBackground * chore: one local colors * wip: some colors * wip: colors * wip: colors * wip: end colors * test: update * chore: fix some colors * chore: fix lint * chore: back to text props * chore: fix ts errors * revert * chore: fix lint * test: update snapshot * update storybook * cocoapods * fix app theme color * remove unused color * fix login service button color * remove unused color * unused backgroundColor * fix background color * fix transparent color * fix background color * wip: key * fix color * chore: revert to 1 tick * test: update * chore: use same color as front end * test: update * fix radius * fix background color * fix wrong color * change some colors * chore: update stories * chore: fix button style * chore: fix item color * lint * update snapshot * link * remove background color * change send to channel color * call icons * video conf colors * fix app default color * bottom sheet * remove background * two factor color * update tests * feat: add force-logout stream listener * remove icon colors * improve badge color * update tests * fix header colors * fix collapsible icon color * imagePreview color * wip * update test * lint --------- Co-authored-by: Diego Mello <diegolmello@gmail.com>
2024-04-18 10:19:54 +00:00
<Switch value={crashReportState} onValueChange={toggleCrashReport} />
)}
/>
<List.Separator />
<List.Info info='Crash_report_disclaimer' />
</List.Section>
</>
) : null}
</List.Container>
</SafeAreaView>
);
};
export default SecurityPrivacyView;