-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
NotificationPreferencePage.tsx
56 lines (51 loc) · 2.89 KB
/
NotificationPreferencePage.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import type {StackScreenProps} from '@react-navigation/stack';
import React from 'react';
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import SelectionList from '@components/SelectionList';
import RadioListItem from '@components/SelectionList/RadioListItem';
import useLocalize from '@hooks/useLocalize';
import * as ReportUtils from '@libs/ReportUtils';
import type {ReportSettingsNavigatorParamList} from '@navigation/types';
import withReportOrNotFound from '@pages/home/report/withReportOrNotFound';
import type {WithReportOrNotFoundProps} from '@pages/home/report/withReportOrNotFound';
import * as ReportActions from '@userActions/Report';
import CONST from '@src/CONST';
import type SCREENS from '@src/SCREENS';
type NotificationPreferencePageProps = WithReportOrNotFoundProps & StackScreenProps<ReportSettingsNavigatorParamList, typeof SCREENS.REPORT_SETTINGS.NOTIFICATION_PREFERENCES>;
function NotificationPreferencePage({report}: NotificationPreferencePageProps) {
const {translate} = useLocalize();
const shouldDisableNotificationPreferences = ReportUtils.isArchivedRoom(report) || ReportUtils.isSelfDM(report);
const notificationPreferenceOptions = Object.values(CONST.REPORT.NOTIFICATION_PREFERENCE)
.filter((pref) => pref !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN)
.map((preference) => ({
value: preference,
text: translate(`notificationPreferencesPage.notificationPreferences.${preference}`),
keyForList: preference,
isSelected: preference === report?.notificationPreference,
}));
return (
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
testID={NotificationPreferencePage.displayName}
>
<FullPageNotFoundView shouldShow={shouldDisableNotificationPreferences}>
<HeaderWithBackButton
title={translate('notificationPreferencesPage.header')}
onBackButtonPress={() => ReportUtils.goBackToDetailsPage(report)}
/>
<SelectionList
sections={[{data: notificationPreferenceOptions}]}
ListItem={RadioListItem}
onSelectRow={(option) =>
report && ReportActions.updateNotificationPreference(report.reportID, report.notificationPreference, option.value, true, undefined, undefined, report)
}
initiallyFocusedOptionKey={notificationPreferenceOptions.find((locale) => locale.isSelected)?.keyForList}
/>
</FullPageNotFoundView>
</ScreenWrapper>
);
}
NotificationPreferencePage.displayName = 'NotificationPreferencePage';
export default withReportOrNotFound()(NotificationPreferencePage);