Do not submit address if not given
This commit is contained in:
parent
11e6743ad7
commit
f2330bd662
1 changed files with 22 additions and 2 deletions
|
@ -8,6 +8,7 @@ import { maybe, transformFormToAddress } from "../../misc";
|
||||||
import CustomerCreatePage from "../components/CustomerCreatePage";
|
import CustomerCreatePage from "../components/CustomerCreatePage";
|
||||||
import { TypedCreateCustomerMutation } from "../mutations";
|
import { TypedCreateCustomerMutation } from "../mutations";
|
||||||
import { TypedCustomerCreateDataQuery } from "../queries";
|
import { TypedCustomerCreateDataQuery } from "../queries";
|
||||||
|
import { AddressTypeInput } from "../types";
|
||||||
import { CreateCustomer } from "../types/CreateCustomer";
|
import { CreateCustomer } from "../types/CreateCustomer";
|
||||||
import { customerListUrl, customerUrl } from "../urls";
|
import { customerListUrl, customerUrl } from "../urls";
|
||||||
|
|
||||||
|
@ -57,6 +58,21 @@ export const CustomerCreate: React.StatelessComponent<{}> = () => {
|
||||||
}
|
}
|
||||||
onBack={() => navigate(customerListUrl())}
|
onBack={() => navigate(customerListUrl())}
|
||||||
onSubmit={formData => {
|
onSubmit={formData => {
|
||||||
|
const areAddressInputFieldsModified = ([
|
||||||
|
"city",
|
||||||
|
"companyName",
|
||||||
|
"country",
|
||||||
|
"countryArea",
|
||||||
|
"firstName",
|
||||||
|
"lastName",
|
||||||
|
"phone",
|
||||||
|
"postalCode",
|
||||||
|
"streetAddress1",
|
||||||
|
"streetAddress2"
|
||||||
|
] as Array<keyof AddressTypeInput>)
|
||||||
|
.map(key => formData[key])
|
||||||
|
.some(field => field !== "");
|
||||||
|
|
||||||
const address = {
|
const address = {
|
||||||
city: formData.city,
|
city: formData.city,
|
||||||
cityArea: formData.cityArea,
|
cityArea: formData.cityArea,
|
||||||
|
@ -73,8 +89,12 @@ export const CustomerCreate: React.StatelessComponent<{}> = () => {
|
||||||
createCustomer({
|
createCustomer({
|
||||||
variables: {
|
variables: {
|
||||||
input: {
|
input: {
|
||||||
defaultBillingAddress: transformFormToAddress(address),
|
defaultBillingAddress: areAddressInputFieldsModified
|
||||||
defaultShippingAddress: transformFormToAddress(address),
|
? transformFormToAddress(address)
|
||||||
|
: null,
|
||||||
|
defaultShippingAddress: areAddressInputFieldsModified
|
||||||
|
? transformFormToAddress(address)
|
||||||
|
: null,
|
||||||
email: formData.email,
|
email: formData.email,
|
||||||
firstName: formData.customerFirstName,
|
firstName: formData.customerFirstName,
|
||||||
lastName: formData.customerLastName,
|
lastName: formData.customerLastName,
|
||||||
|
|
Loading…
Reference in a new issue