feat(notes): let organizations define their own note fields
The note form was fixed. Owners can add fields and each note keeps those values. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
ALTER TYPE "CustomFieldEntity" ADD VALUE IF NOT EXISTS 'note';
|
||||||
|
|
||||||
|
ALTER TABLE "Note" ADD COLUMN IF NOT EXISTS "customFields" JSONB NOT NULL DEFAULT '{}';
|
||||||
@@ -52,6 +52,7 @@ enum CustomFieldEntity {
|
|||||||
person
|
person
|
||||||
company
|
company
|
||||||
deal
|
deal
|
||||||
|
note
|
||||||
}
|
}
|
||||||
|
|
||||||
enum CustomFieldType {
|
enum CustomFieldType {
|
||||||
@@ -941,6 +942,8 @@ model Note {
|
|||||||
checklist Json?
|
checklist Json?
|
||||||
locationText String?
|
locationText String?
|
||||||
analyzeEnabled Boolean @default(true)
|
analyzeEnabled Boolean @default(true)
|
||||||
|
/// مقادیر فیلدهای سفارشی یادداشت
|
||||||
|
customFields Json @default("{}")
|
||||||
personId String?
|
personId String?
|
||||||
person Person? @relation(fields: [personId], references: [id], onDelete: SetNull)
|
person Person? @relation(fields: [personId], references: [id], onDelete: SetNull)
|
||||||
companyId String?
|
companyId String?
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ export enum CustomFieldEntityDto {
|
|||||||
person = 'person',
|
person = 'person',
|
||||||
company = 'company',
|
company = 'company',
|
||||||
deal = 'deal',
|
deal = 'deal',
|
||||||
|
note = 'note',
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum CustomFieldTypeDto {
|
export enum CustomFieldTypeDto {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
IsDateString,
|
IsDateString,
|
||||||
IsIn,
|
IsIn,
|
||||||
IsInt,
|
IsInt,
|
||||||
|
IsObject,
|
||||||
IsOptional,
|
IsOptional,
|
||||||
IsString,
|
IsString,
|
||||||
Max,
|
Max,
|
||||||
@@ -171,6 +172,10 @@ export class CreateNoteDto {
|
|||||||
@ValidateIf((_, v) => v !== '' && v != null)
|
@ValidateIf((_, v) => v !== '' && v != null)
|
||||||
@IsString()
|
@IsString()
|
||||||
activityId?: string | null;
|
activityId?: string | null;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsObject()
|
||||||
|
customFields?: Record<string, unknown>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class UpdateNoteDto {
|
export class UpdateNoteDto {
|
||||||
@@ -248,6 +253,10 @@ export class UpdateNoteDto {
|
|||||||
@ValidateIf((_, v) => v !== '' && v != null)
|
@ValidateIf((_, v) => v !== '' && v != null)
|
||||||
@IsString()
|
@IsString()
|
||||||
activityId?: string | null;
|
activityId?: string | null;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsObject()
|
||||||
|
customFields?: Record<string, unknown>;
|
||||||
}
|
}
|
||||||
|
|
||||||
class NoteAiNextActionDtoClass {
|
class NoteAiNextActionDtoClass {
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import { PrismaService } from '../prisma/prisma.service';
|
|||||||
import { buildSearchWhere, ci } from '../common/search';
|
import { buildSearchWhere, ci } from '../common/search';
|
||||||
import { LocalFileStorage } from '../storage/local-file.storage';
|
import { LocalFileStorage } from '../storage/local-file.storage';
|
||||||
import { GamificationService } from '../gamification/gamification.service';
|
import { GamificationService } from '../gamification/gamification.service';
|
||||||
|
import { asCustomFields, toJsonCustomFields } from '../common/custom-fields';
|
||||||
import {
|
import {
|
||||||
type Actor,
|
type Actor,
|
||||||
noteAccessWhere,
|
noteAccessWhere,
|
||||||
@@ -45,6 +46,7 @@ type NoteRow = {
|
|||||||
checklist: Prisma.JsonValue | null;
|
checklist: Prisma.JsonValue | null;
|
||||||
locationText: string | null;
|
locationText: string | null;
|
||||||
analyzeEnabled: boolean;
|
analyzeEnabled: boolean;
|
||||||
|
customFields: Prisma.JsonValue;
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
person: { id: string; firstName: string; lastName: string } | null;
|
person: { id: string; firstName: string; lastName: string } | null;
|
||||||
@@ -224,6 +226,7 @@ export class NotesService {
|
|||||||
: Prisma.JsonNull,
|
: Prisma.JsonNull,
|
||||||
locationText: emptyToNull(dto.locationText ?? null),
|
locationText: emptyToNull(dto.locationText ?? null),
|
||||||
analyzeEnabled,
|
analyzeEnabled,
|
||||||
|
customFields: toJsonCustomFields(dto.customFields),
|
||||||
personId: emptyToNull(dto.personId ?? null),
|
personId: emptyToNull(dto.personId ?? null),
|
||||||
companyId: emptyToNull(dto.companyId ?? null),
|
companyId: emptyToNull(dto.companyId ?? null),
|
||||||
dealId: emptyToNull(dto.dealId ?? null),
|
dealId: emptyToNull(dto.dealId ?? null),
|
||||||
@@ -280,6 +283,9 @@ export class NotesService {
|
|||||||
if (dto.analyzeEnabled !== undefined) {
|
if (dto.analyzeEnabled !== undefined) {
|
||||||
data.analyzeEnabled = dto.analyzeEnabled;
|
data.analyzeEnabled = dto.analyzeEnabled;
|
||||||
}
|
}
|
||||||
|
if ('customFields' in dto) {
|
||||||
|
data.customFields = toJsonCustomFields(dto.customFields);
|
||||||
|
}
|
||||||
if ('personId' in dto) data.personId = emptyToNull(dto.personId ?? null);
|
if ('personId' in dto) data.personId = emptyToNull(dto.personId ?? null);
|
||||||
if ('companyId' in dto) data.companyId = emptyToNull(dto.companyId ?? null);
|
if ('companyId' in dto) data.companyId = emptyToNull(dto.companyId ?? null);
|
||||||
if ('dealId' in dto) data.dealId = emptyToNull(dto.dealId ?? null);
|
if ('dealId' in dto) data.dealId = emptyToNull(dto.dealId ?? null);
|
||||||
@@ -616,6 +622,7 @@ export class NotesService {
|
|||||||
checklist: parseChecklist(row.checklist),
|
checklist: parseChecklist(row.checklist),
|
||||||
locationText: row.locationText ?? null,
|
locationText: row.locationText ?? null,
|
||||||
analyzeEnabled: row.analyzeEnabled ?? true,
|
analyzeEnabled: row.analyzeEnabled ?? true,
|
||||||
|
customFields: asCustomFields(row.customFields),
|
||||||
person: row.person
|
person: row.person
|
||||||
? {
|
? {
|
||||||
id: row.person.id,
|
id: row.person.id,
|
||||||
|
|||||||
@@ -0,0 +1,128 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { CustomFieldDefinitionDto } from '@mento/shared';
|
||||||
|
import JalaliDateInput from '@/components/JalaliDateInput.vue';
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
fields: CustomFieldDefinitionDto[];
|
||||||
|
modelValue: Record<string, unknown>;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
'update:modelValue': [value: Record<string, unknown>];
|
||||||
|
}>();
|
||||||
|
|
||||||
|
function setValue(key: string, value: unknown) {
|
||||||
|
emit('update:modelValue', { ...props.modelValue, [key]: value });
|
||||||
|
}
|
||||||
|
|
||||||
|
function textValue(key: string) {
|
||||||
|
const value = props.modelValue[key];
|
||||||
|
if (value == null) return '';
|
||||||
|
return String(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
function numberValue(key: string) {
|
||||||
|
const value = props.modelValue[key];
|
||||||
|
if (value == null || value === '') return '';
|
||||||
|
const n = Number(value);
|
||||||
|
return Number.isFinite(n) ? String(n) : '';
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div v-if="fields.length" class="note-custom-fields">
|
||||||
|
<p class="note-custom-title">فیلدهای اختصاصی</p>
|
||||||
|
<div v-for="field in fields" :key="field.id" class="field">
|
||||||
|
<span>
|
||||||
|
{{ field.label }}
|
||||||
|
<em v-if="field.required">*</em>
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<select
|
||||||
|
v-if="field.fieldType === 'select'"
|
||||||
|
:value="textValue(field.key)"
|
||||||
|
@change="setValue(field.key, ($event.target as HTMLSelectElement).value)"
|
||||||
|
>
|
||||||
|
<option value="">انتخاب کنید</option>
|
||||||
|
<option v-for="opt in field.options" :key="opt" :value="opt">{{ opt }}</option>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<label v-else-if="field.fieldType === 'boolean'" class="check-line">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
:checked="props.modelValue[field.key] === true"
|
||||||
|
@change="setValue(field.key, ($event.target as HTMLInputElement).checked)"
|
||||||
|
/>
|
||||||
|
<span>بله</span>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<input
|
||||||
|
v-else-if="field.fieldType === 'number'"
|
||||||
|
type="number"
|
||||||
|
:value="numberValue(field.key)"
|
||||||
|
@input="
|
||||||
|
setValue(
|
||||||
|
field.key,
|
||||||
|
($event.target as HTMLInputElement).value === ''
|
||||||
|
? null
|
||||||
|
: Number(($event.target as HTMLInputElement).value),
|
||||||
|
)
|
||||||
|
"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<JalaliDateInput
|
||||||
|
v-else-if="field.fieldType === 'date'"
|
||||||
|
:model-value="textValue(field.key)"
|
||||||
|
@update:model-value="setValue(field.key, $event || null)"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<input
|
||||||
|
v-else
|
||||||
|
type="text"
|
||||||
|
:value="textValue(field.key)"
|
||||||
|
@input="setValue(field.key, ($event.target as HTMLInputElement).value)"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.note-custom-fields {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.55rem;
|
||||||
|
}
|
||||||
|
.note-custom-title {
|
||||||
|
margin: 0.2rem 0 0;
|
||||||
|
font-size: 0.82rem;
|
||||||
|
font-weight: 700;
|
||||||
|
color: #0f766e;
|
||||||
|
}
|
||||||
|
.field {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.3rem;
|
||||||
|
font-size: 0.82rem;
|
||||||
|
color: #64748b;
|
||||||
|
}
|
||||||
|
.field em {
|
||||||
|
color: #b91c1c;
|
||||||
|
font-style: normal;
|
||||||
|
}
|
||||||
|
.field select,
|
||||||
|
.field input[type='text'],
|
||||||
|
.field input[type='number'] {
|
||||||
|
border: 1px solid #e2e8f0;
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 0.45rem 0.55rem;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
color: #0f172a;
|
||||||
|
background: #fff;
|
||||||
|
}
|
||||||
|
.check-line {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.4rem;
|
||||||
|
color: #0f172a;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,313 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { onMounted, ref } from 'vue';
|
||||||
|
import axios from 'axios';
|
||||||
|
import { api } from '@/lib/api';
|
||||||
|
import UiIcon from '@/components/UiIcon.vue';
|
||||||
|
import type {
|
||||||
|
CreateCustomFieldRequest,
|
||||||
|
CustomFieldDefinitionDto,
|
||||||
|
CustomFieldType,
|
||||||
|
} from '@mento/shared';
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
close: [];
|
||||||
|
saved: [];
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const loading = ref(false);
|
||||||
|
const saving = ref(false);
|
||||||
|
const error = ref('');
|
||||||
|
const fields = ref<CustomFieldDefinitionDto[]>([]);
|
||||||
|
const label = ref('');
|
||||||
|
const fieldType = ref<CustomFieldType>('text');
|
||||||
|
const optionsRaw = ref('');
|
||||||
|
const required = ref(false);
|
||||||
|
|
||||||
|
const typeLabels: Record<CustomFieldType, string> = {
|
||||||
|
text: 'متن',
|
||||||
|
number: 'عدد',
|
||||||
|
date: 'تاریخ',
|
||||||
|
boolean: 'بله/خیر',
|
||||||
|
select: 'لیست انتخابی',
|
||||||
|
};
|
||||||
|
|
||||||
|
async function load() {
|
||||||
|
loading.value = true;
|
||||||
|
error.value = '';
|
||||||
|
try {
|
||||||
|
fields.value = (
|
||||||
|
await api.get<CustomFieldDefinitionDto[]>('/custom-fields', {
|
||||||
|
params: { entityType: 'note' },
|
||||||
|
})
|
||||||
|
).data;
|
||||||
|
} catch {
|
||||||
|
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: 'note',
|
||||||
|
label: label.value.trim(),
|
||||||
|
fieldType: fieldType.value,
|
||||||
|
required: required.value,
|
||||||
|
options:
|
||||||
|
fieldType.value === 'select'
|
||||||
|
? optionsRaw.value
|
||||||
|
.split(/[,،\n]/)
|
||||||
|
.map((item) => item.trim())
|
||||||
|
.filter(Boolean)
|
||||||
|
: undefined,
|
||||||
|
};
|
||||||
|
await api.post('/custom-fields', payload);
|
||||||
|
label.value = '';
|
||||||
|
optionsRaw.value = '';
|
||||||
|
required.value = false;
|
||||||
|
fieldType.value = 'text';
|
||||||
|
await load();
|
||||||
|
emit('saved');
|
||||||
|
} 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();
|
||||||
|
emit('saved');
|
||||||
|
}
|
||||||
|
|
||||||
|
async function removeField(field: CustomFieldDefinitionDto) {
|
||||||
|
if (!confirm(`فیلد «${field.label}» حذف شود؟ مقدارهای قبلی روی یادداشتها میماند.`)) return;
|
||||||
|
await api.delete(`/custom-fields/${field.id}`);
|
||||||
|
await load();
|
||||||
|
emit('saved');
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(load);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="fields-root">
|
||||||
|
<div class="fields-backdrop" aria-hidden="true" @click="emit('close')" />
|
||||||
|
<aside class="fields-panel" role="dialog" aria-label="فیلدهای یادداشت">
|
||||||
|
<header class="fields-head">
|
||||||
|
<h2>فیلدهای یادداشت</h2>
|
||||||
|
<button type="button" class="icon-btn" @click="emit('close')">
|
||||||
|
<UiIcon name="x" :size="20" />
|
||||||
|
</button>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="fields-scroll">
|
||||||
|
<p class="hint">
|
||||||
|
فیلدهایی که اینجا میسازید روی فرم هر یادداشت دیده میشوند.
|
||||||
|
</p>
|
||||||
|
<p v-if="error" class="banner-error">{{ error }}</p>
|
||||||
|
|
||||||
|
<form class="create-form" @submit.prevent="createField">
|
||||||
|
<label class="field">
|
||||||
|
<span>عنوان</span>
|
||||||
|
<input v-model="label" type="text" placeholder="مثلاً نتیجه تماس" />
|
||||||
|
</label>
|
||||||
|
<label class="field">
|
||||||
|
<span>نوع</span>
|
||||||
|
<select v-model="fieldType">
|
||||||
|
<option value="text">متن</option>
|
||||||
|
<option value="number">عدد</option>
|
||||||
|
<option value="date">تاریخ</option>
|
||||||
|
<option value="boolean">بله/خیر</option>
|
||||||
|
<option value="select">لیست انتخابی</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
<label v-if="fieldType === 'select'" class="field">
|
||||||
|
<span>گزینهها (با کاما جدا کنید)</span>
|
||||||
|
<input v-model="optionsRaw" type="text" placeholder="مثلاً موفق، پیگیری، ناموفق" />
|
||||||
|
</label>
|
||||||
|
<label class="check-line">
|
||||||
|
<input v-model="required" type="checkbox" />
|
||||||
|
<span>اجباری</span>
|
||||||
|
</label>
|
||||||
|
<button type="submit" class="btn-primary" :disabled="saving">
|
||||||
|
{{ saving ? 'در حال ثبت…' : 'افزودن فیلد' }}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<p v-if="loading" class="hint">در حال بارگذاری…</p>
|
||||||
|
<p v-else-if="!fields.length" class="hint">هنوز فیلد اختصاصی ندارید.</p>
|
||||||
|
<ul v-else class="field-list">
|
||||||
|
<li v-for="field in fields" :key="field.id">
|
||||||
|
<div>
|
||||||
|
<strong>{{ field.label }}</strong>
|
||||||
|
<span>{{ typeLabels[field.fieldType] }}</span>
|
||||||
|
<span v-if="field.required">اجباری</span>
|
||||||
|
<span v-if="!field.isActive">غیرفعال</span>
|
||||||
|
</div>
|
||||||
|
<div class="row-actions">
|
||||||
|
<button type="button" @click="toggleActive(field)">
|
||||||
|
{{ field.isActive ? 'غیرفعال' : 'فعال' }}
|
||||||
|
</button>
|
||||||
|
<button type="button" class="danger" @click="removeField(field)">حذف</button>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.fields-root {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
z-index: 140;
|
||||||
|
}
|
||||||
|
.fields-backdrop {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
background: rgba(15, 23, 42, 0.35);
|
||||||
|
}
|
||||||
|
.fields-panel {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
width: min(420px, 100%);
|
||||||
|
background: #fff;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
box-shadow: 0 12px 40px rgba(15, 23, 42, 0.18);
|
||||||
|
}
|
||||||
|
.fields-head {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
padding: 0.9rem 1rem;
|
||||||
|
border-bottom: 1px solid #e2e8f0;
|
||||||
|
}
|
||||||
|
.fields-head h2 {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 1.05rem;
|
||||||
|
}
|
||||||
|
.fields-scroll {
|
||||||
|
overflow: auto;
|
||||||
|
padding: 1rem;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.75rem;
|
||||||
|
}
|
||||||
|
.hint {
|
||||||
|
margin: 0;
|
||||||
|
color: #64748b;
|
||||||
|
font-size: 0.88rem;
|
||||||
|
}
|
||||||
|
.banner-error {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0.55rem 0.7rem;
|
||||||
|
border-radius: 10px;
|
||||||
|
background: #fef2f2;
|
||||||
|
color: #b91c1c;
|
||||||
|
font-size: 0.88rem;
|
||||||
|
}
|
||||||
|
.create-form,
|
||||||
|
.field {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.35rem;
|
||||||
|
}
|
||||||
|
.field span,
|
||||||
|
.check-line {
|
||||||
|
font-size: 0.82rem;
|
||||||
|
color: #64748b;
|
||||||
|
}
|
||||||
|
.field input,
|
||||||
|
.field select {
|
||||||
|
border: 1px solid #e2e8f0;
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 0.45rem 0.55rem;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
color: #0f172a;
|
||||||
|
background: #fff;
|
||||||
|
}
|
||||||
|
.check-line {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.4rem;
|
||||||
|
color: #0f172a;
|
||||||
|
}
|
||||||
|
.btn-primary,
|
||||||
|
.row-actions button,
|
||||||
|
.icon-btn {
|
||||||
|
border: 0;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
.btn-primary {
|
||||||
|
background: #0f766e;
|
||||||
|
color: #fff;
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 0.55rem 1rem;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
.btn-primary:disabled {
|
||||||
|
opacity: 0.65;
|
||||||
|
}
|
||||||
|
.icon-btn {
|
||||||
|
background: transparent;
|
||||||
|
color: #64748b;
|
||||||
|
}
|
||||||
|
.field-list {
|
||||||
|
list-style: none;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.55rem;
|
||||||
|
}
|
||||||
|
.field-list li {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 0.75rem;
|
||||||
|
align-items: center;
|
||||||
|
padding: 0.65rem 0.7rem;
|
||||||
|
border: 1px solid #e2e8f0;
|
||||||
|
border-radius: 10px;
|
||||||
|
}
|
||||||
|
.field-list strong {
|
||||||
|
display: block;
|
||||||
|
color: #0f172a;
|
||||||
|
}
|
||||||
|
.field-list span {
|
||||||
|
margin-inline-start: 0.35rem;
|
||||||
|
color: #64748b;
|
||||||
|
font-size: 0.78rem;
|
||||||
|
}
|
||||||
|
.row-actions {
|
||||||
|
display: flex;
|
||||||
|
gap: 0.35rem;
|
||||||
|
}
|
||||||
|
.row-actions button {
|
||||||
|
background: #f8fafc;
|
||||||
|
color: #334155;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 0.3rem 0.5rem;
|
||||||
|
}
|
||||||
|
.row-actions .danger {
|
||||||
|
color: #b91c1c;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -36,6 +36,7 @@ const entityLabels: Record<CustomFieldEntity, string> = {
|
|||||||
person: 'شخص',
|
person: 'شخص',
|
||||||
company: 'شرکت',
|
company: 'شرکت',
|
||||||
deal: 'معامله',
|
deal: 'معامله',
|
||||||
|
note: 'یادداشت',
|
||||||
};
|
};
|
||||||
|
|
||||||
const typeLabels: Record<CustomFieldType, string> = {
|
const typeLabels: Record<CustomFieldType, string> = {
|
||||||
@@ -126,7 +127,7 @@ onMounted(load);
|
|||||||
<section class="crm-page narrow">
|
<section class="crm-page narrow">
|
||||||
<UiPageHeader
|
<UiPageHeader
|
||||||
title="فیلدهای سفارشی"
|
title="فیلدهای سفارشی"
|
||||||
lead="فیلدهای اختصاصی سازمان را برای شخص، شرکت یا معامله تعریف کنید."
|
lead="فیلدهای اختصاصی سازمان را برای شخص، شرکت، معامله یا یادداشت تعریف کنید."
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<form class="crm-form" @submit.prevent="createField">
|
<form class="crm-form" @submit.prevent="createField">
|
||||||
@@ -147,6 +148,7 @@ onMounted(load);
|
|||||||
<option value="person">شخص</option>
|
<option value="person">شخص</option>
|
||||||
<option value="company">شرکت</option>
|
<option value="company">شرکت</option>
|
||||||
<option value="deal">معامله</option>
|
<option value="deal">معامله</option>
|
||||||
|
<option value="note">یادداشت</option>
|
||||||
</UiSelect>
|
</UiSelect>
|
||||||
</UiField>
|
</UiField>
|
||||||
|
|
||||||
@@ -197,6 +199,7 @@ onMounted(load);
|
|||||||
<option value="person">شخص</option>
|
<option value="person">شخص</option>
|
||||||
<option value="company">شرکت</option>
|
<option value="company">شرکت</option>
|
||||||
<option value="deal">معامله</option>
|
<option value="deal">معامله</option>
|
||||||
|
<option value="note">یادداشت</option>
|
||||||
</UiSelect>
|
</UiSelect>
|
||||||
<UiButton variant="ghost" type="button" @click="load">
|
<UiButton variant="ghost" type="button" @click="load">
|
||||||
<UiIcon name="refresh" :size="16" />
|
<UiIcon name="refresh" :size="16" />
|
||||||
|
|||||||
@@ -5,10 +5,14 @@ import { useRoute } from 'vue-router';
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { api } from '@/lib/api';
|
import { api } from '@/lib/api';
|
||||||
import NoteAiSuggestionPanel from '@/components/NoteAiSuggestionPanel.vue';
|
import NoteAiSuggestionPanel from '@/components/NoteAiSuggestionPanel.vue';
|
||||||
|
import NoteCustomFields from '@/components/notes/NoteCustomFields.vue';
|
||||||
|
import NoteFieldsManager from '@/components/notes/NoteFieldsManager.vue';
|
||||||
import JalaliDateInput from '@/components/JalaliDateInput.vue';
|
import JalaliDateInput from '@/components/JalaliDateInput.vue';
|
||||||
import VoiceToTextButton from '@/components/VoiceToTextButton.vue';
|
import VoiceToTextButton from '@/components/VoiceToTextButton.vue';
|
||||||
import UiIcon from '@/components/UiIcon.vue';
|
import UiIcon from '@/components/UiIcon.vue';
|
||||||
import { appendSpokenText } from '@/lib/spoken-text';
|
import { appendSpokenText } from '@/lib/spoken-text';
|
||||||
|
import { canManageSettings } from '@/lib/roles';
|
||||||
|
import { useAuthStore } from '@/stores/auth';
|
||||||
import {
|
import {
|
||||||
calendarDaysBetween,
|
calendarDaysBetween,
|
||||||
formatClockFa,
|
formatClockFa,
|
||||||
@@ -28,6 +32,7 @@ import type {
|
|||||||
PaginatedResponse,
|
PaginatedResponse,
|
||||||
PersonDto,
|
PersonDto,
|
||||||
PipelineBoardDto,
|
PipelineBoardDto,
|
||||||
|
CustomFieldDefinitionDto,
|
||||||
} from '@mento/shared';
|
} from '@mento/shared';
|
||||||
import { NOTE_VISIBILITY_LABELS } from '@mento/shared';
|
import { NOTE_VISIBILITY_LABELS } from '@mento/shared';
|
||||||
|
|
||||||
@@ -37,6 +42,8 @@ type ColorKey = 'sand' | 'rose' | 'sky' | 'mint' | 'lavender' | 'default';
|
|||||||
type OpenMode = 'default' | 'image' | 'mic' | 'attach' | 'audio' | 'checklist';
|
type OpenMode = 'default' | 'image' | 'mic' | 'attach' | 'audio' | 'checklist';
|
||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
const auth = useAuthStore();
|
||||||
|
const canManageNoteFields = computed(() => canManageSettings(auth.user?.role));
|
||||||
|
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
const saving = ref(false);
|
const saving = ref(false);
|
||||||
@@ -74,8 +81,11 @@ const draftAnalyze = ref(true);
|
|||||||
const draftPinned = ref(false);
|
const draftPinned = ref(false);
|
||||||
const draftVisibility = ref<NoteVisibility>('team');
|
const draftVisibility = ref<NoteVisibility>('team');
|
||||||
const draftChecklist = ref<NoteChecklistItemDto[]>([]);
|
const draftChecklist = ref<NoteChecklistItemDto[]>([]);
|
||||||
|
const draftCustomFields = ref<Record<string, unknown>>({});
|
||||||
const draftFiles = ref<File[]>([]);
|
const draftFiles = ref<File[]>([]);
|
||||||
const existingAttachments = ref<NoteAttachmentDto[]>([]);
|
const existingAttachments = ref<NoteAttachmentDto[]>([]);
|
||||||
|
const noteFieldDefs = ref<CustomFieldDefinitionDto[]>([]);
|
||||||
|
const fieldsOpen = ref(false);
|
||||||
|
|
||||||
const historyOpen = ref(false);
|
const historyOpen = ref(false);
|
||||||
const historyLoading = ref(false);
|
const historyLoading = ref(false);
|
||||||
@@ -229,6 +239,28 @@ function previewBody(body: string) {
|
|||||||
return `${t.slice(0, 160)}…`;
|
return `${t.slice(0, 160)}…`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function customFieldLines(note: NoteDto) {
|
||||||
|
const values = note.customFields ?? {};
|
||||||
|
return noteFieldDefs.value.flatMap((field) => {
|
||||||
|
const value = values[field.key];
|
||||||
|
if (value == null || value === '') return [];
|
||||||
|
const text = field.fieldType === 'boolean' ? (value ? 'بله' : 'خیر') : String(value);
|
||||||
|
return [{ key: field.key, label: field.label, text }];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadNoteFields() {
|
||||||
|
try {
|
||||||
|
noteFieldDefs.value = (
|
||||||
|
await api.get<CustomFieldDefinitionDto[]>('/custom-fields', {
|
||||||
|
params: { entityType: 'note', activeOnly: true },
|
||||||
|
})
|
||||||
|
).data;
|
||||||
|
} catch {
|
||||||
|
noteFieldDefs.value = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function isImageAtt(att: NoteAttachmentDto) {
|
function isImageAtt(att: NoteAttachmentDto) {
|
||||||
return att.mimeType.startsWith('image/');
|
return att.mimeType.startsWith('image/');
|
||||||
}
|
}
|
||||||
@@ -383,6 +415,7 @@ function resetDraft() {
|
|||||||
draftPinned.value = false;
|
draftPinned.value = false;
|
||||||
draftVisibility.value = 'team';
|
draftVisibility.value = 'team';
|
||||||
draftChecklist.value = [];
|
draftChecklist.value = [];
|
||||||
|
draftCustomFields.value = {};
|
||||||
draftFiles.value = [];
|
draftFiles.value = [];
|
||||||
existingAttachments.value = [];
|
existingAttachments.value = [];
|
||||||
showChecklistEditor.value = false;
|
showChecklistEditor.value = false;
|
||||||
@@ -408,6 +441,7 @@ function openEditor(mode: OpenMode = 'default', note?: NoteDto) {
|
|||||||
draftVisibility.value =
|
draftVisibility.value =
|
||||||
note.visibility === 'personal' ? 'personal' : 'team';
|
note.visibility === 'personal' ? 'personal' : 'team';
|
||||||
draftChecklist.value = [...(note.checklist ?? [])];
|
draftChecklist.value = [...(note.checklist ?? [])];
|
||||||
|
draftCustomFields.value = { ...(note.customFields ?? {}) };
|
||||||
draftFiles.value = [];
|
draftFiles.value = [];
|
||||||
existingAttachments.value = [...note.attachments];
|
existingAttachments.value = [...note.attachments];
|
||||||
showChecklistEditor.value = (note.checklist?.length ?? 0) > 0;
|
showChecklistEditor.value = (note.checklist?.length ?? 0) > 0;
|
||||||
@@ -503,6 +537,16 @@ async function saveNote() {
|
|||||||
error.value = 'متن یادداشت یا چکلیست لازم است.';
|
error.value = 'متن یادداشت یا چکلیست لازم است.';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const missingField = noteFieldDefs.value.find((field) => {
|
||||||
|
if (!field.required) return false;
|
||||||
|
const value = draftCustomFields.value[field.key];
|
||||||
|
if (field.fieldType === 'boolean') return value !== true && value !== false;
|
||||||
|
return value == null || String(value).trim() === '';
|
||||||
|
});
|
||||||
|
if (missingField) {
|
||||||
|
error.value = `فیلد «${missingField.label}» لازم است.`;
|
||||||
|
return;
|
||||||
|
}
|
||||||
saving.value = true;
|
saving.value = true;
|
||||||
error.value = '';
|
error.value = '';
|
||||||
try {
|
try {
|
||||||
@@ -523,6 +567,7 @@ async function saveNote() {
|
|||||||
analyzeEnabled: draftAnalyze.value,
|
analyzeEnabled: draftAnalyze.value,
|
||||||
pinned: draftPinned.value,
|
pinned: draftPinned.value,
|
||||||
checklist,
|
checklist,
|
||||||
|
customFields: draftCustomFields.value,
|
||||||
};
|
};
|
||||||
const pending = [...draftFiles.value];
|
const pending = [...draftFiles.value];
|
||||||
let noteId = editingId.value;
|
let noteId = editingId.value;
|
||||||
@@ -581,6 +626,9 @@ async function openHistory(note: NoteDto) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
useEscClose(() => editorOpen.value, () => closeEditor());
|
useEscClose(() => editorOpen.value, () => closeEditor());
|
||||||
|
useEscClose(() => fieldsOpen.value, () => {
|
||||||
|
fieldsOpen.value = false;
|
||||||
|
});
|
||||||
useEscClose(() => moreSheetOpen.value, () => { moreSheetOpen.value = false; });
|
useEscClose(() => moreSheetOpen.value, () => { moreSheetOpen.value = false; });
|
||||||
useEscClose(() => historyOpen.value, () => closeHistory());
|
useEscClose(() => historyOpen.value, () => closeHistory());
|
||||||
|
|
||||||
@@ -683,6 +731,7 @@ onMounted(() => {
|
|||||||
}
|
}
|
||||||
void load();
|
void load();
|
||||||
void loadActivities();
|
void loadActivities();
|
||||||
|
void loadNoteFields();
|
||||||
});
|
});
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
@@ -699,6 +748,14 @@ onBeforeUnmount(() => {
|
|||||||
<h1>یادداشتها</h1>
|
<h1>یادداشتها</h1>
|
||||||
<p class="lead">فکر کنید، یادداشت کنید، هیچ چیز را فراموش نکنید.</p>
|
<p class="lead">فکر کنید، یادداشت کنید، هیچ چیز را فراموش نکنید.</p>
|
||||||
</div>
|
</div>
|
||||||
|
<button
|
||||||
|
v-if="canManageNoteFields"
|
||||||
|
type="button"
|
||||||
|
class="fields-manage"
|
||||||
|
@click="fieldsOpen = true"
|
||||||
|
>
|
||||||
|
فیلدهای یادداشت
|
||||||
|
</button>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<p v-if="error" class="banner-error">{{ error }}</p>
|
<p v-if="error" class="banner-error">{{ error }}</p>
|
||||||
@@ -921,6 +978,11 @@ onBeforeUnmount(() => {
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p v-else-if="note.body" class="card-body">{{ previewBody(note.body) }}</p>
|
<p v-else-if="note.body" class="card-body">{{ previewBody(note.body) }}</p>
|
||||||
|
<ul v-if="customFieldLines(note).length" class="card-fields">
|
||||||
|
<li v-for="line in customFieldLines(note)" :key="line.key">
|
||||||
|
<b>{{ line.label }}:</b> {{ line.text }}
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
<div v-if="firstImage(note)" class="card-thumb">
|
<div v-if="firstImage(note)" class="card-thumb">
|
||||||
<img
|
<img
|
||||||
@@ -1067,6 +1129,7 @@ onBeforeUnmount(() => {
|
|||||||
</header>
|
</header>
|
||||||
|
|
||||||
<div class="panel-scroll">
|
<div class="panel-scroll">
|
||||||
|
<p v-if="error" class="banner-error">{{ error }}</p>
|
||||||
<input
|
<input
|
||||||
v-model="draftTitle"
|
v-model="draftTitle"
|
||||||
class="title-input"
|
class="title-input"
|
||||||
@@ -1237,6 +1300,7 @@ onBeforeUnmount(() => {
|
|||||||
<p>پس از ذخیره، پیشنهاد کار بعدی و حافظه مشتری استخراج میشود.</p>
|
<p>پس از ذخیره، پیشنهاد کار بعدی و حافظه مشتری استخراج میشود.</p>
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</label>
|
||||||
|
<NoteCustomFields v-model="draftCustomFields" :fields="noteFieldDefs" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="chip-summary mobile-only-flex">
|
<div class="chip-summary mobile-only-flex">
|
||||||
@@ -1379,6 +1443,7 @@ onBeforeUnmount(() => {
|
|||||||
<p>پس از ذخیره اجرا میشود.</p>
|
<p>پس از ذخیره اجرا میشود.</p>
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</label>
|
||||||
|
<NoteCustomFields v-model="draftCustomFields" :fields="noteFieldDefs" />
|
||||||
<button type="button" class="btn-primary sheet-done" @click="moreSheetOpen = false">
|
<button type="button" class="btn-primary sheet-done" @click="moreSheetOpen = false">
|
||||||
تأیید
|
تأیید
|
||||||
</button>
|
</button>
|
||||||
@@ -1388,6 +1453,12 @@ onBeforeUnmount(() => {
|
|||||||
</div>
|
</div>
|
||||||
</Teleport>
|
</Teleport>
|
||||||
|
|
||||||
|
<NoteFieldsManager
|
||||||
|
v-if="fieldsOpen"
|
||||||
|
@close="fieldsOpen = false"
|
||||||
|
@saved="loadNoteFields"
|
||||||
|
/>
|
||||||
|
|
||||||
<Teleport to="body">
|
<Teleport to="body">
|
||||||
<div v-if="historyOpen" class="history-root">
|
<div v-if="historyOpen" class="history-root">
|
||||||
<div class="history-backdrop" aria-hidden="true" />
|
<div class="history-backdrop" aria-hidden="true" />
|
||||||
@@ -1460,6 +1531,12 @@ onBeforeUnmount(() => {
|
|||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.page-head {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 0.75rem;
|
||||||
|
}
|
||||||
.page-head h1 {
|
.page-head h1 {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
font-size: 1.55rem;
|
font-size: 1.55rem;
|
||||||
@@ -1471,6 +1548,29 @@ onBeforeUnmount(() => {
|
|||||||
color: #64748b;
|
color: #64748b;
|
||||||
font-size: 0.95rem;
|
font-size: 0.95rem;
|
||||||
}
|
}
|
||||||
|
.fields-manage {
|
||||||
|
border: 1px solid #e2e8f0;
|
||||||
|
background: #fff;
|
||||||
|
color: #0f766e;
|
||||||
|
border-radius: var(--radius);
|
||||||
|
padding: 0.45rem 0.8rem;
|
||||||
|
font-weight: 700;
|
||||||
|
cursor: pointer;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.card-fields {
|
||||||
|
margin: 0.4rem 0 0;
|
||||||
|
padding: 0;
|
||||||
|
list-style: none;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.15rem;
|
||||||
|
font-size: 0.82rem;
|
||||||
|
color: #334155;
|
||||||
|
}
|
||||||
|
.card-fields b {
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
.banner-error {
|
.banner-error {
|
||||||
margin: 0.75rem 0 0;
|
margin: 0.75rem 0 0;
|
||||||
|
|||||||
@@ -1797,7 +1797,7 @@ export interface ReorderActivityTypesRequest {
|
|||||||
typeIds: string[];
|
typeIds: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CustomFieldEntity = "person" | "company" | "deal";
|
export type CustomFieldEntity = "person" | "company" | "deal" | "note";
|
||||||
export type CustomFieldType = "text" | "number" | "date" | "boolean" | "select";
|
export type CustomFieldType = "text" | "number" | "date" | "boolean" | "select";
|
||||||
|
|
||||||
export interface CustomFieldDefinitionDto {
|
export interface CustomFieldDefinitionDto {
|
||||||
@@ -1992,6 +1992,7 @@ export interface NoteDto {
|
|||||||
checklist: NoteChecklistItemDto[];
|
checklist: NoteChecklistItemDto[];
|
||||||
locationText: string | null;
|
locationText: string | null;
|
||||||
analyzeEnabled: boolean;
|
analyzeEnabled: boolean;
|
||||||
|
customFields: Record<string, unknown>;
|
||||||
person: PersonSummaryDto | null;
|
person: PersonSummaryDto | null;
|
||||||
company: CompanySummaryDto | null;
|
company: CompanySummaryDto | null;
|
||||||
deal: DealSummaryDto | null;
|
deal: DealSummaryDto | null;
|
||||||
@@ -2041,6 +2042,7 @@ export interface CreateNoteRequest {
|
|||||||
companyId?: string | null;
|
companyId?: string | null;
|
||||||
dealId?: string | null;
|
dealId?: string | null;
|
||||||
activityId?: string | null;
|
activityId?: string | null;
|
||||||
|
customFields?: Record<string, unknown>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UpdateNoteRequest {
|
export interface UpdateNoteRequest {
|
||||||
@@ -2059,6 +2061,7 @@ export interface UpdateNoteRequest {
|
|||||||
companyId?: string | null;
|
companyId?: string | null;
|
||||||
dealId?: string | null;
|
dealId?: string | null;
|
||||||
activityId?: string | null;
|
activityId?: string | null;
|
||||||
|
customFields?: Record<string, unknown>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type NoteAiSuggestionStatus =
|
export type NoteAiSuggestionStatus =
|
||||||
|
|||||||
Reference in New Issue
Block a user