-
Notifications
You must be signed in to change notification settings - Fork 3k
/
SystemChatReportFooterMessage.tsx
91 lines (80 loc) · 3.66 KB
/
SystemChatReportFooterMessage.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
import React, {useMemo} from 'react';
import {withOnyx} from 'react-native-onyx';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import Banner from '@components/Banner';
import * as Expensicons from '@components/Icon/Expensicons';
import Text from '@components/Text';
import TextLink from '@components/TextLink';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import * as PolicyUtils from '@libs/PolicyUtils';
import * as ReportUtils from '@libs/ReportUtils';
import Navigation from '@navigation/Navigation';
import * as ReportInstance from '@userActions/Report';
import type {OnboardingPurposeType} from '@src/CONST';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {Policy as PolicyType} from '@src/types/onyx';
type SystemChatReportFooterMessageOnyxProps = {
/** Saved onboarding purpose selected by the user */
choice: OnyxEntry<OnboardingPurposeType>;
/** The list of this user's policies */
policies: OnyxCollection<PolicyType>;
/** policyID for main workspace */
activePolicyID: OnyxEntry<Required<string>>;
};
type SystemChatReportFooterMessageProps = SystemChatReportFooterMessageOnyxProps;
function SystemChatReportFooterMessage({choice, policies, activePolicyID}: SystemChatReportFooterMessageProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const adminChatReport = useMemo(() => {
const adminPolicy = activePolicyID
? PolicyUtils.getPolicy(activePolicyID ?? '')
: Object.values(policies ?? {}).find((policy) => PolicyUtils.shouldShowPolicy(policy, false) && policy?.role === CONST.POLICY.ROLE.ADMIN && policy?.chatReportIDAdmins);
return ReportUtils.getReport(String(adminPolicy?.chatReportIDAdmins));
}, [activePolicyID, policies]);
const content = useMemo(() => {
switch (choice) {
case CONST.ONBOARDING_CHOICES.MANAGE_TEAM:
return (
<>
{translate('systemChatFooterMessage.newDotManageTeam.phrase1')}
<TextLink onPress={() => Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(adminChatReport?.reportID ?? ''))}>
{adminChatReport?.reportName ?? CONST.REPORT.WORKSPACE_CHAT_ROOMS.ADMINS}
</TextLink>
{translate('systemChatFooterMessage.newDotManageTeam.phrase2')}
</>
);
default:
return (
<>
{translate('systemChatFooterMessage.default.phrase1')}
<TextLink onPress={() => ReportInstance.navigateToConciergeChat()}>{CONST?.CONCIERGE_CHAT_NAME}</TextLink>
{translate('systemChatFooterMessage.default.phrase2')}
</>
);
}
}, [adminChatReport?.reportName, adminChatReport?.reportID, choice, translate]);
return (
<Banner
containerStyles={[styles.archivedReportFooter]}
shouldShowIcon
icon={Expensicons.Lightbulb}
content={<Text suppressHighlighting>{content}</Text>}
/>
);
}
SystemChatReportFooterMessage.displayName = 'SystemChatReportFooterMessage';
export default withOnyx<SystemChatReportFooterMessageProps, SystemChatReportFooterMessageOnyxProps>({
choice: {
key: ONYXKEYS.ONBOARDING_PURPOSE_SELECTED,
},
policies: {
key: ONYXKEYS.COLLECTION.POLICY,
},
activePolicyID: {
key: ONYXKEYS.NVP_ACTIVE_POLICY_ID,
initialValue: null,
},
})(SystemChatReportFooterMessage);