-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8796dda
commit 34aa3ba
Showing
6 changed files
with
211 additions
and
20 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
src/components/MortgageCalculator/ComparisonPage/ComparisonPage.tsx
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,54 @@ | ||
import React from "react"; | ||
import { ComparisonSection } from "./ComparisonSection"; | ||
|
||
interface ComparisonPageProps {} | ||
|
||
const ComparisonPage: React.FC<ComparisonPageProps> = ( | ||
props: ComparisonPageProps | ||
) => { | ||
return ( | ||
<div> | ||
<h1>Compare Mortgages</h1> | ||
<ComparisonSection | ||
option1={{ | ||
housePrice: 440000, | ||
depositPercentage: 0.1, | ||
mortgageTerm: 35, | ||
interestRate: 3.8, | ||
fees: { | ||
valuationFee: 185, | ||
surveyFee: 500, | ||
legalFee: 3300, | ||
searchFee: 250, | ||
}, | ||
}} | ||
option2={{ | ||
housePrice: 450000, | ||
depositPercentage: 0.1, | ||
mortgageTerm: 35, | ||
interestRate: 3.8, | ||
fees: { | ||
valuationFee: 185, | ||
surveyFee: 500, | ||
legalFee: 3300, | ||
searchFee: 250, | ||
}, | ||
}} | ||
option3={{ | ||
housePrice: 460000, | ||
depositPercentage: 0.1, | ||
mortgageTerm: 35, | ||
interestRate: 3.8, | ||
fees: { | ||
valuationFee: 185, | ||
surveyFee: 500, | ||
legalFee: 3300, | ||
searchFee: 250, | ||
}, | ||
}} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ComparisonPage; |
86 changes: 86 additions & 0 deletions
86
src/components/MortgageCalculator/ComparisonPage/ComparisonSection.tsx
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,86 @@ | ||
import React from "react"; | ||
import { MortgageProperties } from "../../MortgageProperties"; | ||
import { getMonthlyPayment } from "../MortgageCalculator"; | ||
import { formatter } from "../MortgageCalculator.mapper"; | ||
|
||
interface ComparisonSectionProps { | ||
option1: MortgageProperties; | ||
option2: MortgageProperties; | ||
option3: MortgageProperties; | ||
} | ||
|
||
export const ComparisonSection: React.FC<ComparisonSectionProps> = ( | ||
props: ComparisonSectionProps | ||
) => { | ||
const { option1, option2, option3 } = props; | ||
|
||
return ( | ||
<div> | ||
<div className="columns"> | ||
<div className="column column-1"> | ||
<OptionSection id={1} option={option1} /> | ||
</div> | ||
|
||
<div className="column column-2"> | ||
<OptionSection id={2} option={option2} /> | ||
</div> | ||
|
||
<div className="column column-3"> | ||
<OptionSection id={3} option={option3} /> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
const OptionSection: React.FC<{ | ||
id: number; | ||
option: MortgageProperties; | ||
}> = (props: { id: number; option: MortgageProperties }) => { | ||
const { id, option } = props; | ||
const [housePrice, setHousePrice] = React.useState(option.housePrice); | ||
// const [interestRate, setInterestRate] = React.useState(option.interestRate); | ||
// const [mortgageTerm, setMortgageTerm] = React.useState(option.mortgageTerm); | ||
|
||
return ( | ||
<div> | ||
<h2 | ||
style={{ | ||
fontSize: "1.75rem", | ||
}} | ||
> | ||
Option {id} | ||
</h2> | ||
<label> | ||
House Price (€) | ||
<input | ||
type="number" | ||
value={housePrice} | ||
onChange={(e) => setHousePrice(parseInt(e.target.value))} | ||
/> | ||
</label> | ||
<h3>House Price: {formatter.format(housePrice)}</h3> | ||
<h3> | ||
Monthly Payment:{" "} | ||
{formatter.format( | ||
getMonthlyPayment( | ||
housePrice * 0.9, | ||
option.interestRate, | ||
option.mortgageTerm | ||
) | ||
)} | ||
</h3> | ||
<h3> | ||
Savings Required:{" "} | ||
{formatter.format( | ||
housePrice * option.depositPercentage + | ||
option.fees.valuationFee + | ||
option.fees.surveyFee + | ||
option.fees.legalFee + | ||
housePrice * 0.01 + // stamp duty | ||
option.fees.searchFee | ||
)} | ||
</h3> | ||
</div> | ||
); | ||
}; |
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
14 changes: 9 additions & 5 deletions
14
src/components/MortgageCalculator/MortgageCalculator.mapper.ts
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 |
---|---|---|
@@ -1,13 +1,17 @@ | ||
export interface MortgageFees { | ||
deposit: number; | ||
valuationFee: number; | ||
surveyFee: number; | ||
legalFee: number; | ||
stampDuty: number; | ||
stampDuty?: number; | ||
searchFee: number; | ||
} | ||
|
||
export const savingsRequired = (deposit: number, fees: MortgageFees) => { | ||
return deposit + fees.valuationFee + fees.surveyFee + fees.legalFee + (fees.stampDuty ?? deposit / 10) + fees.searchFee; | ||
}; | ||
|
||
export const savingsRequired = (fees: MortgageFees) => { | ||
return fees.deposit + fees.valuationFee + fees.surveyFee + fees.legalFee + fees.stampDuty + fees.searchFee; | ||
}; | ||
export const formatter = new Intl.NumberFormat("en-IE", { | ||
style: "currency", | ||
currency: "EUR", | ||
minimumFractionDigits: 2, | ||
}); |
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,9 @@ | ||
import { MortgageFees } from "./MortgageCalculator/MortgageCalculator.mapper"; | ||
|
||
export interface MortgageProperties { | ||
housePrice: number; | ||
depositPercentage: number; | ||
mortgageTerm: number; | ||
interestRate: number; | ||
fees: MortgageFees; | ||
} |