From 748e70a86633c8bb3ba57a5136ed55bbaebe9c4c Mon Sep 17 00:00:00 2001 From: MikunoNaka Date: Fri, 2 Jul 2021 20:00:14 +0530 Subject: added reset buttons to the form --- src/components/Form/Items/AddNewItemForm.tsx | 108 ++++++++++++++++++++------- 1 file changed, 82 insertions(+), 26 deletions(-) (limited to 'src/components/Form/Items') diff --git a/src/components/Form/Items/AddNewItemForm.tsx b/src/components/Form/Items/AddNewItemForm.tsx index 3d4e65f..7060f51 100644 --- a/src/components/Form/Items/AddNewItemForm.tsx +++ b/src/components/Form/Items/AddNewItemForm.tsx @@ -7,10 +7,12 @@ */ import React, { useState } from "react"; -import "./../Form.scss"; import { Item } from "../../../interfaces"; +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' +import { faSync } from '@fortawesome/free-solid-svg-icons' +import "./../Form.scss"; -interface props { +interface Props { savedItems: Item[] addItem: (item: Item) => void defGSTValue: number @@ -18,15 +20,23 @@ interface props { registerPersonFormVisibility: any } -const AddNewItemForm: React.FC = (props) => { +const AddNewItemForm: React.FC = (props) => { const [itemNameValue, setItemNameValue] = useState(""); const [itemDescValue, setItemDescValue] = useState(""); const [itemPriceValue, setItemPriceValue] = useState(0.00); const [itemDiscountPercentage, setItemDiscountPercentage] = useState(0.00); - const [itemGSTPercentage, setItemGSTValue] = useState(props.defGSTValue); + const [itemGSTPercentage, setItemGSTPercentage] = useState(props.defGSTValue); const [itemQTYValue, setItemQTYValue] = useState(1); const [itemHSNValue, setItemHSNValue] = useState(""); + // store the current item to easily reset a value to the default one + const [currentItem, setCurrentItem] = useState({ + Description: "", + UnitPrice: 0.00, + GSTPercentage: props.defGSTValue, + HSN: "" + }); + // to be handled by DocumentInfo // check if client is in same state // and apply cgst+sgst or igst accordingly @@ -41,8 +51,10 @@ const AddNewItemForm: React.FC = (props) => { setItemDescValue(i.Description); setItemPriceValue(i.UnitPrice); setItemHSNValue(i.HSN); - setItemGSTValue(i.TotalGST); + setItemGSTPercentage(i.TotalGST); + setCurrentItem(i) } + console.log(currentItem) // check the item name value and do stuff accordingly const setItemInfo = (itemName: string) => @@ -58,7 +70,7 @@ const AddNewItemForm: React.FC = (props) => { setItemPriceValue(1); setItemDiscountPercentage(0); setItemHSNValue(""); - setItemGSTValue(props.defGSTValue); + setItemGSTPercentage(props.defGSTValue); } return ( @@ -70,8 +82,12 @@ const AddNewItemForm: React.FC = (props) => { const totalValue: number = itemPriceValue * itemQTYValue; // the values below are being rounded to two decimal places - const discountValue: number = parseFloat(((itemDiscountPercentage / 100) * totalValue).toFixed(2)) - const totalGSTValue: number = parseFloat(((itemGSTPercentage / 100) * totalValue).toFixed(2)) + // i see no reason doing this anymore + // const discountvalue: number = parsefloat(((itemdiscountpercentage / 100) * totalvalue).tofixed(2)) + // const totalgstvalue: number = parsefloat(((itemgstpercentage / 100) * totalvalue).tofixed(2)) + + const discountValue: number = (itemDiscountPercentage / 100) * totalValue; + const totalGSTValue: number = (itemGSTPercentage / 100) * totalValue; const newInvoiceItem: Item = { Model: itemNameValue, @@ -117,9 +133,19 @@ const AddNewItemForm: React.FC = (props) => { @@ -136,12 +162,22 @@ const AddNewItemForm: React.FC = (props) => {