feat(web): continue Ant settings migration and tighten page chrome

Migrate remaining settings screens to Ant Design Vue, densify teams/roles UI, drop page-header subtitles project-wide, and polish notes cards plus contacts row actions.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-04 10:05:28 +03:30
co-authored by Cursor
parent b11affbdfd
commit cb3a488b21
46 changed files with 6024 additions and 7679 deletions
+287 -281
View File
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { computed, onMounted, ref } from 'vue';
import TableColumnsMenu from '@/components/TableColumnsMenu.vue';
import axios from 'axios';
import { api } from '@/lib/api';
@@ -12,16 +12,42 @@ import type {
WebhookEvent,
} from '@mento/shared';
import { WEBHOOK_EVENTS } from '@mento/shared';
import {
UiButton,
UiCard,
UiEmptyState,
UiField,
UiInput,
UiPageHeader,
} from '@/components/ui';
import UiIcon from '@/components/UiIcon.vue';
import { formatJalaliNumeric, toFaDigits } from '@/lib/jalali';
import { registerTableColumns, useTableColumns } from '@/lib/tableColumns';
import {
Alert as AAlert,
Button as AButton,
Card as ACard,
Col as ACol,
Divider as ADivider,
Empty as AEmpty,
Flex as AFlex,
Form as AForm,
FormItem as AFormItem,
Input as AInput,
List as AList,
ListItem as AListItem,
ListItemMeta as AListItemMeta,
Row as ARow,
Space as ASpace,
Spin as ASpin,
Table as ATable,
Tag as ATag,
Typography,
} from 'ant-design-vue';
import type { TableColumnsType } from 'ant-design-vue';
import { CopyOutlined, PlusOutlined, ReloadOutlined } from '@ant-design/icons-vue';
const { Title: ATypographyTitle, Text: ATypographyText, Paragraph: ATypographyParagraph } = Typography;
const ACheckableTag = ATag.CheckableTag;
const KEY_COL_LABELS = ['نام', 'پیشوند', 'آخرین استفاده', 'وضعیت'] as const;
const DELIVERY_COL_LABELS = ['زمان', 'رویداد', 'وضعیت', 'کد', 'تلاش'] as const;
registerTableColumns('public-api.keys', [...KEY_COL_LABELS]);
registerTableColumns('public-api.deliveries', [...DELIVERY_COL_LABELS]);
const keyTableCols = useTableColumns(() => 'public-api.keys');
const deliveryTableCols = useTableColumns(() => 'public-api.deliveries');
const loading = ref(false);
const saving = ref(false);
@@ -50,6 +76,37 @@ const EVENT_LABELS: Record<WebhookEvent, string> = {
'activity.created': 'ایجاد فعالیت',
};
const keyColumns = computed<TableColumnsType<OrganizationApiKeyDto>>(() => {
const all: TableColumnsType<OrganizationApiKeyDto> = [
{ title: 'نام', key: 'نام', dataIndex: 'name' },
{ title: 'پیشوند', key: 'پیشوند' },
{ title: 'آخرین استفاده', key: 'آخرین استفاده' },
{ title: 'وضعیت', key: 'وضعیت', width: 100 },
{ title: '', key: 'عملیات', width: 120 },
];
return all.filter((col) => {
const key = String(col.key ?? '');
if (key === 'عملیات') return true;
if (!KEY_COL_LABELS.includes(key as (typeof KEY_COL_LABELS)[number])) return true;
return keyTableCols.isVisible(key);
});
});
const deliveryColumns = computed<TableColumnsType<WebhookDeliveryDto>>(() => {
const all: TableColumnsType<WebhookDeliveryDto> = [
{ title: 'زمان', key: 'زمان' },
{ title: 'رویداد', key: 'رویداد' },
{ title: 'وضعیت', key: 'وضعیت' },
{ title: 'کد', key: 'کد', width: 80 },
{ title: 'تلاش', key: 'تلاش', width: 80 },
];
return all.filter((col) => {
const key = String(col.key ?? '');
if (!DELIVERY_COL_LABELS.includes(key as (typeof DELIVERY_COL_LABELS)[number])) return true;
return deliveryTableCols.isVisible(key);
});
});
async function load() {
loading.value = true;
error.value = '';
@@ -161,292 +218,241 @@ async function copyText(text: string) {
}
}
function endpointEventsLabel(ep: WebhookEndpointDto) {
return ep.events.map((e) => EVENT_LABELS[e as WebhookEvent] ?? e).join('، ');
}
onMounted(() => {
void load();
});
</script>
<template>
<div class="page">
<UiPageHeader
title="API و وب‌هوک"
description="کلید عمومی برای یکپارچه‌سازی و ارسال رویداد به سرور شما"
>
<template #actions>
<UiButton variant="secondary" :disabled="loading" @click="load">
<UiIcon name="refresh" />
بروزرسانی
</UiButton>
</template>
</UiPageHeader>
<a-flex vertical :gap="16">
<a-flex justify="space-between" align="flex-start" wrap="wrap" :gap="12">
<a-typography-title :level="3" :style="{ margin: 0 }">API و وب‌هوک</a-typography-title>
<a-button :disabled="loading" @click="load">
<template #icon><ReloadOutlined /></template>
بروزرسانی
</a-button>
</a-flex>
<p v-if="error" class="error">{{ error }}</p>
<p v-if="ok" class="ok">{{ ok }}</p>
<a-alert v-if="error" type="error" show-icon :message="error" closable @close="error = ''" />
<a-alert v-if="ok" type="success" show-icon :message="ok" closable @close="ok = ''" />
<UiCard title="کلیدهای API">
<p class="hint">
هدر درخواست:
<code>X-Api-Key: mk_…</code>
یا
<code>Authorization: Bearer mk_…</code>
— مسیرها:
<code>/api/public/v1/people</code>
و
<code>/api/public/v1/deals</code>
</p>
<div class="row">
<UiField label="نام کلید">
<UiInput v-model="newKeyName" placeholder="مثلاً اتصال سایت" />
</UiField>
<UiButton :loading="saving" @click="createKey">ساخت کلید</UiButton>
</div>
<div v-if="createdRawKey" class="raw-key">
<code>{{ createdRawKey }}</code>
<UiButton variant="secondary" @click="copyText(createdRawKey)">کپی</UiButton>
</div>
<UiEmptyState
v-if="!loading && !keys.length"
title="کلیدی نیست"
description="برای دسترسی خارجی یک کلید بسازید."
/>
<div v-else class="table-wrap">
<div class="tc-row">
<TableColumnsMenu table-key="public-api.keys" align="end" />
</div>
<table v-table-cols="'public-api.keys'">
<thead>
<tr>
<th>نام</th>
<th>پیشوند</th>
<th>آخرین استفاده</th>
<th>وضعیت</th>
<th></th>
</tr>
</thead>
<tbody>
<tr v-for="k in keys" :key="k.id">
<td>{{ k.name }}</td>
<td><code>{{ k.prefix }}…</code></td>
<td>
<a-spin :spinning="loading">
<a-card :bordered="false">
<a-divider orientation="right">کلیدهای API</a-divider>
<a-typography-paragraph type="secondary">
هدر درخواست:
<code>X-Api-Key: mk_…</code>
یا
<code>Authorization: Bearer mk_…</code>
— مسیرها:
<code>/api/public/v1/people</code>
و
<code>/api/public/v1/deals</code>
</a-typography-paragraph>
<a-form layout="vertical" @finish="createKey">
<a-row :gutter="[16, 0]">
<a-col :xs="24" :md="12">
<a-form-item label="نام کلید" required>
<a-input v-model:value="newKeyName" placeholder="مثلاً اتصال سایت" />
</a-form-item>
</a-col>
<a-col :xs="24" :md="8">
<a-form-item label=" ">
<a-button type="primary" html-type="submit" :loading="saving">
<template #icon><PlusOutlined /></template>
ساخت کلید
</a-button>
</a-form-item>
</a-col>
</a-row>
</a-form>
<a-alert
v-if="createdRawKey"
type="success"
show-icon
:message="createdRawKey"
:style="{ marginBottom: '12px' }"
>
<template #action>
<a-button @click="copyText(createdRawKey)">
<template #icon><CopyOutlined /></template>
کپی
</a-button>
</template>
</a-alert>
<a-empty
v-if="!loading && !keys.length"
description="کلیدی نیست. برای دسترسی خارجی یک کلید بسازید."
/>
<template v-else-if="keys.length">
<a-flex justify="flex-end" :style="{ marginBottom: '12px' }">
<TableColumnsMenu table-key="public-api.keys" align="end" />
</a-flex>
<a-table
:columns="keyColumns"
:data-source="keys"
:pagination="false"
row-key="id"
:scroll="{ x: 640 }"
>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'نام'">
{{ (record as OrganizationApiKeyDto).name }}
</template>
<template v-else-if="column.key === 'پیشوند'">
<code>{{ (record as OrganizationApiKeyDto).prefix }}…</code>
</template>
<template v-else-if="column.key === 'آخرین استفاده'">
{{
k.lastUsedAt
? formatJalaliNumeric(new Date(k.lastUsedAt))
(record as OrganizationApiKeyDto).lastUsedAt
? formatJalaliNumeric(new Date((record as OrganizationApiKeyDto).lastUsedAt!))
: '—'
}}
</td>
<td>{{ k.revokedAt ? 'باطل' : 'فعال' }}</td>
<td>
<UiButton
v-if="!k.revokedAt"
variant="secondary"
@click="revokeKey(k.id)"
</template>
<template v-else-if="column.key === 'وضعیت'">
<a-tag
:color="(record as OrganizationApiKeyDto).revokedAt ? 'default' : 'success'"
:bordered="false"
>
{{ (record as OrganizationApiKeyDto).revokedAt ? 'باطل' : 'فعال' }}
</a-tag>
</template>
<template v-else-if="column.key === 'عملیات'">
<a-button
v-if="!(record as OrganizationApiKeyDto).revokedAt"
danger
@click="revokeKey((record as OrganizationApiKeyDto).id)"
>
باطل‌سازی
</UiButton>
</td>
</tr>
</tbody>
</table>
</div>
</UiCard>
</a-button>
</template>
</template>
</a-table>
</template>
<UiCard title="وب‌هوک‌های خروجی">
<div class="form-grid">
<UiField label="نام">
<UiInput v-model="whName" placeholder="مثلاً n8n" />
</UiField>
<UiField label="آدرس URL">
<UiInput v-model="whUrl" placeholder="https://example.com/hook" />
</UiField>
</div>
<div class="events">
<button
v-for="ev in WEBHOOK_EVENTS"
:key="ev"
type="button"
class="chip"
:class="{ on: whEvents.includes(ev) }"
@click="toggleEvent(ev)"
<a-divider orientation="right">وب‌هوک‌های خروجی</a-divider>
<a-form layout="vertical" @finish="createWebhook">
<a-row :gutter="[16, 0]">
<a-col :xs="24" :md="8">
<a-form-item label="نام" required>
<a-input v-model:value="whName" placeholder="مثلاً n8n" />
</a-form-item>
</a-col>
<a-col :xs="24" :md="12">
<a-form-item label="آدرس URL" required>
<a-input
v-model:value="whUrl"
placeholder="https://example.com/hook"
dir="ltr"
style="width: 100%"
/>
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item label="رویدادها" required>
<a-space wrap>
<a-checkable-tag
v-for="ev in WEBHOOK_EVENTS"
:key="ev"
:checked="whEvents.includes(ev)"
@change="() => toggleEvent(ev)"
>
{{ EVENT_LABELS[ev] }}
</a-checkable-tag>
</a-space>
</a-form-item>
</a-col>
<a-col :span="24">
<a-button type="primary" html-type="submit" :loading="saving">
<template #icon><PlusOutlined /></template>
افزودن وب‌هوک
</a-button>
</a-col>
</a-row>
</a-form>
<a-alert
v-if="createdWebhookSecret"
type="success"
show-icon
:message="`HMAC secret: ${createdWebhookSecret}`"
:style="{ marginTop: '12px', marginBottom: '12px' }"
>
{{ EVENT_LABELS[ev] }}
</button>
</div>
<UiButton :loading="saving" @click="createWebhook">افزودن وب‌هوک</UiButton>
<div v-if="createdWebhookSecret" class="raw-key">
<span>HMAC secret:</span>
<code>{{ createdWebhookSecret }}</code>
<UiButton variant="secondary" @click="copyText(createdWebhookSecret)">کپی</UiButton>
</div>
<template #action>
<a-button @click="copyText(createdWebhookSecret)">
<template #icon><CopyOutlined /></template>
کپی
</a-button>
</template>
</a-alert>
<UiEmptyState
v-if="!loading && !endpoints.length"
title="وب‌هوکی نیست"
description="رویدادهای CRM به آدرس شما POST می‌شوند."
/>
<div v-else class="list">
<article v-for="ep in endpoints" :key="ep.id" class="item">
<div>
<strong>{{ ep.name }}</strong>
<p class="muted">{{ ep.url }}</p>
<p class="muted">
{{ ep.events.map((e) => EVENT_LABELS[e as WebhookEvent] ?? e).join('، ') }}
</p>
</div>
<UiButton variant="secondary" @click="removeWebhook(ep.id)">حذف</UiButton>
</article>
</div>
</UiCard>
<a-empty
v-if="!loading && !endpoints.length"
description="وب‌هوکی نیست. رویدادهای CRM به آدرس شما POST می‌شوند."
/>
<a-list v-else-if="endpoints.length" item-layout="horizontal" :data-source="endpoints">
<template #renderItem="{ item }">
<a-list-item>
<template #actions>
<a-button danger @click="removeWebhook(item.id)">حذف</a-button>
</template>
<a-list-item-meta
:description="`${item.url} · ${endpointEventsLabel(item)}`"
>
<template #title>
<a-typography-text strong>{{ item.name }}</a-typography-text>
</template>
</a-list-item-meta>
</a-list-item>
</template>
</a-list>
<UiCard title="آخرین ارسال‌های وب‌هوک">
<UiEmptyState
v-if="!deliveries.length"
title="ارسالی ثبت نشده"
description="پس از وقوع رویدادها اینجا دیده می‌شوند."
/>
<div v-else class="table-wrap">
<div class="tc-row">
<TableColumnsMenu table-key="public-api.deliveries" align="end" />
</div>
<table v-table-cols="'public-api.deliveries'">
<thead>
<tr>
<th>زمان</th>
<th>رویداد</th>
<th>وضعیت</th>
<th>کد</th>
<th>تلاش</th>
</tr>
</thead>
<tbody>
<tr v-for="d in deliveries" :key="d.id">
<td>{{ formatJalaliNumeric(new Date(d.createdAt)) }}</td>
<td>{{ EVENT_LABELS[d.event as WebhookEvent] ?? d.event }}</td>
<td>{{ d.status }}</td>
<td>{{ d.statusCode ?? '—' }}</td>
<td>{{ toFaDigits(d.attempts) }}</td>
</tr>
</tbody>
</table>
</div>
</UiCard>
</div>
<a-divider orientation="right">آخرین ارسال‌های وب‌هوک</a-divider>
<a-empty
v-if="!deliveries.length"
description="ارسالی ثبت نشده. پس از وقوع رویدادها اینجا دیده می‌شوند."
/>
<template v-else>
<a-flex justify="flex-end" :style="{ marginBottom: '12px' }">
<TableColumnsMenu table-key="public-api.deliveries" align="end" />
</a-flex>
<a-table
:columns="deliveryColumns"
:data-source="deliveries"
:pagination="false"
row-key="id"
:scroll="{ x: 640 }"
>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'زمان'">
{{ formatJalaliNumeric(new Date((record as WebhookDeliveryDto).createdAt)) }}
</template>
<template v-else-if="column.key === 'رویداد'">
{{
EVENT_LABELS[(record as WebhookDeliveryDto).event as WebhookEvent] ??
(record as WebhookDeliveryDto).event
}}
</template>
<template v-else-if="column.key === 'وضعیت'">
{{ (record as WebhookDeliveryDto).status }}
</template>
<template v-else-if="column.key === 'کد'">
{{ (record as WebhookDeliveryDto).statusCode ?? '—' }}
</template>
<template v-else-if="column.key === 'تلاش'">
{{ toFaDigits((record as WebhookDeliveryDto).attempts) }}
</template>
</template>
</a-table>
</template>
</a-card>
</a-spin>
</a-flex>
</template>
<style scoped>
.page {
display: grid;
grid-template-columns: minmax(0, 1fr);
gap: 1rem;
}
.hint {
color: #64748b;
font-size: 0.88rem;
line-height: 1.7;
}
.hint code {
background: #f1f5f9;
padding: 0.1rem 0.35rem;
border-radius: 6px;
font-size: 0.8rem;
}
.row {
display: grid;
grid-template-columns: 1fr auto;
gap: 0.75rem;
align-items: end;
margin: 0.75rem 0;
}
.raw-key {
display: flex;
gap: 0.75rem;
align-items: center;
flex-wrap: wrap;
padding: 0.75rem;
background: #f0fdfa;
border-radius: var(--radius);
margin-bottom: 0.75rem;
}
.raw-key code {
word-break: break-all;
font-weight: 700;
color: #0f766e;
}
.form-grid {
display: grid;
grid-template-columns: 1fr 1.4fr;
gap: 0.75rem;
margin-bottom: 0.75rem;
}
.events {
display: flex;
flex-wrap: wrap;
gap: 0.45rem;
margin-bottom: 0.85rem;
}
.chip {
border: 1px solid #e2e8f0;
background: #fff;
border-radius: 999px;
padding: 0.35rem 0.75rem;
font: inherit;
cursor: pointer;
color: #334155;
}
.chip.on {
background: #f0fdfa;
border-color: #99f6e4;
color: #0f766e;
font-weight: 700;
}
.list {
display: grid;
gap: 0.65rem;
margin-top: 1rem;
}
.item {
display: flex;
justify-content: space-between;
gap: 0.75rem;
padding: 0.75rem;
border: 1px solid #eef2f7;
border-radius: var(--radius);
}
.muted {
color: #64748b;
margin: 0.2rem 0 0;
font-size: 0.85rem;
}
.error {
color: #b91c1c;
font-weight: 600;
}
.ok {
color: #0f766e;
font-weight: 600;
}
.table-wrap {
overflow: auto;
margin-top: 0.75rem;
}
table {
width: 100%;
border-collapse: collapse;
font-size: 0.9rem;
}
th,
td {
text-align: right;
padding: 0.55rem;
border-bottom: 1px solid #eef2f7;
}
th {
color: #64748b;
font-size: 0.8rem;
}
@media (max-width: 800px) {
.row,
.form-grid {
grid-template-columns: 1fr;
}
}
</style>