saleor-dashboard/src/components/ChannelsAvailabilityCard/ChannelsAvailabilityCardWrapper.tsx
Wojciech Mista 9a7c9a3bc3
Add permission-based restrictions in Customer views (#1879)
* Update customer queries - add permissions

* Filter the customer filter by permissions

* Code refactor + optionally render components based on permissions

* Update stories

* Minor code refactor

* Move useUserPermissions to RequirePermissions component

* Change user provider component name

* Change macaw-ui version
2022-03-01 09:38:23 +01:00

81 lines
2.3 KiB
TypeScript

import { Card, CardContent, Typography } from "@material-ui/core";
import CardTitle from "@saleor/components/CardTitle";
import Hr from "@saleor/components/Hr";
import RequirePermissions from "@saleor/components/RequirePermissions";
import { Button } from "@saleor/macaw-ui";
import { PermissionEnum } from "@saleor/types/globalTypes";
import React from "react";
import { useIntl } from "react-intl";
import { useStyles } from "./styles";
export interface ChannelsAvailabilityWrapperProps {
selectedChannelsCount: number;
allChannelsCount: number;
children: React.ReactNode;
managePermissions: PermissionEnum[];
openModal: () => void;
}
export const ChannelsAvailabilityWrapper: React.FC<ChannelsAvailabilityWrapperProps> = props => {
const {
selectedChannelsCount,
allChannelsCount,
children,
managePermissions,
openModal
} = props;
const intl = useIntl();
const classes = useStyles({});
const channelsAvailabilityText = intl.formatMessage(
{
defaultMessage:
"Available at {selectedChannelsCount} out of {allChannelsCount, plural, one {# channel} other {# channels}}",
description: "channels availability text"
},
{
allChannelsCount,
selectedChannelsCount
}
);
return (
<>
<Card>
<CardTitle
title={intl.formatMessage({
defaultMessage: "Availability",
description: "section header"
})}
toolbar={
<RequirePermissions requiredPermissions={managePermissions}>
<Button
onClick={openModal}
data-test-id="channels-availability-manage-button"
>
{intl.formatMessage({
defaultMessage: "Manage",
description: "section header button"
})}
</Button>
</RequirePermissions>
}
/>
<CardContent className={classes.card}>
{!!channelsAvailabilityText && (
<>
<Typography className={classes.channelInfo}>
{channelsAvailabilityText}
</Typography>
<Hr className={classes.hr} />
</>
)}
{children}
</CardContent>
</Card>
</>
);
};
export default ChannelsAvailabilityWrapper;