-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from CSE437s/calculators
Calculators
- Loading branch information
Showing
8 changed files
with
303 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// This file contains mock data for development and testing purposes | ||
// src/__mocks__/mockData.js | ||
|
||
export const mockSavingsData = [ | ||
{ year: 2024, startingBalance: 25000, contributions: 1200, interestEarned: 275, endBalance: 26475 }, | ||
// ...additional mock data | ||
]; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React, { useState } from 'react'; | ||
import SavingsForm from './SavingsForm'; | ||
import SavingsBreakdown from './SavingsBreakdown'; | ||
import SavingsComparison from './SavingsComparison'; | ||
import SavingsSummary from './SavingsSummary'; | ||
import { mockSavingsData } from '../../__mocks__/MockData'; // Make sure the path is correct | ||
import './SaveNowVsLaterCalc.css'; // The CSS file with your styles | ||
|
||
function SaveNowVsLater() { | ||
const [savingsData, setSavingsData] = useState(mockSavingsData); | ||
|
||
// Replace this with your actual calculation logic | ||
const handleCalculate = (formData) => { | ||
// Assume calculateSavings is a function that returns the updated data | ||
const updatedData = calculateSavings(formData); | ||
setSavingsData(updatedData); | ||
}; | ||
|
||
return ( | ||
<div className="save-now-vs-later-container"> | ||
<SavingsForm onCalculate={handleCalculate} /> | ||
<SavingsSummary data={savingsData} /> | ||
<SavingsBreakdown data={savingsData} /> | ||
<SavingsComparison currentApy={1.2} /> | ||
</div> | ||
); | ||
} | ||
|
||
export default SaveNowVsLater; | ||
|
||
// Add a calculateSavings function that handles the calculation logic | ||
// This is a placeholder - you will need to implement this based on your own logic | ||
function calculateSavings(formData) { | ||
// Perform calculation here | ||
return mockSavingsData; // return the calculated data | ||
} |
101 changes: 101 additions & 0 deletions
101
lumo/src/components/SaveNowVsLaterCalc/SaveNowVsLaterCalc.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* SaveNowVsLaterCalc.css - place this file in the same directory as your components */ | ||
|
||
.save-now-vs-later-container { | ||
font-family: 'Arial', sans-serif; | ||
margin: 20px; | ||
} | ||
|
||
.savings-form { | ||
display: flex; | ||
flex-direction: column; | ||
max-width: 400px; | ||
margin-bottom: 20px; | ||
} | ||
|
||
.form-input, | ||
.form-select { | ||
padding: 10px; | ||
margin-bottom: 10px; | ||
border: 1px solid #ccc; | ||
border-radius: 4px; | ||
} | ||
|
||
.form-button { | ||
background-color: #005a9c; | ||
color: white; | ||
padding: 10px 15px; | ||
border: none; | ||
border-radius: 4px; | ||
cursor: pointer; | ||
font-size: 16px; | ||
} | ||
|
||
.form-button:hover { | ||
background-color: #004080; | ||
} | ||
|
||
.chart-container { | ||
margin: 20px 0; | ||
padding: 20px; | ||
background-color: #f8f9fa; | ||
border-radius: 8px; | ||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); | ||
} | ||
|
||
.table { | ||
width: 100%; | ||
border-collapse: collapse; | ||
margin-top: 20px; | ||
} | ||
|
||
.table th, | ||
.table td { | ||
border: 1px solid #ddd; | ||
padding: 8px; | ||
text-align: left; | ||
} | ||
|
||
.table th { | ||
background-color: #f0f0f0; | ||
} | ||
|
||
.apy-comparison { | ||
padding: 20px; | ||
margin-top: 20px; | ||
background-color: #f2f2f2; | ||
border-radius: 4px; | ||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); | ||
} | ||
|
||
.apy-item { | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
margin-bottom: 10px; | ||
} | ||
|
||
.apy-item:last-child { | ||
margin-bottom: 0; | ||
} | ||
|
||
.apy-bar { | ||
height: 20px; | ||
border-radius: 5px; | ||
} | ||
|
||
.your-apy { | ||
background-color: #4caf50; | ||
} | ||
|
||
.national-apy { | ||
background-color: #f44336; | ||
} | ||
|
||
.online-apy { | ||
background-color: #2196f3; | ||
} | ||
|
||
.todays-apy { | ||
background-color: #ff9800; | ||
} | ||
|
34 changes: 34 additions & 0 deletions
34
lumo/src/components/SaveNowVsLaterCalc/SavingsBreakdown.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react'; | ||
import './SaveNowVsLaterCalc.css'; // Assuming the CSS file is in the same directory | ||
|
||
function SavingsBreakdown({ data }) { | ||
return ( | ||
<div> | ||
<h3>Breakdown by Year</h3> | ||
<table className="table"> | ||
<thead> | ||
<tr> | ||
<th>Year</th> | ||
<th>Starting Balance</th> | ||
<th>Contributions</th> | ||
<th>Interest Earned</th> | ||
<th>End Balance</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{data.map((yearData, index) => ( | ||
<tr key={index}> | ||
<td>{yearData.year}</td> | ||
<td>${yearData.startingBalance.toFixed(2)}</td> | ||
<td>${yearData.contributions.toFixed(2)}</td> | ||
<td>${yearData.interestEarned.toFixed(2)}</td> | ||
<td>${yearData.endBalance.toFixed(2)}</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
</div> | ||
); | ||
} | ||
|
||
export default SavingsBreakdown; |
33 changes: 33 additions & 0 deletions
33
lumo/src/components/SaveNowVsLaterCalc/SavingsComparison.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from 'react'; | ||
import './SaveNowVsLaterCalc.css'; // Assuming the CSS file is in the same directory | ||
|
||
function SavingsComparison({ userApy }) { | ||
// These widths are just placeholders, you might calculate them based on the APY values | ||
const nationalAverageApyWidth = '10%'; | ||
const onlineAverageApyWidth = '60%'; | ||
const todaysTopApyWidth = '100%'; | ||
|
||
return ( | ||
<div className="apy-comparison"> | ||
<h3>How Interest Can Impact Your Savings</h3> | ||
<div className="apy-item"> | ||
<span>Your Rate: {userApy}% APY</span> | ||
<div className="apy-bar your-apy" style={{ width: `${userApy}%` }}></div> | ||
</div> | ||
<div className="apy-item"> | ||
<span>National Average: 0.09% APY</span> | ||
<div className="apy-bar national-apy" style={{ width: nationalAverageApyWidth }}></div> | ||
</div> | ||
<div className="apy-item"> | ||
<span>Online Average: 1.1% APY</span> | ||
<div className="apy-bar online-apy" style={{ width: onlineAverageApyWidth }}></div> | ||
</div> | ||
<div className="apy-item"> | ||
<span>Today's Top Rate: 1.86% APY</span> | ||
<div className="apy-bar todays-apy" style={{ width: todaysTopApyWidth }}></div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default SavingsComparison; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React, { useState } from 'react'; | ||
|
||
function SavingsForm({ onCalculate }) { | ||
const [startingBalance, setStartingBalance] = useState(0); | ||
const [apy, setApy] = useState(0); | ||
const [monthlyContribution, setMonthlyContribution] = useState(0); | ||
const [yearsToSave, setYearsToSave] = useState(1); | ||
|
||
const handleSubmit = (event) => { | ||
event.preventDefault(); | ||
onCalculate({ startingBalance, apy, monthlyContribution, yearsToSave }); | ||
}; | ||
|
||
return ( | ||
<form onSubmit={handleSubmit}> | ||
<input | ||
type="number" | ||
value={startingBalance} | ||
onChange={(e) => setStartingBalance(e.target.value)} | ||
placeholder="Starting Balance" | ||
/> | ||
{/* ...Other inputs for APY, monthly contribution, years to save... */} | ||
<button type="submit">Calculate</button> | ||
</form> | ||
); | ||
} | ||
|
||
export default SavingsForm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from 'react'; | ||
import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, Legend } from 'recharts'; | ||
|
||
function SavingsSummary({ data }) { | ||
// You'll need to map your data to the format expected by Recharts | ||
const chartData = data.map(item => ({ | ||
year: item.year, | ||
balance: item.endBalance | ||
})); | ||
|
||
return ( | ||
<div className="chart-container"> | ||
<h2>Your savings balance at the end of the period will be ${data[data.length - 1].endBalance.toFixed(2)}</h2> | ||
<BarChart width={600} height={300} data={chartData}> | ||
<CartesianGrid strokeDasharray="3 3" /> | ||
<XAxis dataKey="year" /> | ||
<YAxis /> | ||
<Tooltip /> | ||
<Legend /> | ||
<Bar dataKey="balance" fill="#82ca9d" /> | ||
</BarChart> | ||
</div> | ||
); | ||
} | ||
|
||
export default SavingsSummary; |