-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathVisibilityPage.tsx
102 lines (93 loc) · 4.49 KB
/
VisibilityPage.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import type {StackScreenProps} from '@react-navigation/stack';
import React, {useCallback, useMemo, useState} from 'react';
import {useOnyx} from 'react-native-onyx';
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
import ConfirmModal from '@components/ConfirmModal';
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 type {ReportSettingsNavigatorParamList} from '@libs/Navigation/types';
import * as ReportUtils from '@libs/ReportUtils';
import type {WithReportOrNotFoundProps} from '@pages/home/report/withReportOrNotFound';
import withReportOrNotFound from '@pages/home/report/withReportOrNotFound';
import * as ReportActions from '@userActions/Report';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type SCREENS from '@src/SCREENS';
import type {RoomVisibility} from '@src/types/onyx/Report';
type VisibilityProps = WithReportOrNotFoundProps & StackScreenProps<ReportSettingsNavigatorParamList, typeof SCREENS.REPORT_SETTINGS.VISIBILITY>;
function VisibilityPage({report}: VisibilityProps) {
const [showConfirmModal, setShowConfirmModal] = useState(false);
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID || -1}`);
const shouldDisableVisibility = ReportUtils.isArchivedRoom(report, reportNameValuePairs);
const {translate} = useLocalize();
const visibilityOptions = useMemo(
() =>
Object.values(CONST.REPORT.VISIBILITY)
.filter((visibilityOption) => visibilityOption !== CONST.REPORT.VISIBILITY.PUBLIC_ANNOUNCE)
.map((visibilityOption) => ({
text: translate(`newRoomPage.visibilityOptions.${visibilityOption}`),
value: visibilityOption,
alternateText: translate(`newRoomPage.${visibilityOption}Description`),
keyForList: visibilityOption,
isSelected: visibilityOption === report?.visibility,
})),
[translate, report?.visibility],
);
const changeVisibility = useCallback(
(newVisibility: RoomVisibility) => {
if (!report) {
return;
}
ReportActions.updateRoomVisibility(report.reportID, report.visibility, newVisibility, true, report);
},
[report],
);
const hideModal = useCallback(() => {
setShowConfirmModal(false);
}, []);
return (
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
testID={VisibilityPage.displayName}
>
<FullPageNotFoundView shouldShow={shouldDisableVisibility}>
<HeaderWithBackButton
title={translate('newRoomPage.visibility')}
onBackButtonPress={() => ReportUtils.goBackToDetailsPage(report)}
/>
<SelectionList
shouldPreventDefaultFocusOnSelectRow
sections={[{data: visibilityOptions}]}
onSelectRow={(option) => {
if (option.value === CONST.REPORT.VISIBILITY.PUBLIC) {
setShowConfirmModal(true);
return;
}
changeVisibility(option.value);
}}
shouldSingleExecuteRowSelect
initiallyFocusedOptionKey={visibilityOptions.find((visibility) => visibility.isSelected)?.keyForList}
ListItem={RadioListItem}
/>
<ConfirmModal
isVisible={showConfirmModal}
onConfirm={() => {
changeVisibility(CONST.REPORT.VISIBILITY.PUBLIC);
hideModal();
}}
onCancel={hideModal}
title={translate('common.areYouSure')}
prompt={translate('newRoomPage.publicDescription')}
confirmText={translate('common.yes')}
cancelText={translate('common.no')}
danger
/>
</FullPageNotFoundView>
</ScreenWrapper>
);
}
VisibilityPage.displayName = 'VisibilityPage';
export default withReportOrNotFound()(VisibilityPage);