diff options
-rw-r--r-- | package-lock.json | 17 | ||||
-rw-r--r-- | package.json | 3 | ||||
-rw-r--r-- | server/main.go | 28 | ||||
-rw-r--r-- | src/components/BillingPage.js | 54 |
4 files changed, 61 insertions, 41 deletions
diff --git a/package-lock.json b/package-lock.json index f042387..7207709 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "@types/node": "^14.14.37", "@types/react": "^17.0.3", "@types/react-dom": "^17.0.3", + "axios": "^0.21.1", "create-react-app": "^4.0.3", "node-sass": "^5.0.0", "react": "^17.0.2", @@ -4043,6 +4044,14 @@ "node": ">=4" } }, + "node_modules/axios": { + "version": "0.21.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz", + "integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==", + "dependencies": { + "follow-redirects": "^1.10.0" + } + }, "node_modules/axobject-query": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-2.2.0.tgz", @@ -25760,6 +25769,14 @@ "resolved": "https://registry.npmjs.org/axe-core/-/axe-core-4.1.3.tgz", "integrity": "sha512-vwPpH4Aj4122EW38mxO/fxhGKtwWTMLDIJfZ1He0Edbtjcfna/R3YB67yVhezUMzqc3Jr3+Ii50KRntlENL4xQ==" }, + "axios": { + "version": "0.21.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz", + "integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==", + "requires": { + "follow-redirects": "^1.10.0" + } + }, "axobject-query": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-2.2.0.tgz", diff --git a/package.json b/package.json index 2b0dece..6c63305 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "openbills", "version": "0.1.0", "private": true, - "proxy": "http://localhost:4000", + "proxy": "http://localhost:8080", "dependencies": { "@testing-library/jest-dom": "^5.11.10", "@testing-library/react": "^11.2.5", @@ -11,6 +11,7 @@ "@types/node": "^14.14.37", "@types/react": "^17.0.3", "@types/react-dom": "^17.0.3", + "axios": "^0.21.1", "create-react-app": "^4.0.3", "node-sass": "^5.0.0", "react": "^17.0.2", diff --git a/server/main.go b/server/main.go index 4f984da..2a02269 100644 --- a/server/main.go +++ b/server/main.go @@ -31,14 +31,40 @@ func main() { } func getAllItems(ctx *gin.Context) { - allItems := [1]Item{ + allItems := [6]Item{ { "Kisan Chair", "Very Good Chair", 100, 9403, + }, { + "Supreme Chair", + "Even Better Chair", + 200, + 9403, + }, { + "Action Houseware", + "Not a chair", + 50, + 69, + }, { + "Coirfit Mattress", + "I wanna sleep", + 900, + 420, + }, { + "AVRO Chair", + "Formerly AVON lol", + 150, + 9403, + }, { + "Mystery Item", + "hehe hehehehe", + 1000, + 177013, }, } + ctx.Header("Content-Type", "application/json") ctx.JSON(http.StatusOK, allItems) } diff --git a/src/components/BillingPage.js b/src/components/BillingPage.js index 06a80a6..a7e4ef0 100644 --- a/src/components/BillingPage.js +++ b/src/components/BillingPage.js @@ -1,49 +1,28 @@ import React, { useState, useEffect } from "react"; +import axios from "axios"; + import AddNewItemForm from "./Form/AddNewItemForm"; import ItemsDisplay from "./Display/ItemsDisplay"; import SummaryDisplay from "./Display/SummaryDisplay"; -const sampleData = [ - { - "Model": "Kisan Chair", - "Description": "Very good chair", - "Price": 10000, - "HSN": 9403 - }, { - "Model": "Supreme Chair", - "Description": "Even better chair", - "Price": "2134983", - "HSN": 9403 - }, { - "Model": "Action Houseware", - "Description": "Not a chair", - "Price": 69, - "HSN": 69 - }, { - "Model": "Coirfit Mattress", - "Description": "Not a chair (neither houseware)", - "Price": 19, - "HSN": 420 - }, { - "Model": "AVRO Chair", - "Description": "Formerly AVON lol", - "Price": 291, - "HSN": 9403 - }, { - "Model": "Mystery Item", - "Description": "hehe heheheheheh", - "Price": 1212312, - "HSN": 42069 - } -]; - const BillingPage = () => { + const [savedItems, getSavedItems] = useState([]) + + // get data from server on startup useEffect(() => { - alert("yo this app in beta"); + axios.get(`/api/items`) + .then((res) => { + getSavedItems(res.data); + }) + .catch((res) => { + alert("The promise returned an error idk what to do"); + console.log(res); + }) }, []); // to be handled by backend const defGSTValue = 18; + // update the items from AddNewItemForm const [items, setItems] = useState([]); const getItems = (item) => { setItems( @@ -51,12 +30,9 @@ const BillingPage = () => { ); }; - useEffect(() => { - }, [items]); - return ( <div> - <AddNewItemForm savedItems={sampleData} addItem={getItems} defGSTValue={defGSTValue}/> + <AddNewItemForm savedItems={savedItems} addItem={getItems} defGSTValue={defGSTValue}/> <ItemsDisplay items={items} defGSTValue={defGSTValue}/> <SummaryDisplay items={items}/> </div> |