Skip to content

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

Add customer create page

dominik-zeglenc5d00ee71d70
diff --git a/saleor/static/dashboard-next/components/AddressEdit/AddressEdit.tsx b/saleor/static/dashboard-next/components/AddressEdit/AddressEdit.tsx
index 6ce69af36b..0186a5233c 100644
--- a/saleor/static/dashboard-next/components/AddressEdit/AddressEdit.tsx
+++ b/saleor/static/dashboard-next/components/AddressEdit/AddressEdit.tsx
@@ -4,6 +4,7 @@ import * as React from "react";
import { AddressTypeInput } from "../../customers/types";
import i18n from "../../i18n";
+import { maybe } from "../../misc";
import FormSpacer from "../FormSpacer";
import SingleSelectField from "../SingleSelectField";
@@ -13,6 +14,7 @@ interface AddressEditProps {
label: string;
}>;
data: AddressTypeInput;
+ disabled?: boolean;
errors: { [T in keyof AddressTypeInput]?: string };
onChange(event: React.ChangeEvent<any>);
}
@@ -25,11 +27,12 @@ const decorate = withStyles(theme => ({
}
}));
const AddressEdit = decorate<AddressEditProps>(
- ({ classes, countries, data, errors, onChange }) => (
+ ({ classes, countries, data, disabled, errors, onChange }) => (
<>
<div className={classes.root}>
<div>
<TextField
+ disabled={disabled}
error={!!errors.firstName}
helperText={errors.firstName}
label={i18n.t("First name")}
@@ -41,6 +44,7 @@ const AddressEdit = decorate<AddressEditProps>(
</div>
<div>
<TextField
+ disabled={disabled}
error={!!errors.lastName}
helperText={errors.lastName}
label={i18n.t("Last name")}
@@ -52,20 +56,38 @@ const AddressEdit = decorate<AddressEditProps>(
</div>
</div>
<FormSpacer />
- <TextField
- error={!!errors.companyName}
- helperText={errors.companyName}
- label={i18n.t("Company")}
- name="companyName"
- onChange={onChange}
- value={data.companyName}
- fullWidth
- />
+ <div className={classes.root}>
+ <div>
+ <TextField
+ disabled={disabled}
+ error={!!errors.companyName}
+ helperText={errors.companyName}
+ label={i18n.t("Company")}
+ name="companyName"
+ onChange={onChange}
+ value={data.companyName}
+ fullWidth
+ />
+ </div>
+ <div>
+ <TextField
+ disabled={disabled}
+ error={!!errors.phone}
+ fullWidth
+ helperText={errors.phone}
+ label={i18n.t("Phone")}
+ name="phone"
+ value={data.phone}
+ onChange={onChange}
+ />
+ </div>
+ </div>
<FormSpacer />
<TextField
+ disabled={disabled}
error={!!errors.streetAddress1}
helperText={errors.streetAddress1}
- label={i18n.t("Address")}
+ label={i18n.t("Address line 1")}
name="streetAddress1"
onChange={onChange}
value={data.streetAddress1}
@@ -73,73 +95,73 @@ const AddressEdit = decorate<AddressEditProps>(
/>
<FormSpacer />
<TextField
+ disabled={disabled}
error={!!errors.streetAddress2}
helperText={errors.streetAddress2}
- label={i18n.t("Address")}
+ label={i18n.t("Address line 2")}
name="streetAddress2"
onChange={onChange}
value={data.streetAddress2}
fullWidth
/>
<FormSpacer />
- <TextField
- error={!!errors.city}
- helperText={errors.city}
- label={i18n.t("City")}
- name="city"
- onChange={onChange}
- value={data.city}
- fullWidth
- />
- <FormSpacer />
- <TextField
- error={!!errors.cityArea}
- helperText={errors.cityArea}
- label={i18n.t("City area")}
- name="cityArea"
- onChange={onChange}
- value={data.cityArea}
- fullWidth
- />
- <FormSpacer />
- <TextField
- error={!!errors.postalCode}
- helperText={errors.postalCode}
- label={i18n.t("Postal code")}
- name="postalCode"
- onChange={onChange}
- value={data.postalCode}
- fullWidth
- />
- <FormSpacer />
- <SingleSelectField
- error={!!errors.country}
- hint={errors.country}
- label={i18n.t("Country")}
- name="country"
- onChange={onChange}
- value={data.country}
- choices={countries.map(c => ({ ...c, value: c.code }))}
- />
- <FormSpacer />
- <TextField
- error={!!errors.countryArea}
- helperText={errors.countryArea}
- label={i18n.t("Country area")}
- name="countryArea"
- onChange={onChange}
- value={data.countryArea}
- fullWidth
- />
+ <div className={classes.root}>
+ <div>
+ <TextField
+ disabled={disabled}
+ error={!!errors.city}
+ helperText={errors.city}
+ label={i18n.t("City")}
+ name="city"
+ onChange={onChange}
+ value={data.city}
+ fullWidth
+ />
+ </div>
+ <div>
+ <TextField
+ disabled={disabled}
+ error={!!errors.postalCode}
+ helperText={errors.postalCode}
+ label={i18n.t("ZIP / Postal code")}
+ name="postalCode"
+ onChange={onChange}
+ value={data.postalCode}
+ fullWidth
+ />
+ </div>
+ </div>
+
<FormSpacer />
- <TextField
- error={!!errors.phone}
- helperText={errors.phone}
- label={i18n.t("Phone")}
- name="phone"
- value={data.phone}
- onChange={onChange}
- />
+ <div className={classes.root}>
+ <div>
+ <SingleSelectField
+ disabled={disabled}
+ error={!!errors.country}
+ hint={errors.country}
+ label={i18n.t("Country")}
+ name="country"
+ onChange={onChange}
+ value={data.country}
+ choices={maybe(
+ () => countries.map(c => ({ ...c, value: c.code })),
+ []
+ )}
+ />
+ </div>
+ <div>
+ <TextField
+ disabled={disabled}
+ error={!!errors.countryArea}
+ helperText={errors.countryArea}
+ label={i18n.t("Country area")}
+ name="countryArea"
+ onChange={onChange}
+ value={data.countryArea}
+ fullWidth
+ />
+ </div>
+ </div>
</>
)
);
diff --git a/saleor/static/dashboard-next/customers/components/CustomerCreateAddress/CustomerCreateAddress.tsx b/saleor/static/dashboard-next/customers/components/CustomerCreateAddress/CustomerCreateAddress.tsx
new file mode 100644
index 0000000000..cd7fd2454f
--- /dev/null
+++ b/saleor/static/dashboard-next/customers/components/CustomerCreateAddress/CustomerCreateAddress.tsx
@@ -0,0 +1,37 @@
+import Card from "@material-ui/core/Card";
+import CardContent from "@material-ui/core/CardContent";
+import Typography from "@material-ui/core/Typography";
+import * as React from "react";
+
+import AddressEdit from "../../../components/AddressEdit/AddressEdit";
+import CardTitle from "../../../components/CardTitle";
+import { FormSpacer } from "../../../components/FormSpacer";
+import i18n from "../../../i18n";
+import { AddressTypeInput } from "../../types";
+
+export interface CustomerCreateAddressProps {
+ data: AddressTypeInput;
+ disabled: boolean;
+ errors: { [T in keyof AddressTypeInput]?: string };
+ onChange(event: React.ChangeEvent<any>);
+}
+
+const CustomerCreateAddress: React.StatelessComponent<
+ CustomerCreateAddressProps
+> = ({ data, disabled, errors, onChange }) => (
+ <Card>
+ <CardTitle title={i18n.t("Primary address")} />
+ <CardContent>
+ <Typography>{i18n.t("The primary address of this customer.")}</Typography>
+ <FormSpacer />
+ <AddressEdit
+ data={data}
+ disabled={disabled}
+ errors={errors}
+ onChange={onChange}
+ />
+ </CardContent>
+ </Card>
+);
+CustomerCreateAddress.displayName = "CustomerCreateAddress";
+export default CustomerCreateAddress;
diff --git a/saleor/static/dashboard-next/customers/components/CustomerCreateAddress/index.ts b/saleor/static/dashboard-next/customers/components/CustomerCreateAddress/index.ts
new file mode 100644
index 0000000000..32bb82edee
--- /dev/null
+++ b/saleor/static/dashboard-next/customers/components/CustomerCreateAddress/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./CustomerCreateAddress";
+export * from "./CustomerCreateAddress";
diff --git a/saleor/static/dashboard-next/customers/components/CustomerCreateDetails/CustomerCreateDetails.tsx b/saleor/static/dashboard-next/customers/components/CustomerCreateDetails/CustomerCreateDetails.tsx
new file mode 100644
index 0000000000..2481453e3e
--- /dev/null
+++ b/saleor/static/dashboard-next/customers/components/CustomerCreateDetails/CustomerCreateDetails.tsx
@@ -0,0 +1,49 @@
+import Card from "@material-ui/core/Card";
+import CardContent from "@material-ui/core/CardContent";
+import { withStyles } from "@material-ui/core/styles";
+import TextField from "@material-ui/core/TextField";
+import * as React from "react";
+
+import CardTitle from "../../../components/CardTitle";
+import i18n from "../../../i18n";
+
+export interface CustomerCreateDetailsProps {
+ data: {
+ email: string;
+ };
+ disabled: boolean;
+ errors: Partial<{
+ email: string;
+ }>;
+ onChange: (event: React.ChangeEvent<any>) => void;
+}
+
+const decorate = withStyles(theme => ({
+ root: {
+ display: "grid" as "grid",
+ gridColumnGap: theme.spacing.unit * 2 + "px",
+ gridTemplateColumns: "1fr 1fr"
+ }
+}));
+const CustomerCreateDetails = decorate<CustomerCreateDetailsProps>(
+ ({ classes, data, disabled, onChange }) => (
+ <Card>
+ <CardTitle title={i18n.t("Customer overview")} />
+ <CardContent>
+ <div className={classes.root}>
+ <TextField
+ disabled={disabled}
+ fullWidth
+ name="email"
+ label={i18n.t("E-mail")}
+ type="email"
+ value={data.email}
+ onChange={onChange}
+ />
+ </div>
+ </CardContent>
+ </Card>
+ )
+);
+CustomerCreateDetails.displayName = "CustomerCreateDetails";
+export default CustomerCreateDetails;
diff --git a/saleor/static/dashboard-next/customers/components/CustomerCreateDetails/index.ts b/saleor/static/dashboard-next/customers/components/CustomerCreateDetails/index.ts
new file mode 100644
index 0000000000..b7353f089c
--- /dev/null
+++ b/saleor/static/dashboard-next/customers/components/CustomerCreateDetails/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./CustomerCreateDetails";
+export * from "./CustomerCreateDetails";
diff --git a/saleor/static/dashboard-next/customers/components/CustomerCreateNote/CustomerCreateNote.tsx b/saleor/static/dashboard-next/customers/components/CustomerCreateNote/CustomerCreateNote.tsx
new file mode 100644
index 0000000000..69b8a1c673
--- /dev/null
+++ b/saleor/static/dashboard-next/customers/components/CustomerCreateNote/CustomerCreateNote.tsx
@@ -0,0 +1,47 @@
+import Card from "@material-ui/core/Card";
+import CardContent from "@material-ui/core/CardContent";
+import TextField from "@material-ui/core/TextField";
+import Typography from "@material-ui/core/Typography";
+import * as React from "react";
+
+import CardTitle from "../../../components/CardTitle";
+import { FormSpacer } from "../../../components/FormSpacer";
+import i18n from "../../../i18n";
+
+export interface CustomerCreateNoteProps {
+ data: {
+ note: string;
+ };
+ disabled: boolean;
+ errors: Partial<{
+ note: string;
+ }>;
+ onChange: (event: React.ChangeEvent<any>) => void;
+}
+
+const CustomerCreateNote: React.StatelessComponent<CustomerCreateNoteProps> = ({
+ data,
+ disabled,
+ onChange
+}) => (
+ <Card>
+ <CardTitle title={i18n.t("Notes")} />
+ <CardContent>
+ <Typography>
+ {i18n.t("Enter any extra infotmation regarding this customer.")}
+ </Typography>
+ <FormSpacer />
+ <TextField
+ disabled={disabled}
+ fullWidth
+ multiline
+ name="note"
+ label={i18n.t("E-mail")}
+ value={data.note}
+ onChange={onChange}
+ />
+ </CardContent>
+ </Card>
+);
+CustomerCreateNote.displayName = "CustomerCreateNote";
+export default CustomerCreateNote;
diff --git a/saleor/static/dashboard-next/customers/components/CustomerCreateNote/index.ts b/saleor/static/dashboard-next/customers/components/CustomerCreateNote/index.ts
new file mode 100644
index 0000000000..71a3ac5dd4
--- /dev/null
+++ b/saleor/static/dashboard-next/customers/components/CustomerCreateNote/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./CustomerCreateNote";
+export * from "./CustomerCreateNote";
diff --git a/saleor/static/dashboard-next/customers/components/CustomerCreatePage/CustomerCreatePage.tsx b/saleor/static/dashboard-next/customers/components/CustomerCreatePage/CustomerCreatePage.tsx
new file mode 100644
index 0000000000..079db334eb
--- /dev/null
+++ b/saleor/static/dashboard-next/customers/components/CustomerCreatePage/CustomerCreatePage.tsx
@@ -0,0 +1,89 @@
+import { withStyles } from "@material-ui/core/styles";
+import * as React from "react";
+
+import { CardSpacer } from "../../../components/CardSpacer";
+import Container from "../../../components/Container";
+import Form from "../../../components/Form";
+import PageHeader from "../../../components/PageHeader";
+import SaveButtonBar from "../../../components/SaveButtonBar";
+import i18n from "../../../i18n";
+import { AddressTypeInput } from "../../types";
+import CustomerCreateAddress from "../CustomerCreateAddress/CustomerCreateAddress";
+import CustomerCreateDetails from "../CustomerCreateDetails";
+import CustomerCreateNote from "../CustomerCreateNote/CustomerCreateNote";
+
+export interface CustomerCreatePageFormData extends AddressTypeInput {
+ email: string;
+ note: string;
+}
+
+export interface CustomerCreatePageProps {
+ disabled: boolean;
+ onBack: () => void;
+}
+
+const initialForm: CustomerCreatePageFormData = {
+ city: "",
+ cityArea: "",
+ companyName: "",
+ country: "",
+ countryArea: "",
+ email: "",
+ firstName: "",
+ lastName: "",
+ note: "",
+ phone: "",
+ postalCode: "",
+ streetAddress1: "",
+ streetAddress2: ""
+};
+
+const decorate = withStyles(theme => ({
+ root: {
+ display: "grid" as "grid",
+ gridColumnGap: theme.spacing.unit * 3 + "px",
+ gridTemplateColumns: "9fr 4fr"
+ }
+}));
+const CustomerCreatePage = decorate<CustomerCreatePageProps>(
+ ({ classes, disabled, onBack }) => (
+ <Form initial={initialForm}>
+ {({ change, data, errors: formErrors, hasChanged, submit }) => (
+ <Container width="md">
+ <PageHeader title={i18n.t("Add customer")} onBack={onBack} />
+ <div className={classes.root}>
+ <div>
+ <CustomerCreateDetails
+ data={data}
+ disabled={disabled}
+ errors={formErrors}
+ onChange={change}
+ />
+ <CardSpacer />
+ <CustomerCreateAddress
+ data={data}
+ disabled={disabled}
+ errors={formErrors}
+ onChange={change}
+ />
+ <CardSpacer />
+ <CustomerCreateNote
+ data={data}
+ disabled={disabled}
+ errors={formErrors}
+ onChange={change}
+ />
+ </div>
+ </div>
+ <SaveButtonBar
+ disabled={disabled || !hasChanged}
+ onSave={submit}
+ onCancel={onBack}
+ />
+ </Container>
+ )}
+ </Form>
+ )
+);
+CustomerCreatePage.displayName = "CustomerCreatePage";
+export default CustomerCreatePage;
diff --git a/saleor/static/dashboard-next/customers/components/CustomerCreatePage/index.ts b/saleor/static/dashboard-next/customers/components/CustomerCreatePage/index.ts
new file mode 100644
index 0000000000..c30fee3175
--- /dev/null
+++ b/saleor/static/dashboard-next/customers/components/CustomerCreatePage/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./CustomerCreatePage";
+export * from "./CustomerCreatePage";
diff --git a/saleor/static/dashboard-next/customers/index.tsx b/saleor/static/dashboard-next/customers/index.tsx
index 23a17641ac..3a5dc5619a 100644
--- a/saleor/static/dashboard-next/customers/index.tsx
+++ b/saleor/static/dashboard-next/customers/index.tsx
@@ -3,6 +3,7 @@ import * as React from "react";
import { Route, RouteComponentProps, Switch } from "react-router-dom";
import { customerListUrl, customerUrl } from "./urls";
+// import CustomerCreateView from "./views/CustomerCreate";
import CustomerDetailsViewComponent from "./views/CustomerDetails";
import CustomerListViewComponent from "./views/CustomerList";
@@ -29,6 +30,7 @@ const CustomerDetailsView: React.StatelessComponent<
export const CustomerSection: React.StatelessComponent<{}> = () => (
<Switch>
<Route exact path={customerListUrl} component={CustomerListView} />
+ {/* <Route exact path={customerUrl("add")} component={CustomerDetailsView} /> */}
<Route path={customerUrl(":id")} component={CustomerDetailsView} />
</Switch>
);
diff --git a/saleor/static/dashboard-next/customers/views/CustomerCreate.tsx b/saleor/static/dashboard-next/customers/views/CustomerCreate.tsx
new file mode 100644
index 0000000000..a798f7473b
--- /dev/null
+++ b/saleor/static/dashboard-next/customers/views/CustomerCreate.tsx
@@ -0,0 +1,5 @@
+import * as React from 'react'
+
+import Navigator from '../../components/Navigator'
+import Messages from '../../components/messages'
+import
\ No newline at end of file
diff --git a/saleor/static/dashboard-next/storybook/config.js b/saleor/static/dashboard-next/storybook/config.js
index 62e82cc64a..ac48676a0e 100644
--- a/saleor/static/dashboard-next/storybook/config.js
+++ b/saleor/static/dashboard-next/storybook/config.js
@@ -47,6 +47,7 @@ function loadStories() {
require("./stories/configuration/ConfigurationPage");
// Customers
+ require("./stories/customers/CustomerCreatePage");
require("./stories/customers/CustomerDetailsPage");
require("./stories/customers/CustomerListPage");
diff --git a/saleor/static/dashboard-next/storybook/stories/customers/CustomerCreatePage.tsx b/saleor/static/dashboard-next/storybook/stories/customers/CustomerCreatePage.tsx
new file mode 100644
index 0000000000..ee6379561e
--- /dev/null
+++ b/saleor/static/dashboard-next/storybook/stories/customers/CustomerCreatePage.tsx
@@ -0,0 +1,17 @@
+import { storiesOf } from "@storybook/react";
+import * as React from "react";
+
+import CustomerCreatePage, {
+ CustomerCreatePageProps
+} from "../../../customers/components/CustomerCreatePage";
+import Decorator from "../../Decorator";
+
+const props: CustomerCreatePageProps = {
+ disabled: false,
+ onBack: () => undefined
+};
+
+storiesOf("Views / Customers / Create customer", module)
+ .addDecorator(Decorator)
+ .add("default", () => <CustomerCreatePage {...props} />)
+ .add("loading", () => <CustomerCreatePage {...props} disabled={true} />);