From f2330bd662924c1883fa7174280f334ecadab286 Mon Sep 17 00:00:00 2001 From: dominik-zeglen Date: Wed, 6 Nov 2019 14:26:59 +0100 Subject: [PATCH] Do not submit address if not given --- src/customers/views/CustomerCreate.tsx | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/customers/views/CustomerCreate.tsx b/src/customers/views/CustomerCreate.tsx index 7713ad076..e53886b9a 100644 --- a/src/customers/views/CustomerCreate.tsx +++ b/src/customers/views/CustomerCreate.tsx @@ -8,6 +8,7 @@ import { maybe, transformFormToAddress } from "../../misc"; import CustomerCreatePage from "../components/CustomerCreatePage"; import { TypedCreateCustomerMutation } from "../mutations"; import { TypedCustomerCreateDataQuery } from "../queries"; +import { AddressTypeInput } from "../types"; import { CreateCustomer } from "../types/CreateCustomer"; import { customerListUrl, customerUrl } from "../urls"; @@ -57,6 +58,21 @@ export const CustomerCreate: React.StatelessComponent<{}> = () => { } onBack={() => navigate(customerListUrl())} onSubmit={formData => { + const areAddressInputFieldsModified = ([ + "city", + "companyName", + "country", + "countryArea", + "firstName", + "lastName", + "phone", + "postalCode", + "streetAddress1", + "streetAddress2" + ] as Array) + .map(key => formData[key]) + .some(field => field !== ""); + const address = { city: formData.city, cityArea: formData.cityArea, @@ -73,8 +89,12 @@ export const CustomerCreate: React.StatelessComponent<{}> = () => { createCustomer({ variables: { input: { - defaultBillingAddress: transformFormToAddress(address), - defaultShippingAddress: transformFormToAddress(address), + defaultBillingAddress: areAddressInputFieldsModified + ? transformFormToAddress(address) + : null, + defaultShippingAddress: areAddressInputFieldsModified + ? transformFormToAddress(address) + : null, email: formData.email, firstName: formData.customerFirstName, lastName: formData.customerLastName,