From 04ef09bba76f8ce3572120c19a3070c45a4af86c Mon Sep 17 00:00:00 2001 From: MikunoNaka Date: Sun, 8 Aug 2021 18:10:50 +0530 Subject: added support for Item Brand and Category --- src/components/Form/Items/AddNewItemForm.tsx | 40 ++++++++++++++++++++++---- src/components/Form/Items/RegisterItemForm.tsx | 24 ++++++++++++---- 2 files changed, 54 insertions(+), 10 deletions(-) (limited to 'src/components/Form/Items') diff --git a/src/components/Form/Items/AddNewItemForm.tsx b/src/components/Form/Items/AddNewItemForm.tsx index 5be2eea..b810964 100644 --- a/src/components/Form/Items/AddNewItemForm.tsx +++ b/src/components/Form/Items/AddNewItemForm.tsx @@ -28,13 +28,17 @@ const AddNewItemForm: React.FC = (props) => { const [itemGSTPercentage, setItemGSTPercentage] = useState(props.defGSTValue); const [itemQTYValue, setItemQTYValue] = useState(1); const [itemHSNValue, setItemHSNValue] = useState(""); + const [itemBrand, setItemBrand] = useState(""); + const [itemCategory, setItemCategory] = useState(""); // default item object const defaultItem: any = { Description: "", UnitPrice: 0.00, TotalGST: props.defGSTValue, - HSN: "" + HSN: "", + Brand: "", + Category: "" } // store the current item to easily reset a value to the default one @@ -50,12 +54,15 @@ const AddNewItemForm: React.FC = (props) => { const emptyItemNames: string[] = [enterItemNamePrompt, registerItemPrompt, ""]; // set description and price if match found in DB - const applyItemInfo = (i: any) => { + const applyItemInfo = (i: Item) => { setItemDescValue(i.Description); setItemPriceValue(i.UnitPrice); setItemHSNValue(i.HSN); setItemGSTPercentage(i.TotalGST); - setCurrentItem(i) + setItemBrand(i.Brand); + setItemCategory(i.Category); + console.log(i); + setCurrentItem(i); } // check the item name value and do stuff accordingly @@ -63,7 +70,7 @@ const AddNewItemForm: React.FC = (props) => { (props.savedItems === null || itemName === registerItemPrompt) ? props.registerItemFormVisibility(true) : props.savedItems.some((i) => - itemName === i.Model.toLowerCase() && applyItemInfo(i)) + itemName === i.Model.toLowerCase() && applyItemInfo(i)); const resetAllValues = () => { setItemNameValue(""); @@ -107,7 +114,10 @@ const AddNewItemForm: React.FC = (props) => { // this also checks if igst applies or not SGST: inState && totalGSTValue / 2, CGST: inState && totalGSTValue / 2, - IGST: inState || totalGSTValue + IGST: inState || totalGSTValue, + + Brand: itemBrand, + Category: itemCategory } props.addItem(newInvoiceItem); @@ -150,6 +160,26 @@ const AddNewItemForm: React.FC = (props) => { /> + + + +
diff --git a/src/components/Form/Items/RegisterItemForm.tsx b/src/components/Form/Items/RegisterItemForm.tsx index 886628c..7e9f67b 100644 --- a/src/components/Form/Items/RegisterItemForm.tsx +++ b/src/components/Form/Items/RegisterItemForm.tsx @@ -9,14 +9,14 @@ // TODO: Code isn't tested properly // I'd be surprised if it < 10 bugs -import React, { useState } from "react"; +import React, { useState, Dispatch, SetStateAction } from "react"; import "./../Form.scss"; import { NewItem } from "./../../../interfaces" import axios from "axios"; interface props { defGSTValue: number - setVisibility: any // this component's visibility + setVisibility: Dispatch> // this component's visibility updateItemsList: () => Promise } @@ -26,8 +26,8 @@ const RegisterItemForm: React.FC = (props) => { const [newItemPrice, setNewItemPrice] = useState(0.00); const [newItemHSN, setNewItemHSN] = useState(""); const [newItemGST, setNewItemGST] = useState(props.defGSTValue); - // const [newItemBrand, setNewItemBrand] = useState(""); - // const [newItemType, setNewItemType] = useState(""); + const [newItemBrand, setNewItemBrand] = useState(""); + const [newItemCategory, setNewItemCategory] = useState(""); const hideSelf = () => props.setVisibility(false); @@ -42,7 +42,9 @@ const RegisterItemForm: React.FC = (props) => { Description: newItemDesc, UnitPrice: newItemPrice, HSN: newItemHSN, - TotalGST: newItemGST + TotalGST: newItemGST, + Brand: newItemBrand, + Category: newItemCategory } // TODO: show confirmation before being invisible @@ -79,7 +81,19 @@ const RegisterItemForm: React.FC = (props) => { } /> + + +
+