2021-05-14 08:15:15 +00:00
|
|
|
import { Card, CardContent, Typography } from "@material-ui/core";
|
2020-05-14 09:30:32 +00:00
|
|
|
import { IconProps } from "@material-ui/core/Icon";
|
2020-07-07 10:14:12 +00:00
|
|
|
import { User } from "@saleor/fragments/types/User";
|
2020-05-14 09:30:32 +00:00
|
|
|
import { sectionNames } from "@saleor/intl";
|
2021-03-30 07:40:18 +00:00
|
|
|
import { makeStyles } from "@saleor/theme";
|
2019-08-09 10:26:22 +00:00
|
|
|
import React from "react";
|
2019-08-26 12:56:31 +00:00
|
|
|
import { useIntl } from "react-intl";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2019-09-12 14:38:40 +00:00
|
|
|
import { hasPermission } from "../auth/misc";
|
2019-06-19 14:40:52 +00:00
|
|
|
import Container from "../components/Container";
|
|
|
|
import PageHeader from "../components/PageHeader";
|
|
|
|
import { PermissionEnum } from "../types/globalTypes";
|
|
|
|
|
|
|
|
export interface MenuItem {
|
2019-09-16 11:43:02 +00:00
|
|
|
description: string;
|
|
|
|
icon: React.ReactElement<IconProps>;
|
|
|
|
permission: PermissionEnum;
|
|
|
|
title: string;
|
|
|
|
url?: string;
|
2021-03-26 09:33:35 +00:00
|
|
|
testId?: string;
|
2019-09-16 11:43:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface MenuSection {
|
2019-09-12 14:38:40 +00:00
|
|
|
label: string;
|
2019-09-16 11:43:02 +00:00
|
|
|
menuItems: MenuItem[];
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
|
|
|
|
2019-12-03 15:28:40 +00:00
|
|
|
const useStyles = makeStyles(
|
|
|
|
theme => ({
|
|
|
|
card: {
|
|
|
|
"&:hover": {
|
|
|
|
boxShadow: "0px 5px 15px rgba(0, 0, 0, 0.15);"
|
|
|
|
},
|
|
|
|
cursor: "pointer",
|
|
|
|
marginBottom: theme.spacing(3),
|
|
|
|
transition: theme.transitions.duration.standard + "ms"
|
2019-06-19 14:40:52 +00:00
|
|
|
},
|
2019-12-03 15:28:40 +00:00
|
|
|
cardContent: {
|
|
|
|
// Overrides Material-UI default theme
|
|
|
|
"&:last-child": {
|
|
|
|
paddingBottom: 16
|
|
|
|
},
|
|
|
|
display: "grid",
|
|
|
|
gridColumnGap: theme.spacing(4),
|
|
|
|
gridTemplateColumns: "48px 1fr"
|
2019-06-19 14:40:52 +00:00
|
|
|
},
|
2019-12-03 15:28:40 +00:00
|
|
|
cardDisabled: {
|
|
|
|
"& $icon, & $sectionTitle, & $sectionDescription": {
|
|
|
|
color: theme.palette.text.disabled
|
|
|
|
},
|
|
|
|
marginBottom: theme.spacing(3)
|
2019-06-19 14:40:52 +00:00
|
|
|
},
|
2019-12-03 15:28:40 +00:00
|
|
|
configurationCategory: {
|
|
|
|
[theme.breakpoints.down("md")]: {
|
|
|
|
gridTemplateColumns: "1fr"
|
|
|
|
},
|
|
|
|
borderTop: `solid 1px ${theme.palette.divider}`,
|
|
|
|
display: "grid",
|
|
|
|
gridColumnGap: theme.spacing(4) + "px",
|
|
|
|
gridTemplateColumns: "1fr 3fr",
|
|
|
|
paddingTop: theme.spacing(3)
|
2019-09-03 08:58:58 +00:00
|
|
|
},
|
2019-12-03 15:28:40 +00:00
|
|
|
configurationItem: {
|
|
|
|
[theme.breakpoints.down("md")]: {
|
|
|
|
gridTemplateColumns: "1fr"
|
|
|
|
},
|
|
|
|
display: "grid",
|
|
|
|
gridColumnGap: theme.spacing(4),
|
|
|
|
gridTemplateColumns: "1fr 1fr"
|
2019-11-04 19:32:57 +00:00
|
|
|
},
|
2019-12-03 15:28:40 +00:00
|
|
|
configurationLabel: {
|
|
|
|
paddingBottom: 20
|
|
|
|
},
|
|
|
|
header: {
|
|
|
|
margin: 0
|
|
|
|
},
|
|
|
|
icon: {
|
2020-05-12 01:20:21 +00:00
|
|
|
"& path": {
|
|
|
|
fill: theme.palette.primary.main
|
|
|
|
},
|
|
|
|
fontSize: 48
|
2019-12-03 15:28:40 +00:00
|
|
|
},
|
|
|
|
sectionDescription: {},
|
|
|
|
sectionTitle: {
|
|
|
|
fontSize: 20,
|
|
|
|
fontWeight: 600 as 600
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
{ name: "ConfigurationPage" }
|
|
|
|
);
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2019-08-26 12:56:31 +00:00
|
|
|
export interface ConfigurationPageProps {
|
2019-09-16 11:43:02 +00:00
|
|
|
menu: MenuSection[];
|
2019-06-19 14:40:52 +00:00
|
|
|
user: User;
|
|
|
|
onSectionClick: (sectionName: string) => void;
|
|
|
|
}
|
|
|
|
|
2019-10-30 14:34:24 +00:00
|
|
|
export const ConfigurationPage: React.FC<ConfigurationPageProps> = props => {
|
|
|
|
const { menu: menus, user, onSectionClick } = props;
|
|
|
|
const classes = useStyles(props);
|
|
|
|
|
|
|
|
const intl = useIntl();
|
|
|
|
return (
|
|
|
|
<Container>
|
|
|
|
<PageHeader
|
|
|
|
className={classes.header}
|
|
|
|
title={intl.formatMessage(sectionNames.configuration)}
|
|
|
|
/>
|
|
|
|
{menus
|
|
|
|
.filter(menu =>
|
|
|
|
menu.menuItems.some(menuItem =>
|
|
|
|
hasPermission(menuItem.permission, user)
|
2019-09-12 14:38:40 +00:00
|
|
|
)
|
2019-10-30 14:34:24 +00:00
|
|
|
)
|
|
|
|
.map((menu, menuIndex) => (
|
|
|
|
<div className={classes.configurationCategory} key={menuIndex}>
|
|
|
|
<div className={classes.configurationLabel}>
|
|
|
|
<Typography>{menu.label}</Typography>
|
2019-09-12 14:38:40 +00:00
|
|
|
</div>
|
2019-10-30 14:34:24 +00:00
|
|
|
<div className={classes.configurationItem}>
|
|
|
|
{menu.menuItems
|
|
|
|
.filter(menuItem => hasPermission(menuItem.permission, user))
|
|
|
|
.map((item, itemIndex) => (
|
|
|
|
<Card
|
|
|
|
className={item.url ? classes.card : classes.cardDisabled}
|
|
|
|
onClick={() => onSectionClick(item.url)}
|
|
|
|
key={itemIndex}
|
2020-07-20 09:42:44 +00:00
|
|
|
data-test="settingsSubsection"
|
2020-09-25 14:45:27 +00:00
|
|
|
data-testid={item.title.toLowerCase()}
|
2021-03-26 09:33:35 +00:00
|
|
|
data-test-id={item.testId}
|
2019-10-30 14:34:24 +00:00
|
|
|
>
|
|
|
|
<CardContent className={classes.cardContent}>
|
|
|
|
<div className={classes.icon}>{item.icon}</div>
|
|
|
|
<div>
|
|
|
|
<Typography
|
|
|
|
className={classes.sectionTitle}
|
|
|
|
color="primary"
|
|
|
|
>
|
|
|
|
{item.title}
|
|
|
|
</Typography>
|
|
|
|
<Typography className={classes.sectionDescription}>
|
|
|
|
{item.description}
|
|
|
|
</Typography>
|
|
|
|
</div>
|
|
|
|
</CardContent>
|
|
|
|
</Card>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
};
|
2019-06-19 14:40:52 +00:00
|
|
|
ConfigurationPage.displayName = "ConfigurationPage";
|
|
|
|
export default ConfigurationPage;
|