From 4768022b5cbba845941ffb9e6ae72c3b6e74a7be Mon Sep 17 00:00:00 2001 From: devzeeh <148837352+devzeeh@users.noreply.github.com> Date: Wed, 10 Jun 2026 10:03:17 +0800 Subject: [PATCH 1/7] feat: implement user dashboard backend endpoint and frontend UI with sidebar and logout functionality --- backend/internal/user/dashboard.go | 9 +- frontend/assets/js/dashboard.js | 37 +++---- .../templates/customer/customer_sidebar.html | 55 +++++++++ frontend/templates/customer/dashboard.html | 104 ++---------------- tmp_app.exe | Bin 0 -> 15253504 bytes 5 files changed, 88 insertions(+), 117 deletions(-) create mode 100644 frontend/templates/customer/customer_sidebar.html create mode 100644 tmp_app.exe diff --git a/backend/internal/user/dashboard.go b/backend/internal/user/dashboard.go index 1d605f8..f432bf4 100644 --- a/backend/internal/user/dashboard.go +++ b/backend/internal/user/dashboard.go @@ -38,9 +38,14 @@ type DashboardUser struct { func (h *Handler) DashboardView(w http.ResponseWriter, r *http.Request) { fmt.Println("Dashboard view is running...") - // Check if session cookie is present (Removed) + username := r.PathValue("username") + data := struct { + Username string + }{ + Username: username, + } - h.Tpl.ExecuteTemplate(w, "dashboard.html", nil) + h.Tpl.ExecuteTemplate(w, "dashboard.html", data) } func (h *Handler) DashboardHandler(w http.ResponseWriter, r *http.Request) { diff --git a/frontend/assets/js/dashboard.js b/frontend/assets/js/dashboard.js index 4521b28..06ca486 100644 --- a/frontend/assets/js/dashboard.js +++ b/frontend/assets/js/dashboard.js @@ -22,10 +22,10 @@ document.addEventListener("DOMContentLoaded", function () { // --- Sidebar Logic --- if (sidebar && sidebarOverlay && toggleButton && openIcon && closeIcon && mainContent) { - + function toggleSidebar() { sidebar.classList.toggle('-translate-x-full'); - mainContent.classList.toggle('md:pl-64'); + mainContent.classList.toggle('md:pl-72'); openIcon.classList.toggle('hidden'); closeIcon.classList.toggle('hidden'); if (window.innerWidth < 768) { @@ -33,12 +33,12 @@ document.addEventListener("DOMContentLoaded", function () { } } - toggleButton.addEventListener('click', function(e) { + toggleButton.addEventListener('click', function (e) { e.stopPropagation(); toggleSidebar(); }); - sidebarOverlay.addEventListener('click', function() { + sidebarOverlay.addEventListener('click', function () { toggleSidebar(); }); @@ -47,28 +47,27 @@ document.addEventListener("DOMContentLoaded", function () { navLinks.forEach(link => { link.addEventListener('click', () => { if (window.innerWidth < 768 && !closeIcon.classList.contains('hidden')) { - toggleSidebar(); + toggleSidebar(); } }); }); - + } else { console.error("Sidebar elements not found. Make sure all IDs are correct."); } // --- Profile Dropdown Logic --- if (profileButton && profileMenu) { - - profileButton.addEventListener('click', function(event) { + + profileButton.addEventListener('click', function (event) { event.stopPropagation(); profileMenu.classList.toggle('hidden'); }); - document.addEventListener('click', function(event) { - if (!profileMenu.classList.contains('hidden') && - !profileButton.contains(event.target) && - !profileMenu.contains(event.target)) - { + document.addEventListener('click', function (event) { + if (!profileMenu.classList.contains('hidden') && + !profileButton.contains(event.target) && + !profileMenu.contains(event.target)) { profileMenu.classList.add('hidden'); } }); @@ -80,7 +79,7 @@ document.addEventListener("DOMContentLoaded", function () { // --- Logout Modal Logic --- // Check for all required modal elements const modalElementsExist = logoutModal && logoutModalContent && closeModalButton && cancelModalButton && confirmLogoutButton; - + if (modalElementsExist) { // Function to open the modal @@ -98,14 +97,14 @@ document.addEventListener("DOMContentLoaded", function () { logoutModalContent.classList.add('scale-95', 'opacity-0'); logoutModalContent.classList.remove('scale-100', 'opacity-100'); logoutModal.classList.remove('opacity-100'); - + setTimeout(() => { logoutModal.classList.add('hidden'); }, 300); } // --- UPDATED: Attach to all logout buttons --- - + // 1. Sidebar Logout Button if (logoutButton) { logoutButton.addEventListener('click', (e) => { @@ -113,7 +112,7 @@ document.addEventListener("DOMContentLoaded", function () { openLogoutModal(); }); } - + // 2. Profile Dropdown Logout Button if (profileLogoutButton) { profileLogoutButton.addEventListener('click', (e) => { @@ -127,7 +126,7 @@ document.addEventListener("DOMContentLoaded", function () { // Close modal buttons closeModalButton.addEventListener('click', closeLogoutModal); cancelModalButton.addEventListener('click', closeLogoutModal); - + // Also close if clicking on the background overlay logoutModal.addEventListener('click', (e) => { if (e.target === logoutModal) { @@ -208,7 +207,7 @@ document.addEventListener("DOMContentLoaded", function () { if (profileViewEmail) profileViewEmail.innerText = data.email || ""; if (profileViewPhone) profileViewPhone.innerText = data.phone || ""; if (profileViewUsername) profileViewUsername.innerText = data.username || ""; - + if (profileEditName) profileEditName.value = data.name || ""; if (profileEditEmail) profileEditEmail.value = data.email || ""; if (profileEditPhone) profileEditPhone.value = data.phone || ""; diff --git a/frontend/templates/customer/customer_sidebar.html b/frontend/templates/customer/customer_sidebar.html new file mode 100644 index 0000000..50971cc --- /dev/null +++ b/frontend/templates/customer/customer_sidebar.html @@ -0,0 +1,55 @@ +{{define "customer_sidebar"}} + +{{end}} diff --git a/frontend/templates/customer/dashboard.html b/frontend/templates/customer/dashboard.html index b994874..fd73ad1 100644 --- a/frontend/templates/customer/dashboard.html +++ b/frontend/templates/customer/dashboard.html @@ -31,96 +31,8 @@ - - - - - - - + {{template "customer_sidebar" .}}
| + | Date | -+ | Description | -+ | Type | -+ | Amount |
|---|