-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
ReportActionItemParentAction.tsx
110 lines (100 loc) · 5.21 KB
/
ReportActionItemParentAction.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
103
104
105
106
107
108
109
110
import React, {useEffect, useRef, useState} from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import Navigation from '@libs/Navigation/Navigation';
import onyxSubscribe from '@libs/onyxSubscribe';
import * as ReportUtils from '@libs/ReportUtils';
import * as Report from '@userActions/Report';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type * as OnyxTypes from '@src/types/onyx';
import AnimatedEmptyStateBackground from './AnimatedEmptyStateBackground';
import ReportActionItem from './ReportActionItem';
type ReportActionItemParentActionOnyxProps = {
/** The current report is displayed */
report: OnyxEntry<OnyxTypes.Report>;
};
type ReportActionItemParentActionProps = ReportActionItemParentActionOnyxProps & {
/** Flag to show, hide the thread divider line */
shouldHideThreadDividerLine?: boolean;
/** Position index of the report parent action in the overall report FlatList view */
index: number;
/** The id of the report */
// eslint-disable-next-line react/no-unused-prop-types
reportID: string;
};
function ReportActionItemParentAction({report, index = 0, shouldHideThreadDividerLine = false}: ReportActionItemParentActionProps) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {isSmallScreenWidth} = useWindowDimensions();
const ancestorIDs = useRef(ReportUtils.getAllAncestorReportActionIDs(report));
const [allAncestors, setAllAncestors] = useState<ReportUtils.Ancestor[]>([]);
useEffect(() => {
const unsubscribeReports: Array<() => void> = [];
const unsubscribeReportActions: Array<() => void> = [];
ancestorIDs.current.reportIDs.forEach((ancestorReportID) => {
unsubscribeReports.push(
onyxSubscribe({
key: `${ONYXKEYS.COLLECTION.REPORT}${ancestorReportID}`,
callback: () => {
setAllAncestors(ReportUtils.getAllAncestorReportActions(report, shouldHideThreadDividerLine));
},
}),
);
unsubscribeReportActions.push(
onyxSubscribe({
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${ancestorReportID}`,
callback: () => {
setAllAncestors(ReportUtils.getAllAncestorReportActions(report, shouldHideThreadDividerLine));
},
}),
);
});
return () => {
unsubscribeReports.forEach((unsubscribeReport) => unsubscribeReport());
unsubscribeReportActions.forEach((unsubscribeReportAction) => unsubscribeReportAction());
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return (
<>
<View style={[StyleUtils.getReportWelcomeContainerStyle(isSmallScreenWidth), styles.justifyContentEnd]}>
<AnimatedEmptyStateBackground />
<View style={[styles.p5, StyleUtils.getReportWelcomeTopMarginStyle(isSmallScreenWidth)]} />
{allAncestors.map((ancestor) => (
<OfflineWithFeedback
key={ancestor.reportAction.reportActionID}
shouldDisableOpacity={Boolean(ancestor.reportAction?.pendingAction)}
pendingAction={ancestor.report?.pendingFields?.addWorkspaceRoom ?? ancestor.report?.pendingFields?.createChat}
errors={ancestor.report?.errorFields?.addWorkspaceRoom ?? ancestor.report?.errorFields?.createChat}
errorRowStyles={[styles.ml10, styles.mr2]}
onClose={() => Report.navigateToConciergeChatAndDeleteReport(ancestor.report.reportID)}
>
<ReportActionItem
// @ts-expect-error TODO: Remove this once ReportActionItem (https://github.com/Expensify/App/issues/31982) is migrated to TypeScript.
onPress={() => Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(ancestor.report.reportID))}
report={ancestor.report}
action={ancestor.reportAction}
displayAsGroup={false}
isMostRecentIOUReportAction={false}
shouldDisplayNewMarker={ancestor.shouldDisplayNewMarker}
index={index}
/>
{!ancestor.shouldHideThreadDividerLine && <View style={[styles.threadDividerLine]} />}
</OfflineWithFeedback>
))}
</View>
</>
);
}
ReportActionItemParentAction.displayName = 'ReportActionItemParentAction';
export default withOnyx<ReportActionItemParentActionProps, ReportActionItemParentActionOnyxProps>({
report: {
key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
},
})(ReportActionItemParentAction);