From 5846185f5a6662265c5330fbed229f49efb26b89 Mon Sep 17 00:00:00 2001 From: MikunoNaka Date: Mon, 3 May 2021 12:26:47 +0530 Subject: added some features and many bugs to DocumentInfoForm --- src/components/BillingPage.js | 19 ++- src/components/Form/Document/DocumentInfoForm.js | 191 +++++------------------ src/components/Form/Items/AddNewItemForm.js | 8 +- 3 files changed, 61 insertions(+), 157 deletions(-) (limited to 'src/components') diff --git a/src/components/BillingPage.js b/src/components/BillingPage.js index be2e299..40917e5 100644 --- a/src/components/BillingPage.js +++ b/src/components/BillingPage.js @@ -14,6 +14,7 @@ import RegisterItemForm from "./Form/Items/RegisterItemForm"; import RegisterPersonForm from "./Form/People/RegisterPersonForm"; +import DocumentInfoForm from "./Form/Document/DocumentInfoForm"; import MetaInfoForm from "./Form/MetaInfoForm"; import ItemsDisplay from "./Display/ItemsDisplay"; @@ -21,6 +22,7 @@ import SummaryDisplay from "./Display/SummaryDisplay"; const BillingPage = () => { const [savedItems, getSavedItems] = useState([]); + const [savedPeople, getSavedPeople] = useState([]); const [registerItemFormVisibility, setRegisterItemFormVisibility] = useState(false); const [registerPersonFormVisibility, setRegisterPersonFormVisibility] = useState(false); @@ -35,9 +37,21 @@ const BillingPage = () => { }) } + const getRegisteredPeople = () => { + axios.get(`/api/people`) + .then((res) => { + getSavedPeople(res.data); + }) + .catch((res) => { + alert("The promise returned an error idk what to do"); + console.log(res); + }) + } + // get data from server on startup useEffect(() => { getRegisteredItems(); + getRegisteredPeople(); }, []); // TODO: to be handled by backend const defGSTValue = 18; @@ -62,12 +76,15 @@ const BillingPage = () => { {registerPersonFormVisibility && } + + { - const [itemNameValue, setItemNameValue] = useState(""); - const [itemDescValue, setItemDescValue] = useState(""); - const [itemPriceValue, setItemPriceValue] = useState(0.00); - const [itemDiscountValue, setItemDiscountValue] = useState(0.00); - const [itemGSTValue, setItemGSTValue] = useState(props.defGSTValue); - const [itemQtyValue, setItemQtyValue] = useState(1); - const [itemHSNValue, setItemHSNValue] = useState(0); +const DocumentInfoForm = (props) => { + const [clientName, setClientName] = useState(0); + /* TODO: implement a way such that the database also + * gives the ID of the client and all the functions + * are carried out from the ID because if two people + * with same name are added then this shit is done for + */ - const [itemToAdd, setItemToAdd] = useState({}); + const selectPersonPrompt = "start typing here"; + const registerPersonPrompt = "add new"; - const enterItemNamePrompt = "start typing here"; - const registerItemPrompt = "add new"; - const emptyItemNames = [enterItemNamePrompt, registerItemPrompt, ""]; + // const emptyPersonNames = [enterItemNamePrompt, registerItemPrompt, ""]; // Extract the model names from savedItems - let savedItemNames= []; + let savedPeopleNames = []; if (props.savedItems !== null) { - for (let i = 0; i < props.savedItems.length; i++) { - savedItemNames.push(props.savedItems[i].Model); + for (let i = 0; i < props.savedPeople.length; i++) { + savedPeopleNames.push(props.savedPeople[i].Name); } } // set description and price // when item is entered + /* const setItemInfo = (itemName) => { for (let i = 0; i < props.savedItems.length; i++) { const mod = props.savedItems[i].Model.toLowerCase(); @@ -52,7 +51,9 @@ const AddNewItemForm = (props) => { } } } + */ + /* const resetAllValues = () => { setItemNameValue(""); setItemDescValue(""); @@ -62,145 +63,31 @@ const AddNewItemForm = (props) => { setItemHSNValue(0); setItemGSTValue(props.defGSTValue); } + */ return ( -
-
{ - event.preventDefault(); - const newInvoiceItem = { - "Model": itemNameValue, - "Description": itemDescValue, - "Quantity": parseInt(itemQtyValue), - "UnitPrice": parseFloat(itemPriceValue), - "TotalPrice": parseFloat(itemPriceValue * itemQtyValue), - "Discount": parseInt(itemDiscountValue), - "HSN": parseInt(itemHSNValue), - "GST": parseInt(itemGSTValue) - }; - props.addItem(newInvoiceItem); - resetAllValues(); - } - }> -
- - - -
- -
- - - - - - - - - -
- -
- props.registerFormVisibility(true)} - /> - - - - - - + Client Name: + + + ); } -export default AddNewItemForm; +export default DocumentInfoForm; diff --git a/src/components/Form/Items/AddNewItemForm.js b/src/components/Form/Items/AddNewItemForm.js index 4eaea7d..78d1437 100644 --- a/src/components/Form/Items/AddNewItemForm.js +++ b/src/components/Form/Items/AddNewItemForm.js @@ -181,13 +181,13 @@ const AddNewItemForm = (props) => {
props.registerItemFormVisibility(true)} + value="Register New Client" + onClick={() => props.registerPersonFormVisibility(true)} /> props.registerPersonFormVisibility(true)} + value="Register New Item" + onClick={() => props.registerItemFormVisibility(true)} /> -- cgit v1.2.3