Add upgrade plan

Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
soupette 2020-07-01 18:17:35 +02:00 committed by Alexandre Bodin
parent 5bbdccc9d2
commit cc8944c20f
3 changed files with 43 additions and 6 deletions

View File

@ -65,7 +65,7 @@ const UpgradePlanModal = ({ isOpen, onToggle }) => {
}; };
UpgradePlanModal.defaultProps = { UpgradePlanModal.defaultProps = {
isOpen: true, isOpen: false,
onToggle: () => {}, onToggle: () => {},
}; };

View File

@ -1,10 +1,12 @@
import React, { useEffect } from 'react'; import React, { useCallback, useEffect, useState } from 'react';
import { List, Header } from '@buffetjs/custom'; import { List, Header } from '@buffetjs/custom';
import { Pencil } from '@buffetjs/icons'; import { Button } from '@buffetjs/core';
import { Duplicate, Pencil, Plus } from '@buffetjs/icons';
import matchSorter from 'match-sorter'; import matchSorter from 'match-sorter';
import { useIntl } from 'react-intl'; import { useIntl } from 'react-intl';
import { useHistory } from 'react-router-dom'; import { useHistory } from 'react-router-dom';
import { useGlobalContext, useQuery, useUserPermissions } from 'strapi-helper-plugin'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { ListButton, useGlobalContext, useQuery, useUserPermissions } from 'strapi-helper-plugin';
import adminPermissions from '../../../permissions'; import adminPermissions from '../../../permissions';
import PageTitle from '../../../components/SettingsPageTitle'; import PageTitle from '../../../components/SettingsPageTitle';
import { EmptyRole, RoleListWrapper, RoleRow } from '../../../components/Roles'; import { EmptyRole, RoleListWrapper, RoleRow } from '../../../components/Roles';
@ -15,6 +17,7 @@ import BaselineAlignment from './BaselineAlignment';
const RoleListPage = () => { const RoleListPage = () => {
const { formatMessage } = useIntl(); const { formatMessage } = useIntl();
const { push } = useHistory(); const { push } = useHistory();
const [isOpen, setIsOpen] = useState(false);
const { settingsBaseURL } = useGlobalContext(); const { settingsBaseURL } = useGlobalContext();
const { roles, isLoading } = useRolesList(); const { roles, isLoading } = useRolesList();
const { toggleHeaderSearch } = useSettingsHeaderSearchContext(); const { toggleHeaderSearch } = useSettingsHeaderSearchContext();
@ -34,6 +37,21 @@ const RoleListPage = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, []); }, []);
const handleToggle = useCallback(() => setIsOpen(prev => !prev), []);
const headerActions = [
{
label: formatMessage({
id: 'Settings.roles.list.button.add',
defaultMessage: 'Add new role',
}),
onClick: handleToggle,
color: 'primary',
type: 'button',
icon: true,
},
];
const resultsCount = results.length; const resultsCount = results.length;
return ( return (
@ -53,6 +71,7 @@ const RoleListPage = () => {
})} })}
// Show a loader in the header while requesting data // Show a loader in the header while requesting data
isLoading={isLoading} isLoading={isLoading}
actions={headerActions}
/> />
<BaselineAlignment /> <BaselineAlignment />
<RoleListWrapper> <RoleListWrapper>
@ -69,18 +88,36 @@ const RoleListPage = () => {
<RoleRow <RoleRow
canUpdate={canUpdate} canUpdate={canUpdate}
links={[ links={[
{
icon: <Duplicate fill="#0e1622" />,
onClick: handleToggle,
},
{ {
icon: canUpdate ? <Pencil fill="#0e1622" /> : null, icon: canUpdate ? <Pencil fill="#0e1622" /> : null,
onClick: () => push(`${settingsBaseURL}/roles/${role.id}`), onClick: () => push(`${settingsBaseURL}/roles/${role.id}`),
}, },
{
icon: <FontAwesomeIcon icon="trash-alt" />,
onClick: handleToggle,
},
]} ]}
role={role} role={role}
/> />
)} )}
/> />
{!resultsCount && !isLoading && <EmptyRole />} {!resultsCount && !isLoading && <EmptyRole />}
<ListButton>
<Button
onClick={handleToggle}
icon={<Plus fill="#007eff" width="11px" height="11px" />}
label={formatMessage({
id: 'Settings.roles.list.button.add',
defaultMessage: 'Add new role',
})}
/>
</ListButton>
</RoleListWrapper> </RoleListWrapper>
<UpgradePlanModal /> <UpgradePlanModal isOpen={isOpen} onToggle={handleToggle} />
</> </>
); );
}; };

View File

@ -4,4 +4,4 @@ const fs = require('fs-extra');
const path = require('path'); const path = require('path');
const appAdminPath = path.join(__dirname, 'admin'); const appAdminPath = path.join(__dirname, 'admin');
module.exports = fs.existsSync(path.join(appAdminPath, 'eee')); module.exports = fs.existsSync(path.join(appAdminPath, 'ee'));