From a4f67d768d65235d1bcaf5e20872819de035a232 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Tue, 3 Dec 2024 22:24:58 +0700 Subject: [PATCH] Create dashboard.js --- src/ui/dashboard.js | 68 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/ui/dashboard.js diff --git a/src/ui/dashboard.js b/src/ui/dashboard.js new file mode 100644 index 000000000..3137fbd8e --- /dev/null +++ b/src/ui/dashboard.js @@ -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 = ` +

User Dashboard

+
+

Transaction History

+ + `; + document.body.appendChild(dashboardContainer); + } + + // Render account balance + renderAccountBalance() { + const balanceElement = document.getElementById('account-balance'); + balanceElement.innerHTML = `Account Balance: $${this.accountBalance}`; + } + + // Render transaction history + renderTransactionHistory() { + const historyElement = document.getElementById('transaction-history'); + historyElement.innerHTML = this.transactionHistory.map(tx => ` +
  • ${tx.date}: $${tx.amount} (${tx.type})
  • + `).join(''); + } +} + +// Example usage +const userId = 'user123'; +const userDashboard = new Dashboard(userId); + +export default Dashboard;