-
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.
Add the monthly spending report to the UI
- Loading branch information
1 parent
b7df13b
commit 59d61db
Showing
7 changed files
with
117 additions
and
0 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
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,37 @@ | ||
import useMonthlySpend from "@/hooks/useMonthlySpend"; | ||
import MonthlySpendReportRow from "./monthlySpendReportRow"; | ||
|
||
/** | ||
* Component to display the monthly spending report page and its results | ||
* @param {*} logout | ||
* @returns | ||
*/ | ||
const MonthlySpendReport = ({ logout }) => { | ||
const { records, setRecords } = useMonthlySpend(logout); | ||
|
||
return ( | ||
<> | ||
<div className="row mb-2 pageTitle"> | ||
<h5 className="themeFontColor text-center">Monthly Spending Report</h5> | ||
</div> | ||
<table className="table table-hover"> | ||
<thead> | ||
<tr> | ||
<th>Year</th> | ||
<th>Month</th> | ||
<th>Total Spend</th> | ||
</tr> | ||
</thead> | ||
{records != null && ( | ||
<tbody> | ||
{records.map((r) => ( | ||
<MonthlySpendReportRow key={`${r.year}.${r.month}`} record={r} /> | ||
))} | ||
</tbody> | ||
)} | ||
</table> | ||
</> | ||
); | ||
}; | ||
|
||
export default MonthlySpendReport; |
20 changes: 20 additions & 0 deletions
20
src/music-catalogue-ui/components/monthlySpendReportRow.js
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,20 @@ | ||
import CurrencyFormatter from "./currencyFormatter"; | ||
|
||
/** | ||
* Component to render a row containing the details for a single monthly spending record | ||
* @param {*} record | ||
* @returns | ||
*/ | ||
const MonthlySpendReportRow = ({ record }) => { | ||
return ( | ||
<tr> | ||
<td>{record.year}</td> | ||
<td>{record.month}</td> | ||
<td> | ||
<CurrencyFormatter value={record.spend} renderZeroAsBlank={true} /> | ||
</td> | ||
</tr> | ||
); | ||
}; | ||
|
||
export default MonthlySpendReportRow; |
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
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,29 @@ | ||
import { useState, useEffect } from "react"; | ||
import { apiMonthlySpendReport } from "@/helpers/apiReports"; | ||
|
||
/** | ||
* Hook that uses the API helpers to retrieve a list of artists from the | ||
* Music Catalogue REST API | ||
* @param {*} logout | ||
* @returns | ||
*/ | ||
const useMonthlySpend = (logout) => { | ||
// Current list of artists and the method to change it | ||
const [records, setRecords] = useState([]); | ||
|
||
useEffect(() => { | ||
const fetchReport = async () => { | ||
try { | ||
// Get a list of records via the service, store it in state | ||
var fetchedRecords = await apiMonthlySpendReport(logout); | ||
setRecords(fetchedRecords); | ||
} catch {} | ||
}; | ||
|
||
fetchReport(); | ||
}, [logout]); | ||
|
||
return { records, setRecords }; | ||
}; | ||
|
||
export default useMonthlySpend; |