Initial Mento CRM: portal OTP, reports, SMS, and deploy for crm.montzar.ir.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,326 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
import axios from 'axios';
|
||||
import { api } from '@/lib/api';
|
||||
import type {
|
||||
CreateCustomFieldRequest,
|
||||
CustomFieldDefinitionDto,
|
||||
CustomFieldEntity,
|
||||
CustomFieldType,
|
||||
} from '@mento/shared';
|
||||
|
||||
const loading = ref(false);
|
||||
const saving = ref(false);
|
||||
const error = ref('');
|
||||
const fields = ref<CustomFieldDefinitionDto[]>([]);
|
||||
const filter = ref<'all' | CustomFieldEntity>('all');
|
||||
|
||||
const label = ref('');
|
||||
const entityType = ref<CustomFieldEntity>('person');
|
||||
const fieldType = ref<CustomFieldType>('text');
|
||||
const optionsRaw = ref('');
|
||||
const required = ref(false);
|
||||
|
||||
const entityLabels: Record<CustomFieldEntity, string> = {
|
||||
person: 'شخص',
|
||||
company: 'شرکت',
|
||||
deal: 'معامله',
|
||||
};
|
||||
|
||||
const typeLabels: Record<CustomFieldType, string> = {
|
||||
text: 'متن',
|
||||
number: 'عدد',
|
||||
date: 'تاریخ',
|
||||
boolean: 'بله/خیر',
|
||||
select: 'لیست انتخابی',
|
||||
};
|
||||
|
||||
const visible = computed(() =>
|
||||
filter.value === 'all'
|
||||
? fields.value
|
||||
: fields.value.filter((f) => f.entityType === filter.value),
|
||||
);
|
||||
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
fields.value = (await api.get<CustomFieldDefinitionDto[]>('/custom-fields')).data;
|
||||
} catch (e) {
|
||||
if (axios.isAxiosError(e) && !e.response) {
|
||||
error.value = 'اتصال به API برقرار نشد.';
|
||||
} else {
|
||||
error.value = 'بارگذاری فیلدها ناموفق بود.';
|
||||
}
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function createField() {
|
||||
if (!label.value.trim()) {
|
||||
error.value = 'عنوان فیلد را وارد کنید.';
|
||||
return;
|
||||
}
|
||||
saving.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
const payload: CreateCustomFieldRequest = {
|
||||
entityType: entityType.value,
|
||||
label: label.value.trim(),
|
||||
fieldType: fieldType.value,
|
||||
required: required.value,
|
||||
options:
|
||||
fieldType.value === 'select'
|
||||
? optionsRaw.value
|
||||
.split(/[,،\n]/)
|
||||
.map((o) => o.trim())
|
||||
.filter(Boolean)
|
||||
: undefined,
|
||||
};
|
||||
await api.post('/custom-fields', payload);
|
||||
label.value = '';
|
||||
optionsRaw.value = '';
|
||||
required.value = false;
|
||||
await load();
|
||||
} catch (e) {
|
||||
if (axios.isAxiosError(e)) {
|
||||
const msg = (e.response?.data as { message?: string | string[] })?.message;
|
||||
error.value = Array.isArray(msg)
|
||||
? msg.join('، ')
|
||||
: (msg ?? 'ثبت فیلد ناموفق بود');
|
||||
} else {
|
||||
error.value = 'ثبت فیلد ناموفق بود';
|
||||
}
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function toggleActive(field: CustomFieldDefinitionDto) {
|
||||
await api.patch(`/custom-fields/${field.id}`, { isActive: !field.isActive });
|
||||
await load();
|
||||
}
|
||||
|
||||
async function removeField(field: CustomFieldDefinitionDto) {
|
||||
if (!confirm(`فیلد «${field.label}» حذف شود؟`)) return;
|
||||
await api.delete(`/custom-fields/${field.id}`);
|
||||
await load();
|
||||
}
|
||||
|
||||
onMounted(load);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<section class="page">
|
||||
<header class="page-head">
|
||||
<div>
|
||||
<p class="eyebrow">تنظیمات</p>
|
||||
<h1>فیلدهای سفارشی</h1>
|
||||
<p class="muted">
|
||||
فیلدهای اختصاصی سازمان را برای شخص، شرکت یا معامله تعریف کنید.
|
||||
</p>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<form class="form-card" @submit.prevent="createField">
|
||||
<h2>فیلد جدید</h2>
|
||||
<div class="grid">
|
||||
<div class="field">
|
||||
<label for="cf-label">عنوان</label>
|
||||
<input id="cf-label" v-model="label" required placeholder="مثلاً صنعت" />
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="cf-entity">روی چه چیزی؟</label>
|
||||
<select id="cf-entity" v-model="entityType">
|
||||
<option value="person">شخص</option>
|
||||
<option value="company">شرکت</option>
|
||||
<option value="deal">معامله</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="cf-type">نوع</label>
|
||||
<select id="cf-type" v-model="fieldType">
|
||||
<option value="text">متن</option>
|
||||
<option value="number">عدد</option>
|
||||
<option value="date">تاریخ</option>
|
||||
<option value="boolean">بله/خیر</option>
|
||||
<option value="select">لیست انتخابی</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="field check-field">
|
||||
<label class="check">
|
||||
<input v-model="required" type="checkbox" />
|
||||
اجباری
|
||||
</label>
|
||||
</div>
|
||||
<div v-if="fieldType === 'select'" class="field wide">
|
||||
<label for="cf-options">گزینهها (با کاما جدا کنید)</label>
|
||||
<input
|
||||
id="cf-options"
|
||||
v-model="optionsRaw"
|
||||
placeholder="مثلاً فناوری، تولید، خدمات"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<button class="btn" type="submit" :disabled="saving">
|
||||
{{ saving ? 'در حال ثبت…' : 'افزودن فیلد' }}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<div class="toolbar">
|
||||
<select v-model="filter">
|
||||
<option value="all">همه</option>
|
||||
<option value="person">شخص</option>
|
||||
<option value="company">شرکت</option>
|
||||
<option value="deal">معامله</option>
|
||||
</select>
|
||||
<button class="btn btn-ghost" type="button" @click="load">بروزرسانی</button>
|
||||
</div>
|
||||
|
||||
<p v-if="error" class="error">{{ error }}</p>
|
||||
<p v-if="loading" class="muted">در حال بارگذاری…</p>
|
||||
|
||||
<div v-else class="list">
|
||||
<article v-for="field in visible" :key="field.id" class="row">
|
||||
<div>
|
||||
<strong>{{ field.label }}</strong>
|
||||
<p class="meta">
|
||||
{{ entityLabels[field.entityType] }} · {{ typeLabels[field.fieldType] }}
|
||||
· کلید: <code>{{ field.key }}</code>
|
||||
<span v-if="!field.isActive"> · غیرفعال</span>
|
||||
</p>
|
||||
</div>
|
||||
<div class="actions">
|
||||
<button class="btn btn-ghost" type="button" @click="toggleActive(field)">
|
||||
{{ field.isActive ? 'غیرفعال' : 'فعال' }}
|
||||
</button>
|
||||
<button class="btn btn-danger" type="button" @click="removeField(field)">
|
||||
حذف
|
||||
</button>
|
||||
</div>
|
||||
</article>
|
||||
<p v-if="!visible.length" class="muted">هنوز فیلدی تعریف نشده است.</p>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.page {
|
||||
display: grid;
|
||||
gap: 1.1rem;
|
||||
max-width: 920px;
|
||||
}
|
||||
|
||||
.page-head h1 {
|
||||
margin: 0.2rem 0 0.35rem;
|
||||
font-size: 1.7rem;
|
||||
}
|
||||
|
||||
.eyebrow {
|
||||
margin: 0;
|
||||
color: var(--accent);
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.muted {
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.form-card,
|
||||
.row {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: var(--radius);
|
||||
box-shadow: var(--shadow);
|
||||
padding: 1.1rem;
|
||||
}
|
||||
|
||||
.form-card {
|
||||
display: grid;
|
||||
gap: 0.9rem;
|
||||
}
|
||||
|
||||
.form-card h2 {
|
||||
margin: 0;
|
||||
font-size: 1.05rem;
|
||||
}
|
||||
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 0.85rem;
|
||||
}
|
||||
|
||||
.wide {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
|
||||
select,
|
||||
input[type='text'] {
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 12px;
|
||||
padding: 0.8rem 0.95rem;
|
||||
background: #fff;
|
||||
font: inherit;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.check-field {
|
||||
display: flex;
|
||||
align-items: end;
|
||||
}
|
||||
|
||||
.check {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.45rem;
|
||||
}
|
||||
|
||||
.toolbar {
|
||||
display: flex;
|
||||
gap: 0.6rem;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.list {
|
||||
display: grid;
|
||||
gap: 0.7rem;
|
||||
}
|
||||
|
||||
.row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.meta {
|
||||
margin: 0.25rem 0 0;
|
||||
color: var(--muted);
|
||||
font-size: 0.92rem;
|
||||
}
|
||||
|
||||
.actions {
|
||||
display: flex;
|
||||
gap: 0.45rem;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: Consolas, monospace;
|
||||
font-size: 0.85em;
|
||||
}
|
||||
|
||||
@media (max-width: 700px) {
|
||||
.grid,
|
||||
.row {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.row {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user