From 5d2222d9fa782b94ba6787e5c6b23aab1e468308 Mon Sep 17 00:00:00 2001 From: MikunoNaka Date: Thu, 24 Jun 2021 20:00:10 +0530 Subject: Multiple minor bug fixes and convert more compnents to TS --- src/components/Form/Document/MetaInfoForm.tsx | 17 ---- src/components/Form/Items/AddNewItemForm.tsx | 63 +++++------- src/components/Form/Items/RegisterItemForm.js | 135 ------------------------- src/components/Form/Items/RegisterItemForm.tsx | 125 +++++++++++++++++++++++ 4 files changed, 148 insertions(+), 192 deletions(-) delete mode 100644 src/components/Form/Items/RegisterItemForm.js create mode 100644 src/components/Form/Items/RegisterItemForm.tsx (limited to 'src/components') diff --git a/src/components/Form/Document/MetaInfoForm.tsx b/src/components/Form/Document/MetaInfoForm.tsx index da484ab..bcddad6 100644 --- a/src/components/Form/Document/MetaInfoForm.tsx +++ b/src/components/Form/Document/MetaInfoForm.tsx @@ -9,24 +9,7 @@ import React from "react"; import "./../Form.scss"; -interface Transport { - name: string, - vehicleNum: string, - method: string, // shipment method - gstin: string, - builty: string // goods receipt -} - const MetaInfoForm: React.FC = () => { - // don't push it to github! - const sampleTransport: Transport = { - name: "Own Vehicle", - vehicleNum: "HR61C9220", - method: "By Road", - gstin: "", - builty: "" - } - console.log(sampleTransport); return (
diff --git a/src/components/Form/Items/AddNewItemForm.tsx b/src/components/Form/Items/AddNewItemForm.tsx index 283d779..ae64b06 100644 --- a/src/components/Form/Items/AddNewItemForm.tsx +++ b/src/components/Form/Items/AddNewItemForm.tsx @@ -13,13 +13,12 @@ import { Item } from "../../../interfaces"; interface props { savedItems: Item[] addItem: (item: Item) => void - defGSTValue: number, - registerItemFormVisibility: any, + defGSTValue: number + registerItemFormVisibility: any registerPersonFormVisibility: any } const AddNewItemForm: React.FC = (props) => { - console.log(props) const [itemNameValue, setItemNameValue] = useState(""); const [itemDescValue, setItemDescValue] = useState(""); const [itemPriceValue, setItemPriceValue] = useState(0.00); @@ -35,18 +34,19 @@ const AddNewItemForm: React.FC = (props) => { const enterItemNamePrompt: string = "start typing here"; const registerItemPrompt: string = "add new"; - const emptyItemNames: any[] = [enterItemNamePrompt, registerItemPrompt, ""]; + const emptyItemNames: string[] = [enterItemNamePrompt, registerItemPrompt, ""]; // set description and price if match found in DB const applyItemInfo = (i: any) => { + console.log(i) setItemDescValue(i.Description); - setItemPriceValue(i.Price); + setItemPriceValue(i.UnitPrice); setItemHSNValue(i.HSN); - setItemGSTValue(i.GST); + setItemGSTValue(i.TotalGST); } // check the item name value and do stuff accordingly - const setItemInfo = (itemName: any) => + const setItemInfo = (itemName: string) => (props.savedItems === null || itemName === registerItemPrompt) ? props.registerItemFormVisibility(true) : props.savedItems.some((i) => @@ -77,12 +77,13 @@ const AddNewItemForm: React.FC = (props) => { TotalValue: (itemPriceValue * itemQTYValue), Discount: itemDiscountValue, HSN: itemHSNValue, + TotalGST: itemGSTValue, // this also checks if igst applies or not // TODO: fix this - sgst: 0, - cgst: 0, - igst: 0 + SGST: 0, + CGST: 0, + IGST: 0 // sgst: inState ? parseInt(itemGSTValue) / 2 : "", // cgst: inState ? parseInt(itemGSTValue) / 2 : "", // igst: inState ? "" : parseInt(itemGSTValue) @@ -115,11 +116,7 @@ const AddNewItemForm: React.FC = (props) => {
@@ -129,10 +126,8 @@ const AddNewItemForm: React.FC = (props) => { Quantity: ) => { - const value: number = parseInt(event.currentTarget.value); - setItemQTYValue(value); - } + (event: React.FormEvent) => + setItemQTYValue(parseInt(event.currentTarget.value)) } required /> @@ -141,10 +136,8 @@ const AddNewItemForm: React.FC = (props) => { Price: ) => { - const value: number = parseFloat(event.currentTarget.value); - setItemPriceValue(value); - } + (event: React.FormEvent) => + setItemPriceValue(parseFloat(event.currentTarget.value)) } required /> @@ -153,10 +146,8 @@ const AddNewItemForm: React.FC = (props) => { Discount: ) => { - const value: number = parseInt(event.currentTarget.value); - setItemDiscountValue(value); - } + (event: React.FormEvent) => + setItemDiscountValue(parseInt(event.currentTarget.value)) } /> @@ -165,10 +156,8 @@ const AddNewItemForm: React.FC = (props) => { HSN: ) => { - const value: number = parseInt(event.currentTarget.value); - setItemHSNValue(value); - } + (event: React.FormEvent) => + setItemHSNValue(parseInt(event.currentTarget.value)) } required /> @@ -177,10 +166,8 @@ const AddNewItemForm: React.FC = (props) => { GST: ) => { - const value: number = parseInt(event.currentTarget.value); - setItemGSTValue(value); - } + (event: React.FormEvent) => + setItemGSTValue(parseInt(event.currentTarget.value)) } required /> @@ -197,10 +184,6 @@ const AddNewItemForm: React.FC = (props) => { onClick={() => props.registerItemFormVisibility(true)} /> - - - - = (props) => { - ) + ); } export default AddNewItemForm; diff --git a/src/components/Form/Items/RegisterItemForm.js b/src/components/Form/Items/RegisterItemForm.js deleted file mode 100644 index 6ad4c1f..0000000 --- a/src/components/Form/Items/RegisterItemForm.js +++ /dev/null @@ -1,135 +0,0 @@ -/* - * OpenBills - Self hosted browser app to generate and keep track of simple invoices - * Version - 0 - * Licensed under the MIT license - https://opensource.org/licenses/MIT - * - * Copyright (c) 2021 Vidhu Kant Sharma -*/ - -// TODO: Code isn't tested properly -// I'd be surprised if it < 10 bugs - -// TODO: Implement override protection - -import React, { useState } from "react"; -import axios from "axios"; -import "./../Form.scss"; - - -const RegisterItemForm = (props) => { - const [newItemNameValue, setNewItemNameValue] = useState(""); - const [newItemDescValue, setNewItemDescValue] = useState(""); - const [newItemPriceValue, setNewItemPriceValue] = useState(0.00); - const [newItemHSNValue, setNewItemHSNValue] = useState(""); - const [newItemGSTValue, setNewItemGSTValue] = useState(props.defGSTValue); - // const [newItemBrandValue, setNewItemBrandValue] = useState(""); - // const [newItemTypeValue, setNewItemTypeValue] = useState(""); - - const hideSelf = () => props.setVisibility(false); - - const closeOnBGClicked = (event) => - event.target.className === "floatingMenuBG" && hideSelf(); - - const postForm = (event) => { - event.preventDefault(); - - // TODO: show confirmation before being invisible - axios.post( - `/api/items/register/` - + `?model=${newItemNameValue}` - + `&desc=${newItemDescValue}` - + `&price=${newItemPriceValue}` - + `&hsn=${newItemHSNValue}` - + `&gst=${newItemGSTValue}` - ) - .then((res) => { - console.log(res); - props.setVisibility(false); - props.updateItemsList(); - }) - .catch((err) => { - console.log(err); - alert("Something went wrong, please check the log by opening the console.") - }); - } - - - return ( -
-
-
-
-
-
- - - - -
-
- - - - - -
-
- -
- { - props.setVisibility(false); - } - } - /> - - -
-
-
-
-
- ); -} - -export default RegisterItemForm; diff --git a/src/components/Form/Items/RegisterItemForm.tsx b/src/components/Form/Items/RegisterItemForm.tsx new file mode 100644 index 0000000..dc48d3c --- /dev/null +++ b/src/components/Form/Items/RegisterItemForm.tsx @@ -0,0 +1,125 @@ +/* + * OpenBills - Self hosted browser app to generate and keep track of simple invoices + * Version - 0 + * Licensed under the MIT license - https://opensource.org/licenses/MIT + * + * Copyright (c) 2021 Vidhu Kant Sharma +*/ + +// TODO: Code isn't tested properly +// I'd be surprised if it < 10 bugs + +// TODO: Implement override protection + +import React, { useState } from "react"; +import axios from "axios"; +import "./../Form.scss"; + +interface props { + defGSTValue: number + setVisibility: any // this component's visibility + updateItemsList: () => Promise +} + +const RegisterItemForm: React.FC = (props) => { + const [newItemNameValue, setNewItemNameValue] = useState(""); + const [newItemDescValue, setNewItemDescValue] = useState(""); + const [newItemPriceValue, setNewItemPriceValue] = useState(0.00); + const [newItemHSNValue, setNewItemHSNValue] = useState(); + const [newItemGSTValue, setNewItemGSTValue] = useState(props.defGSTValue); + // const [newItemBrandValue, setNewItemBrandValue] = useState(""); + // const [newItemTypeValue, setNewItemTypeValue] = useState(""); + + const hideSelf = () => props.setVisibility(false); + + const closeOnBGClicked = (event: any) => + event.target.className === "floatingMenuBG" && hideSelf(); + + const postForm = (event: any) => { + event.preventDefault(); + // TODO: show confirmation before being invisible + axios.post( + `/api/items/register/` + + `?model=${newItemNameValue}` + + `&desc=${newItemDescValue}` + + `&price=${newItemPriceValue}` + + `&hsn=${newItemHSNValue}` + + `&gst=${newItemGSTValue}` + ) + .then((res) => { + console.log(res); + hideSelf(); + props.updateItemsList(); + }) + .catch((err) => { + console.log(err); + alert("Something went wrong, please check the log by opening the console.") + }); + } + + + return ( +
+
+
+
+
+
+ + + + +
+
+ + + + + +
+
+ +
+ hideSelf()} + /> + + +
+
+
+
+
+ ); +} + +export default RegisterItemForm; -- cgit v1.2.3