-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
PrivateNotesListPage.tsx
117 lines (108 loc) · 4.85 KB
/
PrivateNotesListPage.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
111
112
113
114
115
116
117
import React, {useCallback, useMemo} from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import {AttachmentContext} from '@components/AttachmentContext';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import ScreenWrapper from '@components/ScreenWrapper';
import ScrollView from '@components/ScrollView';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import type {WithReportAndPrivateNotesOrNotFoundProps} from '@pages/home/report/withReportAndPrivateNotesOrNotFound';
import withReportAndPrivateNotesOrNotFound from '@pages/home/report/withReportAndPrivateNotesOrNotFound';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {PersonalDetailsList, Report} from '@src/types/onyx';
type PrivateNotesListPageOnyxProps = {
/** All of the personal details for everyone */
personalDetailsList: OnyxEntry<PersonalDetailsList>;
};
type PrivateNotesListPageProps = WithReportAndPrivateNotesOrNotFoundProps &
PrivateNotesListPageOnyxProps & {
/** The report currently being looked at */
report: Report;
};
type NoteListItem = {
title: string;
action: () => void;
brickRoadIndicator: ValueOf<typeof CONST.BRICK_ROAD_INDICATOR_STATUS> | undefined;
note: string;
disabled: boolean;
reportID: string;
accountID: string;
};
function PrivateNotesListPage({report, personalDetailsList, session}: PrivateNotesListPageProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const getAttachmentValue = useCallback((item: NoteListItem) => ({reportID: item.reportID, accountID: Number(item.accountID), type: CONST.ATTACHMENT_TYPE.NOTE}), []);
/**
* Gets the menu item for each workspace
*/
function getMenuItem(item: NoteListItem) {
return (
<AttachmentContext.Provider value={getAttachmentValue(item)}>
<MenuItemWithTopDescription
key={item.title}
description={item.title}
title={item.note}
onPress={item.action}
shouldShowRightIcon={!item.disabled}
numberOfLinesTitle={0}
shouldRenderAsHTML
brickRoadIndicator={item.brickRoadIndicator}
disabled={item.disabled}
shouldGreyOutWhenDisabled={false}
/>
</AttachmentContext.Provider>
);
}
/**
* Returns a list of private notes on the given chat report
*/
const privateNotes = useMemo(() => {
const privateNoteBrickRoadIndicator = (accountID: number) => (report.privateNotes?.[accountID].errors ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined);
return Object.keys(report.privateNotes ?? {}).map((accountID: string) => {
const privateNote = report.privateNotes?.[Number(accountID)];
return {
reportID: report.reportID,
accountID,
title: Number(session?.accountID) === Number(accountID) ? translate('privateNotes.myNote') : personalDetailsList?.[accountID]?.login ?? '',
action: () => Navigation.navigate(ROUTES.PRIVATE_NOTES_EDIT.getRoute(report.reportID, accountID)),
brickRoadIndicator: privateNoteBrickRoadIndicator(Number(accountID)),
note: privateNote?.note ?? '',
disabled: Number(session?.accountID) !== Number(accountID),
};
});
}, [report, personalDetailsList, session, translate]);
return (
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
testID={PrivateNotesListPage.displayName}
>
<HeaderWithBackButton
title={translate('privateNotes.title')}
shouldShowBackButton
onCloseButtonPress={() => Navigation.dismissModal()}
/>
<Text style={[styles.mb5, styles.ph5]}>{translate('privateNotes.personalNoteMessage')}</Text>
<ScrollView
contentContainerStyle={styles.flexGrow1}
bounces={false}
>
{privateNotes.map((item) => getMenuItem(item))}
</ScrollView>
</ScreenWrapper>
);
}
PrivateNotesListPage.displayName = 'PrivateNotesListPage';
export default withReportAndPrivateNotesOrNotFound('privateNotes.title')(
withOnyx<PrivateNotesListPageProps, PrivateNotesListPageOnyxProps>({
personalDetailsList: {
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
},
})(PrivateNotesListPage),
);