saleor-dashboard/src/storybook/stories/home/HomePage.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.5 KiB
TypeScript

import placeholderImage from "@assets/images/placeholder60x60.png";
import { adminUserPermissions } from "@saleor/fixtures";
import { PermissionEnum } from "@saleor/types/globalTypes";
import { mapEdgesToItems } from "@saleor/utils/maps";
import { storiesOf } from "@storybook/react";
import React from "react";
import HomePageComponent, {
HomePageProps
} from "../../../home/components/HomePage";
import { shop as shopFixture } from "../../../home/fixtures";
import Decorator from "../../Decorator";
import { MockedUserProvider } from "../customers/MockedUserProvider";
const shop = shopFixture(placeholderImage);
const homePageProps: Omit<HomePageProps, "classes"> = {
activities: mapEdgesToItems(shop.activities),
noChannel: false,
onCreateNewChannelClick: () => undefined,
onOrdersToCaptureClick: () => undefined,
onOrdersToFulfillClick: () => undefined,
onProductClick: () => undefined,
onProductsOutOfStockClick: () => undefined,
orders: shop.ordersToday.totalCount,
ordersToCapture: shop.ordersToCapture.totalCount,
ordersToFulfill: shop.ordersToFulfill.totalCount,
productsOutOfStock: shop.productsOutOfStock.totalCount,
sales: shop.salesToday.gross,
topProducts: mapEdgesToItems(shop.productTopToday),
userName: "admin@example.com"
};
const HomePage = props => {
const customPermissions = props?.customPermissions;
return (
<MockedUserProvider customPermissions={customPermissions}>
<HomePageComponent {...props} />
</MockedUserProvider>
);
};
storiesOf("Views / HomePage", module)
.addDecorator(Decorator)
.add("default", () => <HomePage {...homePageProps} />)
.add("loading", () => (
<HomePage
{...homePageProps}
activities={undefined}
orders={undefined}
ordersToCapture={undefined}
ordersToFulfill={undefined}
productsOutOfStock={undefined}
sales={undefined}
topProducts={undefined}
userName={undefined}
/>
))
.add("no data", () => (
<HomePage {...homePageProps} topProducts={[]} activities={[]} />
))
.add("no permissions", () => (
<HomePage {...homePageProps} customPermissions={[]} />
))
.add("product permissions", () => (
<HomePage
{...homePageProps}
customPermissions={adminUserPermissions.filter(
perm => perm.code === PermissionEnum.MANAGE_PRODUCTS
)}
/>
))
.add("order permissions", () => (
<HomePage
{...homePageProps}
customPermissions={adminUserPermissions.filter(
perm => perm.code === PermissionEnum.MANAGE_ORDERS
)}
/>
));