-
-
Notifications
You must be signed in to change notification settings - Fork 41
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
Showing
1 changed file
with
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// dashboard.js | ||
|
||
class Dashboard { | ||
constructor(userId) { | ||
this.userId = userId; | ||
this.transactionHistory = []; | ||
this.accountBalance = 0; | ||
this.init(); | ||
} | ||
|
||
// Initialize the dashboard | ||
init() { | ||
this.render(); | ||
this.fetchTransactionHistory(); | ||
this.updateAccountBalance(); | ||
} | ||
|
||
// Fetch transaction history (mock data) | ||
fetchTransactionHistory() { | ||
// In a real application, this would be an API call | ||
this.transactionHistory = [ | ||
{ id: 1, amount: 200, date: '2023-10-01', type: 'credit' }, | ||
{ id: 2, amount: 150, date: '2023-10-02', type: 'debit' }, | ||
{ id: 3, amount: 300, date: '2023-10-03', type: 'credit' }, | ||
]; | ||
this.renderTransactionHistory(); | ||
} | ||
|
||
// Update account balance (mock data) | ||
updateAccountBalance() { | ||
// In a real application, this would be an API call | ||
this.accountBalance = 1000; // Example balance | ||
this.renderAccountBalance(); | ||
} | ||
|
||
// Render the dashboard | ||
render() { | ||
const dashboardContainer = document.createElement('div'); | ||
dashboardContainer.id = 'dashboard'; | ||
dashboardContainer.innerHTML = ` | ||
<h1>User Dashboard</h1> | ||
<div id="account-balance"></div> | ||
<h2>Transaction History</h2> | ||
<ul id="transaction-history"></ul> | ||
`; | ||
document.body.appendChild(dashboardContainer); | ||
} | ||
|
||
// Render account balance | ||
renderAccountBalance() { | ||
const balanceElement = document.getElementById('account-balance'); | ||
balanceElement.innerHTML = `<strong>Account Balance: $${this.accountBalance}</strong>`; | ||
} | ||
|
||
// Render transaction history | ||
renderTransactionHistory() { | ||
const historyElement = document.getElementById('transaction-history'); | ||
historyElement.innerHTML = this.transactionHistory.map(tx => ` | ||
<li>${tx.date}: $${tx.amount} (${tx.type})</li> | ||
`).join(''); | ||
} | ||
} | ||
|
||
// Example usage | ||
const userId = 'user123'; | ||
const userDashboard = new Dashboard(userId); | ||
|
||
export default Dashboard; |