aboutsummaryrefslogtreecommitdiff
path: root/src/components/editors
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/editors')
-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)
}