Self-hosted email delivery platform that enables applications to send emails via HTTP APIs while handling SMTP delivery, templates, storage, security, and analytics. Fully self-hostable alternative to services like SendGrid or Mailgun.
Go email-relayemail-routinghttp-to-smtpmail-deliverymailchimp-alternativemailgun-alternativemailsendermailservermailtemplatemailtestpostmark-alternativesend-emailsendgrid-alternativesendmailtransactional-emailtransactional-outbox
feat(admin): add user search functionality and enhance UI/UX
Jonas Kaninda862009add021
diff --git a/internal/handlers/admin_handler.go b/internal/handlers/admin_handler.goindex 4c95f39..d624209 100644--- a/internal/handlers/admin_handler.go+++ b/internal/handlers/admin_handler.go@@ -220,11 +220,16 @@ func (h *AdminHandler) CreateUser(c *okapi.Context, req *AdminCreateUserRequest)return created(c, user)}-// ListUsers returns all users.-func (h *AdminHandler) ListUsers(c *okapi.Context, req *ListRequest) error {+type ListUsersRequest struct {+ Page int `query:"page" default:"0"`+ Size int `query:"size" default:"20"`+ Search string `query:"search"`+}++func (h *AdminHandler) ListUsers(c *okapi.Context, req *ListUsersRequest) error {page, size, offset := normalizePageParams(req.Page, req.Size)- users, total, err := h.userRepo.FindAll(size, offset)+ users, total, err := h.userRepo.FindAll(req.Search, size, offset)if err != nil {return c.AbortInternalServerError("failed to list users")}diff --git a/internal/routes/admin_routes.go b/internal/routes/admin_routes.goindex 11ee5d2..f4512b1 100644--- a/internal/routes/admin_routes.go+++ b/internal/routes/admin_routes.go@@ -56,7 +56,7 @@ func (r *Router) adminRoutes() []okapi.RouteDefinition {Handler: okapi.H(r.h.admin.ListUsers),Group: adminGroup,Summary: "List all users",- Request: &handlers.ListRequest{},+ Request: &handlers.ListUsersRequest{},Response: &dto.PageableResponse[models.User]{},},{diff --git a/internal/storage/repositories/user_repo.go b/internal/storage/repositories/user_repo.goindex 72b3499..b02657c 100644--- a/internal/storage/repositories/user_repo.go+++ b/internal/storage/repositories/user_repo.go@@ -63,13 +63,21 @@ func (r *UserRepository) PersonalWorkspaceID(userID uint) (*uint, error) {return user.PersonalWorkspaceID, nil}-func (r *UserRepository) FindAll(limit, offset int) ([]models.User, int64, error) {+func (r *UserRepository) FindAll(search string, limit, offset int) ([]models.User, int64, error) {var users []models.Uservar total int64- r.db.Model(&models.User{}).Count(&total)+ countQ := r.db.Model(&models.User{})+ findQ := r.db.Model(&models.User{})+ if search != "" {+ like := "%" + search + "%"+ countQ = countQ.Where("name ILIKE ? OR email ILIKE ?", like, like)+ findQ = findQ.Where("name ILIKE ? OR email ILIKE ?", like, like)+ }++ countQ.Count(&total)- if err := r.db.Order("created_at DESC").+ if err := findQ.Order("created_at DESC").Limit(limit).Offset(offset).Find(&users).Error; err != nil {return nil, 0, errdiff --git a/web/src/api/admin.ts b/web/src/api/admin.tsindex 3ca8197..60dc4cc 100644--- a/web/src/api/admin.ts+++ b/web/src/api/admin.ts@@ -2,8 +2,8 @@ import api from './client'import type { ApiResponse, PaginatedResponse, User, ApiKey, Email, Event, AdminMetrics, UserDetailMetrics, CronJob, AdminWorkspace } from './types'export const adminApi = {- listUsers(page = 0, size = 20) {- return api.get<PaginatedResponse<User>>('/admin/users', { params: { page, size } })+ listUsers(page = 0, size = 20, search = '') {+ return api.get<PaginatedResponse<User>>('/admin/users', { params: { page, size, search: search || undefined } })},createUser(name: string, email: string, password: string, role: string) {return api.post<ApiResponse<User>>('/admin/users', { name, email, password, role })diff --git a/web/src/assets/styles.css b/web/src/assets/styles.cssindex 4f57857..7e75521 100644--- a/web/src/assets/styles.css+++ b/web/src/assets/styles.css@@ -358,10 +358,14 @@ td {font-size: 14px;border-bottom: 1px solid var(--border-secondary);color: var(--text-secondary);+ vertical-align: middle;}+/* Last row sits flush against the card/pagination border. */+tbody tr:last-child td { border-bottom: none; }+tr { transition: background var(--transition); }-tr:hover td { background: var(--bg-hover); }+tbody tr:hover td { background: var(--bg-hover); }/* ─── Badges ─── */.badge {@@ -851,6 +855,95 @@ input[type="checkbox"]:checked::before {cursor: pointer;}+/* ─── Data table polish ─── */+/* Rounded scroll container so wide tables clip cleanly inside cards. */+.table-wrapper { overflow-x: auto; border-radius: var(--radius); }++/* Two-line identity cell: avatar + stacked title/subtitle.+ <td><div class="cell-id"><span class="avatar">JK</span>+ <span class="cell-text"><span class="cell-title">Name</span>+ <span class="cell-sub">email</span></span></div></td> */+.cell-id { display: flex; align-items: center; gap: 11px; min-width: 0; }+.cell-text { display: flex; flex-direction: column; min-width: 0; gap: 1px; }+.cell-title {+ font-weight: 550;+ color: var(--text-primary);+ overflow: hidden; text-overflow: ellipsis; white-space: nowrap;+}+.cell-sub {+ font-size: 12.5px;+ color: var(--text-muted);+ overflow: hidden; text-overflow: ellipsis; white-space: nowrap;+}+/* Right-align + tabular figures for numeric columns (set on th and td). */+.cell-num { text-align: right; font-variant-numeric: tabular-nums; }++/* Circular initials avatar. */+.avatar {+ flex-shrink: 0;+ width: 34px; height: 34px;+ border-radius: 50%;+ display: inline-flex; align-items: center; justify-content: center;+ font-size: 13px; font-weight: 600;+ background: var(--primary-100); color: var(--primary-700);+ text-transform: uppercase;+ user-select: none;+}+[data-theme="dark"] .avatar { background: var(--primary-900); color: var(--primary-200); }+.avatar-sm { width: 26px; height: 26px; font-size: 11px; }++/* Right-aligned row action cluster — keeps icon buttons from wrapping oddly. */+.table-actions { display: flex; align-items: center; gap: 4px; justify-content: flex-end; }++/* Clickable table rows (navigate on click; inner buttons use @click.stop). */+.row-clickable { cursor: pointer; }+.row-clickable:hover td { background: var(--bg-hover); }++/* Status pill with a leading colored dot — inherits the badge color. */+.badge-dot::before {+ content: "";+ width: 6px; height: 6px;+ border-radius: 50%;+ background: currentColor;+ margin-right: 6px;+ flex-shrink: 0;+}++/* Square icon button (overrides the earlier compact .btn-icon). */+.btn-icon {+ width: 32px; height: 32px;+ padding: 0;+ border-radius: var(--radius-sm);+ font-size: 17px;+ line-height: 1;+}+.btn-icon .mdi { line-height: 1; }+/* Borderless icon buttons for dense row actions. */+.btn-icon-muted {+ background: transparent; border-color: transparent; color: var(--text-tertiary);+}+.btn-icon-muted:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-primary); }+.btn-icon-danger {+ background: transparent; border-color: transparent; color: var(--text-tertiary);+}+.btn-icon-danger:hover:not(:disabled) { background: var(--danger-50); color: var(--danger-600); }++/* Warning button (referenced by views but previously undefined). */+.btn-warning {+ background: var(--warning-500); color: #fff; border-color: var(--warning-500);+}+.btn-warning:hover:not(:disabled) { background: var(--warning-600); border-color: var(--warning-600); }++/* Shimmer skeleton for loading rows/blocks. */+.skeleton {+ background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--bg-hover) 37%, var(--bg-tertiary) 63%);+ background-size: 400% 100%;+ animation: skeleton 1.4s ease infinite;+ border-radius: var(--radius-sm);+}+.skeleton-text { display: block; height: 12px; width: 70%; }+@keyframes skeleton { from { background-position: 100% 50%; } to { background-position: 0 50%; } }+/* ─── Scrollbar ─── */::-webkit-scrollbar { width: 6px; height: 6px; }::-webkit-scrollbar-track { background: transparent; }diff --git a/web/src/main.ts b/web/src/main.tsindex 0b45632..5192aae 100644--- a/web/src/main.ts+++ b/web/src/main.ts@@ -2,6 +2,7 @@ import { createApp } from 'vue'import { createPinia } from 'pinia'import App from './App.vue'import router from './router'+import '@mdi/font/css/materialdesignicons.css'import './assets/styles.css'const app = createApp(App)diff --git a/web/src/views/admin/Users.vue b/web/src/views/admin/Users.vueindex 2ff1cff..9757689 100644--- a/web/src/views/admin/Users.vue+++ b/web/src/views/admin/Users.vue@@ -50,10 +50,13 @@ async function createUser() {}+const search = ref('')+let searchTimeout: ReturnType<typeof setTimeout> | null = null+const { pageable, goToPage } = usePagination(async (page) => {loading.value = truetry {- const res = await adminApi.listUsers(page)+ const res = await adminApi.listUsers(page, pageable.value.size, search.value)users.value = res.data.datapageable.value = res.data.pageable} catch (e) {@@ -63,6 +66,12 @@ const { pageable, goToPage } = usePagination(async (page) => {}})+// Debounce keystrokes, then reset to the first page of results.+function onSearchInput() {+ if (searchTimeout) clearTimeout(searchTimeout)+ searchTimeout = setTimeout(() => goToPage(0), 300)+}+function roleBadgeClass(role: string) {switch (role) {case 'admin': return 'badge badge-info'@@ -75,6 +84,18 @@ function formatDate(date: string) {return new Date(date).toLocaleString()}+function formatDateShort(date: string) {+ return new Date(date).toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' })+}++// Up to two initials for the avatar, falling back to the email when unnamed.+function getInitials(user: User) {+ const base = (user.name || user.email || '?').trim()+ const parts = base.split(/\s+/)+ if (parts.length >= 2 && parts[0] && parts[1]) return (parts[0][0] + parts[1][0])+ return base.slice(0, 2)+}+function startEdit(user: User) {editingUser.value = usereditForm.value = { role: user.role, active: user.active }@@ -194,63 +215,118 @@ const { watchClickStart, confirmClickEnd } = useModalSafeClose(() => {</div></div>- <div v-if="loading" class="loading-page">- <div class="spinner"></div>- </div>+ <div class="card">+ <div class="card-header" style="display: flex; gap: 12px; align-items: center;">+ <h2>Users</h2>+ <input+ v-model="search"+ type="text"+ class="form-input"+ placeholder="Search by name or email..."+ style="max-width: 320px; margin-left: auto;"+ @input="onSearchInput"+ />+ </div>- <template v-else>- <div class="card">- <div class="card-header">- <h2>Users</h2>- </div>- <div v-if="users.length === 0" class="empty-state">- <h3>No users found</h3>- <p>There are no registered users.</p>- </div>- <div v-else class="card-body">- <table class="table">- <thead>- <tr>- <th>Name</th>- <th>Email</th>- <th>Role</th>- <th>Status</th>- <th>Created At</th>- <th>Actions</th>- </tr>- </thead>- <tbody>- <tr v-for="user in users" :key="user.id">- <td>{{ user.name }}</td>- <td>{{ user.email }}</td>- <td><span :class="roleBadgeClass(user.role)">{{ user.role }}</span></td>- <td>- <span :class="user.active ? 'badge badge-success' : 'badge badge-danger'">- {{ user.active ? 'Active' : 'Disabled' }}+ <!-- Loading: skeleton rows preserve the table layout while data streams in. -->+ <div v-if="loading" class="card-body">+ <table class="table">+ <thead>+ <tr>+ <th>User</th>+ <th>Role</th>+ <th>Status</th>+ <th>Created</th>+ <th style="text-align: right;">Actions</th>+ </tr>+ </thead>+ <tbody>+ <tr v-for="n in 6" :key="n">+ <td>+ <div class="cell-id">+ <span class="avatar skeleton"></span>+ <span class="cell-text" style="flex: 1;">+ <span class="skeleton skeleton-text" style="width: 45%;"></span>+ <span class="skeleton skeleton-text" style="width: 65%; margin-top: 5px;"></span></span>- </td>- <td>{{ formatDate(user.created_at) }}</td>- <td style="display: flex; gap: 0.5rem; align-items: center;">- <button class="btn btn-sm btn-secondary" @click="startEdit(user)">Edit</button>- <button class="btn btn-sm btn-secondary" @click="router.push(`/admin/users/${user.id}`)">Details</button>+ </div>+ </td>+ <td><span class="skeleton skeleton-text" style="width: 52px;"></span></td>+ <td><span class="skeleton skeleton-text" style="width: 68px;"></span></td>+ <td><span class="skeleton skeleton-text" style="width: 88px;"></span></td>+ <td><span class="skeleton skeleton-text" style="width: 120px; margin-left: auto;"></span></td>+ </tr>+ </tbody>+ </table>+ </div>++ <div v-else-if="users.length === 0" class="empty-state">+ <span class="mdi mdi-account-multiple-outline" style="font-size: 44px; display: block; margin-bottom: 10px;"></span>+ <h3>No users found</h3>+ <p v-if="search">No users match “{{ search }}”.</p>+ <p v-else>There are no registered users yet.</p>+ </div>++ <div v-else class="card-body">+ <table class="table">+ <thead>+ <tr>+ <th>User</th>+ <th>Role</th>+ <th>Status</th>+ <th>Created</th>+ <th style="text-align: right;">Actions</th>+ </tr>+ </thead>+ <tbody>+ <tr+ v-for="user in users"+ :key="user.id"+ class="row-clickable"+ @click="router.push(`/admin/users/${user.id}`)"+ >+ <td>+ <div class="cell-id">+ <span class="avatar">{{ getInitials(user) }}</span>+ <span class="cell-text">+ <span class="cell-title">{{ user.name || '—' }}</span>+ <span class="cell-sub">{{ user.email }}</span>+ </span>+ </div>+ </td>+ <td><span :class="roleBadgeClass(user.role)">{{ user.role }}</span></td>+ <td>+ <span class="badge badge-dot" :class="user.active ? 'badge-success' : 'badge-danger'">+ {{ user.active ? 'Active' : 'Disabled' }}+ </span>+ </td>+ <td><span :title="formatDate(user.created_at)">{{ formatDateShort(user.created_at) }}</span></td>+ <td>+ <div class="table-actions">+ <button class="btn btn-icon btn-icon-muted" title="Edit role" @click.stop="startEdit(user)">+ <span class="mdi mdi-pencil-outline"></span>+ </button><button- class="btn btn-sm"- :class="user.active ? 'btn-warning' : 'btn-primary'"- @click="toggleActive(user)"+ class="btn btn-icon btn-icon-muted"+ :title="user.active ? 'Disable user' : 'Enable user'"+ @click.stop="toggleActive(user)">- {{ user.active ? 'Disable' : 'Enable' }}+ <span class="mdi" :class="user.active ? 'mdi-account-off-outline' : 'mdi-account-check-outline'"></span></button>- <button class="btn btn-sm btn-danger" @click="deleteUser(user)">Delete</button>- <button v-if="!user.active" class="btn btn-sm btn-danger" @click="forceDeleteUser(user)">Force Delete</button>- </td>- </tr>- </tbody>- </table>- <Pagination :pageable="pageable" @page="goToPage" />-- </div>+ <button class="btn btn-icon btn-icon-danger" title="Delete user" @click.stop="deleteUser(user)">+ <span class="mdi mdi-trash-can-outline"></span>+ </button>+ <button v-if="!user.active" class="btn btn-icon btn-icon-danger" title="Force delete (permanent)" @click.stop="forceDeleteUser(user)">+ <span class="mdi mdi-delete-alert-outline"></span>+ </button>+ </div>+ </td>+ </tr>+ </tbody>+ </table>+ <Pagination :pageable="pageable" @page="goToPage" /></div>- </template>+ </div><!-- Edit User Modal --><div v-if="editingUser" class="modal-overlay" @mousedown="watchClickStart"