diff options
author | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2022-10-01 20:32:57 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2022-10-01 20:32:57 +0530 |
commit | 8c01e16a8336a91659db7bf73ffe94077f90e25b (patch) | |
tree | 53ded616dd4a730acdbd204ab563dbde52375a51 /src/components/editors/client-editor.js | |
parent | 1e5743b1596276307f3028d5767488a7ffe11c4c (diff) |
Bug Fix: Couldn't add shipping address while editing existing client
Diffstat (limited to 'src/components/editors/client-editor.js')
-rw-r--r-- | src/components/editors/client-editor.js | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/components/editors/client-editor.js b/src/components/editors/client-editor.js index e65ab8f..e07c749 100644 --- a/src/components/editors/client-editor.js +++ b/src/components/editors/client-editor.js @@ -35,22 +35,23 @@ const ClientEditor = (props) => { : props.client.ShippingAddresses.length === 0 ); - useEffect(() => { - // will delete existing shipping addresses if false - setShippingAddresses(shipToBillingAddress ? [] : [new Address()]) - }, [shipToBillingAddress]); + // will delete existing shipping addresses if false + useEffect(() => + setShippingAddresses(shipToBillingAddress ? [] : (shippingAddresses.length > 0 ? shippingAddresses : [new Address()])) + , [shipToBillingAddress]); const handleSubmit = (e) => { e.preventDefault(); const client = new Client(); + client.Id = props.client.Id; client.Name = name; client.GSTIN = GSTIN; client.Contact = contact; client.BillingAddress = billingAddress; client.ShippingAddresses = shipToBillingAddress ? [billingAddress] - : shippingAddresses + : shippingAddresses; // remove blank phone numbers/email addresses client.Contact.Phones = client.Contact.Phones.filter(i => i !== ""); @@ -61,20 +62,21 @@ const ClientEditor = (props) => { : saveClient(client, handleSuccess, handleFail); } - const handleSuccess = () => { + const handleSuccess = (res) => { + console.log("Successfully saved client", res) clearAll(); props.successCallback(); props.editing && props.hide(); } const handleFail = (err) => { - alert("fail"); + alert("error while saving client. please check logs"); console.log(err); } const clearAll = () => { setName(""); - setGSTIN("") + setGSTIN(""); setContact(new Contact()); setBillingAddress(new Address()); setShippingAddresses([]); |