feat(automations): add test run button and send log modal in admin

Expose run-now and sends APIs in the automations UI, show SMS hour and last run columns, and group advanced settings toolbar actions together.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-24 21:46:13 +03:30
co-authored by Cursor
parent 71bf8dfc47
commit 3838d0a56c
6 changed files with 149 additions and 32 deletions
+73 -1
View File
@@ -7,6 +7,8 @@
@edit="openEdit"
@toggle="toggleActive"
@delete="deleteItem"
@run-now="runNow"
@sends="openSends"
/>
<BasicActionSheet
@@ -27,19 +29,51 @@
<div v-if="isMobile" class="mb-3 text-base font-bold">{{ sheetTitle }}</div>
<AutomationEditorFormBody ref="editorRef" :form="form" />
</BasicActionSheet>
<BasicModal
v-model:visible="sendsVisible"
:title="sendsTitle"
:show-footer="false"
width="48rem"
>
<a-spin :spinning="sendsLoading">
<div v-if="!sendsLoading && sendsRows.length === 0" class="py-6 text-center text-gray-500">
هنوز ارسالی ثبت نشده
</div>
<div v-else class="flex flex-col gap-2">
<div
v-for="row in sendsRows"
:key="row.id"
class="rounded-lg border border-gray-100 px-3 py-2 text-sm dark:border-slate-700"
>
<div class="flex items-center justify-between gap-2">
<span>{{ row.customer_name || '—' }} · {{ row.customer_mobile || '—' }}</span>
<span :class="row.status === 'sent' ? 'text-green-600' : 'text-red-600'">
{{ row.status === 'sent' ? 'موفق' : 'ناموفق' }}
</span>
</div>
<div class="text-xs text-gray-500">{{ row.created_at }}</div>
<div v-if="row.error" class="mt-1 text-xs text-red-600">{{ row.error }}</div>
</div>
</div>
</a-spin>
</BasicModal>
</div>
</template>
<script setup lang="ts">
import { computed, ref } from 'vue'
import { message } from 'ant-design-vue'
import { Modal, message } from 'ant-design-vue'
import { cloneDeep } from 'lodash'
import tbl from './components/table.vue'
import AutomationEditorFormBody from './components/AutomationEditorFormBody.vue'
import BasicModal from '@/components/BasicModal.vue'
import { emptyAutomation, type Automation } from '@/model/automations'
import {
createAutomation,
deleteAutomation,
getAutomationSendsTable,
runAutomationNow,
toggleAutomationActive,
updateAutomation,
} from '@/api/automations'
@@ -56,6 +90,10 @@ const loading = ref(false)
const editorVisible = ref(false)
const editId = ref<number | undefined>()
const form = ref<Automation>(emptyAutomation())
const sendsVisible = ref(false)
const sendsLoading = ref(false)
const sendsTitle = ref('لاگ ارسال')
const sendsRows = ref<Array<Record<string, unknown>>>([])
const sheetTitle = computed(() => (editId.value ? 'ویرایش اتوماسیون' : 'افزودن اتوماسیون'))
@@ -129,4 +167,38 @@ async function toggleActive(record: Automation) {
function deleteItem(id: number) {
confirmDeleteItem('اتوماسیون', id, deleteAutomation, refreshTable)
}
function runNow(record: Automation) {
if (!record.id) return
Modal.confirm({
title: 'اجرای آزمایشی',
content: `پیام «${record.name}» همین الان برای مخاطبان واجد شرط ارسال شود؟ (بدون انتظار ساعت ${record.sms_send_hour ?? '—'})`,
okText: 'ارسال',
cancelText: 'انصراف',
async onOk() {
const res = await runAutomationNow(record.id!)
message.success(res?.message || 'اجرای آزمایشی انجام شد')
refreshTable()
},
})
}
async function openSends(record: Automation) {
if (!record.id) return
sendsTitle.value = `لاگ ارسال — ${record.name}`
sendsVisible.value = true
sendsLoading.value = true
try {
const res = await getAutomationSendsTable(record.id, { page: 1, limit: 30, select: [] })
const rows = (res as { rows?: Array<Record<string, unknown>> })?.rows
?? (Array.isArray(res) ? res : [])
sendsRows.value = rows
} catch (e) {
console.error(e)
message.error('بارگذاری لاگ ناموفق بود')
sendsRows.value = []
} finally {
sendsLoading.value = false
}
}
</script>