2022-03-09 08:56:55 +00:00
|
|
|
import { AccountErrorCode } from "@saleor/graphql";
|
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
|
|
|
|
2022-03-01 08:38:23 +00:00
|
|
|
import CustomerDetailsPageComponent, {
|
2019-06-19 14:40:52 +00:00
|
|
|
CustomerDetailsPageProps
|
|
|
|
} from "../../../customers/components/CustomerDetailsPage";
|
|
|
|
import { customer } from "../../../customers/fixtures";
|
|
|
|
import Decorator from "../../Decorator";
|
2022-03-01 08:38:23 +00:00
|
|
|
import { MockedUserProvider } from "./MockedUserProvider";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
|
|
|
const props: Omit<CustomerDetailsPageProps, "classes"> = {
|
2022-05-06 08:59:55 +00:00
|
|
|
customerId: "123",
|
2019-06-19 14:40:52 +00:00
|
|
|
customer,
|
|
|
|
disabled: false,
|
|
|
|
errors: [],
|
|
|
|
onDelete: () => undefined,
|
|
|
|
onSubmit: () => undefined,
|
|
|
|
saveButtonBar: "default"
|
|
|
|
};
|
|
|
|
|
|
|
|
interface CustomerDetailsPageErrors {
|
|
|
|
firstName: string;
|
|
|
|
email: string;
|
|
|
|
lastName: string;
|
|
|
|
note: string;
|
|
|
|
}
|
|
|
|
|
2022-03-01 08:38:23 +00:00
|
|
|
const CustomerDetailsPage = props => (
|
|
|
|
<MockedUserProvider>
|
|
|
|
<CustomerDetailsPageComponent {...props} />
|
|
|
|
</MockedUserProvider>
|
|
|
|
);
|
|
|
|
|
2019-06-19 14:40:52 +00:00
|
|
|
storiesOf("Views / Customers / Customer details", module)
|
|
|
|
.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,
|
2021-05-06 11:38:15 +00:00
|
|
|
field,
|
2022-03-04 10:52:58 +00:00
|
|
|
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="
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
))
|
|
|
|
.add("never logged", () => (
|
|
|
|
<CustomerDetailsPage
|
|
|
|
{...props}
|
|
|
|
customer={{
|
|
|
|
...customer,
|
|
|
|
lastLogin: null
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
))
|
|
|
|
.add("never placed order", () => (
|
|
|
|
<CustomerDetailsPage
|
|
|
|
{...props}
|
|
|
|
customer={{
|
|
|
|
...customer,
|
|
|
|
lastPlacedOrder: {
|
|
|
|
...customer.lastPlacedOrder,
|
|
|
|
edges: []
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
))
|
|
|
|
.add("no default billing address", () => (
|
|
|
|
<CustomerDetailsPage
|
|
|
|
{...props}
|
|
|
|
customer={{
|
|
|
|
...customer,
|
|
|
|
defaultBillingAddress: null
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
))
|
|
|
|
.add("no default shipping address", () => (
|
|
|
|
<CustomerDetailsPage
|
|
|
|
{...props}
|
|
|
|
customer={{
|
|
|
|
...customer,
|
|
|
|
defaultShippingAddress: null
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
))
|
|
|
|
.add("no address at all", () => (
|
|
|
|
<CustomerDetailsPage
|
|
|
|
{...props}
|
|
|
|
customer={{
|
|
|
|
...customer,
|
|
|
|
defaultBillingAddress: null,
|
|
|
|
defaultShippingAddress: null
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
));
|