Skip to content

armgit / posta

Public Imported from GitHub
0

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.

refactor: replace all custom pagination by new pagination component and composable

Jude mpoyo57c500766a2c
diff --git a/web/src/composables/usePagination.ts b/web/src/composables/usePagination.ts
index 05ef5e5..d457d69 100644
--- a/web/src/composables/usePagination.ts
+++ b/web/src/composables/usePagination.ts
@@ -7,7 +7,7 @@ export function usePagination(fetchFn: (page: number) => Promise<void>) {
const router = useRouter()
const pageable = ref<Pageable>({ current_page: 0, size: 20, total_pages: 0, total_elements: 0, empty: true })
- function goToPage(page: number) {
+ async function goToPage(page: number) {
router.replace({ query: { ...route.query, page: page > 0 ? String(page + 1) : undefined } })
fetchFn(page)
}
diff --git a/web/src/views/admin/Events.vue b/web/src/views/admin/Events.vue
index 11919a6..032ebcf 100644
--- a/web/src/views/admin/Events.vue
+++ b/web/src/views/admin/Events.vue
@@ -3,11 +3,11 @@ import { ref, onMounted, onBeforeUnmount } from 'vue'
import { adminApi } from '../../api/admin'
import { useAuthStore } from '../../stores/auth'
import type { Event, Pageable } from '../../api/types'
-
+import { usePagination } from '@/composables/usePagination'
+import Pagination from '@/components/Pagination.vue'
const auth = useAuthStore()
const loading = ref(true)
const events = ref<Event[]>([])
-const pageable = ref<Pageable | null>(null)
const page = ref(0)
const category = ref('')
const liveEvents = ref<Event[]>([])
@@ -15,7 +15,6 @@ const streaming = ref(false)
let eventSource: EventSource | null = null
onMounted(() => {
- loadEvents()
startStream()
})
@@ -23,10 +22,11 @@ onBeforeUnmount(() => {
stopStream()
})
-async function loadEvents() {
+
+const { pageable, goToPage } = usePagination(async (page) => {
loading.value = true
try {
- const res = await adminApi.listEvents(page.value, 20, category.value || undefined)
+ const res = await adminApi.listEvents(page, 20, category.value || undefined)
events.value = res.data.data
pageable.value = res.data.pageable
} catch (e) {
@@ -34,17 +34,15 @@ async function loadEvents() {
} finally {
loading.value = false
}
-}
+})
+
-async function changePage(newPage: number) {
- page.value = newPage
- await loadEvents()
-}
function filterByCategory(cat: string) {
category.value = cat
page.value = 0
- loadEvents()
+ goToPage(pageable.value.current_page
+ )
}
function startStream() {
@@ -53,7 +51,7 @@ function startStream() {
if (!token) return
const url = `${baseUrl}/admin/events/stream?token=${encodeURIComponent(token)}`
eventSource = new EventSource(url)
-
+
eventSource.onopen = () => {
streaming.value = true
}
@@ -200,11 +198,8 @@ function timeAgo(date: string) {
</tr>
</tbody>
</table>
- <div v-if="pageable && pageable.total_pages > 1" class="pagination">
- <button class="btn btn-sm btn-secondary" :disabled="page === 0" @click="changePage(page - 1)">Previous</button>
- <span>Page {{ page + 1 }} of {{ pageable.total_pages }}</span>
- <button class="btn btn-sm btn-secondary" :disabled="page >= pageable.total_pages - 1" @click="changePage(page + 1)">Next</button>
- </div>
+ <Pagination :pageable="pageable" @page="goToPage" />
+
</div>
</div>
</template>
diff --git a/web/src/views/admin/Plans.vue b/web/src/views/admin/Plans.vue
index 5888b59..84a3abe 100644
--- a/web/src/views/admin/Plans.vue
+++ b/web/src/views/admin/Plans.vue
@@ -6,13 +6,15 @@ import type { Plan, PlanInput, Pageable } from '../../api/types'
import { useNotificationStore } from '../../stores/notification'
import { useConfirm } from '../../composables/useConfirm'
import { useModalSafeClose } from '../../composables/useModalSafeClose'
+import { usePagination } from '@/composables/usePagination'
+import Pagination from '@/components/Pagination.vue'
+
const router = useRouter()
const notify = useNotificationStore()
const { confirm } = useConfirm()
const plans = ref<Plan[]>([])
-const pageable = ref<Pageable | null>(null)
const loading = ref(true)
const currentPage = ref(0)
@@ -36,19 +38,18 @@ const defaultForm = (): PlanInput => ({
})
const form = ref<PlanInput>(defaultForm())
-
-async function fetchPlans() {
+const { pageable, goToPage } = usePagination(async (page) => {
loading.value = true
try {
const res = await plansApi.list(currentPage.value)
plans.value = res.data.data
pageable.value = res.data.pageable
- } catch {
- notify.error('Failed to load plans')
+ } catch (e) {
+ console.error('Failed to load plans', e)
} finally {
loading.value = false
}
-}
+})
function openCreate() {
editing.value = null
@@ -86,7 +87,7 @@ async function save() {
notify.success('Plan created')
}
showModal.value = false
- await fetchPlans()
+ await goToPage(pageable.value.current_page)
} catch (e: any) {
const message = e?.response?.data?.error?.message || 'Failed to save plan'
notify.error(message)
@@ -106,7 +107,7 @@ async function deletePlan(plan: Plan) {
try {
await plansApi.delete(plan.id, true)
notify.success('Plan deleted')
- await fetchPlans()
+ await goToPage(pageable.value.current_page)
} catch (e: any) {
const message = e?.response?.data?.error?.message || 'Failed to delete plan'
notify.error(message)
@@ -117,7 +118,7 @@ async function setDefault(plan: Plan) {
try {
await plansApi.setDefault(plan.id)
notify.success(`"${plan.name}" set as default`)
- await fetchPlans()
+ await goToPage(pageable.value.current_page)
} catch {
notify.error('Failed to set default plan')
}
@@ -127,25 +128,10 @@ function formatLimit(value: number): string {
return value === 0 ? 'Unlimited' : value.toLocaleString()
}
-function prevPage() {
- if (currentPage.value > 0) {
- currentPage.value--
- fetchPlans()
- }
-}
-
-function nextPage() {
- if (pageable.value && currentPage.value < pageable.value.total_pages - 1) {
- currentPage.value++
- fetchPlans()
- }
-}
-
const { watchClickStart, confirmClickEnd } = useModalSafeClose(() => {
showModal.value = false
})
-onMounted(fetchPlans)
</script>
<template>
@@ -218,17 +204,7 @@ onMounted(fetchPlans)
<h3>No plans</h3>
<p>Create a plan to define usage limits and resource quotas for workspaces.</p>
</div>
-
- <div v-if="pageable && !pageable.empty" class="pagination">
- <span class="pagination-info">
- Page {{ pageable.current_page + 1 }} of {{ pageable.total_pages }}
- ({{ pageable.total_elements }} total)
- </span>
- <div class="pagination-buttons">
- <button class="btn btn-secondary btn-sm" :disabled="currentPage === 0" @click="prevPage">Previous</button>
- <button class="btn btn-secondary btn-sm" :disabled="currentPage >= pageable.total_pages - 1" @click="nextPage">Next</button>
- </div>
- </div>
+<Pagination :pageable="pageable" @page="goToPage" />
</div>
</template>
diff --git a/web/src/views/admin/Servers.vue b/web/src/views/admin/Servers.vue
index 1ba679b..7ae0f6d 100644
--- a/web/src/views/admin/Servers.vue
+++ b/web/src/views/admin/Servers.vue
@@ -6,19 +6,22 @@ import type { SharedServer, SharedServerInput, Pageable } from '../../api/types'
import { useNotificationStore } from '../../stores/notification'
import { useConfirm } from '../../composables/useConfirm'
import { useModalSafeClose } from '../../composables/useModalSafeClose';
+import { usePagination } from '@/composables/usePagination'
+import Pagination from '@/components/Pagination.vue'
+
+
const router = useRouter()
const notify = useNotificationStore()
const { confirm } = useConfirm()
const servers = ref<SharedServer[]>([])
-const pageable = ref<Pageable | null>(null)
const loading = ref(true)
const currentPage = ref(0)
const showModal = ref(false)
const editing = ref<SharedServer | null>(null)
-const form = ref<SharedServerInput>({
+ const form = ref<SharedServerInput>({
name: '',
host: '',
port: 587,
@@ -31,19 +34,18 @@ const form = ref<SharedServerInput>({
})
const allowedDomainsText = ref('')
const saving = ref(false)
-
-async function fetchServers() {
+const { pageable, goToPage } = usePagination(async (page) => {
loading.value = true
try {
const res = await serversApi.list(currentPage.value)
servers.value = res.data.data
pageable.value = res.data.pageable
- } catch {
- notify.error('Failed to load shared servers')
+ } catch (e) {
+ console.error('Failed to load shared servers', e)
} finally {
loading.value = false
}
-}
+})
function openCreate() {
editing.value = null
@@ -87,7 +89,7 @@ async function save() {
notify.success('Server created')
}
showModal.value = false
- await fetchServers()
+ await goToPage(pageable.value.current_page)
} catch {
notify.error('Failed to save server')
} finally {
@@ -107,31 +109,16 @@ async function deleteServer(server: SharedServer) {
try {
await serversApi.delete(server.id)
notify.success('Server deleted')
- await fetchServers()
+ await goToPage(pageable.value.current_page)
} catch {
notify.error('Failed to delete server')
}
}
-function prevPage() {
- if (currentPage.value > 0) {
- currentPage.value--
- fetchServers()
- }
-}
-
-function nextPage() {
- if (pageable.value && currentPage.value < pageable.value.total_pages - 1) {
- currentPage.value++
- fetchServers()
- }
-}
-
const { watchClickStart, confirmClickEnd } = useModalSafeClose(() => {
showModal.value = false;
});
-onMounted(fetchServers)
</script>
<template>
@@ -202,16 +189,8 @@ onMounted(fetchServers)
<p>Add a shared SMTP server to give accounts without personal SMTP configuration a delivery path.</p>
</div>
- <div v-if="pageable && !pageable.empty" class="pagination">
- <span class="pagination-info">
- Page {{ pageable.current_page + 1 }} of {{ pageable.total_pages }}
- ({{ pageable.total_elements }} total)
- </span>
- <div class="pagination-buttons">
- <button class="btn btn-secondary btn-sm" :disabled="currentPage === 0" @click="prevPage">Previous</button>
- <button class="btn btn-secondary btn-sm" :disabled="currentPage >= pageable.total_pages - 1" @click="nextPage">Next</button>
- </div>
- </div>
+<Pagination :pageable="pageable" @page="goToPage" />
+
</div>
</template>
diff --git a/web/src/views/admin/Users.vue b/web/src/views/admin/Users.vue
index 1c19c2b..2ff1cff 100644
--- a/web/src/views/admin/Users.vue
+++ b/web/src/views/admin/Users.vue
@@ -6,13 +6,15 @@ import type { User, Pageable } from '../../api/types'
import { useNotificationStore } from '../../stores/notification'
import { useConfirm } from '../../composables/useConfirm'
import { useModalSafeClose } from '../../composables/useModalSafeClose';
+import { usePagination } from '@/composables/usePagination'
+import Pagination from '@/components/Pagination.vue'
+
const router = useRouter()
const notify = useNotificationStore()
const { confirm } = useConfirm()
const loading = ref(true)
const users = ref<User[]>([])
-const pageable = ref<Pageable | null>(null)
const page = ref(0)
const showCreateForm = ref(false)
@@ -23,10 +25,6 @@ const editingUser = ref<User | null>(null)
const editForm = ref({ role: '', active: true })
const editLoading = ref(false)
-onMounted(() => {
- loadUsers()
-})
-
async function createUser() {
if (!newUser.value.email || !newUser.value.password) {
notify.error('Email and password are required')
@@ -42,7 +40,7 @@ async function createUser() {
notify.success('User created successfully')
showCreateForm.value = false
newUser.value = { name: '', email: '', password: '', role: 'user' }
- await loadUsers()
+ await goToPage(pageable.value.current_page)
} catch (e: any) {
const message = e?.response?.data?.error?.message || 'Failed to create user'
notify.error(message)
@@ -51,23 +49,19 @@ async function createUser() {
}
}
-async function loadUsers() {
+
+const { pageable, goToPage } = usePagination(async (page) => {
loading.value = true
try {
- const res = await adminApi.listUsers(page.value)
+ const res = await adminApi.listUsers(page)
users.value = res.data.data
pageable.value = res.data.pageable
} catch (e) {
- notify.error('Failed to load users')
+ console.error('Failed to load API users', e)
} finally {
loading.value = false
}
-}
-
-async function changePage(newPage: number) {
- page.value = newPage
- await loadUsers()
-}
+})
function roleBadgeClass(role: string) {
switch (role) {
@@ -132,7 +126,7 @@ async function deleteUser(user: User) {
try {
await adminApi.deleteUser(user.id)
notify.success('Account disabled and scheduled for deletion.')
- await loadUsers()
+ await goToPage(pageable.value.current_page)
} catch (e: any) {
const message = e?.response?.data?.error?.message || 'Failed to delete user'
notify.error(message)
@@ -149,7 +143,7 @@ async function forceDeleteUser(user: User) {
try {
await adminApi.forceDeleteUser(user.id)
notify.success('User permanently deleted.')
- await loadUsers()
+ await goToPage(pageable.value.current_page)
} catch (e: any) {
const message = e?.response?.data?.error?.message || 'Failed to force delete user'
notify.error(message)
@@ -252,23 +246,8 @@ const { watchClickStart, confirmClickEnd } = useModalSafeClose(() => {
</tr>
</tbody>
</table>
- <div v-if="pageable && pageable.total_pages > 1" class="pagination">
- <button
- class="btn btn-sm btn-secondary"
- :disabled="page === 0"
- @click="changePage(page - 1)"
- >
- Previous
- </button>
- <span>Page {{ page + 1 }} of {{ pageable.total_pages }}</span>
- <button
- class="btn btn-sm btn-secondary"
- :disabled="page >= pageable.total_pages - 1"
- @click="changePage(page + 1)"
- >
- Next
- </button>
- </div>
+ <Pagination :pageable="pageable" @page="goToPage" />
+
</div>
</div>
</template>
diff --git a/web/src/views/apikeys/ApiKeys.vue b/web/src/views/apikeys/ApiKeys.vue
index 781326f..38ec197 100644
--- a/web/src/views/apikeys/ApiKeys.vue
+++ b/web/src/views/apikeys/ApiKeys.vue
@@ -7,13 +7,14 @@ import { useNotificationStore } from '../../stores/notification'
import { useConfirm } from '../../composables/useConfirm'
import { useModalSafeClose } from '../../composables/useModalSafeClose';
import { useWorkspaceStore } from '../../stores/workspace'
+import { usePagination } from '@/composables/usePagination'
+import Pagination from '../../components/Pagination.vue'
const notify = useNotificationStore()
const wsStore = useWorkspaceStore()
const { confirm } = useConfirm()
const keys = ref<ApiKey[]>([])
-const pageable = ref<Pageable>({ current_page: 0, size: 20, total_pages: 0, total_elements: 0, empty: true })
const loading = ref(true)
const showCreateModal = ref(false)
@@ -46,18 +47,20 @@ async function loadSettings() {
}
}
-async function loadKeys(page = 0) {
+
+const { pageable, goToPage } = usePagination(async (page) => {
loading.value = true
try {
- const res = await apiKeysApi.list(page, pageable.value.size)
+ const res = await apiKeysApi.list(page, pageable.value.size)
keys.value = res.data.data
pageable.value = res.data.pageable
- } catch {
- notify.error('Failed to load API keys')
+ } catch (e) {
+ console.error('Failed to load API keys', e)
} finally {
loading.value = false
}
-}
+})
+
function resolveExpiryDays(): number | undefined {
if (newKeyExpiry.value === 'never') return 0
@@ -86,7 +89,7 @@ async function createKey() {
newKeyExpiry.value = 'default'
showKeyModal.value = true
notify.success('API key created')
- await loadKeys(pageable.value.current_page)
+ await goToPage(pageable.value.current_page)
} catch {
notify.error('Failed to create API key')
} finally {
@@ -105,7 +108,7 @@ async function revokeKey(key: ApiKey) {
try {
await apiKeysApi.revoke(key.id)
notify.success('API key revoked')
- await loadKeys(pageable.value.current_page)
+ await goToPage(pageable.value.current_page)
} catch {
notify.error('Failed to revoke API key')
}
@@ -122,7 +125,7 @@ async function deleteKey(key: ApiKey) {
try {
await apiKeysApi.delete(key.id)
notify.success('API key deleted')
- await loadKeys(pageable.value.current_page)
+ await goToPage(pageable.value.current_page)
} catch {
notify.error('Failed to delete API key')
}
@@ -164,7 +167,6 @@ const { watchClickStart, confirmClickEnd } = useModalSafeClose(() => {
onMounted(() => {
loadSettings()
- loadKeys()
})
</script>
@@ -239,28 +241,8 @@ onMounted(() => {
</tbody>
</table>
</div>
+ <Pagination :pageable="pageable" @page="goToPage" />
- <div class="pagination">
- <span class="pagination-info">
- Page {{ pageable.current_page + 1 }} of {{ pageable.total_pages }} ({{ pageable.total_elements }} keys)
- </span>
- <div class="pagination-buttons">
- <button
- class="btn btn-secondary btn-sm"
- :disabled="pageable.current_page === 0"
- @click="loadKeys(pageable.current_page - 1)"
- >
- Previous
- </button>
- <button
- class="btn btn-secondary btn-sm"
- :disabled="pageable.current_page >= pageable.total_pages - 1"
- @click="loadKeys(pageable.current_page + 1)"
- >
- Next
- </button>
- </div>
- </div>
</template>
</div>
@@ -283,7 +265,7 @@ onMounted(() => {
</div>
<div class="form-group">
<label class="form-label">Expiration</label>
- <select v-model="newKeyExpiry" class="form-input">
+ <select v-model="newKeyExpiry" class="form-select">
<option v-for="opt in expiryOptions" :key="opt.value" :value="opt.value">
{{ opt.value === 'default' ? `${opt.label} (${defaultExpiryDays} days)` : opt.label }}
</option>
diff --git a/web/src/views/audit/AuditLog.vue b/web/src/views/audit/AuditLog.vue
index ff3e54a..2a526e4 100644
--- a/web/src/views/audit/AuditLog.vue
+++ b/web/src/views/audit/AuditLog.vue
@@ -2,13 +2,17 @@
import { ref, onMounted } from 'vue'
import { auditApi } from '../../api/audit'
import type { Event, Pageable } from '../../api/types'
+import Pagination from '../../components/Pagination.vue'
+import { usePagination } from '@/composables/usePagination'
+
const events = ref<Event[]>([])
-const pageable = ref<Pageable>({ current_page: 0, size: 20, total_pages: 0, total_elements: 0, empty: true })
const loading = ref(true)
const categoryFilter = ref('')
-async function loadEvents(page = 0) {
+
+
+const { pageable, goToPage } = usePagination(async (page) => {
loading.value = true
try {
const res = await auditApi.list(page, pageable.value.size, categoryFilter.value || undefined)
@@ -19,7 +23,7 @@ async function loadEvents(page = 0) {
} finally {
loading.value = false
}
-}
+})
function formatDate(dateStr: string): string {
return new Date(dateStr).toLocaleString()
@@ -34,7 +38,6 @@ function categoryBadgeClass(category: string): string {
}
}
-onMounted(() => loadEvents())
</script>
<template>
@@ -42,7 +45,7 @@ onMounted(() => loadEvents())
<div class="page-header">
<h1>Audit Log</h1>
<div class="page-header-actions">
- <select v-model="categoryFilter" class="form-input" style="min-width: 140px" @change="loadEvents(0)">
+ <select v-model="categoryFilter" class="form-select" style="min-width: 140px" @change="goToPage(0)">
<option value="">All categories</option>
<option value="user">User</option>
<option value="email">Email</option>
@@ -85,15 +88,9 @@ onMounted(() => loadEvents())
</table>
</div>
- <div class="pagination">
- <span class="pagination-info">
- Page {{ pageable.current_page + 1 }} of {{ pageable.total_pages }} ({{ pageable.total_elements }} events)
- </span>
- <div class="pagination-buttons">
- <button class="btn btn-secondary btn-sm" :disabled="pageable.current_page === 0" @click="loadEvents(pageable.current_page - 1)">Previous</button>
- <button class="btn btn-secondary btn-sm" :disabled="pageable.current_page >= pageable.total_pages - 1" @click="loadEvents(pageable.current_page + 1)">Next</button>
- </div>
- </div>
+ <Pagination :pageable="pageable" @page="goToPage" />
+
+
</template>
</div>
</div>
diff --git a/web/src/views/bounces/Bounces.vue b/web/src/views/bounces/Bounces.vue
index 8f5b49a..8ff20ad 100644
--- a/web/src/views/bounces/Bounces.vue
+++ b/web/src/views/bounces/Bounces.vue
@@ -5,6 +5,8 @@ import type { Bounce, Suppression, Pageable } from '../../api/types'
import { useNotificationStore } from '../../stores/notification'
import { useConfirm } from '../../composables/useConfirm'
import { useModalSafeClose } from '../../composables/useModalSafeClose';
+import { usePagination } from '@/composables/usePagination'
+import Pagination from '@/components/Pagination.vue'
const notify = useNotificationStore()
const { confirm } = useConfirm()
@@ -13,43 +15,38 @@ const activeTab = ref<'bounces' | 'suppressions'>('bounces')
const loading = ref(true)
const bounces = ref<Bounce[]>([])
-const bouncesPageable = ref<Pageable | null>(null)
-const bouncesPage = ref(0)
const suppressions = ref<Suppression[]>([])
-const suppressionsPageable = ref<Pageable | null>(null)
-const suppressionsPage = ref(0)
const showAddModal = ref(false)
const addForm = ref({ email: '', reason: '' })
-onMounted(() => {
- loadBounces()
- loadSuppressions()
-})
-async function loadBounces() {
+const { pageable: bouncesPageable, goToPage: loadBounces } = usePagination(async (page) => {
loading.value = true
try {
- const res = await bouncesApi.list(bouncesPage.value)
+ const res = await bouncesApi.list(page)
bounces.value = res.data.data
bouncesPageable.value = res.data.pageable
} catch (e) {
- notify.error('Failed to load bounces')
+ console.error('Failed to load bounces', e)
} finally {
loading.value = false
}
-}
+})
-async function loadSuppressions() {
+const { pageable: suppressionsPageable, goToPage: loadSuppressions } = usePagination(async (page) => {
+ loading.value = true
try {
- const res = await suppressionsApi.list(suppressionsPage.value)
+ const res = await suppressionsApi.list(page)
suppressions.value = res.data.data
suppressionsPageable.value = res.data.pageable
} catch (e) {
- notify.error('Failed to load suppressions')
+ console.error('Failed to load suppressions', e)
+ } finally {
+ loading.value = false
}
-}
+})
function switchTab(tab: 'bounces' | 'suppressions') {
activeTab.value = tab
@@ -68,16 +65,6 @@ function formatDate(date: string) {
return new Date(date).toLocaleString()
}
-async function changebouncesPage(page: number) {
- bouncesPage.value = page
- await loadBounces()
-}
-
-async function changeSuppressionsPage(page: number) {
- suppressionsPage.value = page
- await loadSuppressions()
-}
-
async function deleteSuppression(email: string) {
const confirmed = await confirm({
title: 'Remove Suppression',
@@ -89,7 +76,7 @@ async function deleteSuppression(email: string) {
try {
await suppressionsApi.delete(email)
notify.success('Suppression removed')
- await loadSuppressions()
+ await loadSuppressions(suppressionsPageable.value.current_page)
} catch (e) {
notify.error('Failed to remove suppression')
}
@@ -109,7 +96,7 @@ async function addSuppression() {
await suppressionsApi.create(addForm.value)
notify.success('Suppression added')
showAddModal.value = false
- await loadSuppressions()
+ await loadSuppressions(suppressionsPageable.value.current_page)
} catch (e) {
notify.error('Failed to add suppression')
}
@@ -127,7 +114,8 @@ const { watchClickStart, confirmClickEnd } = useModalSafeClose(() => {
<div class="tabs">
<button class="tab" :class="{ active: activeTab === 'bounces' }" @click="switchTab('bounces')">Bounces</button>
- <button class="tab" :class="{ active: activeTab === 'suppressions' }" @click="switchTab('suppressions')">Suppressions</button>
+ <button class="tab" :class="{ active: activeTab === 'suppressions' }"
+ @click="switchTab('suppressions')">Suppressions</button>
</div>
<div v-if="loading" class="loading-page">
@@ -163,23 +151,8 @@ const { watchClickStart, confirmClickEnd } = useModalSafeClose(() => {
</tr>
</tbody>
</table>
- <div v-if="bouncesPageable && bouncesPageable.total_pages > 1" class="pagination">
- <button
- class="btn btn-sm btn-secondary"
- :disabled="bouncesPage === 0"
- @click="changebouncesPage(bouncesPage - 1)"
- >
- Previous
- </button>
- <span>Page {{ bouncesPage + 1 }} of {{ bouncesPageable.total_pages }}</span>
- <button
- class="btn btn-sm btn-secondary"
- :disabled="bouncesPage >= bouncesPageable.total_pages - 1"
- @click="changebouncesPage(bouncesPage + 1)"
- >
- Next
- </button>
- </div>
+ <Pagination :pageable="bouncesPageable" @page="loadBounces" />
+
</div>
</div>
@@ -216,30 +189,15 @@ const { watchClickStart, confirmClickEnd } = useModalSafeClose(() => {
</tr>
</tbody>
</table>
- <div v-if="suppressionsPageable && suppressionsPageable.total_pages > 1" class="pagination">
- <button
- class="btn btn-sm btn-secondary"
- :disabled="suppressionsPage === 0"
- @click="changeSuppressionsPage(suppressionsPage - 1)"
- >
- Previous
- </button>
- <span>Page {{ suppressionsPage + 1 }} of {{ suppressionsPageable.total_pages }}</span>
- <button
- class="btn btn-sm btn-secondary"
- :disabled="suppressionsPage >= suppressionsPageable.total_pages - 1"
- @click="changeSuppressionsPage(suppressionsPage + 1)"
- >
- Next
- </button>
- </div>
+ <Pagination :pageable="suppressionsPageable" @page="loadSuppressions" />
+
+
</div>
</div>
</template>
<!-- Add Suppression Modal -->
- <div v-if="showAddModal" class="modal-overlay" @mousedown="watchClickStart"
- @mouseup="confirmClickEnd">
+ <div v-if="showAddModal" class="modal-overlay" @mousedown="watchClickStart" @mouseup="confirmClickEnd">
<div class="modal" @mousedown.stop @mouseup.stop>
<div class="modal-header">
<h2>Add Suppression</h2>
diff --git a/web/src/views/campaigns/Campaigns.vue b/web/src/views/campaigns/Campaigns.vue
index 8e4d9e6..87a7f25 100644
--- a/web/src/views/campaigns/Campaigns.vue
+++ b/web/src/views/campaigns/Campaigns.vue
@@ -8,6 +8,8 @@ import { useNotificationStore } from '../../stores/notification'
import { useConfirm } from '../../composables/useConfirm'
import { useModalSafeClose } from '../../composables/useModalSafeClose'
import { useWorkspaceStore } from '../../stores/workspace'
+import { usePagination } from '@/composables/usePagination'
+import Pagination from '@/components/Pagination.vue'
const router = useRouter()
const notify = useNotificationStore()
@@ -15,7 +17,6 @@ const wsStore = useWorkspaceStore()
const { confirm } = useConfirm()
const campaigns = ref<Campaign[]>([])
-const pageable = ref<Pageable>({ current_page: 0, size: 20, total_pages: 0, total_elements: 0, empty: true })
const loading = ref(true)
const statusFilter = ref<string>('')
@@ -44,22 +45,23 @@ const saving = ref(false)
const lists = ref<SubscriberListItem[]>([])
const templates = ref<{ id: number; name: string }[]>([])
-async function loadCampaigns(page = 0) {
+
+const { pageable, goToPage } = usePagination(async (page) => {
loading.value = true
try {
const res = await campaignsApi.list(page, pageable.value.size, statusFilter.value || undefined)
campaigns.value = res.data.data ?? []
pageable.value = res.data.pageable
- } catch {
- notify.error('Failed to load campaigns')
+ } catch (e) {
+ console.error('Failed to load campaigns', e)
} finally {
loading.value = false
}
-}
+})
function switchStatus(status: string) {
statusFilter.value = status
- loadCampaigns(0)
+ goToPage(0)
}
async function loadFormData() {
@@ -110,7 +112,7 @@ async function saveCampaign() {
})
notify.success('Campaign created')
showModal.value = false
- await loadCampaigns(pageable.value.current_page)
+ await goToPage(pageable.value.current_page)
} catch (e: any) {
notify.error(e?.response?.data?.error?.message || 'Failed to create campaign')
} finally {
@@ -132,7 +134,7 @@ async function deleteCampaign(campaign: Campaign) {
try {
await campaignsApi.delete(campaign.id)
notify.success('Campaign deleted')
- await loadCampaigns(pageable.value.current_page)
+ await goToPage(pageable.value.current_page)
} catch (e: any) {
notify.error(e?.response?.data?.error?.message || 'Failed to delete campaign')
}
@@ -169,7 +171,6 @@ const { watchClickStart, confirmClickEnd } = useModalSafeClose(() => {
showModal.value = false
})
-onMounted(() => loadCampaigns())
</script>
<template>
@@ -181,14 +182,9 @@ onMounted(() => loadCampaigns())
<!-- Status filter tabs -->
<div class="tabs" style="margin-bottom: 16px;">
- <button
- v-for="tab in statusTabs"
- :key="tab.value"
- class="btn btn-sm"
- :class="statusFilter === tab.value ? 'btn-primary' : 'btn-secondary'"
- @click="switchStatus(tab.value)"
- style="margin-right: 4px;"
- >
+ <button v-for="tab in statusTabs" :key="tab.value" class="btn btn-sm"
+ :class="statusFilter === tab.value ? 'btn-primary' : 'btn-secondary'" @click="switchStatus(tab.value)"
+ style="margin-right: 4px;">
{{ tab.label }}
</button>
</div>
@@ -226,12 +222,10 @@ onMounted(() => loadCampaigns())
<td>{{ formatDate(campaign.created_at) }}</td>
<td>
<div style="display: flex; gap: 6px">
- <button class="btn btn-secondary btn-sm" @click="router.push(`/campaigns/${campaign.id}`)">View</button>
- <button
- v-if="wsStore.canEdit && canDeleteStatus(campaign.status)"
- class="btn btn-danger btn-sm"
- @click="deleteCampaign(campaign)"
- >Delete</button>
+ <button class="btn btn-secondary btn-sm"
+ @click="router.push(`/campaigns/${campaign.id}`)">View</button>
+ <button v-if="wsStore.canEdit && canDeleteStatus(campaign.status)" class="btn btn-danger btn-sm"
+ @click="deleteCampaign(campaign)">Delete</button>
</div>
</td>
</tr>
@@ -239,15 +233,8 @@ onMounted(() => loadCampaigns())
</table>
</div>
- <div class="pagination">
- <span class="pagination-info">
- Page {{ pageable.current_page + 1 }} of {{ pageable.total_pages }} ({{ pageable.total_elements }} campaigns)
- </span>
- <div class="pagination-buttons">
- <button class="btn btn-secondary btn-sm" :disabled="pageable.current_page === 0" @click="loadCampaigns(pageable.current_page - 1)">Previous</button>
- <button class="btn btn-secondary btn-sm" :disabled="pageable.current_page >= pageable.total_pages - 1" @click="loadCampaigns(pageable.current_page + 1)">Next</button>
- </div>
- </div>
+ <Pagination :pageable="pageable" @page="goToPage" />
+
</template>
</div>
@@ -310,6 +297,7 @@ onMounted(() => loadCampaigns())
cursor: pointer;
font-weight: 500;
}
+
.link:hover {
text-decoration: underline;
}
diff --git a/web/src/views/contact-lists/ContactLists.vue b/web/src/views/contact-lists/ContactLists.vue
index dd07369..89fe2a3 100644
--- a/web/src/views/contact-lists/ContactLists.vue
+++ b/web/src/views/contact-lists/ContactLists.vue
@@ -7,6 +7,9 @@ import { useNotificationStore } from '../../stores/notification'
import { useConfirm } from '../../composables/useConfirm'
import { useModalSafeClose } from '../../composables/useModalSafeClose';
import { useWorkspaceStore } from '../../stores/workspace'
+import { usePagination } from '@/composables/usePagination'
+import Pagination from '@/components/Pagination.vue'
+
const router = useRouter()
const notify = useNotificationStore()
@@ -14,7 +17,6 @@ const wsStore = useWorkspaceStore()
const { confirm } = useConfirm()
const lists = ref<ContactListWithCount[]>([])
-const pageable = ref<Pageable>({ current_page: 0, size: 20, total_pages: 0, total_elements: 0, empty: true })
const loading = ref(true)
// Create/Edit modal
@@ -24,18 +26,19 @@ const formName = ref('')
const formDescription = ref('')
const saving = ref(false)
-async function loadLists(page = 0) {
+const { pageable, goToPage } = usePagination(async (page) => {
loading.value = true
try {
const res = await contactListsApi.list(page, pageable.value.size)
lists.value = res.data.data
pageable.value = res.data.pageable
- } catch {
- notify.error('Failed to load contact lists')
+ } catch (e) {
+ console.error('Failed to load contact lists', e)
} finally {
loading.value = false
}
-}
+})
+
function openCreate() {
editingId.value = null
@@ -63,7 +66,7 @@ async function saveList() {
notify.success('Contact list created')
}
showModal.value = false
- await loadLists(pageable.value.current_page)
+ await goToPage(pageable.value.current_page)
} catch (e: any) {
notify.error(e?.response?.data?.error?.message || 'Failed to save contact list')
} finally {
@@ -82,7 +85,7 @@ async function deleteList(list: ContactListWithCount) {
try {
await contactListsApi.delete(list.id)
notify.success('Contact list deleted')
- await loadLists(pageable.value.current_page)
+ await goToPage(pageable.value.current_page)
} catch {
notify.error('Failed to delete contact list')
}
@@ -98,7 +101,6 @@ function formatDate(dateStr: string): string {
const { watchClickStart, confirmClickEnd } = useModalSafeClose(() => {
showModal.value = false;
});
-onMounted(() => loadLists())
</script>
<template>
@@ -150,15 +152,8 @@ onMounted(() => loadLists())
</table>
</div>
- <div class="pagination">
- <span class="pagination-info">
- Page {{ pageable.current_page + 1 }} of {{ pageable.total_pages }} ({{ pageable.total_elements }} lists)
- </span>
- <div class="pagination-buttons">
- <button class="btn btn-secondary btn-sm" :disabled="pageable.current_page === 0" @click="loadLists(pageable.current_page - 1)">Previous</button>
- <button class="btn btn-secondary btn-sm" :disabled="pageable.current_page >= pageable.total_pages - 1" @click="loadLists(pageable.current_page + 1)">Next</button>
- </div>
- </div>
+ <Pagination :pageable="pageable" @page="goToPage" />
+
</template>
</div>
diff --git a/web/src/views/contacts/Contacts.vue b/web/src/views/contacts/Contacts.vue
index 3741a60..c308a0f 100644
--- a/web/src/views/contacts/Contacts.vue
+++ b/web/src/views/contacts/Contacts.vue
@@ -30,20 +30,19 @@ const contactLists = ref<ContactListWithCount[]>([])
const selectedListId = ref<number | null>(null)
const addingToList = ref(false)
-const { pageable, goToPage } = usePagination(loadContacts)
-
-async function loadContacts(page = 0) {
+const { pageable, goToPage } = usePagination(async (page) => {
loading.value = true
try {
const res = await contactsApi.list(page, pageable.value.size, search.value)
contacts.value = res.data.data
pageable.value = res.data.pageable
- } catch {
- notify.error('Failed to load contacts')
+ } catch (e) {
+ console.error('Failed to load contacts', e)
} finally {
loading.value = false
}
-}
+})
+
function onSearchInput() {
if (searchTimeout) clearTimeout(searchTimeout)
@@ -62,7 +61,7 @@ async function suppressContact(contact: Contact) {
try {
await suppressionsApi.create({ email: contact.email, reason: 'Manually suppressed from contacts' })
notify.success(`${contact.email} has been suppressed.`)
- await loadContacts(pageable.value.current_page)
+ await goToPage(pageable.value.current_page)
} catch (err: any) {
const message = err?.response?.data?.error?.message || err?.response?.data?.error || 'Failed to suppress contact.'
notify.error(message)
diff --git a/web/src/views/domains/Domains.vue b/web/src/views/domains/Domains.vue
index c6cf5f7..62b1198 100644
--- a/web/src/views/domains/Domains.vue
+++ b/web/src/views/domains/Domains.vue
@@ -6,13 +6,15 @@ import { useNotificationStore } from '../../stores/notification'
import { useConfirm } from '../../composables/useConfirm'
import { useModalSafeClose } from '../../composables/useModalSafeClose';
import { useWorkspaceStore } from '../../stores/workspace'
+import { usePagination } from '@/composables/usePagination'
+import Pagination from '@/components/Pagination.vue'
+
const notify = useNotificationStore()
const wsStore = useWorkspaceStore()
const { confirm } = useConfirm()
const domains = ref<Domain[]>([])
-const pageable = ref<Pageable | null>(null)
const loading = ref(true)
const currentPage = ref(0)
@@ -59,9 +61,9 @@ const recordRows = computed<RecordRow[]>(() => {
if (!d || !d.dns_records) return []
return [
{ key: 'verification', ...recordDescriptions.verification, record: d.dns_records.verification, verified: !!d.ownership_verified },
- { key: 'spf', ...recordDescriptions.spf, record: d.dns_records.spf, verified: !!d.spf_verified },
- { key: 'dkim', ...recordDescriptions.dkim, record: d.dns_records.dkim, verified: !!d.dkim_verified },
- { key: 'dmarc', ...recordDescriptions.dmarc, record: d.dns_records.dmarc, verified: !!d.dmarc_verified },
+ { key: 'spf', ...recordDescriptions.spf, record: d.dns_records.spf, verified: !!d.spf_verified },
+ { key: 'dkim', ...recordDescriptions.dkim, record: d.dns_records.dkim, verified: !!d.dkim_verified },
+ { key: 'dmarc', ...recordDescriptions.dmarc, record: d.dns_records.dmarc, verified: !!d.dmarc_verified },
]
})
@@ -92,18 +94,19 @@ async function copyAllRecords() {
await copy(lines.join('\n'), 'All records')
}
-async function fetchDomains() {
+const { pageable, goToPage } = usePagination(async (page) => {
loading.value = true
try {
const res = await domainsApi.list(currentPage.value)
domains.value = res.data.data
pageable.value = res.data.pageable
- } catch {
- notify.error('Failed to load domains')
+ } catch (e) {
+ console.error('Failed to load domains', e)
} finally {
loading.value = false
}
-}
+})
+
async function addDomain() {
if (!newDomain.value.trim()) return
@@ -113,7 +116,7 @@ async function addDomain() {
notify.success('Domain added')
showAddModal.value = false
newDomain.value = ''
- await fetchDomains()
+ await goToPage(pageable.value.current_page)
} catch {
notify.error('Failed to add domain')
} finally {
@@ -126,7 +129,7 @@ async function verifyDomain(domain: Domain) {
try {
await domainsApi.verify(domain.id)
notify.success(`Verification initiated for ${domain.domain}`)
- await fetchDomains()
+ await goToPage(pageable.value.current_page)
if (expandedDomainId.value === domain.id) {
const res = await domainsApi.get(domain.id)
dnsRecordsDomain.value = res.data.data
@@ -172,29 +175,14 @@ async function deleteDomain(domain: Domain) {
expandedDomainId.value = null
dnsRecordsDomain.value = null
}
- await fetchDomains()
+ await goToPage(pageable.value.current_page)
} catch {
notify.error('Failed to delete domain')
}
}
-
-function prevPage() {
- if (currentPage.value > 0) {
- currentPage.value--
- fetchDomains()
- }
-}
-
-function nextPage() {
- if (pageable.value && currentPage.value < pageable.value.total_pages - 1) {
- currentPage.value++
- fetchDomains()
- }
-}
const { watchClickStart, confirmClickEnd } = useModalSafeClose(() => {
showAddModal.value = false;
});
-onMounted(fetchDomains)
</script>
<template>
@@ -244,11 +232,13 @@ onMounted(fetchDomains)
</td>
<td>
<div class="flex gap-2">
- <button v-if="wsStore.canEdit" class="btn btn-secondary btn-sm" @click="verifyDomain(domain)">Verify</button>
+ <button v-if="wsStore.canEdit" class="btn btn-secondary btn-sm"
+ @click="verifyDomain(domain)">Verify</button>
<button class="btn btn-secondary btn-sm" @click="viewDnsRecords(domain)">
{{ expandedDomainId === domain.id ? 'Hide DNS' : 'View DNS Records' }}
</button>
- <button v-if="wsStore.canEdit" class="btn btn-danger btn-sm" @click="deleteDomain(domain)">Delete</button>
+ <button v-if="wsStore.canEdit" class="btn btn-danger btn-sm"
+ @click="deleteDomain(domain)">Delete</button>
</div>
</td>
</tr>
@@ -263,29 +253,22 @@ onMounted(fetchDomains)
<h4 class="dns-panel-title">DNS records for {{ domain.domain }}</h4>
<p class="dns-panel-subtitle">
Add the records below at your DNS provider, then click
- <strong>Re-check</strong>. Propagation is usually under 15 minutes but can take up to 48 hours.
+ <strong>Re-check</strong>. Propagation is usually under 15 minutes but can take up to 48
+ hours.
</p>
</div>
<div class="dns-panel-actions">
<button class="btn btn-secondary btn-sm" @click="copyAllRecords">Copy all</button>
- <button
- v-if="wsStore.canEdit"
- class="btn btn-primary btn-sm"
- :disabled="verifying"
- @click="verifyDomain(domain)"
- >
+ <button v-if="wsStore.canEdit" class="btn btn-primary btn-sm" :disabled="verifying"
+ @click="verifyDomain(domain)">
{{ verifying ? 'Checking…' : 'Re-check' }}
</button>
</div>
</div>
<div class="dns-record-list">
- <div
- v-for="row in recordRows"
- :key="row.key"
- class="dns-record"
- :class="{ 'dns-record-highlight': row.key === 'verification', 'dns-record-verified': row.verified }"
- >
+ <div v-for="row in recordRows" :key="row.key" class="dns-record"
+ :class="{ 'dns-record-highlight': row.key === 'verification', 'dns-record-verified': row.verified }">
<div class="dns-record-head">
<div class="dns-record-head-left">
<span class="dns-label">{{ row.label }}</span>
@@ -304,16 +287,11 @@ onMounted(fetchDomains)
<div class="dns-field-label">Host / Name</div>
<div class="dns-field-row">
<code class="dns-field-value">{{ row.record.name }}</code>
- <button
- type="button"
- class="btn btn-ghost btn-xs"
- @click="copy(row.record.name, 'Host')"
- >Copy</button>
+ <button type="button" class="btn btn-ghost btn-xs"
+ @click="copy(row.record.name, 'Host')">Copy</button>
</div>
- <div
- v-if="hostShortForm(row.record.name, domain.domain) !== row.record.name"
- class="dns-field-hint"
- >
+ <div v-if="hostShortForm(row.record.name, domain.domain) !== row.record.name"
+ class="dns-field-hint">
Some providers (Cloudflare, Route 53, GoDaddy) only accept the subdomain part —
use <code>{{ hostShortForm(row.record.name, domain.domain) }}</code> instead.
</div>
@@ -323,11 +301,8 @@ onMounted(fetchDomains)
<div class="dns-field-label">Value</div>
<div class="dns-field-row">
<code class="dns-field-value dns-field-value-block">{{ row.record.value }}</code>
- <button
- type="button"
- class="btn btn-ghost btn-xs"
- @click="copy(row.record.value, 'Value')"
- >Copy</button>
+ <button type="button" class="btn btn-ghost btn-xs"
+ @click="copy(row.record.value, 'Value')">Copy</button>
</div>
</div>
@@ -351,23 +326,14 @@ onMounted(fetchDomains)
<h3>No domains</h3>
<p>Add a domain to verify your sending identity.</p>
</div>
+ <Pagination :pageable="pageable" @page="goToPage" />
+
- <div v-if="pageable && !pageable.empty" class="pagination">
- <span class="pagination-info">
- Page {{ pageable.current_page + 1 }} of {{ pageable.total_pages }}
- ({{ pageable.total_elements }} total)
- </span>
- <div class="pagination-buttons">
- <button class="btn btn-secondary btn-sm" :disabled="currentPage === 0" @click="prevPage">Previous</button>
- <button class="btn btn-secondary btn-sm" :disabled="currentPage >= pageable.total_pages - 1" @click="nextPage">Next</button>
- </div>
- </div>
</div>
</template>
<!-- Add Domain Modal -->
- <div v-if="showAddModal" class="modal-overlay" @mousedown="watchClickStart"
- @mouseup="confirmClickEnd">
+ <div v-if="showAddModal" class="modal-overlay" @mousedown="watchClickStart" @mouseup="confirmClickEnd">
<div class="modal" @mousedown.stop @mouseup.stop>
<div class="modal-header">
<h3>Add Domain</h3>
diff --git a/web/src/views/languages/Languages.vue b/web/src/views/languages/Languages.vue
index 91ce077..77aeb64 100644
--- a/web/src/views/languages/Languages.vue
+++ b/web/src/views/languages/Languages.vue
@@ -6,13 +6,15 @@ import { useNotificationStore } from '../../stores/notification'
import { useConfirm } from '../../composables/useConfirm'
import { useModalSafeClose } from '../../composables/useModalSafeClose';
import { useWorkspaceStore } from '../../stores/workspace'
+import { usePagination } from '@/composables/usePagination'
+import Pagination from '@/components/Pagination.vue'
+
const notify = useNotificationStore()
const wsStore = useWorkspaceStore()
const { confirm } = useConfirm()
const languages = ref<Language[]>([])
-const pageable = ref<Pageable>({ current_page: 0, size: 20, total_pages: 0, total_elements: 0, empty: true })
const loading = ref(true)
const showModal = ref(false)
@@ -49,19 +51,19 @@ function closeModal() {
showModal.value = false
resetForm()
}
-
-async function loadLanguages(page = 0) {
+const { pageable, goToPage } = usePagination(async (page) => {
loading.value = true
try {
const res = await languagesApi.list(page, pageable.value.size)
languages.value = res.data.data
pageable.value = res.data.pageable
- } catch {
- notify.error('Failed to load languages')
+ } catch (e) {
+ console.error('Failed to load languages', e)
} finally {
loading.value = false
}
-}
+})
+
async function saveLanguage() {
if (!form.value.code.trim() || !form.value.name.trim()) return
@@ -75,7 +77,7 @@ async function saveLanguage() {
notify.success('Language created')
}
closeModal()
- await loadLanguages(pageable.value.current_page)
+ await goToPage(pageable.value.current_page)
} catch {
notify.error(editing.value ? 'Failed to update language' : 'Language code already exists')
} finally {
@@ -94,7 +96,7 @@ async function deleteLanguage(lang: Language) {
try {
await languagesApi.delete(lang.id)
notify.success('Language deleted')
- await loadLanguages(pageable.value.current_page)
+ await goToPage(pageable.value.current_page)
} catch {
notify.error('Failed to delete language')
}
@@ -106,7 +108,6 @@ function formatDate(dateStr: string): string {
const { watchClickStart, confirmClickEnd } = useModalSafeClose(() => {
closeModal()
});
-onMounted(() => loadLanguages())
</script>
<template>
@@ -155,27 +156,8 @@ onMounted(() => loadLanguages())
</table>
</div>
- <div class="pagination">
- <span class="pagination-info">
- Page {{ pageable.current_page + 1 }} of {{ pageable.total_pages }} ({{ pageable.total_elements }} languages)
- </span>
- <div class="pagination-buttons">
- <button
- class="btn btn-secondary btn-sm"
- :disabled="pageable.current_page === 0"
- @click="loadLanguages(pageable.current_page - 1)"
- >
- Previous
- </button>
- <button
- class="btn btn-secondary btn-sm"
- :disabled="pageable.current_page >= pageable.total_pages - 1"
- @click="loadLanguages(pageable.current_page + 1)"
- >
- Next
- </button>
- </div>
- </div>
+ <Pagination :pageable="pageable" @page="goToPage" />
+
</template>
</div>
diff --git a/web/src/views/smtp/SmtpServers.vue b/web/src/views/smtp/SmtpServers.vue
index f9f1f0c..a596ef4 100644
--- a/web/src/views/smtp/SmtpServers.vue
+++ b/web/src/views/smtp/SmtpServers.vue
@@ -7,6 +7,9 @@ import { useNotificationStore } from '../../stores/notification'
import { useConfirm } from '../../composables/useConfirm'
import { useModalSafeClose } from '../../composables/useModalSafeClose';
import { useWorkspaceStore } from '../../stores/workspace'
+import { usePagination } from '@/composables/usePagination'
+import Pagination from '@/components/Pagination.vue'
+
const router = useRouter()
const notify = useNotificationStore()
@@ -14,13 +17,12 @@ const wsStore = useWorkspaceStore()
const { confirm } = useConfirm()
const servers = ref<SmtpServer[]>([])
-const pageable = ref<Pageable | null>(null)
const loading = ref(true)
const currentPage = ref(0)
const showModal = ref(false)
const editing = ref<SmtpServer | null>(null)
-const form = ref<SmtpServerInput>({
+ const form = ref<SmtpServerInput>({
host: '',
port: 587,
username: '',
@@ -31,18 +33,18 @@ const form = ref<SmtpServerInput>({
const allowedEmailsText = ref('')
const saving = ref(false)
-async function fetchServers() {
+const { pageable, goToPage } = usePagination(async (page) => {
loading.value = true
try {
const res = await smtpApi.list(currentPage.value)
servers.value = res.data.data
pageable.value = res.data.pageable
- } catch {
- notify.error('Failed to load SMTP servers')
+ } catch (e) {
+ console.error('Failed to load SMTP servers', e)
} finally {
loading.value = false
}
-}
+})
function openCreate() {
editing.value = null
@@ -74,7 +76,7 @@ async function save() {
.split(',')
.map(e => e.trim())
.filter(e => e.length > 0),
- }
+ }
try {
if (editing.value) {
await smtpApi.update(editing.value.id, data)
@@ -84,7 +86,7 @@ async function save() {
notify.success('SMTP server created')
}
showModal.value = false
- await fetchServers()
+ await goToPage(pageable.value.current_page)
} catch {
notify.error('Failed to save SMTP server')
} finally {
@@ -103,29 +105,15 @@ async function deleteServer(server: SmtpServer) {
try {
await smtpApi.delete(server.id)
notify.success('SMTP server deleted')
- await fetchServers()
+ await goToPage(pageable.value.current_page)
} catch {
notify.error('Failed to delete SMTP server')
}
}
-function prevPage() {
- if (currentPage.value > 0) {
- currentPage.value--
- fetchServers()
- }
-}
-
-function nextPage() {
- if (pageable.value && currentPage.value < pageable.value.total_pages - 1) {
- currentPage.value++
- fetchServers()
- }
-}
const { watchClickStart, confirmClickEnd } = useModalSafeClose(() => {
showModal.value = false;
});
-onMounted(fetchServers)
</script>
<template>
@@ -194,16 +182,7 @@ onMounted(fetchServers)
<p>Add an SMTP server to start sending emails.</p>
</div>
- <div v-if="pageable && !pageable.empty" class="pagination">
- <span class="pagination-info">
- Page {{ pageable.current_page + 1 }} of {{ pageable.total_pages }}
- ({{ pageable.total_elements }} total)
- </span>
- <div class="pagination-buttons">
- <button class="btn btn-secondary btn-sm" :disabled="currentPage === 0" @click="prevPage">Previous</button>
- <button class="btn btn-secondary btn-sm" :disabled="currentPage >= pageable.total_pages - 1" @click="nextPage">Next</button>
- </div>
- </div>
+ <Pagination :pageable="pageable" @page="goToPage" />
</div>
</template>
diff --git a/web/src/views/stylesheets/Stylesheets.vue b/web/src/views/stylesheets/Stylesheets.vue
index 77cb4c7..b1f89f4 100644
--- a/web/src/views/stylesheets/Stylesheets.vue
+++ b/web/src/views/stylesheets/Stylesheets.vue
@@ -6,20 +6,22 @@ import { useNotificationStore } from '../../stores/notification'
import { useConfirm } from '../../composables/useConfirm'
import { useModalSafeClose } from '../../composables/useModalSafeClose';
import { useWorkspaceStore } from '../../stores/workspace'
+import { usePagination } from '@/composables/usePagination'
+import Pagination from '@/components/Pagination.vue'
+
const notify = useNotificationStore()
const wsStore = useWorkspaceStore()
const { confirm } = useConfirm()
const stylesheets = ref<StyleSheet[]>([])
-const pageable = ref<Pageable>({ current_page: 0, size: 20, total_pages: 0, total_elements: 0, empty: true })
-const loading = ref(true)
+ const loading = ref(true)
const showModal = ref(false)
const editing = ref<StyleSheet | null>(null)
-const saving = ref(false)
+ const saving = ref(false)
-const form = ref<StyleSheetInput>({
+ const form = ref<StyleSheetInput>({
name: '',
css: '',
})
@@ -47,19 +49,19 @@ function closeModal() {
showModal.value = false
resetForm()
}
-
-async function loadStylesheets(page = 0) {
+const { pageable, goToPage } = usePagination(async (page) => {
loading.value = true
try {
const res = await stylesheetsApi.list(page, pageable.value.size)
stylesheets.value = res.data.data
pageable.value = res.data.pageable
- } catch {
- notify.error('Failed to load stylesheets')
+ } catch (e) {
+ console.error('Failed to load stylesheets', e)
} finally {
loading.value = false
}
-}
+})
+
async function saveStylesheet() {
if (!form.value.name.trim()) return
@@ -73,7 +75,7 @@ async function saveStylesheet() {
notify.success('Stylesheet created')
}
closeModal()
- await loadStylesheets(pageable.value.current_page)
+ await goToPage(pageable.value.current_page)
} catch {
notify.error(editing.value ? 'Failed to update stylesheet' : 'Failed to create stylesheet')
} finally {
@@ -92,7 +94,7 @@ async function deleteStylesheet(sheet: StyleSheet) {
try {
await stylesheetsApi.delete(sheet.id)
notify.success('Stylesheet deleted')
- await loadStylesheets(pageable.value.current_page)
+ await goToPage(pageable.value.current_page)
} catch {
notify.error('Failed to delete stylesheet')
}
@@ -104,7 +106,6 @@ function formatDate(dateStr: string): string {
const { watchClickStart, confirmClickEnd } = useModalSafeClose(() => {
closeModal()
});
-onMounted(() => loadStylesheets())
</script>
<template>
@@ -154,27 +155,8 @@ onMounted(() => loadStylesheets())
</table>
</div>
- <div class="pagination">
- <span class="pagination-info">
- Page {{ pageable.current_page + 1 }} of {{ pageable.total_pages }} ({{ pageable.total_elements }} stylesheets)
- </span>
- <div class="pagination-buttons">
- <button
- class="btn btn-secondary btn-sm"
- :disabled="pageable.current_page === 0"
- @click="loadStylesheets(pageable.current_page - 1)"
- >
- Previous
- </button>
- <button
- class="btn btn-secondary btn-sm"
- :disabled="pageable.current_page >= pageable.total_pages - 1"
- @click="loadStylesheets(pageable.current_page + 1)"
- >
- Next
- </button>
- </div>
- </div>
+<Pagination :pageable="pageable" @page="goToPage" />
+
</template>
</div>
diff --git a/web/src/views/subscriber-lists/SubscriberLists.vue b/web/src/views/subscriber-lists/SubscriberLists.vue
index 48f3ed1..04a948b 100644
--- a/web/src/views/subscriber-lists/SubscriberLists.vue
+++ b/web/src/views/subscriber-lists/SubscriberLists.vue
@@ -7,6 +7,8 @@ import { useNotificationStore } from '../../stores/notification'
import { useConfirm } from '../../composables/useConfirm'
import { useModalSafeClose } from '../../composables/useModalSafeClose'
import { useWorkspaceStore } from '../../stores/workspace'
+import { usePagination } from '@/composables/usePagination'
+import Pagination from '@/components/Pagination.vue'
const router = useRouter()
const notify = useNotificationStore()
@@ -14,7 +16,6 @@ const wsStore = useWorkspaceStore()
const { confirm } = useConfirm()
const lists = ref<SubscriberListItem[]>([])
-const pageable = ref<Pageable>({ current_page: 0, size: 20, total_pages: 0, total_elements: 0, empty: true })
const loading = ref(true)
// Create modal
@@ -36,18 +37,18 @@ const operatorOptions = [
{ value: 'in', label: 'in' },
]
-async function loadLists(page = 0) {
+const { pageable, goToPage } = usePagination(async (page) => {
loading.value = true
try {
const res = await subscriberListsApi.list(page, pageable.value.size)
lists.value = res.data.data ?? []
pageable.value = res.data.pageable
- } catch {
- notify.error('Failed to load subscriber lists')
+ } catch (e) {
+ console.error('Failed to load suscriber lists', e)
} finally {
loading.value = false
}
-}
+})
function openCreate() {
formName.value = ''
@@ -77,7 +78,7 @@ async function saveList() {
})
notify.success('Subscriber list created')
showModal.value = false
- await loadLists(pageable.value.current_page)
+ await goToPage(pageable.value.current_page)
} catch (e: any) {
notify.error(e?.response?.data?.error?.message || 'Failed to create subscriber list')
} finally {
@@ -96,7 +97,7 @@ async function deleteList(list: SubscriberListItem) {
try {
await subscriberListsApi.delete(list.id)
notify.success('Subscriber list deleted')
- await loadLists(pageable.value.current_page)
+ await goToPage(pageable.value.current_page)
} catch {
notify.error('Failed to delete subscriber list')
}
@@ -114,7 +115,6 @@ const { watchClickStart, confirmClickEnd } = useModalSafeClose(() => {
showModal.value = false
})
-onMounted(() => loadLists())
</script>
<template>
@@ -165,15 +165,8 @@ onMounted(() => loadLists())
</table>
</div>
- <div class="pagination">
- <span class="pagination-info">
- Page {{ pageable.current_page + 1 }} of {{ pageable.total_pages }} ({{ pageable.total_elements }} segments)
- </span>
- <div class="pagination-buttons">
- <button class="btn btn-secondary btn-sm" :disabled="pageable.current_page === 0" @click="loadLists(pageable.current_page - 1)">Previous</button>
- <button class="btn btn-secondary btn-sm" :disabled="pageable.current_page >= pageable.total_pages - 1" @click="loadLists(pageable.current_page + 1)">Next</button>
- </div>
- </div>
+ <Pagination :pageable="pageable" @page="goToPage" />
+
</template>
</div>
diff --git a/web/src/views/subscribers/Subscribers.vue b/web/src/views/subscribers/Subscribers.vue
index ceb72f4..a007e91 100644
--- a/web/src/views/subscribers/Subscribers.vue
+++ b/web/src/views/subscribers/Subscribers.vue
@@ -33,20 +33,21 @@ const importing = ref(false)
const csvFileInput = ref<HTMLInputElement | null>(null)
const importingCsv = ref(false)
-const { pageable, goToPage } = usePagination(loadSubscribers)
-async function loadSubscribers(page = 0) {
+
+const { pageable, goToPage } = usePagination(async (page) => {
loading.value = true
try {
const res = await subscribersApi.list(page, pageable.value.size, search.value, statusFilter.value || undefined)
subscribers.value = res.data.data ?? []
pageable.value = res.data.pageable
- } catch {
- notify.error('Failed to load subscribers')
+ } catch (e) {
+ console.error('Failed to load subscribers', e)
} finally {
loading.value = false
}
-}
+})
+
function onSearchInput() {
if (searchTimeout) clearTimeout(searchTimeout)
@@ -77,7 +78,7 @@ async function createSubscriber() {
})
notify.success('Subscriber created')
showCreateModal.value = false
- await loadSubscribers(pageable.value.current_page)
+ await goToPage(pageable.value.current_page)
} catch (e: any) {
if (e instanceof SyntaxError) {
notify.error('Invalid JSON in custom fields')
@@ -104,7 +105,7 @@ async function importJson() {
const result = res.data.data
notify.success(`Import complete: ${result.created} created, ${result.skipped} skipped out of ${result.total}`)
showImportJsonModal.value = false
- await loadSubscribers(pageable.value.current_page)
+ await goToPage(pageable.value.current_page)
} catch (e: any) {
if (e instanceof SyntaxError) {
notify.error('Invalid JSON format')
@@ -129,7 +130,7 @@ async function onCsvFileSelected(event: Event) {
const res = await subscribersApi.bulkImportCSV(file)
const result = res.data.data
notify.success(`CSV import complete: ${result.created} created, ${result.skipped} skipped out of ${result.total}`)
- await loadSubscribers(pageable.value.current_page)
+ await goToPage(pageable.value.current_page)
} catch (e: any) {
notify.error(e?.response?.data?.error?.message || 'Failed to import CSV')
} finally {
diff --git a/web/src/views/templates/Templates.vue b/web/src/views/templates/Templates.vue
index 3788dc4..84736c0 100644
--- a/web/src/views/templates/Templates.vue
+++ b/web/src/views/templates/Templates.vue
@@ -14,6 +14,10 @@ import { useNotificationStore } from "../../stores/notification";
import { useConfirm } from "../../composables/useConfirm";
import { useModalSafeClose } from "../../composables/useModalSafeClose";
import { useWorkspaceStore } from "../../stores/workspace";
+import { usePagination } from '@/composables/usePagination'
+import Pagination from '@/components/Pagination.vue'
+
+
const router = useRouter();
const notify = useNotificationStore();
@@ -21,19 +25,12 @@ const wsStore = useWorkspaceStore();
const { confirm } = useConfirm();
const templates = ref<Template[]>([]);
-const pageable = ref<Pageable>({
- current_page: 0,
- size: 20,
- total_pages: 0,
- total_elements: 0,
- empty: true,
-});
const loading = ref(true);
const search = ref("");
let searchTimeout: ReturnType<typeof setTimeout> | null = null;
-
-const showModal = ref(false);
-const editing = ref<Template | null>(null);
+
+ const showModal = ref(false);
+ const editing = ref<Template | null>(null);
const saving = ref(false);
const languages = ref<Language[]>([]);
@@ -80,22 +77,21 @@ function closeModal() {
resetForm();
}
-async function loadTemplates(page = 0) {
- loading.value = true;
+const { pageable, goToPage } = usePagination(async (page) => {
+ loading.value = true
try {
const res = await templatesApi.list(page, pageable.value.size, search.value);
templates.value = res.data.data;
pageable.value = res.data.pageable;
- } catch {
- notify.error("Failed to load templates");
+ } catch (e) {
+ console.error('Failed to load templates', e)
} finally {
- loading.value = false;
+ loading.value = false
}
-}
-
+})
function onSearchInput() {
if (searchTimeout) clearTimeout(searchTimeout);
- searchTimeout = setTimeout(() => loadTemplates(0), 300);
+ searchTimeout = setTimeout(() => goToPage(0), 300);
}
async function saveTemplate() {
@@ -110,7 +106,7 @@ async function saveTemplate() {
notify.success("Template created");
}
closeModal();
- await loadTemplates(pageable.value.current_page);
+ await goToPage(pageable.value.current_page);
} catch {
notify.error(
editing.value ? "Failed to update template" : "Failed to create template"
@@ -131,7 +127,7 @@ async function deleteTemplate(template: Template) {
try {
await templatesApi.delete(template.id);
notify.success("Template deleted");
- await loadTemplates(pageable.value.current_page);
+ await goToPage(pageable.value.current_page);
} catch {
notify.error("Failed to delete template");
}
@@ -155,7 +151,7 @@ async function exportTemplate(template: Template) {
}
const importInput = ref<HTMLInputElement | null>(null);
-const importing = ref(false);
+ const importing = ref(false);
function triggerImport() {
importInput.value?.click();
@@ -165,7 +161,7 @@ async function handleImportFile(event: Event) {
const input = event.target as HTMLInputElement;
const file = input.files?.[0];
if (!file) return;
-
+
importing.value = true;
try {
const name = file.name.toLowerCase();
@@ -178,7 +174,7 @@ async function handleImportFile(event: Event) {
await templatesApi.importTemplate(data);
notify.success("Template imported");
}
- await loadTemplates(pageable.value.current_page);
+ await goToPage(pageable.value.current_page);
} catch (e: any) {
const msg =
e?.response?.data?.message ||
@@ -202,7 +198,6 @@ const { watchClickStart, confirmClickEnd } = useModalSafeClose(() => {
});
onMounted(() => {
- loadTemplates();
loadLanguages();
});
</script>
@@ -351,30 +346,8 @@ onMounted(() => {
</table>
</div>
- <div class="pagination">
- <span class="pagination-info">
- Page {{ pageable.current_page + 1 }} of {{ pageable.total_pages }} ({{
- pageable.total_elements
- }}
- templates)
- </span>
- <div class="pagination-buttons">
- <button
- class="btn btn-secondary btn-sm"
- :disabled="pageable.current_page === 0"
- @click="loadTemplates(pageable.current_page - 1)"
- >
- Previous
- </button>
- <button
- class="btn btn-secondary btn-sm"
- :disabled="pageable.current_page >= pageable.total_pages - 1"
- @click="loadTemplates(pageable.current_page + 1)"
- >
- Next
- </button>
- </div>
- </div>
+<Pagination :pageable="pageable" @page="goToPage" />
+
</template>
</div>
</div>
diff --git a/web/src/views/webhooks/Webhooks.vue b/web/src/views/webhooks/Webhooks.vue
index d225acd..d86b56b 100644
--- a/web/src/views/webhooks/Webhooks.vue
+++ b/web/src/views/webhooks/Webhooks.vue
@@ -16,8 +16,6 @@ const { confirm } = useConfirm()
const webhooks = ref<Webhook[]>([])
const loading = ref(true)
-const { pageable, goToPage } = usePagination(fetchWebhooks)
-
const showModal = ref(false)
const form = ref<WebhookInput>({
url: '',
@@ -33,18 +31,18 @@ const copied = ref(false)
const availableEvents = ['email.sent', 'email.failed', 'email.inbound']
-async function fetchWebhooks(page = 0) {
+const { pageable, goToPage } = usePagination(async (page) => {
loading.value = true
try {
const res = await webhooksApi.list(page)
webhooks.value = res.data.data
pageable.value = res.data.pageable
- } catch {
- notify.error('Failed to load webhooks')
+ } catch (e) {
+ console.error('Failed to load webhooks', e)
} finally {
loading.value = false
}
-}
+})
function openCreate() {
form.value = { url: '', events: [], filters: [] }
@@ -82,7 +80,7 @@ async function createWebhook() {
showModal.value = false
showSecretModal.value = true
notify.success('Webhook created')
- await fetchWebhooks()
+ await goToPage(pageable.value.current_page)
} catch {
notify.error('Failed to create webhook')
} finally {
@@ -114,7 +112,7 @@ async function deleteWebhook(webhook: Webhook) {
try {
await webhooksApi.delete(webhook.id)
notify.success('Webhook deleted')
- await fetchWebhooks()
+ await goToPage(pageable.value.current_page)
} catch {
notify.error('Failed to delete webhook')
}