diff options
author | MikunoNaka <bokuwakanojogahoshii@yahoo.com> | 2021-05-05 11:00:28 +0530 |
---|---|---|
committer | MikunoNaka <bokuwakanojogahoshii@yahoo.com> | 2021-05-05 11:00:28 +0530 |
commit | 5b630590d7e2f803007911e22f24444aefef541d (patch) | |
tree | 21d0a567bd7fcf9db46d2035dbcd540a22fe2d86 /src/components/BillingPage.js | |
parent | 499c54e8eb53cf49d8ddae68528eb3a8243101d2 (diff) |
made the code less error prone and more oriented towards the functional paradigm
Diffstat (limited to 'src/components/BillingPage.js')
-rw-r--r-- | src/components/BillingPage.js | 37 |
1 files changed, 9 insertions, 28 deletions
diff --git a/src/components/BillingPage.js b/src/components/BillingPage.js index 71d7c81..cb9e74c 100644 --- a/src/components/BillingPage.js +++ b/src/components/BillingPage.js @@ -25,47 +25,28 @@ const BillingPage = () => { const [savedPeople, getSavedPeople] = useState([]); const [registerItemFormVisibility, setRegisterItemFormVisibility] = useState(false); const [registerPersonFormVisibility, setRegisterPersonFormVisibility] = useState(false); + const [items, setItems] = useState([]); - const getRegisteredItems = () => { + const getRegisteredItems = () => axios.get(`/api/items/get-all`) - .then((res) => { - getSavedItems(res.data); - }) - .catch((res) => { - alert("The promise returned an error idk what to do"); - console.log(res); - }) - } - - const getRegisteredPeople = () => { + .then((res) => getSavedItems(res.data)) + .catch((res) => console.log(res)); + + const getRegisteredPeople = () => axios.get(`/api/people/get-all`) - .then((res) => { - getSavedPeople(res.data); - }) - .catch((res) => { - alert("The promise returned an error idk what to do"); - console.log(res); - }) - } + .then((res) => getSavedPeople(res.data)) + .catch((res) => console.log(res)); // get data from server on startup useEffect(() => { - async function fetchdata() { getRegisteredItems(); getRegisteredPeople(); - } - fetchdata() }, []); // TODO: to be handled by backend const defGSTValue = 18; // update the items from AddNewItemForm - const [items, setItems] = useState([]); - const getItems = (item) => { - setItems( - [...items, item] - ); - }; + const getItems = (item) => setItems([...items, item]); return ( <> |