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 +++++++++++++++----------- 1 file changed, 36 insertions(+), 28 deletions(-) (limited to 'src/components/Form') 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) => {
-- cgit v1.2.3