forked from RocketChat/Rocket.Chat
-
Notifications
You must be signed in to change notification settings - Fork 1
/
AdministrationModelList.tsx
87 lines (78 loc) · 2.44 KB
/
AdministrationModelList.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
import { OptionTitle } from '@rocket.chat/fuselage';
import { useTranslation, useRoute } from '@rocket.chat/ui-contexts';
import { FlowRouter } from 'meteor/kadira:flow-router';
import type { FC } from 'react';
import React from 'react';
import { userHasAllPermission } from '../../../app/authorization/client';
import type { AccountBoxItem } from '../../../app/ui-utils/client/lib/AccountBox';
import { getUpgradeTabLabel, isFullyFeature } from '../../../lib/upgradeTab';
import { useUpgradeTabParams } from '../../views/hooks/useUpgradeTabParams';
import Emoji from '../Emoji';
import ListItem from '../Sidebar/ListItem';
type AdministrationModelListProps = {
accountBoxItems: AccountBoxItem[];
showWorkspace: boolean;
onDismiss: () => void;
};
const INFO_PERMISSIONS = ['view-statistics'];
const AdministrationModelList: FC<AdministrationModelListProps> = ({ accountBoxItems, showWorkspace, onDismiss }) => {
const t = useTranslation();
const { tabType, trialEndDate, isLoading } = useUpgradeTabParams();
const shouldShowEmoji = isFullyFeature(tabType);
const label = getUpgradeTabLabel(tabType);
const hasInfoPermission = userHasAllPermission(INFO_PERMISSIONS);
const infoRoute = useRoute('admin-info');
const adminRoute = useRoute('admin-index');
const upgradeRoute = useRoute('upgrade');
const showUpgradeItem = !isLoading && tabType;
return (
<>
<OptionTitle>{t('Administration')}</OptionTitle>
<ul>
{showUpgradeItem && (
<ListItem
icon='arrow-stack-up'
text={
<>
{t(label)} {shouldShowEmoji && <Emoji emojiHandle=':zap:' />}
</>
}
action={(): void => {
upgradeRoute.push({ type: tabType }, trialEndDate ? { trialEndDate } : undefined);
onDismiss();
}}
/>
)}
{showWorkspace && (
<ListItem
icon='cog'
text={t('Workspace')}
action={(): void => {
if (hasInfoPermission) {
infoRoute.push();
onDismiss();
return;
}
adminRoute.push({ context: '/' });
onDismiss();
}}
/>
)}
{accountBoxItems.length > 0 && (
<>
{accountBoxItems.map((item, key) => {
const action = (): void => {
if (item.href) {
FlowRouter.go(item.href);
}
onDismiss();
};
return <ListItem text={t(item.name)} icon={item.icon} action={action} key={item.name + key} />;
})}
</>
)}
</ul>
</>
);
};
export default AdministrationModelList;