Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add customer address book view

dominik-zeglen3eb5736bb280
diff --git a/saleor/static/dashboard-next/customers/components/CustomerAddress/CustomerAddress.tsx b/saleor/static/dashboard-next/customers/components/CustomerAddress/CustomerAddress.tsx
new file mode 100644
index 0000000000..0ff4c50fe2
--- /dev/null
+++ b/saleor/static/dashboard-next/customers/components/CustomerAddress/CustomerAddress.tsx
@@ -0,0 +1,120 @@
+import Button from "@material-ui/core/Button";
+import Card from "@material-ui/core/Card";
+import CardActions from "@material-ui/core/CardActions";
+import CardContent from "@material-ui/core/CardContent";
+import {
+ createStyles,
+ Theme,
+ withStyles,
+ WithStyles
+} from "@material-ui/core/styles";
+import Typography from "@material-ui/core/Typography";
+import * as React from "react";
+
+import AddressFormatter from "../../../components/AddressFormatter";
+import CardMenu from "../../../components/CardMenu";
+import CardTitle from "../../../components/CardTitle";
+import Skeleton from "../../../components/Skeleton";
+import i18n from "../../../i18n";
+import { maybe } from "../../../misc";
+import { AddressTypeEnum } from "../../../types/globalTypes";
+import { CustomerAddresses_user_addresses } from "../../types/CustomerAddresses";
+
+export interface CustomerAddressProps {
+ address: CustomerAddresses_user_addresses;
+ disabled: boolean;
+ isDefaultBillingAddress: boolean;
+ isDefaultShippingAddress: boolean;
+ addressNumber: number;
+ onEdit: () => void;
+ onRemove: () => void;
+ onSetAsDefault: (type: AddressTypeEnum) => void;
+}
+
+const styles = (theme: Theme) =>
+ createStyles({
+ actions: {
+ flexDirection: "row"
+ }
+ });
+const CustomerAddress = withStyles(styles, { name: "CustomerAddress" })(
+ ({
+ address,
+ addressNumber,
+ classes,
+ disabled,
+ isDefaultBillingAddress,
+ isDefaultShippingAddress,
+ onEdit,
+ onRemove,
+ onSetAsDefault
+ }: CustomerAddressProps & WithStyles<typeof styles>) => (
+ <Card>
+ <CardTitle
+ title={
+ address ? (
+ <>
+ {i18n.t("Address {{ addressNumber }}", {
+ addressNumber
+ })}
+ <Typography variant="caption">
+ {isDefaultBillingAddress && isDefaultShippingAddress
+ ? i18n.t("Default Address")
+ : isDefaultShippingAddress
+ ? i18n.t("Default Shipping Address")
+ : isDefaultBillingAddress
+ ? i18n.t("Default Billing Address")
+ : null}
+ </Typography>
+ </>
+ ) : (
+ <Skeleton />
+ )
+ }
+ height="const"
+ toolbar={
+ <CardMenu
+ disabled={disabled}
+ menuItems={[
+ {
+ label: i18n.t("Set as default shipping address", {
+ context: "button"
+ }),
+ onSelect: () => onSetAsDefault(AddressTypeEnum.SHIPPING)
+ },
+ {
+ label: i18n.t("Set as default billing address", {
+ context: "button"
+ }),
+ onSelect: () => onSetAsDefault(AddressTypeEnum.BILLING)
+ }
+ ]}
+ />
+ }
+ />
+ <CardContent>
+ <AddressFormatter address={address} />
+ </CardContent>
+ <CardActions className={classes.actions}>
+ <Button
+ color="secondary"
+ disabled={disabled}
+ variant="flat"
+ onClick={onEdit}
+ >
+ {i18n.t("Edit")}
+ </Button>
+ <Button
+ color="secondary"
+ disabled={disabled}
+ variant="flat"
+ onClick={onRemove}
+ >
+ {i18n.t("Delete")}
+ </Button>
+ </CardActions>
+ </Card>
+ )
+);
+CustomerAddress.displayName = "CustomerAddress";
+export default CustomerAddress;
diff --git a/saleor/static/dashboard-next/customers/components/CustomerAddress/index.ts b/saleor/static/dashboard-next/customers/components/CustomerAddress/index.ts
new file mode 100644
index 0000000000..937bf00487
--- /dev/null
+++ b/saleor/static/dashboard-next/customers/components/CustomerAddress/index.ts
@@ -0,0 +1,2 @@
+export { default } from './CustomerAddress';
+export * from './CustomerAddress';
\ No newline at end of file
diff --git a/saleor/static/dashboard-next/customers/components/CustomerAddressListPage/CustomerAddressListPage.tsx b/saleor/static/dashboard-next/customers/components/CustomerAddressListPage/CustomerAddressListPage.tsx
new file mode 100644
index 0000000000..85b7c8e87f
--- /dev/null
+++ b/saleor/static/dashboard-next/customers/components/CustomerAddressListPage/CustomerAddressListPage.tsx
@@ -0,0 +1,102 @@
+import Button from "@material-ui/core/Button";
+import {
+ createStyles,
+ Theme,
+ withStyles,
+ WithStyles
+} from "@material-ui/core/styles";
+import AddIcon from "@material-ui/icons/Add";
+import * as React from "react";
+
+import AppHeader from "../../../components/AppHeader";
+import Container from "../../../components/Container";
+import PageHeader from "../../../components/PageHeader";
+import i18n from "../../../i18n";
+import { maybe, renderCollection } from "../../../misc";
+import { AddressTypeEnum } from "../../../types/globalTypes";
+import { CustomerAddresses_user } from "../../types/CustomerAddresses";
+import CustomerAddress from "../CustomerAddress/CustomerAddress";
+
+export interface CustomerAddressListPageProps {
+ customer: CustomerAddresses_user;
+ disabled: boolean;
+ onAdd: () => void;
+ onBack: () => void;
+ onEdit: (id: string) => void;
+ onRemove: (id: string) => void;
+ onSetAsDefault: (id: string, type: AddressTypeEnum) => void;
+}
+
+const styles = (theme: Theme) =>
+ createStyles({
+ root: {
+ columnGap: theme.spacing.unit * 3,
+ display: "grid",
+ gridTemplateColumns: "repeat(3, 1fr)",
+ rowGap: theme.spacing.unit * 3
+ }
+ });
+
+const CustomerAddressListPage = withStyles(styles, {
+ name: "CustomerAddressListPage"
+})(
+ ({
+ classes,
+ customer,
+ disabled,
+ onAdd,
+ onBack,
+ onEdit,
+ onRemove,
+ onSetAsDefault
+ }: CustomerAddressListPageProps & WithStyles<typeof styles>) => (
+ <Container>
+ <AppHeader onBack={onBack}>
+ {i18n.t("Customer Info", {
+ context: "navigation"
+ })}
+ </AppHeader>
+ <PageHeader
+ title={maybe(() =>
+ i18n.t("{{ firstName }} {{ lastName }} Address Book", {
+ context: "customer address book",
+ firstName: customer.firstName,
+ lastName: customer.lastName
+ })
+ )}
+ >
+ <Button color="secondary" variant="contained" onClick={onAdd}>
+ {i18n.t("Add address", {
+ context: "add customer address"
+ })}
+ <AddIcon />
+ </Button>
+ </PageHeader>
+ <div className={classes.root}>
+ {renderCollection(
+ maybe(() => customer.addresses),
+ (address, addressNumber) => (
+ <CustomerAddress
+ address={address}
+ addressNumber={addressNumber + 1}
+ disabled={disabled}
+ isDefaultBillingAddress={
+ maybe(() => customer.defaultBillingAddress.id) ===
+ maybe(() => address.id)
+ }
+ isDefaultShippingAddress={
+ maybe(() => customer.defaultShippingAddress.id) ===
+ maybe(() => address.id)
+ }
+ onEdit={() => onEdit(address.id)}
+ onRemove={() => onRemove(address.id)}
+ onSetAsDefault={type => onSetAsDefault(address.id, type)}
+ />
+ )
+ )}
+ </div>
+ </Container>
+ )
+);
+CustomerAddressListPage.displayName = "CustomerAddressListPage";
+export default CustomerAddressListPage;
diff --git a/saleor/static/dashboard-next/customers/components/CustomerAddressListPage/index.ts b/saleor/static/dashboard-next/customers/components/CustomerAddressListPage/index.ts
new file mode 100644
index 0000000000..a2fe444c5d
--- /dev/null
+++ b/saleor/static/dashboard-next/customers/components/CustomerAddressListPage/index.ts
@@ -0,0 +1,2 @@
+export { default } from './CustomerAddressListPage';
+export * from './CustomerAddressListPage';
\ No newline at end of file
diff --git a/saleor/static/dashboard-next/customers/components/CustomerAddresses/CustomerAddresses.tsx b/saleor/static/dashboard-next/customers/components/CustomerAddresses/CustomerAddresses.tsx
index d5666a6b77..441ddc14ac 100644
--- a/saleor/static/dashboard-next/customers/components/CustomerAddresses/CustomerAddresses.tsx
+++ b/saleor/static/dashboard-next/customers/components/CustomerAddresses/CustomerAddresses.tsx
@@ -1,3 +1,4 @@
+import Button from "@material-ui/core/Button";
import Card from "@material-ui/core/Card";
import CardContent from "@material-ui/core/CardContent";
import {
@@ -31,20 +32,25 @@ export interface CustomerAddressesProps extends WithStyles<typeof styles> {
}
const CustomerAddresses = withStyles(styles, { name: "CustomerAddresses" })(
- ({ classes, customer }: CustomerAddressesProps) => (
+ ({
+ classes,
+ customer,
+ disabled,
+ onAddressManageClick
+ }: CustomerAddressesProps) => (
<Card>
<CardTitle
title={i18n.t("Address Information")}
- // toolbar={ // TODO: add address management #3173
- // <Button
- // color="secondary"
- // disabled={disabled}
- // variant="text"
- // onClick={onAddressManageClick}
- // >
- // {i18n.t("Manage", { context: "button" })}
- // </Button>
- // }
+ toolbar={
+ <Button
+ color="secondary"
+ disabled={disabled}
+ variant="text"
+ onClick={onAddressManageClick}
+ >
+ {i18n.t("Manage", { context: "button" })}
+ </Button>
+ }
/>
{customer &&
customer.defaultBillingAddress &&
diff --git a/saleor/static/dashboard-next/customers/fixtures.ts b/saleor/static/dashboard-next/customers/fixtures.ts
index 5393191a1b..bb778393df 100644
--- a/saleor/static/dashboard-next/customers/fixtures.ts
+++ b/saleor/static/dashboard-next/customers/fixtures.ts
@@ -1,6 +1,7 @@
import { PaymentChargeStatusEnum } from "../types/globalTypes";
import { CustomerDetails_user } from "./types/CustomerDetails";
import { ListCustomers_customers_edges_node } from "./types/ListCustomers";
+import { CustomerAddresses_user } from "./types/CustomerAddresses";
export const customers = [
{
@@ -943,8 +944,48 @@ export const customerList: ListCustomers_customers_edges_node[] = [
}
}
];
-export const customer: CustomerDetails_user = {
+export const customer: CustomerDetails_user & CustomerAddresses_user = {
__typename: "User",
+ addresses: [
+ {
+ __typename: "Address",
+ city: "Port Danielshire",
+ cityArea: "",
+ companyName: "",
+ country: {
+ __typename: "CountryDisplay",
+ code: "SE",
+ country: "Szwecja"
+ },
+ countryArea: "",
+ firstName: "Elizabeth",
+ id: "QWRkcmVzczoy",
+ lastName: "Vaughn",
+ phone: "",
+ postalCode: "52203",
+ streetAddress1: "419 Ruiz Orchard Apt. 199",
+ streetAddress2: ""
+ },
+ {
+ __typename: "Address",
+ city: "West Feliciamouth",
+ cityArea: "Montana",
+ companyName: null,
+ country: {
+ __typename: "CountryDisplay",
+ code: "JA",
+ country: "Japan"
+ },
+ countryArea: null,
+ firstName: "Timmy",
+ id: "33855",
+ lastName: "Macejkovic",
+ phone: "+41 460-907-9374",
+ postalCode: "15926",
+ streetAddress1: "0238 Cremin Freeway",
+ streetAddress2: null
+ }
+ ],
dateJoined: "2017-05-07T09:37:30.124154+00:00",
firstName: "Tom",
diff --git a/saleor/static/dashboard-next/customers/index.tsx b/saleor/static/dashboard-next/customers/index.tsx
index d3e8abc87d..ca5e451559 100644
--- a/saleor/static/dashboard-next/customers/index.tsx
+++ b/saleor/static/dashboard-next/customers/index.tsx
@@ -4,7 +4,13 @@ import { Route, RouteComponentProps, Switch } from "react-router-dom";
import { WindowTitle } from "../components/WindowTitle";
import i18n from "../i18n";
-import { customerAddPath, customerListPath, customerPath } from "./urls";
+import {
+ customerAddPath,
+ customerAddressesPath,
+ customerListPath,
+ customerPath
+} from "./urls";
+import CustomerAddressesViewComponent from "./views/CustomerAddresses";
import CustomerCreateView from "./views/CustomerCreate";
import CustomerDetailsViewComponent from "./views/CustomerDetails";
import CustomerListViewComponent, {
@@ -31,12 +37,25 @@ const CustomerDetailsView: React.StatelessComponent<
<CustomerDetailsViewComponent id={decodeURIComponent(match.params.id)} />
);
+interface CustomerAddressesRouteParams {
+ id: string;
+}
+const CustomerAddressesView: React.StatelessComponent<
+ RouteComponentProps<CustomerAddressesRouteParams>
+> = ({ match }) => (
+ <CustomerAddressesViewComponent id={decodeURIComponent(match.params.id)} />
+);
+
export const CustomerSection: React.StatelessComponent<{}> = () => (
<>
<WindowTitle title={i18n.t("Customers")} />
<Switch>
<Route exact path={customerListPath} component={CustomerListView} />
<Route exact path={customerAddPath} component={CustomerCreateView} />
+ <Route
+ path={customerAddressesPath(":id")}
+ component={CustomerAddressesView}
+ />
<Route path={customerPath(":id")} component={CustomerDetailsView} />
</Switch>
</>
diff --git a/saleor/static/dashboard-next/customers/mutations.ts b/saleor/static/dashboard-next/customers/mutations.ts
index cd33917969..0f00d102e5 100644
--- a/saleor/static/dashboard-next/customers/mutations.ts
+++ b/saleor/static/dashboard-next/customers/mutations.ts
@@ -1,7 +1,7 @@
import gql from "graphql-tag";
import { TypedMutation } from "../mutations";
-import { customerDetailsFragment } from "./queries";
+import { customerAddressesFragment, customerDetailsFragment } from "./queries";
import {
CreateCustomer,
CreateCustomerVariables
@@ -10,6 +10,10 @@ import {
RemoveCustomer,
RemoveCustomerVariables
} from "./types/RemoveCustomer";
+import {
+ SetCustomerDefaultAddress,
+ SetCustomerDefaultAddressVariables
+} from "./types/SetCustomerDefaultAddress";
import {
UpdateCustomer,
UpdateCustomerVariables
@@ -66,3 +70,22 @@ export const TypedRemoveCustomerMutation = TypedMutation<
RemoveCustomer,
RemoveCustomerVariables
>(removeCustomer);
+
+const setCustomerDefaultAddress = gql`
+ ${customerAddressesFragment}
+ mutation SetCustomerDefaultAddress($id: ID!, $type: AddressTypeEnum!) {
+ customerSetDefaultAddress(id: $id, type: $type) {
+ errors {
+ field
+ message
+ }
+ user {
+ ...CustomerAddressesFragment
+ }
+ }
+ }
+`;
+export const TypedSetCustomerDefaultAddressMutation = TypedMutation<
+ SetCustomerDefaultAddress,
+ SetCustomerDefaultAddressVariables
+>(setCustomerDefaultAddress);
diff --git a/saleor/static/dashboard-next/customers/queries.ts b/saleor/static/dashboard-next/customers/queries.ts
index 237128b464..9030ecbdf4 100644
--- a/saleor/static/dashboard-next/customers/queries.ts
+++ b/saleor/static/dashboard-next/customers/queries.ts
@@ -2,6 +2,10 @@ import gql from "graphql-tag";
import { fragmentAddress } from "../orders/queries";
import { TypedQuery } from "../queries";
+import {
+ CustomerAddresses,
+ CustomerAddressesVariables
+} from "./types/CustomerAddresses";
import { CustomerCreateData } from "./types/CustomerCreateData";
import {
CustomerDetails,
@@ -36,6 +40,23 @@ export const customerDetailsFragment = gql`
}
`;
+export const customerAddressesFragment = gql`
+ ${customerFragment}
+ ${fragmentAddress}
+ fragment CustomerAddressesFragment on User {
+ ...CustomerFragment
+ addresses {
+ ...AddressFragment
+ }
+ defaultBillingAddress {
+ id
+ }
+ defaultShippingAddress {
+ id
+ }
+ }
+`;
+
const customerList = gql`
${customerFragment}
query ListCustomers(
@@ -104,6 +125,19 @@ export const TypedCustomerDetailsQuery = TypedQuery<
CustomerDetailsVariables
>(customerDetails);
+const customerAddresses = gql`
+ ${customerAddressesFragment}
+ query CustomerAddresses($id: ID!) {
+ user(id: $id) {
+ ...CustomerAddressesFragment
+ }
+ }
+`;
+export const TypedCustomerAddressesQuery = TypedQuery<
+ CustomerAddresses,
+ CustomerAddressesVariables
+>(customerAddresses);
+
const customerCreateData = gql`
query CustomerCreateData {
shop {
diff --git a/saleor/static/dashboard-next/customers/types/CustomerAddresses.ts b/saleor/static/dashboard-next/customers/types/CustomerAddresses.ts
new file mode 100644
index 0000000000..b95d46a287
--- /dev/null
+++ b/saleor/static/dashboard-next/customers/types/CustomerAddresses.ts
@@ -0,0 +1,58 @@
+/* tslint:disable */
+/* eslint-disable */
+// This file was automatically generated and should not be edited.
+
+// ====================================================
+// GraphQL query operation: CustomerAddresses
+// ====================================================
+
+export interface CustomerAddresses_user_addresses_country {
+ __typename: "CountryDisplay";
+ code: string;
+ country: string;
+}
+
+export interface CustomerAddresses_user_addresses {
+ __typename: "Address";
+ city: string;
+ cityArea: string;
+ companyName: string;
+ country: CustomerAddresses_user_addresses_country;
+ countryArea: string;
+ firstName: string;
+ id: string;
+ lastName: string;
+ phone: string | null;
+ postalCode: string;
+ streetAddress1: string;
+ streetAddress2: string;
+}
+
+export interface CustomerAddresses_user_defaultBillingAddress {
+ __typename: "Address";
+ id: string;
+}
+
+export interface CustomerAddresses_user_defaultShippingAddress {
+ __typename: "Address";
+ id: string;
+}
+
+export interface CustomerAddresses_user {
+ __typename: "User";
+ id: string;
+ email: string;
+ firstName: string;
+ lastName: string;
+ addresses: (CustomerAddresses_user_addresses | null)[] | null;
+ defaultBillingAddress: CustomerAddresses_user_defaultBillingAddress | null;
+ defaultShippingAddress: CustomerAddresses_user_defaultShippingAddress | null;
+}
+
+export interface CustomerAddresses {
+ user: CustomerAddresses_user | null;
+}
+
+export interface CustomerAddressesVariables {
+ id: string;
+}
diff --git a/saleor/static/dashboard-next/customers/types/CustomerAddressesFragment.ts b/saleor/static/dashboard-next/customers/types/CustomerAddressesFragment.ts
new file mode 100644
index 0000000000..07fd6c695b
--- /dev/null
+++ b/saleor/static/dashboard-next/customers/types/CustomerAddressesFragment.ts
@@ -0,0 +1,50 @@
+/* tslint:disable */
+/* eslint-disable */
+// This file was automatically generated and should not be edited.
+
+// ====================================================
+// GraphQL fragment: CustomerAddressesFragment
+// ====================================================
+
+export interface CustomerAddressesFragment_addresses_country {
+ __typename: "CountryDisplay";
+ code: string;
+ country: string;
+}
+
+export interface CustomerAddressesFragment_addresses {
+ __typename: "Address";
+ city: string;
+ cityArea: string;
+ companyName: string;
+ country: CustomerAddressesFragment_addresses_country;
+ countryArea: string;
+ firstName: string;
+ id: string;
+ lastName: string;
+ phone: string | null;
+ postalCode: string;
+ streetAddress1: string;
+ streetAddress2: string;
+}
+
+export interface CustomerAddressesFragment_defaultBillingAddress {
+ __typename: "Address";
+ id: string;
+}
+
+export interface CustomerAddressesFragment_defaultShippingAddress {
+ __typename: "Address";
+ id: string;
+}
+
+export interface CustomerAddressesFragment {
+ __typename: "User";
+ id: string;
+ email: string;
+ firstName: string;
+ lastName: string;
+ addresses: (CustomerAddressesFragment_addresses | null)[] | null;
+ defaultBillingAddress: CustomerAddressesFragment_defaultBillingAddress | null;
+ defaultShippingAddress: CustomerAddressesFragment_defaultShippingAddress | null;
+}
diff --git a/saleor/static/dashboard-next/customers/types/SetCustomerDefaultAddress.ts b/saleor/static/dashboard-next/customers/types/SetCustomerDefaultAddress.ts
new file mode 100644
index 0000000000..154543464c
--- /dev/null
+++ b/saleor/static/dashboard-next/customers/types/SetCustomerDefaultAddress.ts
@@ -0,0 +1,73 @@
+/* tslint:disable */
+/* eslint-disable */
+// This file was automatically generated and should not be edited.
+
+import { AddressTypeEnum } from "./../../types/globalTypes";
+
+// ====================================================
+// GraphQL mutation operation: SetCustomerDefaultAddress
+// ====================================================
+
+export interface SetCustomerDefaultAddress_customerSetDefaultAddress_errors {
+ __typename: "Error";
+ field: string | null;
+ message: string | null;
+}
+
+export interface SetCustomerDefaultAddress_customerSetDefaultAddress_user_addresses_country {
+ __typename: "CountryDisplay";
+ code: string;
+ country: string;
+}
+
+export interface SetCustomerDefaultAddress_customerSetDefaultAddress_user_addresses {
+ __typename: "Address";
+ city: string;
+ cityArea: string;
+ companyName: string;
+ country: SetCustomerDefaultAddress_customerSetDefaultAddress_user_addresses_country;
+ countryArea: string;
+ firstName: string;
+ id: string;
+ lastName: string;
+ phone: string | null;
+ postalCode: string;
+ streetAddress1: string;
+ streetAddress2: string;
+}
+
+export interface SetCustomerDefaultAddress_customerSetDefaultAddress_user_defaultBillingAddress {
+ __typename: "Address";
+ id: string;
+}
+
+export interface SetCustomerDefaultAddress_customerSetDefaultAddress_user_defaultShippingAddress {
+ __typename: "Address";
+ id: string;
+}
+
+export interface SetCustomerDefaultAddress_customerSetDefaultAddress_user {
+ __typename: "User";
+ id: string;
+ email: string;
+ firstName: string;
+ lastName: string;
+ addresses: (SetCustomerDefaultAddress_customerSetDefaultAddress_user_addresses | null)[] | null;
+ defaultBillingAddress: SetCustomerDefaultAddress_customerSetDefaultAddress_user_defaultBillingAddress | null;
+ defaultShippingAddress: SetCustomerDefaultAddress_customerSetDefaultAddress_user_defaultShippingAddress | null;
+}
+
+export interface SetCustomerDefaultAddress_customerSetDefaultAddress {
+ __typename: "CustomerSetDefaultAddress";
+ errors: SetCustomerDefaultAddress_customerSetDefaultAddress_errors[] | null;
+ user: SetCustomerDefaultAddress_customerSetDefaultAddress_user | null;
+}
+
+export interface SetCustomerDefaultAddress {
+ customerSetDefaultAddress: SetCustomerDefaultAddress_customerSetDefaultAddress | null;
+}
+
+export interface SetCustomerDefaultAddressVariables {
+ id: string;
+ type: AddressTypeEnum;
+}
diff --git a/saleor/static/dashboard-next/customers/urls.ts b/saleor/static/dashboard-next/customers/urls.ts
index c5fccd972d..0cc583db4c 100644
--- a/saleor/static/dashboard-next/customers/urls.ts
+++ b/saleor/static/dashboard-next/customers/urls.ts
@@ -15,3 +15,8 @@ export const customerRemovePath = (id: string) =>
urlJoin(customerPath(id), "remove");
export const customerRemoveUrl = (id: string) =>
customerRemovePath(encodeURIComponent(id));
+
+export const customerAddressesPath = (id: string) =>
+ urlJoin(customerPath(id), "addresses");
+export const customerAddressesUrl = (id: string) =>
+ customerAddressesPath(encodeURIComponent(id));
diff --git a/saleor/static/dashboard-next/customers/views/CustomerAddresses.tsx b/saleor/static/dashboard-next/customers/views/CustomerAddresses.tsx
new file mode 100644
index 0000000000..0d9a91d7c6
--- /dev/null
+++ b/saleor/static/dashboard-next/customers/views/CustomerAddresses.tsx
@@ -0,0 +1,52 @@
+import * as React from "react";
+
+import Messages from "../../components/messages";
+import Navigator from "../../components/Navigator";
+import { WindowTitle } from "../../components/WindowTitle";
+import i18n from "../../i18n";
+import { maybe } from "../../misc";
+import CustomerAddressListPage from "../components/CustomerAddressListPage";
+import { TypedSetCustomerDefaultAddressMutation } from "../mutations";
+import { TypedCustomerAddressesQuery } from "../queries";
+import { customerUrl } from "../urls";
+
+interface CustomerAddressesProps {
+ id: string;
+}
+
+const CustomerAddresses: React.FC<CustomerAddressesProps> = ({ id }) => (
+ <Navigator>
+ {navigate => (
+ <Messages>
+ {pushMessage => {
+ return (
+ <TypedSetCustomerDefaultAddressMutation>
+ {(setCustomerDefaultAddress, setCustomerDefaultAddressOpts) => (
+ <TypedCustomerAddressesQuery variables={{ id }}>
+ {customerData => {
+ return (
+ <CustomerAddressListPage
+ customer={maybe(() => customerData.data.user)}
+ disabled={customerData.loading}
+ onAdd={() => undefined}
+ onBack={() =>
+ navigate(customerUrl(customerData.data.user.id))
+ }
+ onEdit={() => undefined}
+ onRemove={() => undefined}
+ onSetAsDefault={(id, type) =>
+ setCustomerDefaultAddress({ variables: { id, type } })
+ }
+ />
+ );
+ }}
+ </TypedCustomerAddressesQuery>
+ )}
+ </TypedSetCustomerDefaultAddressMutation>
+ );
+ }}
+ </Messages>
+ )}
+ </Navigator>
+);
+export default CustomerAddresses;
diff --git a/saleor/static/dashboard-next/customers/views/CustomerDetails.tsx b/saleor/static/dashboard-next/customers/views/CustomerDetails.tsx
index d9c151fdde..475bd31bf1 100644
--- a/saleor/static/dashboard-next/customers/views/CustomerDetails.tsx
+++ b/saleor/static/dashboard-next/customers/views/CustomerDetails.tsx
@@ -18,6 +18,7 @@ import { TypedCustomerDetailsQuery } from "../queries";
import { RemoveCustomer } from "../types/RemoveCustomer";
import { UpdateCustomer } from "../types/UpdateCustomer";
import {
+ customerAddressesUrl,
customerListUrl,
customerRemovePath,
customerRemoveUrl,
@@ -104,7 +105,9 @@ export const CustomerDetailsView: React.StatelessComponent<
updateCustomerOpts.data.customerUpdate.errors
)}
saveButtonBar={formTransitionState}
- onAddressManageClick={() => undefined} // TODO: add address management #3173
+ onAddressManageClick={() =>
+ navigate(customerAddressesUrl(id))
+ }
onBack={() => navigate(customerListUrl)}
onRowClick={id => navigate(orderUrl(id))}
onSubmit={formData =>
diff --git a/saleor/static/dashboard-next/storybook/config.js b/saleor/static/dashboard-next/storybook/config.js
index 49ded6b6b3..48b51865a1 100644
--- a/saleor/static/dashboard-next/storybook/config.js
+++ b/saleor/static/dashboard-next/storybook/config.js
@@ -53,6 +53,8 @@ function loadStories() {
require("./stories/configuration/ConfigurationPage");
// Customers
+ require("./stories/customers/CustomerAddressDialog");
+ require("./stories/customers/CustomerAddressListPage");
require("./stories/customers/CustomerCreatePage");
require("./stories/customers/CustomerDetailsPage");
require("./stories/customers/CustomerListPage");
diff --git a/saleor/static/dashboard-next/storybook/stories/customers/CustomerAddressDialog.tsx b/saleor/static/dashboard-next/storybook/stories/customers/CustomerAddressDialog.tsx
new file mode 100644
index 0000000000..613cd2946c
--- /dev/null
+++ b/saleor/static/dashboard-next/storybook/stories/customers/CustomerAddressDialog.tsx
@@ -0,0 +1,15 @@
+import { storiesOf } from "@storybook/react";
+import * as React from "react";
+
+import CustomerAddressDialog, {
+ CustomerAddressDialogProps
+} from "../../../customers/components/CustomerAddressDialog";
+import Decorator from "../../Decorator";
+
+const props: CustomerAddressDialogProps = {
+
+};
+
+storiesOf("Customers / CustomerAddressDialog", module)
+ .addDecorator(Decorator)
+ .add("default", () => <CustomerAddressDialog {...props} />);
diff --git a/saleor/static/dashboard-next/storybook/stories/customers/CustomerAddressListPage.tsx b/saleor/static/dashboard-next/storybook/stories/customers/CustomerAddressListPage.tsx
new file mode 100644
index 0000000000..8ca0a246cf
--- /dev/null
+++ b/saleor/static/dashboard-next/storybook/stories/customers/CustomerAddressListPage.tsx
@@ -0,0 +1,31 @@
+import { storiesOf } from "@storybook/react";
+import * as React from "react";
+
+import CustomerAddressListPage, {
+ CustomerAddressListPageProps
+} from "../../../customers/components/CustomerAddressListPage";
+import { customer } from "../../../customers/fixtures";
+import Decorator from "../../Decorator";
+
+const props: CustomerAddressListPageProps = {
+ customer,
+ disabled: false,
+ onAdd: () => undefined,
+ onBack: () => undefined,
+ onEdit: () => undefined,
+ onRemove: () => undefined,
+ onSetAsDefault: () => undefined
+};
+
+storiesOf("Views / Customers / Address Book", module)
+ .addDecorator(Decorator)
+ .add("default", () => <CustomerAddressListPage {...props} />)
+ .add("loading", () => (
+ <CustomerAddressListPage {...props} customer={undefined} disabled={true} />
+ ))
+ .add("no data", () => (
+ <CustomerAddressListPage
+ {...props}
+ customer={{ ...customer, addresses: [] }}
+ />
+ ));
diff --git a/saleor/static/dashboard-next/types/globalTypes.ts b/saleor/static/dashboard-next/types/globalTypes.ts
index e5e1ff4948..672c9376b0 100644
--- a/saleor/static/dashboard-next/types/globalTypes.ts
+++ b/saleor/static/dashboard-next/types/globalTypes.ts
@@ -6,6 +6,11 @@
// START Enums and Input Objects
//==============================================================
+export enum AddressTypeEnum {
+ BILLING = "BILLING",
+ SHIPPING = "SHIPPING",
+}
+
export enum AttributeTypeEnum {
PRODUCT = "PRODUCT",
VARIANT = "VARIANT",