Skip to content

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

Fix add customer form

dominik-zeglenabca0237af92
diff --git a/saleor/static/dashboard-next/components/AddressEdit/AddressEdit.tsx b/saleor/static/dashboard-next/components/AddressEdit/AddressEdit.tsx
index 7435909db5..0e93fd8237 100644
--- a/saleor/static/dashboard-next/components/AddressEdit/AddressEdit.tsx
+++ b/saleor/static/dashboard-next/components/AddressEdit/AddressEdit.tsx
@@ -10,6 +10,7 @@ import * as React from "react";
import { AddressTypeInput } from "../../customers/types";
import i18n from "../../i18n";
import { maybe } from "../../misc";
+import { FormErrors } from "../../types";
import FormSpacer from "../FormSpacer";
import SingleAutocompleteSelectField from "../SingleAutocompleteSelectField";
@@ -29,7 +30,7 @@ interface AddressEditProps extends WithStyles<typeof styles> {
}>;
data: AddressTypeInput;
disabled?: boolean;
- errors: { [T in keyof AddressTypeInput]?: string };
+ errors: FormErrors<keyof AddressTypeInput>;
onChange(event: React.ChangeEvent<any>);
}
@@ -161,6 +162,9 @@ const AddressEdit = withStyles(styles, { name: "AddressEdit" })(
() => countries.map(c => ({ ...c, value: c.code })),
[]
)}
+ InputProps={{
+ autoComplete: "off"
+ }}
/>
</div>
<div>
diff --git a/saleor/static/dashboard-next/components/SingleAutocompleteSelectField/SingleAutocompleteSelectField.tsx b/saleor/static/dashboard-next/components/SingleAutocompleteSelectField/SingleAutocompleteSelectField.tsx
index 3b122c4c39..152ccc256b 100644
--- a/saleor/static/dashboard-next/components/SingleAutocompleteSelectField/SingleAutocompleteSelectField.tsx
+++ b/saleor/static/dashboard-next/components/SingleAutocompleteSelectField/SingleAutocompleteSelectField.tsx
@@ -1,4 +1,5 @@
import { Omit } from "@material-ui/core";
+import { InputProps } from "@material-ui/core/Input";
import MenuItem from "@material-ui/core/MenuItem";
import Paper from "@material-ui/core/Paper";
import {
@@ -48,6 +49,7 @@ interface SingleAutocompleteSelectFieldProps extends WithStyles<typeof styles> {
custom?: boolean;
helperText?: string;
label?: string;
+ InputProps?: InputProps;
fetchChoices?(value: string);
onChange(event);
}
@@ -78,6 +80,7 @@ const SingleAutocompleteSelectFieldComponent = withStyles(styles, {
name,
placeholder,
value,
+ InputProps,
fetchChoices,
onChange
}: SingleAutocompleteSelectFieldProps) => {
@@ -112,6 +115,7 @@ const SingleAutocompleteSelectFieldComponent = withStyles(styles, {
<div className={classes.container}>
<TextField
InputProps={{
+ ...InputProps,
...getInputProps({
placeholder
}),
diff --git a/saleor/static/dashboard-next/customers/components/CustomerCreateAddress/CustomerCreateAddress.tsx b/saleor/static/dashboard-next/customers/components/CustomerCreateAddress/CustomerCreateAddress.tsx
index 538dbdf181..67ca465bb6 100644
--- a/saleor/static/dashboard-next/customers/components/CustomerCreateAddress/CustomerCreateAddress.tsx
+++ b/saleor/static/dashboard-next/customers/components/CustomerCreateAddress/CustomerCreateAddress.tsx
@@ -8,6 +8,7 @@ import AddressEdit from "../../../components/AddressEdit/AddressEdit";
import CardTitle from "../../../components/CardTitle";
import { FormSpacer } from "../../../components/FormSpacer";
import i18n from "../../../i18n";
+import { FormErrors } from "../../../types";
import { AddressTypeInput } from "../../types";
import { CustomerCreateData_shop_countries } from "../../types/CustomerCreateData";
@@ -21,7 +22,7 @@ export interface CustomerCreateAddressProps extends WithStyles<typeof styles> {
countries: CustomerCreateData_shop_countries[];
data: AddressTypeInput;
disabled: boolean;
- errors: { [T in keyof AddressTypeInput]?: string };
+ errors: FormErrors<keyof AddressTypeInput>;
onChange(event: React.ChangeEvent<any>);
}
diff --git a/saleor/static/dashboard-next/customers/components/CustomerCreateDetails/CustomerCreateDetails.tsx b/saleor/static/dashboard-next/customers/components/CustomerCreateDetails/CustomerCreateDetails.tsx
index 6d742d9879..8861c48266 100644
--- a/saleor/static/dashboard-next/customers/components/CustomerCreateDetails/CustomerCreateDetails.tsx
+++ b/saleor/static/dashboard-next/customers/components/CustomerCreateDetails/CustomerCreateDetails.tsx
@@ -11,6 +11,8 @@ import * as React from "react";
import CardTitle from "../../../components/CardTitle";
import i18n from "../../../i18n";
+import { FormErrors } from "../../../types";
+import { CustomerCreatePageFormData } from "../CustomerCreatePage";
const styles = (theme: Theme) =>
createStyles({
@@ -23,17 +25,9 @@ const styles = (theme: Theme) =>
});
export interface CustomerCreateDetailsProps extends WithStyles<typeof styles> {
- data: {
- email: string;
- firstName: string;
- lastName: string;
- };
+ data: CustomerCreatePageFormData;
disabled: boolean;
- errors: Partial<{
- email: string;
- firstName: string;
- lastName: string;
- }>;
+ errors: FormErrors<"customerFirstName" | "customerLastName" | "email">;
onChange: (event: React.ChangeEvent<any>) => void;
}
@@ -53,24 +47,24 @@ const CustomerCreateDetails = withStyles(styles, {
<div className={classes.root}>
<TextField
disabled={disabled}
- error={!!errors.firstName}
+ error={!!errors.customerFirstName}
fullWidth
- name="firstName"
+ name="customerFirstName"
label={i18n.t("First Name")}
- helperText={errors.firstName}
+ helperText={errors.customerFirstName}
type="text"
- value={data.email}
+ value={data.customerFirstName}
onChange={onChange}
/>
<TextField
disabled={disabled}
- error={!!errors.lastName}
+ error={!!errors.customerLastName}
fullWidth
- name="lastName"
+ name="customerLastName"
label={i18n.t("Last Name")}
- helperText={errors.lastName}
+ helperText={errors.customerLastName}
type="text"
- value={data.lastName}
+ value={data.customerLastName}
onChange={onChange}
/>
<TextField
diff --git a/saleor/static/dashboard-next/customers/components/CustomerCreatePage/CustomerCreatePage.tsx b/saleor/static/dashboard-next/customers/components/CustomerCreatePage/CustomerCreatePage.tsx
index fdb6ba1882..f56ac14b20 100644
--- a/saleor/static/dashboard-next/customers/components/CustomerCreatePage/CustomerCreatePage.tsx
+++ b/saleor/static/dashboard-next/customers/components/CustomerCreatePage/CustomerCreatePage.tsx
@@ -17,6 +17,8 @@ import CustomerCreateDetails from "../CustomerCreateDetails";
import CustomerCreateNote from "../CustomerCreateNote/CustomerCreateNote";
export interface CustomerCreatePageFormData extends AddressTypeInput {
+ customerFirstName: string;
+ customerLastName: string;
email: string;
note: string;
}
@@ -30,6 +32,8 @@ const initialForm: CustomerCreatePageFormData = {
value: ""
},
countryArea: "",
+ customerFirstName: "",
+ customerLastName: "",
email: "",
firstName: "",
lastName: "",
diff --git a/saleor/static/dashboard-next/customers/views/CustomerCreate.tsx b/saleor/static/dashboard-next/customers/views/CustomerCreate.tsx
index 90250df9a2..f148d91e61 100644
--- a/saleor/static/dashboard-next/customers/views/CustomerCreate.tsx
+++ b/saleor/static/dashboard-next/customers/views/CustomerCreate.tsx
@@ -38,10 +38,18 @@ export const CustomerCreate: React.StatelessComponent<{}> = () => (
<CustomerCreatePage
countries={maybe(() => data.shop.countries, [])}
disabled={loading || createCustomerOpts.loading}
- errors={maybe(
- () => createCustomerOpts.data.customerCreate.errors,
- []
- )}
+ errors={maybe(() => {
+ const errs =
+ createCustomerOpts.data.customerCreate.errors;
+ return errs.map(err =>
+ err.field.split(":").length > 1
+ ? {
+ ...err,
+ field: err.field.split(":")[1]
+ }
+ : err
+ );
+ }, [])}
saveButtonBar={
createCustomerOpts.loading ? "loading" : "default"
}
@@ -72,6 +80,8 @@ export const CustomerCreate: React.StatelessComponent<{}> = () => (
country: address.country.value
},
email: formData.email,
+ firstName: formData.customerFirstName,
+ lastName: formData.customerLastName,
note: formData.note,
sendPasswordEmail: true
}