Skip to content

Commit

Permalink
Create dashboard.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Dec 3, 2024
1 parent 43deb58 commit a4f67d7
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions src/ui/dashboard.js
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;

0 comments on commit a4f67d7

Please sign in to comment.