-
Notifications
You must be signed in to change notification settings - Fork 3k
/
FlagCommentPage.js
181 lines (162 loc) · 7.4 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
import React, {useCallback} from 'react';
import _ from 'underscore';
import {View, ScrollView} from 'react-native';
import PropTypes from 'prop-types';
import reportPropTypes from './reportPropTypes';
import reportActionPropTypes from './home/report/reportActionPropTypes';
import withLocalize, {withLocalizePropTypes} from '../components/withLocalize';
import compose from '../libs/compose';
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 withReportAndReportActionOrNotFound from './home/report/withReportAndReportActionOrNotFound';
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,
...withLocalizePropTypes,
};
const defaultProps = {
reportActions: {},
report: {},
};
/**
* 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) {
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 getActionToFlag = useCallback(() => {
let reportAction = props.reportActions[`${props.route.params.reportActionID.toString()}`];
// Handle threads if needed
if (reportAction === undefined || reportAction.reportActionID === undefined) {
reportAction = ReportActionsUtils.getParentReportAction(props.report);
}
return reportAction;
}, [props.report, props.reportActions, props.route.params.reportActionID]);
const flagComment = (severity) => {
let reportID = getReportID(props.route);
const reportAction = getActionToFlag();
// Handle threads if needed
if (ReportUtils.isChatThread(props.report) && reportAction.reportActionID === ReportActionsUtils.getParentReportAction(props.report).reportActionID) {
reportID = ReportUtils.getParentReport(props.report).reportID;
}
if (ReportUtils.canFlagReportAction(reportAction, 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}
/>
));
return (
<ScreenWrapper includeSafeAreaPaddingBottom={false}>
{({safeAreaPaddingBottomStyle}) => (
<FullPageNotFoundView shouldShow={!ReportUtils.shouldShowFlagComment(getActionToFlag(), 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, withReportAndReportActionOrNotFound)(FlagCommentPage);