Advertisement
Painlover

Untitled

Jan 20th, 2025
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.52 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>Transaction List</title>
  7. <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
  8. </head>
  9. <body>
  10. <!-- Navbar -->
  11. <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
  12. <div class="container-fluid">
  13. <a class="navbar-brand" href="#">Our Shop</a>
  14. <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
  15. <span class="navbar-toggler-icon"></span>
  16. </button>
  17. <div class="collapse navbar-collapse" id="navbarNav">
  18. <ul class="navbar-nav mx-auto">
  19. <li class="nav-item">
  20. <a class="nav-link" href="member.html">HOME</a>
  21. </li>
  22. <li class="nav-item">
  23. <a class="nav-link active" aria-current="page" href="transaksi.html">TRANSAKSI</a>
  24. </li>
  25. </ul>
  26. <ul class="navbar-nav">
  27. <li class="nav-item">
  28. <a class="nav-link" href="profile.html">Profile</a>
  29. </li>
  30. <li class="nav-item">
  31. <button class="btn btn-danger btn-sm" onclick="logout()">Logout</button>
  32. </li>
  33. </ul>
  34. </div>
  35. </div>
  36. </nav>
  37.  
  38. <!-- Container -->
  39. <div class="container mt-5">
  40. <h1 class="text-center mb-4">Transaction List</h1>
  41. <table class="table table-bordered table-striped">
  42. <thead class="table-dark">
  43. <tr>
  44. <th>No</th>
  45. <th>User Name</th>
  46. <th>Product</th>
  47. <th>Order ID</th>
  48. <th>Status</th>
  49. <th>Payment Link</th>
  50. </tr>
  51. </thead>
  52. <tbody id="transaction-list"></tbody>
  53. </table>
  54. </div>
  55.  
  56. <script>
  57. fetch('http://localhost:3000/api/get-user-id', {
  58. method: 'GET',
  59. credentials: 'include' // Include cookies in request
  60. })
  61. .then(response => {
  62. if (!response.ok) {
  63. throw new Error('Unauthorized access');
  64. }
  65. return response.json();
  66. })
  67. .catch(error => {
  68. console.error('Error fetching user ID:', error);
  69. alert('Please log in first!');
  70. window.location.href = "http://localhost:5500/";
  71. });
  72.  
  73. // Fungsi untuk logout
  74. function logout() {
  75. fetch('http://localhost:3000/api/logout', { method: 'POST', credentials: 'include' })
  76. .then(() => {
  77. window.location.href = 'login.html';
  78. })
  79. .catch(err => console.error('Logout error:', err));
  80. }
  81.  
  82. // Mengambil data transaksi dari backend
  83. fetch('http://localhost:3000/api/transactions', {
  84. method: 'GET',
  85. credentials: 'include' // Mengirim cookie session
  86. })
  87. .then(response => response.json())
  88. .then(data => {
  89. const transactionList = document.getElementById('transaction-list');
  90. data.forEach((transaction, index) => {
  91. const statusColor =
  92. transaction.status === 'success'
  93. ? 'text-success'
  94. : transaction.status === 'pending'
  95. ? 'text-warning'
  96. : 'text-danger';
  97.  
  98. transactionList.innerHTML += `
  99. <tr>
  100. <td>${index + 1}</td>
  101. <td>${transaction.user_name}</td>
  102. <td>${transaction.product_name}</td>
  103. <td>${transaction.order_id}</td>
  104. <td class="${statusColor} fw-bold">${transaction.status}</td>
  105. <td>
  106. ${
  107. transaction.status === 'pending'
  108. ? `<a href="${transaction.payment_link}" target="_blank" class="btn btn-primary btn-sm">Pay Now</a>`
  109. : '-'
  110. }
  111. </td>
  112. </tr>
  113. `;
  114. });
  115. })
  116. .catch(error => {
  117. console.error('Error fetching transactions:', error);
  118. });
  119.  
  120. function logout() {
  121. fetch('http://localhost:3000/logout', {
  122. method: 'GET',
  123. credentials: 'include'
  124. })
  125. .then(response => response.json())
  126. .then(data => {
  127. alert(data.message);
  128. window.location.href = "http://localhost:5500/";
  129. })
  130. .catch(error => {
  131. console.error('Error during logout:', error);
  132. });
  133. }
  134. </script>
  135.  
  136. <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
  137. </body>
  138. </html>
  139.  
  140. buatkan menggunakan tailwindcss versi 3.4.16 plugin flowbite versi 2.5.2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement