From 0cf29dd48b7d59c731519527e26dda959b340664 Mon Sep 17 00:00:00 2001 From: MikunoNaka Date: Sat, 26 Jun 2021 03:19:19 +0530 Subject: Using types in RegisterItemForm now --- src/components/Form/Items/RegisterItemForm.tsx | 64 +++++++++++++++----------- src/interfaces.ts | 12 ++++- 2 files changed, 47 insertions(+), 29 deletions(-) diff --git a/src/components/Form/Items/RegisterItemForm.tsx b/src/components/Form/Items/RegisterItemForm.tsx index dc48d3c..c782df5 100644 --- a/src/components/Form/Items/RegisterItemForm.tsx +++ b/src/components/Form/Items/RegisterItemForm.tsx @@ -9,11 +9,10 @@ // 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"; +import { NewItem } from "./../../../interfaces" +import axios from "axios"; interface props { defGSTValue: number @@ -22,13 +21,13 @@ interface props { } 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 [newItemName, setNewItemName] = useState(""); + const [newItemDesc, setNewItemDesc] = useState(""); + 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 hideSelf = () => props.setVisibility(false); @@ -37,14 +36,24 @@ const RegisterItemForm: React.FC = (props) => { const postForm = (event: any) => { event.preventDefault(); - // TODO: show confirmation before being invisible + + const newItem: NewItem = { + Model: newItemName, + Description: newItemDesc, + UnitPrice: newItemPrice, + HSN: newItemHSN, + TotalGST: newItemGST + } + + // TODO: show confirmation before being invisible + // TODO: Implement override protection axios.post( `/api/items/register/` - + `?model=${newItemNameValue}` - + `&desc=${newItemDescValue}` - + `&price=${newItemPriceValue}` - + `&hsn=${newItemHSNValue}` - + `&gst=${newItemGSTValue}` + + `?model=${newItem.Model}` + + `&desc=${newItem.Description}` + + `&price=${newItem.UnitPrice}` + + `&hsn=${newItem.HSN}` + + `&gst=${newItem.TotalGST}` ) .then((res) => { console.log(res); @@ -66,37 +75,36 @@ const RegisterItemForm: React.FC = (props) => {
@@ -112,7 +120,7 @@ const RegisterItemForm: React.FC = (props) => {
diff --git a/src/interfaces.ts b/src/interfaces.ts index 1ace032..e85ef29 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -14,7 +14,7 @@ export interface Item { TotalValue: number // UnitPrice * Quantity Discount: number // percentage of discount DiscountValue: number - HSN: number // string?? + HSN: string TotalGST: number // gst percentage SGST: number | boolean @@ -24,6 +24,16 @@ export interface Item { // category and brand } +// for registering new item to DB +export interface NewItem { + Model: string + Description: string + UnitPrice: number // price without tax/discount + HSN: string + TotalGST: number // gst percentage + // category and brand +} + export interface Person { Name: string Address: string -- cgit v1.2.3