From 45d839a40eb71e9ab0d7d702c8269d4367403d14 Mon Sep 17 00:00:00 2001 From: Karthik Murugappan Palaniappan Date: Sat, 10 Sep 2022 13:15:13 -0700 Subject: [PATCH 1/2] Add HouseholdInfo object to hold info from Household component --- src/App.js | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/App.js b/src/App.js index 113567f..295cfa1 100644 --- a/src/App.js +++ b/src/App.js @@ -1,7 +1,27 @@ import './App.css'; import { useState, useEffect } from 'react'; +// TODO: create one of these objects in household component +class HouseholdInfo { + constructor({married, numChildren, zipCode, income}) { + this.married = married; + this.numChildren = numChildren; + this.zipCode = zipCode; + this.income = income; + } +} + function App() { + // TODO: begin with a null household in the PR that creates Household component. + // This is just placeholder data for now + const [household, setHousehold] = useState(new HouseholdInfo({ + married: true, + numChildren: 3, + zipCode: 98102, + income: 50000, + })); + console.log(household, setHousehold); + return (
@@ -27,7 +47,7 @@ const exampleHousehold = { function APIExampleTest() { const [rebateAmount, setRebateAmount] = useState(null); - + useEffect(() => { fetch( "https://policyengine.org/us/api/calculate", { From 585d31c71e9c564393c4ee4c116fc7ac725f9e7e Mon Sep 17 00:00:00 2001 From: Karthik Murugappan Palaniappan Date: Sat, 10 Sep 2022 14:06:51 -0700 Subject: [PATCH 2/2] Create skeleton API within JS for retrieving credits and rebates --- src/App.js | 20 +++----------------- src/calculateCreditsAndRebates.js | 11 +++++++++++ 2 files changed, 14 insertions(+), 17 deletions(-) create mode 100644 src/calculateCreditsAndRebates.js diff --git a/src/App.js b/src/App.js index 295cfa1..644ba0e 100644 --- a/src/App.js +++ b/src/App.js @@ -1,4 +1,5 @@ import './App.css'; +import './calculateCreditsAndRebates'; import { useState, useEffect } from 'react'; // TODO: create one of these objects in household component @@ -49,23 +50,8 @@ function APIExampleTest() { const [rebateAmount, setRebateAmount] = useState(null); useEffect(() => { - fetch( - "https://policyengine.org/us/api/calculate", { - method: 'POST', - headers: { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - household: exampleHousehold, - }) - } - ) - .then(results => results.json()) - .then(data => { - const rebateAmount = data.tax_units.tax_unit.capped_heat_pump_rebate[2023]; - setRebateAmount(rebateAmount); - }); + const moneySavedInfo = calculateCreditsAndRebates(); + console.log('TODO: move this function call to the right place', moneySavedInfo); }, []); // <-- Have to pass in [] here! if(rebateAmount === null) { diff --git a/src/calculateCreditsAndRebates.js b/src/calculateCreditsAndRebates.js new file mode 100644 index 0000000..d31e4ce --- /dev/null +++ b/src/calculateCreditsAndRebates.js @@ -0,0 +1,11 @@ +// householdInfo and expenditures data structures are going to be defined in App.js +export default function ({householdInfo, expenditures}) { + // Need to call API and return this info for real. + return { + credits: 10000, + rebates: { + min: 800, + max: 4200, + } + }; +}