From 5ca14fcf3e949308eb0b2d636169e6601df1908d Mon Sep 17 00:00:00 2001 From: MikunoNaka Date: Wed, 28 Apr 2021 16:19:00 +0530 Subject: New Feature: Ability to register new items in the database --- src/components/BillingPage.js | 14 +++-- src/components/Form/AddNewItemForm.js | 10 ++-- src/components/Form/Form.css | 28 +++++++++ src/components/Form/Form.scss | 53 ++++++++++++---- src/components/Form/RegisterItemForm.js | 103 ++++++++++++++++++++++++++++++++ 5 files changed, 187 insertions(+), 21 deletions(-) create mode 100644 src/components/Form/RegisterItemForm.js (limited to 'src/components') diff --git a/src/components/BillingPage.js b/src/components/BillingPage.js index 7f97b32..fc09694 100644 --- a/src/components/BillingPage.js +++ b/src/components/BillingPage.js @@ -10,15 +10,15 @@ import React, { useState, useEffect } from "react"; import axios from "axios"; import AddNewItemForm from "./Form/AddNewItemForm"; +import RegisterItemForm from "./Form/RegisterItemForm"; +import MetaInfoForm from "./Form/MetaInfoForm"; import ItemsDisplay from "./Display/ItemsDisplay"; import SummaryDisplay from "./Display/SummaryDisplay"; -import MetaInfoForm from "./Form/MetaInfoForm"; const BillingPage = () => { const [savedItems, getSavedItems] = useState([]) - // get data from server on startup - useEffect(() => { + const getRegisteredItems = () => { axios.get(`/api/items`) .then((res) => { getSavedItems(res.data); @@ -27,8 +27,13 @@ const BillingPage = () => { alert("The promise returned an error idk what to do"); console.log(res); }) + } + + // get data from server on startup + useEffect(() => { + getRegisteredItems(); }, []); - // to be handled by backend + // TODO: to be handled by backend const defGSTValue = 18; // update the items from AddNewItemForm @@ -42,6 +47,7 @@ const BillingPage = () => { return ( <> +
diff --git a/src/components/Form/AddNewItemForm.js b/src/components/Form/AddNewItemForm.js index afd5259..5028af2 100644 --- a/src/components/Form/AddNewItemForm.js +++ b/src/components/Form/AddNewItemForm.js @@ -80,7 +80,7 @@ const AddNewItemForm = (props) => { }>
+ { + alert("Coming Soon") + }} /> - - + { + // show/hide this component + const [visibility, setVisibility] = useState(true)// useState(props.visibility); + + const [newItemNameValue, setNewItemNameValue] = useState(""); + const [newItemDescValue, setNewItemDescValue] = useState(""); + // const [newItemBrandValue, setNewItemBrandValue] = useState(""); + // const [newItemTypeValue, setNewItemTypeValue] = useState(""); + const [newItemPriceValue, setNewItemPriceValue] = useState(""); + const [newItemHSNValue, setNewItemHSNValue] = useState(""); + const [newItemGSTValue, setNewItemGSTValue] = useState(""); + + + return ( +
+
{ + event.preventDefault(); + setVisibility(false); + + axios.post(`/api/items/?model=${newItemNameValue}&desc=${newItemDescValue}&price=${newItemPriceValue}&hsn=${newItemHSNValue}&gst=${newItemGSTValue}`) + .then((res) => { + console.log(res); + }) + .catch((err) => { + console.log(err); + }); + } + }> +
+ + + +
+ +
+ + + + + +
+ + +
+
+ ); +} + +export default RegisterItemForm; -- cgit v1.2.3