aboutsummaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-10-01 20:32:57 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-10-01 20:32:57 +0530
commit8c01e16a8336a91659db7bf73ffe94077f90e25b (patch)
tree53ded616dd4a730acdbd204ab563dbde52375a51 /src/components
parent1e5743b1596276307f3028d5767488a7ffe11c4c (diff)
Bug Fix: Couldn't add shipping address while editing existing client
Diffstat (limited to 'src/components')
-rw-r--r--src/components/editors/client-editor.js18
-rw-r--r--src/components/editors/multi-address-editor.js6
2 files changed, 11 insertions, 13 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([]);
diff --git a/src/components/editors/multi-address-editor.js b/src/components/editors/multi-address-editor.js
index a0182f2..bb69e20 100644
--- a/src/components/editors/multi-address-editor.js
+++ b/src/components/editors/multi-address-editor.js
@@ -18,17 +18,13 @@
import { Address } from './../../classes/client';
import AddressEditor from './address-editor';
-import { useState, useEffect } from 'react';
-
const MultiAddressEditor = ({addresses, setAddresses, setShipToBillingAddress}) => {
+ console.log(addresses)
const handleChange = (id, data) => {
- console.log(id, data)
-
const newAddresses = [...addresses];
newAddresses[id] = {
...newAddresses[id], ...data
}
-
setAddresses(newAddresses)
}