feat(notes): let organizations edit the note category bar
The filter chips were fixed labels. Owners can rename, hide, reorder, and add categories. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,204 @@
|
||||
<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 { NoteCategoryDto, NoteCategoryTone } from '@mento/shared';
|
||||
|
||||
const emit = defineEmits<{
|
||||
close: [];
|
||||
saved: [];
|
||||
}>();
|
||||
|
||||
const tones: Array<{ value: NoteCategoryTone; label: string }> = [
|
||||
{ value: 'general', label: 'معمولی' },
|
||||
{ value: 'follow_up', label: 'پیگیری' },
|
||||
{ value: 'idea', label: 'ایده' },
|
||||
{ value: 'suggestion', label: 'پیشنهاد' },
|
||||
{ value: 'meeting', label: 'جلسه' },
|
||||
{ value: 'personal', label: 'شخصی' },
|
||||
];
|
||||
|
||||
const loading = ref(false);
|
||||
const saving = ref(false);
|
||||
const error = ref('');
|
||||
const items = ref<NoteCategoryDto[]>([]);
|
||||
const label = ref('');
|
||||
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
items.value = (await api.get<NoteCategoryDto[]>('/notes/categories')).data;
|
||||
} catch {
|
||||
error.value = 'بارگذاری دستهها ناموفق بود.';
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function createCategory() {
|
||||
if (!label.value.trim()) {
|
||||
error.value = 'عنوان دسته را وارد کنید.';
|
||||
return;
|
||||
}
|
||||
saving.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
await api.post('/notes/categories', { label: label.value.trim(), showInBar: true });
|
||||
label.value = '';
|
||||
await load();
|
||||
emit('saved');
|
||||
} catch (e) {
|
||||
error.value = axios.isAxiosError(e)
|
||||
? 'ثبت دسته ناموفق بود.'
|
||||
: 'ثبت دسته ناموفق بود.';
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function patch(item: NoteCategoryDto, data: Partial<NoteCategoryDto>) {
|
||||
error.value = '';
|
||||
try {
|
||||
await api.patch(`/notes/categories/${item.id}`, data);
|
||||
await load();
|
||||
emit('saved');
|
||||
} catch {
|
||||
error.value = 'ذخیره دسته ناموفق بود.';
|
||||
}
|
||||
}
|
||||
|
||||
async function move(index: number, dir: -1 | 1) {
|
||||
const next = index + dir;
|
||||
if (next < 0 || next >= items.value.length) return;
|
||||
const ids = items.value.map((item) => item.id);
|
||||
const [picked] = ids.splice(index, 1);
|
||||
if (!picked) return;
|
||||
ids.splice(next, 0, picked);
|
||||
try {
|
||||
items.value = (await api.patch<NoteCategoryDto[]>('/notes/categories/reorder', { ids })).data;
|
||||
emit('saved');
|
||||
} catch {
|
||||
error.value = 'جابهجایی ناموفق بود.';
|
||||
}
|
||||
}
|
||||
|
||||
async function remove(item: NoteCategoryDto) {
|
||||
if (!confirm(`دسته «${item.label}» حذف شود؟`)) return;
|
||||
try {
|
||||
await api.delete(`/notes/categories/${item.id}`);
|
||||
await load();
|
||||
emit('saved');
|
||||
} catch {
|
||||
error.value = 'این دستهٔ پیشفرض حذف نمیشود. از نوار پنهانش کنید.';
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(load);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="cat-root">
|
||||
<div class="cat-backdrop" @click="emit('close')" />
|
||||
<aside class="cat-panel" role="dialog" aria-label="دستههای یادداشت">
|
||||
<header class="cat-head">
|
||||
<h2>دستههای نوار یادداشت</h2>
|
||||
<button type="button" class="icon-btn" @click="emit('close')">
|
||||
<UiIcon name="x" :size="20" />
|
||||
</button>
|
||||
</header>
|
||||
<div class="cat-scroll">
|
||||
<p class="hint">همین عنوانها در نوار بالای یادداشتها دیده میشوند. «همه»، «تیمی» و «فقط من» ثابتاند.</p>
|
||||
<p v-if="error" class="banner-error">{{ error }}</p>
|
||||
<form class="create-form" @submit.prevent="createCategory">
|
||||
<input v-model="label" type="text" placeholder="دسته جدید، مثلاً قرارداد" />
|
||||
<button type="submit" class="btn-primary" :disabled="saving">افزودن</button>
|
||||
</form>
|
||||
<p v-if="loading" class="hint">در حال بارگذاری…</p>
|
||||
<ul v-else class="cat-list">
|
||||
<li v-for="(item, index) in items" :key="item.id">
|
||||
<input
|
||||
:value="item.label"
|
||||
type="text"
|
||||
@change="patch(item, { label: ($event.target as HTMLInputElement).value })"
|
||||
/>
|
||||
<select
|
||||
:value="item.tone"
|
||||
@change="patch(item, { tone: ($event.target as HTMLSelectElement).value })"
|
||||
>
|
||||
<option v-for="tone in tones" :key="tone.value" :value="tone.value">
|
||||
{{ tone.label }}
|
||||
</option>
|
||||
</select>
|
||||
<label class="check-line">
|
||||
<input
|
||||
type="checkbox"
|
||||
:checked="item.showInBar && item.isActive"
|
||||
@change="patch(item, { showInBar: ($event.target as HTMLInputElement).checked, isActive: true })"
|
||||
/>
|
||||
<span>در نوار</span>
|
||||
</label>
|
||||
<div class="row-actions">
|
||||
<button type="button" :disabled="index === 0" @click="move(index, -1)">بالا</button>
|
||||
<button type="button" :disabled="index === items.length - 1" @click="move(index, 1)">پایین</button>
|
||||
<button v-if="!item.isSystem" type="button" class="danger" @click="remove(item)">حذف</button>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.cat-root { position: fixed; inset: 0; z-index: 140; }
|
||||
.cat-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, 0.35); }
|
||||
.cat-panel {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
width: min(460px, 100%);
|
||||
background: #fff;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
box-shadow: 0 12px 40px rgba(15, 23, 42, 0.18);
|
||||
}
|
||||
.cat-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 0.9rem 1rem;
|
||||
border-bottom: 1px solid #e2e8f0;
|
||||
}
|
||||
.cat-head h2 { margin: 0; font-size: 1.05rem; }
|
||||
.cat-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; }
|
||||
.create-form { display: flex; gap: 0.45rem; }
|
||||
.create-form input, .cat-list input, .cat-list select {
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: 10px;
|
||||
padding: 0.45rem 0.55rem;
|
||||
font-size: 0.9rem;
|
||||
color: #0f172a;
|
||||
background: #fff;
|
||||
}
|
||||
.create-form input { flex: 1; }
|
||||
.btn-primary, .row-actions button, .icon-btn { border: 0; cursor: pointer; }
|
||||
.btn-primary { background: #0f766e; color: #fff; border-radius: 10px; padding: 0.45rem 0.8rem; font-weight: 700; }
|
||||
.icon-btn { background: transparent; color: #64748b; }
|
||||
.cat-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.55rem; }
|
||||
.cat-list li {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1.4fr) minmax(0, 0.8fr) auto;
|
||||
gap: 0.4rem;
|
||||
align-items: center;
|
||||
}
|
||||
.row-actions { grid-column: 1 / -1; display: flex; gap: 0.35rem; }
|
||||
.row-actions button { background: #f8fafc; color: #334155; border-radius: 8px; padding: 0.3rem 0.5rem; }
|
||||
.row-actions button:disabled { opacity: 0.4; }
|
||||
.row-actions .danger { color: #b91c1c; }
|
||||
.check-line { display: flex; align-items: center; gap: 0.3rem; font-size: 0.8rem; color: #334155; white-space: nowrap; }
|
||||
</style>
|
||||
@@ -1,313 +0,0 @@
|
||||
<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>
|
||||
Reference in New Issue
Block a user