-
Notifications
You must be signed in to change notification settings - Fork 1
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 #42 from Robert-M-Lucas/dev-SCRUM-69
Dev scrum 69
- Loading branch information
Showing
19 changed files
with
294 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {describe, expect, test} from "vitest"; | ||
import {emojis} from "./Transaction.ts"; | ||
import {TransactionCategories} from "../../utils/transaction.ts"; | ||
import _ from "lodash"; | ||
|
||
describe("Input Transaction Test", () => { | ||
test("Category Integrity Test", () => { | ||
expect(_.isEqual(new Set(Object.keys(emojis)), TransactionCategories), "Emoji keys do not match transaction categories").toBeTruthy(); | ||
}); | ||
}); |
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
25 changes: 25 additions & 0 deletions
25
src/pages/dashboard/add transaction tile/AddTransactionTile.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,25 @@ | ||
import {ReactNode, useState} from "react"; | ||
import {CSVUpload} from "../../../components/transactions/CSVUpload.tsx"; | ||
import {InputTransaction} from "../../../components/transactions/InputTransaction.tsx"; | ||
|
||
export default function AddTransactionTile(updateTransactions: () => void): ReactNode { | ||
const [showCSVModal, setShowCSVModal] = useState(false); | ||
const [showTransactionModal, setShowTransactionModal] = useState(false); | ||
|
||
const onCSVModalClose = () => { | ||
setShowCSVModal(false); | ||
updateTransactions(); | ||
}; | ||
|
||
const onTransactionModalClose = () => { | ||
setShowTransactionModal(false); | ||
updateTransactions(); | ||
} | ||
|
||
return <> | ||
<CSVUpload show={showCSVModal} closeModal={onCSVModalClose}/> | ||
<InputTransaction show={showTransactionModal} closeModal={onTransactionModalClose}/> | ||
<button onClick={() => setShowCSVModal(true)}>Upload CSV</button> | ||
<button onClick={() => setShowTransactionModal(true)}>Add Transaction</button> | ||
</> | ||
} |
4 changes: 2 additions & 2 deletions
4
src/pages/dashboard/goals tile/GoalsTile.tsx → ...ard/goal setting tile/GoalSettingTile.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
2 changes: 1 addition & 1 deletion
2
src/pages/dashboard/goals tile/GoalsTile.css → ...rd/goal setting tile/GoalsSettingTile.css
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
85 changes: 85 additions & 0 deletions
85
src/pages/dashboard/goal tracking tile/GoalTrackingTile.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,85 @@ | ||
import {Transaction} from "../../../utils/transaction.ts"; | ||
import {ReactNode} from "react"; | ||
import {max} from "lodash"; | ||
import {UserPrefs} from "../../../utils/user_prefs.ts"; | ||
import {nanDisplay, roundFix} from "../../../utils/numbers.ts"; | ||
|
||
export default function goalTracking(transactions: Transaction[], userPrefs: UserPrefs): ReactNode { | ||
const balance = transactions.reduce((prev, curr): number => prev + curr.amount, 0); | ||
const income = transactions.reduce((prev, curr): number => prev + max([curr.amount, 0])!, 0); | ||
const needs = transactions.reduce((prev, curr): number => { | ||
if (curr.getCategoryCategory() === "Needs" && curr.amount < 0) { | ||
return prev - curr.amount; | ||
} | ||
return prev; | ||
}, 0); | ||
const wants = transactions.reduce((prev, curr): number => { | ||
if (curr.getCategoryCategory() === "Wants" && curr.amount < 0) { | ||
return prev - curr.amount; | ||
} | ||
return prev; | ||
}, 0); | ||
const savings = transactions.reduce((prev, curr): number => { | ||
if (curr.getCategoryCategory() === "Savings" && curr.amount < 0) { | ||
return prev - curr.amount; | ||
} | ||
return prev; | ||
}, 0); | ||
|
||
const needsTarget = income * userPrefs.getNeedsBudget(); | ||
const wantsTarget = income * userPrefs.getWantsBudget(); | ||
const savingsTarget = income * userPrefs.getSavingsBudget(); | ||
|
||
const needsOffsetPercentage = Math.round((needs - needsTarget) / income * 100); | ||
const wantsOffsetPercentage = Math.round((wants - wantsTarget) / income * 100); | ||
const savingsBalanceOffsetPercentage = Math.round(((savings + balance) - savingsTarget) / income * 100); | ||
|
||
return <table className="table h-100 mt-4 mb-4"> | ||
<thead style={{height: "10px!important"}}> | ||
<tr> | ||
<th scope="col" className={"p-0"}>Category</th> | ||
<th scope="col" className={"p-0"}>Actual</th> | ||
<th scope="col" className={"p-0"}>Target</th> | ||
<th scope="col" className={"p-0"}>Difference</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td className={"text-center"} scope="row">Needs</td> | ||
{needsOffsetPercentage > 0 ? | ||
<td className={"text-center"} style={{color: "#ca0f0f"}}>£{roundFix(needs)}</td> : | ||
<td className={"text-center"} style={{color: "green"}}>£{roundFix(needs)}</td> | ||
} | ||
<td className={"text-center"}>£{roundFix(needsTarget)}</td> | ||
{needsOffsetPercentage > 0 ? | ||
<td className={"text-center"} style={{color: "#ca0f0f"}}>{nanDisplay(needsOffsetPercentage)}%</td> : | ||
<td className={"text-center"} style={{color: "green"}}>{nanDisplay(needsOffsetPercentage)}%</td> | ||
} | ||
</tr> | ||
<tr> | ||
<td className={"text-center"} scope="row">Wants</td> | ||
{wantsOffsetPercentage > 0 ? | ||
<td className={"text-center"} style={{color: "#ca0f0f"}}>£{roundFix(wants)}</td> : | ||
<td className={"text-center"} style={{color: "green"}}>£{roundFix(wants)}</td> | ||
} | ||
<td className={"text-center"}>£{roundFix(wantsTarget)}</td> | ||
{wantsOffsetPercentage > 0 ? | ||
<td className={"text-center"} style={{color: "#ca0f0f"}}>{nanDisplay(wantsOffsetPercentage)}%</td> : | ||
<td className={"text-center"} style={{color: "green"}}>{nanDisplay(wantsOffsetPercentage)}%</td> | ||
} | ||
</tr> | ||
<tr style={{borderBottom: "rgba(0, 0, 0, 0)"}}> | ||
<td className={"text-center"} scope="row">Savings + Balance</td> | ||
{savingsBalanceOffsetPercentage < 0 ? | ||
<td className={"text-center"} style={{color: "#ca0f0f"}}>£{roundFix(savings + balance)}</td> : | ||
<td className={"text-center"} style={{color: "green"}}>£{roundFix(savings + balance)}</td> | ||
} | ||
<td className={"text-center"}>£{roundFix(savingsTarget)}</td> | ||
{savingsBalanceOffsetPercentage < 0 ? | ||
<td className={"text-center"} style={{color: "#ca0f0f"}}>{nanDisplay(savingsBalanceOffsetPercentage)}%</td> : | ||
<td className={"text-center"} style={{color: "green"}}>{nanDisplay(savingsBalanceOffsetPercentage)}%</td> | ||
} | ||
</tr> | ||
</tbody> | ||
</table>; | ||
} |
This file was deleted.
Oops, something went wrong.
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,59 @@ | ||
import {Transaction} from "../../../utils/transaction.ts"; | ||
import {ReactNode} from "react"; | ||
import {max} from "lodash"; | ||
import {UserPrefs} from "../../../utils/user_prefs.ts"; | ||
import {nanDisplay} from "../../../utils/numbers.ts"; | ||
|
||
export default function motivationTile(transactions: Transaction[], userPrefs: UserPrefs): ReactNode { | ||
const balance = transactions.reduce((prev, curr): number => prev + curr.amount, 0); | ||
const income = transactions.reduce((prev, curr): number => prev + max([curr.amount, 0])!, 0); | ||
const needs = transactions.reduce((prev, curr): number => { | ||
if (curr.getCategoryCategory() === "Needs" && curr.amount < 0) { | ||
return prev - curr.amount; | ||
} | ||
return prev; | ||
}, 0); | ||
const wants = transactions.reduce((prev, curr): number => { | ||
if (curr.getCategoryCategory() === "Wants" && curr.amount < 0) { | ||
return prev - curr.amount; | ||
} | ||
return prev; | ||
}, 0); | ||
const savings = transactions.reduce((prev, curr): number => { | ||
if (curr.getCategoryCategory() === "Savings" && curr.amount < 0) { | ||
return prev - curr.amount; | ||
} | ||
return prev; | ||
}, 0); | ||
|
||
const needsTarget = income * userPrefs.getNeedsBudget(); | ||
const wantsTarget = income * userPrefs.getWantsBudget(); | ||
const savingsTarget = income * userPrefs.getSavingsBudget(); | ||
|
||
const needsOffsetPercentage = Math.round((needs - needsTarget) / income * 100); | ||
const wantsOffsetPercentage = Math.round((wants - wantsTarget) / income * 100); | ||
const savingsBalanceOffsetPercentage = Math.round(((savings + balance) - savingsTarget) / income * 100); | ||
|
||
const finalOffsetPercentage = (-needsOffsetPercentage) + (-wantsOffsetPercentage) + savingsBalanceOffsetPercentage; | ||
|
||
return <> | ||
<div style={{height: "5%"}}></div> | ||
<div className={"w-100 text-center d-flex align-items-center justify-content-center"} style={{height: "20%"}}> | ||
<span>Your score is:</span> | ||
</div> | ||
<div className={"w-100 text-center d-flex align-items-center justify-content-center"} | ||
style={{height: "50%", lineHeight: "100%"}}> | ||
{finalOffsetPercentage < 0 ? | ||
<span style={{fontSize: "60px", color: "#ca0f0f"}}>{nanDisplay(finalOffsetPercentage)}</span> : | ||
<span style={{fontSize: "60px", color: "green"}}>{nanDisplay(finalOffsetPercentage)}</span> | ||
} | ||
</div> | ||
<div className={"w-100 text-center d-flex align-items-center justify-content-center"} style={{height: "20%"}}> | ||
{finalOffsetPercentage < 0 ? | ||
<span>Keep Trying!</span> : | ||
<span>Good Job!</span> | ||
} | ||
</div> | ||
<div style={{height: "5%"}}></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
Oops, something went wrong.