-
Notifications
You must be signed in to change notification settings - Fork 3k
/
FlagCommentPage.js
196 lines (179 loc) · 7.73 KB
/
FlagCommentPage.js
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import React from 'react';
import _ from 'underscore';
import {View, ScrollView} from 'react-native';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import reportPropTypes from './reportPropTypes';
import reportActionPropTypes from './home/report/reportActionPropTypes';
import withLocalize, {withLocalizePropTypes} from '../components/withLocalize';
import compose from '../libs/compose';
import ONYXKEYS from '../ONYXKEYS';
import ScreenWrapper from '../components/ScreenWrapper';
import HeaderWithBackButton from '../components/HeaderWithBackButton';
import styles from '../styles/styles';
import Navigation from '../libs/Navigation/Navigation';
import Text from '../components/Text';
import * as Expensicons from '../components/Icon/Expensicons';
import MenuItem from '../components/MenuItem';
import * as Report from '../libs/actions/Report';
import CONST from '../CONST';
import * as ReportUtils from '../libs/ReportUtils';
import * as ReportActionsUtils from '../libs/ReportActionsUtils';
import * as Session from '../libs/actions/Session';
import FullPageNotFoundView from '../components/BlockingViews/FullPageNotFoundView';
import FullscreenLoadingIndicator from '../components/FullscreenLoadingIndicator';
const propTypes = {
/** Array of report actions for this report */
reportActions: PropTypes.shape(reportActionPropTypes),
/** The active report */
report: reportPropTypes,
/** Route params */
route: PropTypes.shape({
params: PropTypes.shape({
/** Report ID passed via route r/:reportID/:reportActionID */
reportID: PropTypes.string,
/** ReportActionID passed via route r/:reportID/:reportActionID */
reportActionID: PropTypes.string,
}),
}).isRequired,
/** Indicates whether the report data is loading */
isLoadingReportData: PropTypes.bool,
...withLocalizePropTypes,
};
const defaultProps = {
reportActions: {},
report: {},
isLoadingReportData: true,
};
/**
* Get the reportID for the associated chatReport
*
* @param {Object} route
* @param {Object} route.params
* @param {String} route.params.reportID
* @returns {String}
*/
function getReportID(route) {
return route.params.reportID.toString();
}
function FlagCommentPage(props) {
let reportAction = props.reportActions[`${props.route.params.reportActionID.toString()}`];
// Handle threads if needed
if (reportAction === undefined || reportAction.reportActionID === undefined) {
reportAction = ReportActionsUtils.getParentReportAction(props.report);
}
const severities = [
{
severity: CONST.MODERATION.FLAG_SEVERITY_SPAM,
name: props.translate('moderation.spam'),
icon: Expensicons.FlagLevelOne,
description: props.translate('moderation.spamDescription'),
furtherDetails: props.translate('moderation.levelOneResult'),
furtherDetailsIcon: Expensicons.FlagLevelOne,
},
{
severity: CONST.MODERATION.FLAG_SEVERITY_INCONSIDERATE,
name: props.translate('moderation.inconsiderate'),
icon: Expensicons.FlagLevelOne,
description: props.translate('moderation.inconsiderateDescription'),
furtherDetails: props.translate('moderation.levelOneResult'),
furtherDetailsIcon: Expensicons.FlagLevelOne,
},
{
severity: CONST.MODERATION.FLAG_SEVERITY_INTIMIDATION,
name: props.translate('moderation.intimidation'),
icon: Expensicons.FlagLevelTwo,
description: props.translate('moderation.intimidationDescription'),
furtherDetails: props.translate('moderation.levelTwoResult'),
furtherDetailsIcon: Expensicons.FlagLevelTwo,
},
{
severity: CONST.MODERATION.FLAG_SEVERITY_BULLYING,
name: props.translate('moderation.bullying'),
icon: Expensicons.FlagLevelTwo,
description: props.translate('moderation.bullyingDescription'),
furtherDetails: props.translate('moderation.levelTwoResult'),
furtherDetailsIcon: Expensicons.FlagLevelTwo,
},
{
severity: CONST.MODERATION.FLAG_SEVERITY_HARASSMENT,
name: props.translate('moderation.harassment'),
icon: Expensicons.FlagLevelThree,
description: props.translate('moderation.harassmentDescription'),
furtherDetails: props.translate('moderation.levelThreeResult'),
furtherDetailsIcon: Expensicons.FlagLevelThree,
},
{
severity: CONST.MODERATION.FLAG_SEVERITY_ASSAULT,
name: props.translate('moderation.assault'),
icon: Expensicons.FlagLevelThree,
description: props.translate('moderation.assaultDescription'),
furtherDetails: props.translate('moderation.levelThreeResult'),
furtherDetailsIcon: Expensicons.FlagLevelThree,
},
];
const flagComment = (severity) => {
let reportID = getReportID(props.route);
// Handle threads if needed
if (reportAction === undefined || reportAction.reportActionID === undefined) {
reportID = ReportUtils.getParentReport(props.report).reportID;
}
Report.flagComment(reportID, reportAction, severity);
Navigation.dismissModal();
};
const severityMenuItems = _.map(severities, (item, index) => (
<MenuItem
key={`${item.severity}_${index}`}
shouldShowRightIcon
title={item.name}
description={item.description}
onPress={Session.checkIfActionIsAllowed(() => flagComment(item.severity))}
style={[styles.pt2, styles.pb4, styles.ph5, styles.flexRow]}
furtherDetails={item.furtherDetails}
furtherDetailsIcon={item.furtherDetailsIcon}
/>
));
const shouldShowLoading = props.isLoadingReportData || props.report.isLoadingReportActions;
if (shouldShowLoading) {
return <FullscreenLoadingIndicator />;
}
return (
<ScreenWrapper includeSafeAreaPaddingBottom={false}>
{({safeAreaPaddingBottomStyle}) => (
<FullPageNotFoundView shouldShow={!shouldShowLoading && !ReportUtils.shouldShowFlagComment(reportAction, props.report)}>
<HeaderWithBackButton title={props.translate('reportActionContextMenu.flagAsOffensive')} />
<ScrollView
contentContainerStyle={safeAreaPaddingBottomStyle}
style={styles.settingsPageBackground}
>
<View style={styles.pageWrapper}>
<View style={styles.settingsPageBody}>
<Text style={styles.baseFontStyle}>{props.translate('moderation.flagDescription')}</Text>
</View>
</View>
<Text style={[styles.ph5, styles.textLabelSupporting, styles.mb1]}>{props.translate('moderation.chooseAReason')}</Text>
{severityMenuItems}
</ScrollView>
</FullPageNotFoundView>
)}
</ScreenWrapper>
);
}
FlagCommentPage.propTypes = propTypes;
FlagCommentPage.defaultProps = defaultProps;
FlagCommentPage.displayName = 'FlagCommentPage';
export default compose(
withLocalize,
withOnyx({
reportActions: {
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${getReportID(route)}`,
canEvict: false,
},
report: {
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${getReportID(route)}`,
},
isLoadingReportData: {
key: ONYXKEYS.IS_LOADING_REPORT_DATA,
},
}),
)(FlagCommentPage);