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:
2026-11-01 15:38:05 +03:30
co-authored by Cursor
parent 590f8114cc
commit 8e1e94a439
10 changed files with 572 additions and 2 deletions
@@ -36,6 +36,7 @@ const entityLabels: Record<CustomFieldEntity, string> = {
person: 'شخص',
company: 'شرکت',
deal: 'معامله',
note: 'یادداشت',
};
const typeLabels: Record<CustomFieldType, string> = {
@@ -126,7 +127,7 @@ onMounted(load);
<section class="crm-page narrow">
<UiPageHeader
title="فیلدهای سفارشی"
lead="فیلدهای اختصاصی سازمان را برای شخص، شرکت یا معامله تعریف کنید."
lead="فیلدهای اختصاصی سازمان را برای شخص، شرکت، معامله یا یادداشت تعریف کنید."
/>
<form class="crm-form" @submit.prevent="createField">
@@ -147,6 +148,7 @@ onMounted(load);
<option value="person">شخص</option>
<option value="company">شرکت</option>
<option value="deal">معامله</option>
<option value="note">یادداشت</option>
</UiSelect>
</UiField>
@@ -197,6 +199,7 @@ onMounted(load);
<option value="person">شخص</option>
<option value="company">شرکت</option>
<option value="deal">معامله</option>
<option value="note">یادداشت</option>
</UiSelect>
<UiButton variant="ghost" type="button" @click="load">
<UiIcon name="refresh" :size="16" />
+100
View File
@@ -5,10 +5,14 @@ import { useRoute } from 'vue-router';
import axios from 'axios';
import { api } from '@/lib/api';
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 VoiceToTextButton from '@/components/VoiceToTextButton.vue';
import UiIcon from '@/components/UiIcon.vue';
import { appendSpokenText } from '@/lib/spoken-text';
import { canManageSettings } from '@/lib/roles';
import { useAuthStore } from '@/stores/auth';
import {
calendarDaysBetween,
formatClockFa,
@@ -28,6 +32,7 @@ import type {
PaginatedResponse,
PersonDto,
PipelineBoardDto,
CustomFieldDefinitionDto,
} 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';
const route = useRoute();
const auth = useAuthStore();
const canManageNoteFields = computed(() => canManageSettings(auth.user?.role));
const loading = ref(false);
const saving = ref(false);
@@ -74,8 +81,11 @@ const draftAnalyze = ref(true);
const draftPinned = ref(false);
const draftVisibility = ref<NoteVisibility>('team');
const draftChecklist = ref<NoteChecklistItemDto[]>([]);
const draftCustomFields = ref<Record<string, unknown>>({});
const draftFiles = ref<File[]>([]);
const existingAttachments = ref<NoteAttachmentDto[]>([]);
const noteFieldDefs = ref<CustomFieldDefinitionDto[]>([]);
const fieldsOpen = ref(false);
const historyOpen = ref(false);
const historyLoading = ref(false);
@@ -229,6 +239,28 @@ function previewBody(body: string) {
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) {
return att.mimeType.startsWith('image/');
}
@@ -383,6 +415,7 @@ function resetDraft() {
draftPinned.value = false;
draftVisibility.value = 'team';
draftChecklist.value = [];
draftCustomFields.value = {};
draftFiles.value = [];
existingAttachments.value = [];
showChecklistEditor.value = false;
@@ -408,6 +441,7 @@ function openEditor(mode: OpenMode = 'default', note?: NoteDto) {
draftVisibility.value =
note.visibility === 'personal' ? 'personal' : 'team';
draftChecklist.value = [...(note.checklist ?? [])];
draftCustomFields.value = { ...(note.customFields ?? {}) };
draftFiles.value = [];
existingAttachments.value = [...note.attachments];
showChecklistEditor.value = (note.checklist?.length ?? 0) > 0;
@@ -503,6 +537,16 @@ async function saveNote() {
error.value = 'متن یادداشت یا چک‌لیست لازم است.';
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;
error.value = '';
try {
@@ -523,6 +567,7 @@ async function saveNote() {
analyzeEnabled: draftAnalyze.value,
pinned: draftPinned.value,
checklist,
customFields: draftCustomFields.value,
};
const pending = [...draftFiles.value];
let noteId = editingId.value;
@@ -581,6 +626,9 @@ async function openHistory(note: NoteDto) {
}
useEscClose(() => editorOpen.value, () => closeEditor());
useEscClose(() => fieldsOpen.value, () => {
fieldsOpen.value = false;
});
useEscClose(() => moreSheetOpen.value, () => { moreSheetOpen.value = false; });
useEscClose(() => historyOpen.value, () => closeHistory());
@@ -683,6 +731,7 @@ onMounted(() => {
}
void load();
void loadActivities();
void loadNoteFields();
});
onBeforeUnmount(() => {
@@ -699,6 +748,14 @@ onBeforeUnmount(() => {
<h1>یادداشت‌ها</h1>
<p class="lead">فکر کنید، یادداشت کنید، هیچ چیز را فراموش نکنید.</p>
</div>
<button
v-if="canManageNoteFields"
type="button"
class="fields-manage"
@click="fieldsOpen = true"
>
فیلدهای یادداشت
</button>
</header>
<p v-if="error" class="banner-error">{{ error }}</p>
@@ -921,6 +978,11 @@ onBeforeUnmount(() => {
</li>
</ul>
<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">
<img
@@ -1067,6 +1129,7 @@ onBeforeUnmount(() => {
</header>
<div class="panel-scroll">
<p v-if="error" class="banner-error">{{ error }}</p>
<input
v-model="draftTitle"
class="title-input"
@@ -1237,6 +1300,7 @@ onBeforeUnmount(() => {
<p>پس از ذخیره، پیشنهاد کار بعدی و حافظه مشتری استخراج می‌شود.</p>
</div>
</label>
<NoteCustomFields v-model="draftCustomFields" :fields="noteFieldDefs" />
</div>
<div class="chip-summary mobile-only-flex">
@@ -1379,6 +1443,7 @@ onBeforeUnmount(() => {
<p>پس از ذخیره اجرا می‌شود.</p>
</div>
</label>
<NoteCustomFields v-model="draftCustomFields" :fields="noteFieldDefs" />
<button type="button" class="btn-primary sheet-done" @click="moreSheetOpen = false">
تأیید
</button>
@@ -1388,6 +1453,12 @@ onBeforeUnmount(() => {
</div>
</Teleport>
<NoteFieldsManager
v-if="fieldsOpen"
@close="fieldsOpen = false"
@saved="loadNoteFields"
/>
<Teleport to="body">
<div v-if="historyOpen" class="history-root">
<div class="history-backdrop" aria-hidden="true" />
@@ -1460,6 +1531,12 @@ onBeforeUnmount(() => {
padding: 0;
}
.page-head {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 0.75rem;
}
.page-head h1 {
margin: 0;
font-size: 1.55rem;
@@ -1471,6 +1548,29 @@ onBeforeUnmount(() => {
color: #64748b;
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 {
margin: 0.75rem 0 0;