-
Notifications
You must be signed in to change notification settings - Fork 3k
/
ReportFooter.js
106 lines (93 loc) · 4.39 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
import React from 'react';
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 AnonymousReportFooter from '../../../components/AnonymousReportFooter';
import SwipeableView from '../../../components/SwipeableView';
import OfflineIndicator from '../../../components/OfflineIndicator';
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 variables from '../../../styles/variables';
import reportActionPropTypes from './reportActionPropTypes';
import reportPropTypes from '../../reportPropTypes';
import * as ReportUtils from '../../../libs/ReportUtils';
import * as Session from '../../../libs/actions/Session';
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,
/** 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: () => {},
pendingAction: null,
shouldShowComposeInput: true,
shouldDisableCompose: false,
};
function ReportFooter(props) {
const chatFooterStyles = {...styles.chatFooter, minHeight: !props.isOffline ? CONST.CHAT_FOOTER_MIN_HEIGHT : 0};
const isArchivedRoom = ReportUtils.isArchivedRoom(props.report);
const isAnonymousUser = Session.isAnonymousUser();
const isSmallSizeLayout = props.windowWidth - (props.isSmallScreenWidth ? 0 : variables.sideBarWidth) < variables.anonymousReportFooterBreakpoint;
const hideComposer = ReportUtils.shouldHideComposer(props.report);
return (
<>
{hideComposer && (
<View style={[styles.chatFooter, isArchivedRoom || isAnonymousUser ? styles.mt4 : {}, props.isSmallScreenWidth ? styles.mb5 : null]}>
{isAnonymousUser && !isArchivedRoom && (
<AnonymousReportFooter
report={props.report}
isSmallSizeLayout={isSmallSizeLayout}
/>
)}
{isArchivedRoom && <ArchivedReportFooter report={props.report} />}
{!props.isSmallScreenWidth && (
<View style={styles.offlineIndicatorRow}>{hideComposer && <OfflineIndicator containerStyles={[styles.chatItemComposeSecondaryRow]} />}</View>
)}
</View>
)}
{!hideComposer && (props.shouldShowComposeInput || !props.isSmallScreenWidth) && (
<View style={[chatFooterStyles, props.isComposerFullSize && styles.chatFooterFullCompose]}>
<SwipeableView onSwipeDown={Keyboard.dismiss}>
<ReportActionCompose
onSubmit={props.onSubmitComment}
reportID={props.report.reportID.toString()}
reportActions={props.reportActions}
report={props.report}
pendingAction={props.pendingAction}
isComposerFullSize={props.isComposerFullSize}
disabled={props.shouldDisableCompose}
/>
</SwipeableView>
</View>
)}
</>
);
}
ReportFooter.displayName = 'ReportFooter';
ReportFooter.propTypes = propTypes;
ReportFooter.defaultProps = defaultProps;
export default compose(
withWindowDimensions,
withOnyx({
shouldShowComposeInput: {key: ONYXKEYS.SHOULD_SHOW_COMPOSE_INPUT},
}),
)(ReportFooter);