From 5b630590d7e2f803007911e22f24444aefef541d Mon Sep 17 00:00:00 2001 From: MikunoNaka Date: Wed, 5 May 2021 11:00:28 +0530 Subject: made the code less error prone and more oriented towards the functional paradigm --- src/components/BillingPage.js | 37 +++++++++---------------------------- 1 file changed, 9 insertions(+), 28 deletions(-) (limited to 'src/components/BillingPage.js') 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 ( <> -- cgit v1.2.3