saleor-dashboard/src/customers/components/CustomerDetailsPage/CustomerDetailsPage.stories.tsx

116 lines
2.7 KiB
TypeScript
Raw Normal View History

import { AccountErrorCode } from "@dashboard/graphql";
import Decorator from "@dashboard/storybook/Decorator";
import { MockedUserProvider } from "@dashboard/storybook/MockedUserProvider";
2019-06-19 14:40:52 +00:00
import { storiesOf } from "@storybook/react";
2019-08-09 10:26:22 +00:00
import React from "react";
2019-06-19 14:40:52 +00:00
2023-01-05 12:34:34 +00:00
import { customer } from "../../fixtures";
import CustomerDetailsPageComponent, {
CustomerDetailsPageProps,
2023-01-05 12:34:34 +00:00
} from "./CustomerDetailsPage";
2019-06-19 14:40:52 +00:00
const props: Omit<CustomerDetailsPageProps, "classes"> = {
customerId: "123",
2019-06-19 14:40:52 +00:00
customer,
disabled: false,
errors: [],
onDelete: () => undefined,
onSubmit: () => undefined,
saveButtonBar: "default",
2019-06-19 14:40:52 +00:00
};
interface CustomerDetailsPageErrors {
firstName: string;
email: string;
lastName: string;
note: string;
}
const CustomerDetailsPage = props => (
<MockedUserProvider>
<CustomerDetailsPageComponent {...props} />
</MockedUserProvider>
);
2023-01-05 12:34:34 +00:00
storiesOf("Customers / Customer details", module)
2019-06-19 14:40:52 +00:00
.addDecorator(Decorator)
.add("default", () => <CustomerDetailsPage {...props} />)
.add("loading", () => (
<CustomerDetailsPage {...props} customer={undefined} disabled={true} />
))
.add("form errors", () => (
<CustomerDetailsPage
{...props}
errors={(["email", "firstName", "lastName"] as Array<
keyof CustomerDetailsPageErrors
2020-03-11 09:55:14 +00:00
>).map(field => ({
__typename: "AccountError",
code: AccountErrorCode.INVALID,
field,
addressType: null,
message: "Account invalid",
2020-03-11 09:55:14 +00:00
}))}
2019-06-19 14:40:52 +00:00
/>
))
.add("different addresses", () => (
<CustomerDetailsPage
{...props}
customer={{
...customer,
defaultBillingAddress: {
...customer.defaultBillingAddress,
id: "AvSduf72=",
},
2019-06-19 14:40:52 +00:00
}}
/>
))
.add("never logged", () => (
<CustomerDetailsPage
{...props}
customer={{
...customer,
lastLogin: null,
2019-06-19 14:40:52 +00:00
}}
/>
))
.add("never placed order", () => (
<CustomerDetailsPage
{...props}
customer={{
...customer,
lastPlacedOrder: {
...customer.lastPlacedOrder,
edges: [],
},
2019-06-19 14:40:52 +00:00
}}
/>
))
.add("no default billing address", () => (
<CustomerDetailsPage
{...props}
customer={{
...customer,
defaultBillingAddress: null,
2019-06-19 14:40:52 +00:00
}}
/>
))
.add("no default shipping address", () => (
<CustomerDetailsPage
{...props}
customer={{
...customer,
defaultShippingAddress: null,
2019-06-19 14:40:52 +00:00
}}
/>
))
.add("no address at all", () => (
<CustomerDetailsPage
{...props}
customer={{
...customer,
defaultBillingAddress: null,
defaultShippingAddress: null,
2019-06-19 14:40:52 +00:00
}}
/>
));