Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 24 additions & 18 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
import './App.css';
import './calculateCreditsAndRebates';
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 (
<div className="App">
<header className="App-header">
Expand All @@ -27,25 +48,10 @@ const exampleHousehold = {

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) {
Expand Down
11 changes: 11 additions & 0 deletions src/calculateCreditsAndRebates.js
Original file line number Diff line number Diff line change
@@ -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,
}
};
}