-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathReportFooter.js
121 lines (107 loc) · 4.8 KB
/
ReportFooter.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
import React from 'react';
import _ from 'underscore';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import {View, Keyboard} from 'react-native';
import CONST from '../../../CONST';
import ReportActionCompose from './ReportActionCompose';
import SwipeableView from '../../../components/SwipeableView';
import OfflineIndicator from '../../../components/OfflineIndicator';
import OfflineWithFeedback from '../../../components/OfflineWithFeedback';
import ArchivedReportFooter from '../../../components/ArchivedReportFooter';
import compose from '../../../libs/compose';
import ONYXKEYS from '../../../ONYXKEYS';
import withWindowDimensions, {windowDimensionsPropTypes} from '../../../components/withWindowDimensions';
import styles from '../../../styles/styles';
import reportActionPropTypes from './reportActionPropTypes';
import reportPropTypes from '../../reportPropTypes';
import * as ReportUtils from '../../../libs/ReportUtils';
const propTypes = {
/** Report object for the current report */
report: reportPropTypes,
/** Report actions for the current report */
reportActions: PropTypes.arrayOf(PropTypes.shape(reportActionPropTypes)),
/** Offline status */
isOffline: PropTypes.bool.isRequired,
/** Callback fired when the comment is submitted */
onSubmitComment: PropTypes.func,
/** Any errors associated with an attempt to create a chat */
// eslint-disable-next-line react/forbid-prop-types
errors: PropTypes.object,
/** The pending action when we are adding a chat */
pendingAction: PropTypes.string,
/** Whether the composer input should be shown */
shouldShowComposeInput: PropTypes.bool,
/** Whether user interactions should be disabled */
shouldDisableCompose: PropTypes.bool,
...windowDimensionsPropTypes,
};
const defaultProps = {
report: {reportID: '0'},
reportActions: [],
onSubmitComment: () => {},
errors: {},
pendingAction: null,
shouldShowComposeInput: true,
shouldDisableCompose: false,
};
class ReportFooter extends React.Component {
/**
* @returns {Object}
*/
getChatFooterStyles() {
return {...styles.chatFooter, minHeight: !this.props.isOffline ? CONST.CHAT_FOOTER_MIN_HEIGHT : 0};
}
render() {
const isArchivedRoom = ReportUtils.isArchivedRoom(this.props.report);
const hideComposer = isArchivedRoom || !_.isEmpty(this.props.errors);
return (
<>
{(isArchivedRoom || hideComposer) && (
<View style={[styles.chatFooter, this.props.isSmallScreenWidth ? styles.mb5 : null]}>
{isArchivedRoom && (
<ArchivedReportFooter
report={this.props.report}
/>
)}
{!this.props.isSmallScreenWidth && (
<View style={styles.offlineIndicatorRow}>
{hideComposer && (
<OfflineIndicator containerStyles={[styles.chatItemComposeSecondaryRow]} />
)}
</View>
)}
</View>
)}
{(!hideComposer && this.props.shouldShowComposeInput) && (
<View style={[this.getChatFooterStyles(), this.props.isComposerFullSize && styles.chatFooterFullCompose]}>
<SwipeableView onSwipeDown={Keyboard.dismiss}>
<OfflineWithFeedback
pendingAction={this.props.pendingAction}
style={this.props.isComposerFullSize ? styles.chatItemFullComposeRow : {}}
contentContainerStyle={this.props.isComposerFullSize ? styles.flex1 : {}}
>
<ReportActionCompose
onSubmit={this.props.onSubmitComment}
reportID={this.props.report.reportID.toString()}
reportActions={this.props.reportActions}
report={this.props.report}
isComposerFullSize={this.props.isComposerFullSize}
disabled={this.props.shouldDisableCompose}
/>
</OfflineWithFeedback>
</SwipeableView>
</View>
)}
</>
);
}
}
ReportFooter.propTypes = propTypes;
ReportFooter.defaultProps = defaultProps;
export default compose(
withWindowDimensions,
withOnyx({
shouldShowComposeInput: {key: ONYXKEYS.SHOULD_SHOW_COMPOSE_INPUT},
}),
)(ReportFooter);