Add optional activity experience on leads and people with form mapping and filters.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-19 21:04:43 +03:30
co-authored by Cursor
parent e90f9f9538
commit a455ab71ab
19 changed files with 430 additions and 20 deletions
@@ -0,0 +1,11 @@
-- AlterTable
ALTER TABLE "Lead" ADD COLUMN "activityExperience" TEXT;
-- AlterTable
ALTER TABLE "Person" ADD COLUMN "activityExperience" TEXT;
-- CreateIndex
CREATE INDEX "Lead_organizationId_activityExperience_idx" ON "Lead"("organizationId", "activityExperience");
-- CreateIndex
CREATE INDEX "Person_organizationId_activityExperience_idx" ON "Person"("organizationId", "activityExperience");
+6
View File
@@ -656,6 +656,8 @@ model Person {
birthDate DateTime?
/// نام معرف
referrer String?
/// سابقه فعالیت (ندارم | 1 الی 2 سال | 2 الی 5 سال | بیش از 5 سال)
activityExperience String?
/// لیست آدرس‌ها (JSON array of strings)
addresses Json @default("[]")
notes String?
@@ -710,6 +712,7 @@ model Person {
@@index([ownerId])
@@index([loyaltyTierId])
@@index([organizationId, discLabel])
@@index([organizationId, activityExperience])
}
model Pipeline {
@@ -3158,6 +3161,8 @@ model Lead {
/// صنف
trade String?
source String?
/// سابقه فعالیت (ندارم | 1 الی 2 سال | 2 الی 5 سال | بیش از 5 سال)
activityExperience String?
notes String?
/// لوگوی فروشگاه / شرکت
logoStorageKey String?
@@ -3195,6 +3200,7 @@ model Lead {
@@index([organizationId, city])
@@index([organizationId, trade])
@@index([organizationId, source])
@@index([organizationId, activityExperience])
}
model LeadEvent {
+16
View File
@@ -100,6 +100,12 @@ export class ListQueryDto {
@IsString()
@MaxLength(2000)
groupId?: string;
/** فیلتر سابقه فعالیت؛ چندتایی با کاما */
@IsOptional()
@IsString()
@MaxLength(400)
activityExperience?: string;
}
class CompanyExtraFieldsDto {
@@ -360,6 +366,11 @@ export class CreatePersonDto {
@MaxLength(120)
referrer?: string;
@IsOptional()
@IsString()
@MaxLength(80)
activityExperience?: string | null;
@IsOptional()
@IsArray()
@IsString({ each: true })
@@ -486,6 +497,11 @@ export class UpdatePersonDto {
@MaxLength(120)
referrer?: string;
@IsOptional()
@IsString()
@MaxLength(80)
activityExperience?: string | null;
@IsOptional()
@IsArray()
@IsString({ each: true })
@@ -63,6 +63,7 @@ export class PeopleController {
hasMobile,
disc: query.disc,
groupId: query.groupId,
activityExperience: query.activityExperience,
},
);
}
@@ -81,6 +82,7 @@ export class PeopleController {
hasMobile,
disc: query.disc,
groupId: query.groupId,
activityExperience: query.activityExperience,
});
}
+18
View File
@@ -23,6 +23,7 @@ import {
PERSON_MOODS,
applyPersonGenderTitle,
canViewAllRecords,
normalizeActivityExperience,
splitPersonHonorific,
} from '@mento/shared';
import { Prisma } from '@prisma/client';
@@ -102,6 +103,7 @@ type PersonRow = {
instagram: string | null;
birthDate: Date | null;
referrer: string | null;
activityExperience: string | null;
addresses: unknown;
notes: string | null;
mood: PersonMood;
@@ -174,6 +176,7 @@ export class PeopleService implements OnModuleInit {
hasMobile?: boolean;
disc?: string;
groupId?: string;
activityExperience?: string;
},
): Prisma.PersonWhereInput {
const sources = [...new Set(splitCsv(opts?.importSource).map(normalizePersonImportSource))];
@@ -181,6 +184,7 @@ export class PeopleService implements OnModuleInit {
(PERSON_MOODS as readonly string[]).includes(m),
);
const groupIds = splitCsv(opts?.groupId);
const experiences = splitCsv(opts?.activityExperience);
const search = buildSearchWhere<Prisma.PersonWhereInput>(q, (t) => [
{ firstName: ci(t) },
{ lastName: ci(t) },
@@ -231,6 +235,9 @@ export class PeopleService implements OnModuleInit {
if (sources.length) {
facets.push({ importSource: { in: sources } });
}
if (experiences.length) {
facets.push({ activityExperience: { in: experiences } });
}
if (facets.length === 1) and.push(facets[0]!);
else if (facets.length > 1) and.push({ OR: facets });
return {
@@ -258,6 +265,7 @@ export class PeopleService implements OnModuleInit {
hasMobile?: boolean;
disc?: string;
groupId?: string;
activityExperience?: string;
},
): Promise<PaginatedResponse<PersonDto>> {
const seeDisc = await this.behaviorAccess.canView(actor);
@@ -296,6 +304,7 @@ export class PeopleService implements OnModuleInit {
hasMobile?: boolean;
disc?: string;
groupId?: string;
activityExperience?: string;
},
max = FILTERED_IDS_MAX,
): Promise<FilteredIdsResponse> {
@@ -475,6 +484,9 @@ export class PeopleService implements OnModuleInit {
instagram: emptyToNull(dto.instagram),
birthDate: parseBirthDate(dto.birthDate),
referrer: emptyToNull(dto.referrer),
activityExperience:
normalizeActivityExperience(dto.activityExperience) ??
emptyToNull(dto.activityExperience),
addresses: toJsonAddresses(dto.addresses),
notes: emptyToNull(dto.notes),
mood: dto.mood ?? 'newcomer',
@@ -587,6 +599,11 @@ export class PeopleService implements OnModuleInit {
if ('instagram' in dto) data.instagram = emptyToNull(dto.instagram);
if ('birthDate' in dto) data.birthDate = parseBirthDate(dto.birthDate);
if ('referrer' in dto) data.referrer = emptyToNull(dto.referrer);
if ('activityExperience' in dto) {
data.activityExperience =
normalizeActivityExperience(dto.activityExperience) ??
emptyToNull(dto.activityExperience);
}
if ('addresses' in dto) data.addresses = toJsonAddresses(dto.addresses);
if ('notes' in dto) data.notes = emptyToNull(dto.notes);
if (dto.mood !== undefined) data.mood = dto.mood;
@@ -1022,6 +1039,7 @@ export class PeopleService implements OnModuleInit {
instagram: row.instagram,
birthDate: row.birthDate?.toISOString() ?? null,
referrer: row.referrer,
activityExperience: row.activityExperience,
addresses: (() => {
const fromCol = asAddresses(row.addresses);
if (fromCol.length) return fromCol;
+2
View File
@@ -30,9 +30,11 @@ const MAP_TO = [
'lead.city',
'lead.region',
'lead.trade',
'lead.activityExperience',
'lead.notes',
'lead.source',
'lead.gender',
'person.activityExperience',
'person.gender',
'notes',
'custom',
+31 -2
View File
@@ -13,7 +13,12 @@ import type {
SubmitLeadFormResponse,
UpdateLeadFormRequest,
} from '@mento/shared';
import { isGenderQuestionLabel, parsePersonGenderAnswer } from '@mento/shared';
import {
isActivityExperienceLabel,
isGenderQuestionLabel,
normalizeActivityExperience,
parsePersonGenderAnswer,
} from '@mento/shared';
import { Prisma } from '@prisma/client';
import { PrismaService } from '../prisma/prisma.service';
import { LocalFileStorage } from '../storage/local-file.storage';
@@ -569,6 +574,9 @@ export class LeadFormsService {
region: emptyToNull(mapped.region) ?? existingLead.region,
trade: emptyToNull(mapped.trade) ?? existingLead.trade,
source: source ?? existingLead.source,
activityExperience:
emptyToNull(mapped.activityExperience) ??
existingLead.activityExperience,
notes: emptyToNull(mapped.notes) ?? existingLead.notes,
...(mapped.gender ? { gender: mapped.gender } : {}),
assigneeId: existingLead.assigneeId ?? assigneeId,
@@ -620,6 +628,7 @@ export class LeadFormsService {
region: emptyToNull(mapped.region),
trade: emptyToNull(mapped.trade),
source,
activityExperience: emptyToNull(mapped.activityExperience),
notes: emptyToNull(mapped.notes),
gender: mapped.gender ?? 'none',
stageId,
@@ -684,6 +693,8 @@ export class LeadFormsService {
phone: phone ?? existing.phone,
position: emptyToNull(mapped.position) ?? existing.position,
notes: emptyToNull(mapped.notes) ?? existing.notes,
activityExperience:
emptyToNull(mapped.activityExperience) ?? existing.activityExperience,
...(mapped.gender ? { gender: mapped.gender } : {}),
ownerId: existing.ownerId ?? ownerId,
},
@@ -701,6 +712,7 @@ export class LeadFormsService {
phone,
position: emptyToNull(mapped.position),
notes: emptyToNull(mapped.notes),
activityExperience: emptyToNull(mapped.activityExperience),
gender: mapped.gender ?? 'none',
ownerId,
},
@@ -964,6 +976,7 @@ type MappedValues = {
city?: string;
region?: string;
trade?: string;
activityExperience?: string;
leadSource?: string;
gender?: 'male' | 'female' | 'none';
};
@@ -995,6 +1008,15 @@ function mapValues(
if (gender) mapped.gender = gender;
continue;
}
if (
field.mapTo === 'lead.activityExperience' ||
field.mapTo === 'person.activityExperience' ||
isActivityExperienceLabel(field.label)
) {
mapped.activityExperience =
normalizeActivityExperience(raw) ?? raw;
continue;
}
switch (field.mapTo) {
case 'person.fullName': {
const parts = raw.split(/\s+/).filter(Boolean);
@@ -1048,6 +1070,11 @@ function mapValues(
case 'lead.trade':
mapped.trade = raw;
break;
case 'lead.activityExperience':
case 'person.activityExperience':
mapped.activityExperience =
normalizeActivityExperience(raw) ?? raw;
break;
case 'lead.notes':
mapped.notes = raw;
break;
@@ -1118,7 +1145,9 @@ function collectExtras(
for (const field of fields) {
if (field.fieldType === 'heading' || field.mapTo !== 'custom') continue;
const raw = (values?.[field.key] ?? '').toString().trim();
if (!raw || (isGenderQuestionLabel(field.label) && parsePersonGenderAnswer(raw))) continue;
if (!raw) continue;
if (isGenderQuestionLabel(field.label) && parsePersonGenderAnswer(raw)) continue;
if (isActivityExperienceLabel(field.label)) continue;
lines.push(`${field.label}: ${raw}`);
}
return lines.join('\n');
+2
View File
@@ -37,6 +37,7 @@ export class CreateLeadDto {
@IsOptional() @IsArray() @IsString({ each: true }) addresses?: string[];
@IsOptional() @IsString() trade?: string;
@IsOptional() @IsString() source?: string;
@IsOptional() @IsString() activityExperience?: string | null;
@IsOptional() @IsString() notes?: string;
@IsOptional() @IsNumber() estimatedValue?: number;
@IsOptional() @IsString() stageId?: string;
@@ -60,6 +61,7 @@ export class UpdateLeadDto {
@IsOptional() @IsArray() @IsString({ each: true }) addresses?: string[];
@IsOptional() @IsString() trade?: string | null;
@IsOptional() @IsString() source?: string | null;
@IsOptional() @IsString() activityExperience?: string | null;
@IsOptional() @IsString() notes?: string | null;
@IsOptional() @IsNumber() estimatedValue?: number | null;
@IsOptional() @IsString() stageId?: string;
+4
View File
@@ -249,6 +249,7 @@ export class LeadsController {
@Query('region') region?: string,
@Query('trade') trade?: string,
@Query('source') source?: string,
@Query('activityExperience') activityExperience?: string,
@Query('unassigned') unassigned?: string,
@Query('archived') archived?: string,
@Query('converted') converted?: string,
@@ -265,6 +266,7 @@ export class LeadsController {
region,
trade,
source,
activityExperience,
unassigned: unassigned === '1' || unassigned === 'true',
archived: archived === '1' || archived === 'true',
converted: converted === '1' || converted === 'true',
@@ -287,6 +289,7 @@ export class LeadsController {
@Query('region') region?: string,
@Query('trade') trade?: string,
@Query('source') source?: string,
@Query('activityExperience') activityExperience?: string,
@Query('unassigned') unassigned?: string,
@Query('archived') archived?: string,
@Query('converted') converted?: string,
@@ -306,6 +309,7 @@ export class LeadsController {
region,
trade,
source,
activityExperience,
unassigned: unassigned === '1' || unassigned === 'true',
archived: archived === '1' || archived === 'true',
converted: converted === '1' || converted === 'true',
+44 -6
View File
@@ -20,7 +20,11 @@ import type {
PaginatedResponse,
} from '@mento/shared';
import { FILTERED_IDS_MAX } from '@mento/shared';
import { applyLeadGenderName, applyPersonGenderTitle } from '@mento/shared';
import {
applyLeadGenderName,
applyPersonGenderTitle,
normalizeActivityExperience,
} from '@mento/shared';
import { PrismaService } from '../prisma/prisma.service';
import { SmsGatewayService } from '../sms-billing/sms-gateway.service';
import { renderSmsText } from '../common/sms-text';
@@ -119,6 +123,7 @@ const boardLeadSelect = {
birthDate: true,
trade: true,
source: true,
activityExperience: true,
logoStorageKey: true,
estimatedValue: true,
stageId: true,
@@ -177,6 +182,7 @@ export class LeadsService {
region?: string;
trade?: string;
source?: string;
activityExperience?: string;
unassigned?: boolean;
archived?: boolean;
converted?: boolean;
@@ -196,6 +202,7 @@ export class LeadsService {
{ trade: ci(t) },
{ instagram: ci(t) },
{ source: ci(t) },
{ activityExperience: ci(t) },
]);
const and: Prisma.LeadWhereInput[] = [];
if (search) and.push(search);
@@ -222,6 +229,9 @@ export class LeadsService {
...(opts.source
? { source: { contains: opts.source, mode: 'insensitive' } }
: {}),
...(opts.activityExperience
? { activityExperience: opts.activityExperience }
: {}),
},
...(opts.unassigned ? [{ assigneeId: null }] : []),
...(opts.assigneeId && !opts.unassigned ? [{ assigneeId: opts.assigneeId }] : []),
@@ -288,6 +298,7 @@ export class LeadsService {
region?: string;
trade?: string;
source?: string;
activityExperience?: string;
unassigned?: boolean;
archived?: boolean;
converted?: boolean;
@@ -341,6 +352,7 @@ export class LeadsService {
region?: string;
trade?: string;
source?: string;
activityExperience?: string;
unassigned?: boolean;
archived?: boolean;
converted?: boolean;
@@ -492,6 +504,7 @@ export class LeadsService {
addresses?: string[];
trade?: string | null;
source?: string | null;
activityExperience?: string | null;
notes?: string | null;
estimatedValue?: number | null;
stageId?: string;
@@ -553,6 +566,9 @@ export class LeadsService {
addresses: toJsonAddresses(dto.addresses),
trade: emptyToNull(dto.trade),
source: emptyToNull(dto.source),
activityExperience:
normalizeActivityExperience(dto.activityExperience) ??
emptyToNull(dto.activityExperience),
notes: emptyToNull(dto.notes),
estimatedValue:
dto.estimatedValue != null
@@ -684,6 +700,13 @@ export class LeadsService {
...(dto.source !== undefined
? { source: emptyToNull(dto.source as string) }
: {}),
...(dto.activityExperience !== undefined
? {
activityExperience:
normalizeActivityExperience(dto.activityExperience as string | null) ??
emptyToNull(dto.activityExperience as string),
}
: {}),
...(dto.notes !== undefined
? { notes: emptyToNull(dto.notes as string) }
: {}),
@@ -1194,6 +1217,7 @@ export class LeadsService {
]
.filter(Boolean)
.join('\n'),
activityExperience: lead.activityExperience,
ownerId: lead.assigneeId ?? actor.userId,
createdAt: lead.createdAt,
importSource: 'lead_form',
@@ -1201,11 +1225,23 @@ export class LeadsService {
},
});
createdPerson = true;
} else if (!person.birthDate && lead.birthDate) {
await this.prisma.person.update({
where: { id: person.id },
data: { birthDate: lead.birthDate },
});
} else {
const personPatch: {
birthDate?: Date | null;
activityExperience?: string | null;
} = {};
if (!person.birthDate && lead.birthDate) {
personPatch.birthDate = lead.birthDate;
}
if (!person.activityExperience && lead.activityExperience) {
personPatch.activityExperience = lead.activityExperience;
}
if (Object.keys(personPatch).length) {
await this.prisma.person.update({
where: { id: person.id },
data: personPatch,
});
}
}
const convertedStage = await this.prisma.leadStage.findFirst({
@@ -1626,6 +1662,7 @@ export class LeadsService {
addresses: asAddresses(row.addresses),
trade: row.trade,
source: row.source,
activityExperience: row.activityExperience,
notes: row.notes,
estimatedValue:
row.estimatedValue != null ? Number(row.estimatedValue) : null,
@@ -1668,6 +1705,7 @@ export class LeadsService {
addresses: [],
trade: row.trade,
source: row.source,
activityExperience: row.activityExperience,
notes: null,
estimatedValue:
row.estimatedValue != null ? Number(row.estimatedValue) : null,
@@ -1,6 +1,7 @@
<script setup lang="ts">
import { computed, onBeforeUnmount, onMounted, reactive, ref, watch } from 'vue';
import type { CustomerGroupDto, PersonImportSourceStatDto, PersonMood } from '@mento/shared';
import { ACTIVITY_EXPERIENCE_OPTIONS } from '@mento/shared';
import { PERSON_MOOD_LABELS, PERSON_MOODS } from '@/lib/person-mood';
import { groupSwatch } from '@/lib/customer-groups';
import { toFaDigits } from '@/lib/jalali';
@@ -12,6 +13,7 @@ export type ContactsFilterValue = {
sources: string[];
moods: PersonMood[];
disc: string;
activityExperiences: string[];
};
const props = defineProps<{
@@ -33,7 +35,13 @@ const emit = defineEmits<{
close: [];
}>();
const draft = reactive<ContactsFilterValue>({ groups: [], sources: [], moods: [], disc: '' });
const draft = reactive<ContactsFilterValue>({
groups: [],
sources: [],
moods: [],
disc: '',
activityExperiences: [],
});
const draftSort = ref('');
const groupQuery = ref('');
const GROUP_SEARCH_MIN = 8;
@@ -50,6 +58,7 @@ watch(
draft.sources = [...props.value.sources];
draft.moods = [...props.value.moods];
draft.disc = props.value.disc;
draft.activityExperiences = [...(props.value.activityExperiences ?? [])];
draftSort.value = props.sort ?? defaultSort.value;
groupQuery.value = '';
},
@@ -77,7 +86,12 @@ const filteredGroups = computed(() => {
const draftCount = computed(
() =>
draft.groups.length +
(isPeople.value ? draft.sources.length + draft.moods.length + (draft.disc ? 1 : 0) : 0) +
(isPeople.value
? draft.sources.length +
draft.moods.length +
draft.activityExperiences.length +
(draft.disc ? 1 : 0)
: 0) +
(hasSort.value && draftSort.value !== defaultSort.value ? 1 : 0),
);
@@ -92,6 +106,7 @@ function clearAll() {
draft.sources = [];
draft.moods = [];
draft.disc = '';
draft.activityExperiences = [];
if (hasSort.value) draftSort.value = defaultSort.value;
}
@@ -103,6 +118,7 @@ function apply() {
sources: [...draft.sources],
moods: [...draft.moods],
disc: draft.disc,
activityExperiences: [...draft.activityExperiences],
},
hasSort.value ? draftSort.value : undefined,
);
@@ -210,6 +226,27 @@ function apply() {
</div>
</section>
<section class="sec">
<h4>
سابقه فعالیت
<span v-if="draft.activityExperiences.length" class="sel">
{{ toFaDigits(draft.activityExperiences.length) }} انتخاب
</span>
</h4>
<div class="pills">
<button
v-for="item in ACTIVITY_EXPERIENCE_OPTIONS"
:key="item"
type="button"
class="pill"
:class="{ on: draft.activityExperiences.includes(item) }"
@click="toggle(draft.activityExperiences, item)"
>
{{ item }}
</button>
</div>
</section>
<section v-if="canBehavior" class="sec">
<h4>تیپ DISC</h4>
<div class="pills">
+6
View File
@@ -129,6 +129,12 @@ export function isBirthDateAnswer(label: string): boolean {
return label.trim() === 'تاریخ تولد';
}
/** فیلد سابقه فعالیت روی خود لید/مشتری هست؛ جواب فرم نباید دوباره ردیف بسازد. */
export function isActivityExperienceAnswer(label: string): boolean {
const text = label.trim().replace(/ي/g, 'ی').replace(/ك/g, 'ک');
return /سابقه\s*فعالیت/.test(text);
}
function parseAnswerLine(line: string): LeadNoteRow | null {
const splitAt = line.indexOf(':');
if (splitAt <= 0 || splitAt > 200) return null;
+39 -5
View File
@@ -81,6 +81,7 @@ const discFilter = computed(() => {
return /^[DISC](\/[DISC]){0,3}$/.test(value) ? value : '';
});
const sourceFilters = computed(() => queryList('source'));
const activityExperienceFilters = computed(() => queryList('activityExperience'));
const groupFilters = computed(() => queryList('group'));
const { groups: customerGroups, load: loadCustomerGroups } = useCustomerGroups();
/** گروه‌های فیلتر — با شمارش scoped بر اساس دسترسی کاربر */
@@ -93,9 +94,15 @@ const filterValue = computed<ContactsFilterValue>(() => ({
sources: sourceFilters.value,
moods: moodFilters.value,
disc: discFilter.value,
activityExperiences: activityExperienceFilters.value,
}));
type FilterTag = { kind: 'group' | 'source' | 'mood' | 'disc'; value: string; label: string; color?: string };
type FilterTag = {
kind: 'group' | 'source' | 'mood' | 'disc' | 'activityExperience';
value: string;
label: string;
color?: string;
};
const activeTags = computed<FilterTag[]>(() => {
const tags: FilterTag[] = groupFilters.value.map((id) => {
const g =
@@ -110,6 +117,9 @@ const activeTags = computed<FilterTag[]>(() => {
for (const m of moodFilters.value) {
tags.push({ kind: 'mood', value: m, label: moodLabel(m) });
}
for (const exp of activityExperienceFilters.value) {
tags.push({ kind: 'activityExperience', value: exp, label: `سابقه: ${exp}` });
}
if (discFilter.value) tags.push({ kind: 'disc', value: discFilter.value, label: `DISC: ${discFilter.value}` });
return tags;
});
@@ -208,6 +218,8 @@ const peopleSavedFilters = computed(() => {
if (mood) out.mood = mood;
const source = csv(sourceFilters.value);
if (source) out.source = source;
const activityExperience = csv(activityExperienceFilters.value);
if (activityExperience) out.activityExperience = activityExperience;
if (discFilter.value) out.disc = discFilter.value;
const group = csv(groupFilters.value);
if (group) out.group = group;
@@ -230,7 +242,7 @@ function applyPeopleSavedFilters(filters: Record<string, unknown>) {
// کلیدهای فیلتر را از نو می‌سازیم تا فیلتر قبلی روی صفحه نماند
const query: Record<string, string | string[]> = {};
for (const [key, value] of Object.entries(route.query)) {
if (['q', 'sort', 'mood', 'source', 'disc', 'group', 'page', 'tab'].includes(key)) continue;
if (['q', 'sort', 'mood', 'source', 'activityExperience', 'disc', 'group', 'page', 'tab'].includes(key)) continue;
if (value == null || value === '') continue;
if (Array.isArray(value)) {
const list = value.filter((v): v is string => typeof v === 'string' && v !== '');
@@ -245,6 +257,8 @@ function applyPeopleSavedFilters(filters: Record<string, unknown>) {
if (mood) query.mood = mood;
const source = savedCsv(filters.source);
if (source) query.source = source;
const activityExperience = savedCsv(filters.activityExperience);
if (activityExperience) query.activityExperience = activityExperience;
const disc = savedCsv(filters.disc);
if (disc) query.disc = disc;
const group = savedCsv(filters.group);
@@ -317,6 +331,7 @@ async function load() {
sort: sort.value,
mood: csv(moodFilters.value),
importSource: csv(sourceFilters.value),
activityExperience: csv(activityExperienceFilters.value),
disc: discFilter.value || undefined,
groupId: csv(groupFilters.value),
},
@@ -391,7 +406,12 @@ function applyFilters(next: ContactsFilterValue, nextSort?: string) {
patchQuery({
group: csv(next.groups),
...(people
? { source: csv(next.sources), mood: csv(next.moods), disc: next.disc || undefined }
? {
source: csv(next.sources),
mood: csv(next.moods),
activityExperience: csv(next.activityExperiences),
disc: next.disc || undefined,
}
: {}),
// در موبایل مرتب‌سازی داخل همان شیت فیلتر است؛ یک patch تا query قبلی overwrite نشود
...(nextSort !== undefined
@@ -421,13 +441,25 @@ function removeTag(tag: FilterTag) {
if (tag.kind === 'group') patchQuery({ group: without(groupFilters.value), page: undefined });
else if (tag.kind === 'source') patchQuery({ source: without(sourceFilters.value), page: undefined });
else if (tag.kind === 'mood') patchQuery({ mood: without(moodFilters.value), page: undefined });
else patchQuery({ disc: undefined, page: undefined });
else if (tag.kind === 'activityExperience') {
patchQuery({
activityExperience: without(activityExperienceFilters.value),
page: undefined,
});
} else patchQuery({ disc: undefined, page: undefined });
}
function clearFilters() {
patchQuery({
group: undefined,
...(tab.value === 'people' ? { source: undefined, mood: undefined, disc: undefined } : {}),
...(tab.value === 'people'
? {
source: undefined,
mood: undefined,
activityExperience: undefined,
disc: undefined,
}
: {}),
page: undefined,
});
}
@@ -923,6 +955,7 @@ onMounted(load);
<th>شرکت</th>
<th>تلفن</th>
<th>ایمیل</th>
<th>سابقه فعالیت</th>
<th>تاریخ ثبت</th>
<th></th>
</tr>
@@ -978,6 +1011,7 @@ onMounted(load);
<UiIcon v-if="p.email" name="mail" :size="14" />
</span>
</td>
<td>{{ p.activityExperience || '—' }}</td>
<td>{{ formatDate(p.createdAt) }}</td>
<td class="ops" @click.stop>
<UiDropdownMenu
+40 -2
View File
@@ -46,7 +46,13 @@ import {
UserAddOutlined,
} from '@ant-design/icons-vue';
import { api } from '@/lib/api';
import { isBirthDateAnswer, leadNoteFileIsImage, parseLeadFormNotes } from '@/lib/lead-form-notes';
import {
isActivityExperienceAnswer,
isBirthDateAnswer,
leadNoteFileIsImage,
parseLeadFormNotes,
} from '@/lib/lead-form-notes';
import { ACTIVITY_EXPERIENCE_OPTIONS } from '@mento/shared';
import {
formatClockFa,
formatJalaliNumeric,
@@ -140,9 +146,15 @@ const editForm = ref({
instagram: '',
birthDate: '',
trade: '',
activityExperience: '' as string,
notes: '',
});
const activityExperienceOptions = [
{ value: '', label: '—' },
...ACTIVITY_EXPERIENCE_OPTIONS.map((value) => ({ value, label: value })),
];
function formatDate(value: string | null | undefined) {
if (!value) return '—';
try {
@@ -160,8 +172,18 @@ const shownBirthDate = computed(() => {
if (lead.value?.birthDate) return formatDate(lead.value.birthDate);
return formBirthDate.value || '—';
});
const formActivityExperience = computed(
() =>
noteView.value.rows.find((row) => isActivityExperienceAnswer(row.label) && !row.file)?.text ??
'',
);
const shownActivityExperience = computed(
() => lead.value?.activityExperience || formActivityExperience.value || '—',
);
const answerRows = computed(() =>
noteView.value.rows.filter((row) => !isBirthDateAnswer(row.label)),
noteView.value.rows.filter(
(row) => !isBirthDateAnswer(row.label) && !isActivityExperienceAnswer(row.label),
),
);
const genderOptions = PERSON_GENDERS.map((key) => ({
@@ -246,6 +268,7 @@ function startEdit() {
? formatLocalDateInput(new Date(lead.value.birthDate))
: '',
trade: lead.value.trade ?? '',
activityExperience: lead.value.activityExperience ?? '',
notes: lead.value.notes ?? '',
};
}
@@ -272,6 +295,7 @@ async function saveEdit() {
instagram: editForm.value.instagram.trim() || null,
birthDate: editForm.value.birthDate || null,
trade: editForm.value.trade.trim() || null,
activityExperience: editForm.value.activityExperience.trim() || null,
notes: editForm.value.notes.trim() || null,
});
okMsg.value = 'لید ویرایش شد.';
@@ -710,6 +734,17 @@ onBeforeUnmount(() => narrowMq?.removeEventListener('change', syncNarrow));
<a-input v-model:value="editForm.trade" style="width: 100%" />
</a-form-item>
</a-col>
<a-col :xs="24" :sm="12" :md="8">
<a-form-item label="سابقه فعالیت">
<a-select
v-model:value="editForm.activityExperience"
allow-clear
placeholder="اختیاری"
style="width: 100%"
:options="activityExperienceOptions"
/>
</a-form-item>
</a-col>
<a-col :span="24">
<a-form-item label="یادداشت">
<a-textarea
@@ -782,6 +817,9 @@ onBeforeUnmount(() => narrowMq?.removeEventListener('change', syncNarrow));
<span dir="ltr">{{ lead.instagram || '—' }}</span>
</a-descriptions-item>
<a-descriptions-item label="صنف">{{ lead.trade || '—' }}</a-descriptions-item>
<a-descriptions-item label="سابقه فعالیت">
{{ shownActivityExperience }}
</a-descriptions-item>
<a-descriptions-item label="منبع">
{{ lead.source || '—' }}
</a-descriptions-item>
@@ -18,6 +18,7 @@ import type {
OrgUserDto,
PipelineDto,
} from '@mento/shared';
import { ACTIVITY_EXPERIENCE_OPTIONS } from '@mento/shared';
import { toFaDigits } from '@/lib/jalali';
import { prepareFormCover } from '@/lib/form-cover';
import { useEscClose } from '@/lib/modal-stack';
@@ -96,6 +97,12 @@ const readyGroups = [
{ label: 'شهر', fieldType: 'text' as const, mapTo: 'lead.city' as const },
{ label: 'منطقه', fieldType: 'text' as const, mapTo: 'lead.region' as const },
{ label: 'صنف', fieldType: 'text' as const, mapTo: 'lead.trade' as const },
{
label: 'سابقه فعالیت',
fieldType: 'select' as const,
mapTo: 'lead.activityExperience' as const,
options: [...ACTIVITY_EXPERIENCE_OPTIONS],
},
{ label: 'توضیحات', fieldType: 'textarea' as const, mapTo: 'lead.notes' as const },
],
},
@@ -105,6 +112,12 @@ const readyGroups = [
{ label: 'نام و نام خانوادگی', fieldType: 'text' as const, mapTo: 'person.fullName' as const },
{ label: 'ایمیل', fieldType: 'email' as const, mapTo: 'person.email' as const },
{ label: 'موبایل', fieldType: 'phone' as const, mapTo: 'person.mobile' as const },
{
label: 'سابقه فعالیت',
fieldType: 'select' as const,
mapTo: 'person.activityExperience' as const,
options: [...ACTIVITY_EXPERIENCE_OPTIONS],
},
],
},
{
@@ -995,6 +1008,7 @@ onMounted(load);
<option value="lead.city">شهر</option>
<option value="lead.region">منطقه</option>
<option value="lead.trade">صنف</option>
<option value="lead.activityExperience">سابقه فعالیت</option>
<option value="lead.notes">یادداشت لید</option>
<option value="lead.source">منبع لید</option>
<option value="lead.gender">جنسیت</option>
@@ -1007,6 +1021,7 @@ onMounted(load);
<option value="person.email">ایمیل</option>
<option value="person.phone">تلفن</option>
<option value="person.position">سمت</option>
<option value="person.activityExperience">سابقه فعالیت</option>
<option value="person.gender">جنسیت شخص</option>
</optgroup>
<optgroup label="معامله">
+51 -2
View File
@@ -84,7 +84,13 @@ import type {
PersonGender,
PaginatedResponse,
} from '@mento/shared';
import { brand, PERSON_GENDERS, PERSON_GENDER_LABELS, splitPersonHonorific } from '@mento/shared';
import {
ACTIVITY_EXPERIENCE_OPTIONS,
brand,
PERSON_GENDERS,
PERSON_GENDER_LABELS,
splitPersonHonorific,
} from '@mento/shared';
const { Title: ATypographyTitle, Text: ATypographyText, Paragraph: ATypographyParagraph } =
Typography;
@@ -158,6 +164,7 @@ const LEAD_COL_LABELS = [
'شماره تماس',
'شهر / منطقه',
'منبع لید',
'سابقه فعالیت',
'تاریخ ثبت',
'وضعیت',
'مسئول',
@@ -226,6 +233,9 @@ const regionFilter = computed(() =>
const tradeFilter = computed(() =>
typeof route.query.trade === 'string' ? route.query.trade : '',
);
const activityExperienceFilter = computed(() =>
typeof route.query.activityExperience === 'string' ? route.query.activityExperience : '',
);
const sourceFilter = computed(() =>
typeof route.query.source === 'string' ? route.query.source : '',
);
@@ -270,6 +280,7 @@ const mobileFilterBadgeCount = computed(() =>
cityFilter.value,
regionFilter.value,
tradeFilter.value,
activityExperienceFilter.value,
sourceFilter.value,
createdFromFilter.value,
createdToFilter.value,
@@ -283,7 +294,15 @@ const filterBtnLabel = computed(() =>
: 'فیلتر',
);
type LeadFacetKey = 'assignee' | 'stage' | 'source' | 'followUp' | 'city' | 'region' | 'trade';
type LeadFacetKey =
| 'assignee'
| 'stage'
| 'source'
| 'followUp'
| 'city'
| 'region'
| 'trade'
| 'activityExperience';
const filterSection = ref<LeadFacetKey | 'createdFrom' | 'createdTo' | 'converted' | 'archived' | null>(
null,
);
@@ -468,6 +487,18 @@ const textFacets = computed(() => [
...tradeOptions.value.map((item) => ({ value: item, label: item })),
],
},
{
key: 'activityExperience' as const,
label: 'سابقه فعالیت',
value: activityExperienceFilter.value || 'همه',
active: Boolean(activityExperienceFilter.value),
current: activityExperienceFilter.value,
searchable: false,
options: [
{ value: '', label: 'همه' },
...ACTIVITY_EXPERIENCE_OPTIONS.map((item) => ({ value: item, label: item })),
],
},
]);
function visibleFacetOptions(options: Array<{ value: string; label: string }>) {
@@ -492,6 +523,7 @@ function pickFacet(key: LeadFacetKey, value: string) {
else if (key === 'city') setCityFilter(next);
else if (key === 'region') setRegionFilter(next);
else if (key === 'trade') setTradeFilter(next);
else if (key === 'activityExperience') setActivityExperienceFilter(next);
filterSection.value = null;
}
@@ -808,6 +840,10 @@ function setTradeFilter(value: string) {
patchQuery({ trade: value || undefined, page: undefined });
}
function setActivityExperienceFilter(value: string) {
patchQuery({ activityExperience: value || undefined, page: undefined });
}
function setSourceFilter(value: string) {
patchQuery({ source: value || undefined, page: undefined });
}
@@ -837,6 +873,7 @@ function clearMoreFilters() {
city: undefined,
region: undefined,
trade: undefined,
activityExperience: undefined,
source: undefined,
createdFrom: undefined,
createdTo: undefined,
@@ -964,6 +1001,7 @@ async function load() {
city: cityFilter.value || undefined,
region: regionFilter.value || undefined,
trade: tradeFilter.value || undefined,
activityExperience: activityExperienceFilter.value || undefined,
source: sourceFilter.value || undefined,
unassigned: unassigned.value ? '1' : undefined,
archived: archivedFilter.value ? '1' : undefined,
@@ -1477,6 +1515,7 @@ watch(
route.query.city,
route.query.region,
route.query.trade,
route.query.activityExperience,
route.query.source,
route.query.unassigned,
route.query.archived,
@@ -1521,6 +1560,11 @@ const tableColumns = computed<TableColumnsType<LeadDto>>(() => {
{ title: 'شماره تماس', key: 'mobile', dataIndex: 'mobile' },
{ title: 'شهر / منطقه', key: 'city' },
{ title: 'منبع لید', key: 'source', dataIndex: 'source' },
{
title: 'سابقه فعالیت',
key: 'activityExperience',
dataIndex: 'activityExperience',
},
{ title: 'تاریخ ثبت', key: 'createdAt', dataIndex: 'createdAt' },
{ title: 'وضعیت', key: 'stage', dataIndex: 'stageName' },
{ title: 'مسئول', key: 'assignee', dataIndex: 'assigneeName' },
@@ -2226,6 +2270,11 @@ onBeforeUnmount(() => {
<a-tag v-if="(record as LeadDto).source">{{ (record as LeadDto).source }}</a-tag>
<a-typography-text v-else type="secondary">—</a-typography-text>
</template>
<template v-else-if="column.key === 'activityExperience'">
<a-typography-text>
{{ (record as LeadDto).activityExperience || '—' }}
</a-typography-text>
</template>
<template v-else-if="column.key === 'createdAt'">
{{ formatJalaliNumeric(new Date((record as LeadDto).createdAt)) }}
</template>
+23 -1
View File
@@ -36,7 +36,12 @@ import {
} from '@ant-design/icons-vue';
import { api } from '@/lib/api';
import type { CompanyDto, CreatePersonRequest, PersonDto, PersonGender, PersonMood } from '@mento/shared';
import { PERSON_GENDER_LABELS, PERSON_GENDERS, splitPersonHonorific } from '@mento/shared';
import {
ACTIVITY_EXPERIENCE_OPTIONS,
PERSON_GENDER_LABELS,
PERSON_GENDERS,
splitPersonHonorific,
} from '@mento/shared';
import { PERSON_MOOD_LABELS, PERSON_MOODS } from '@/lib/person-mood';
import { formatLocalDateInput, toFaDigits } from '@/lib/jalali';
import JalaliDateInput from '@/components/JalaliDateInput.vue';
@@ -97,6 +102,7 @@ const website = ref('');
const instagram = ref('');
const birthDate = ref('');
const referrer = ref('');
const activityExperience = ref('');
const nationalId = ref('');
const city = ref('');
const rasteh = ref('');
@@ -279,6 +285,7 @@ function fill(p: PersonDto) {
instagram.value = p.instagram ?? '';
birthDate.value = p.birthDate ? formatLocalDateInput(new Date(p.birthDate)) : '';
referrer.value = p.referrer ?? '';
activityExperience.value = p.activityExperience ?? '';
addresses.value = p.addresses?.length ? [...p.addresses] : [''];
notes.value = p.notes ?? '';
tagsRaw.value = (p.tags ?? []).join('، ');
@@ -382,6 +389,7 @@ function payload(): CreatePersonRequest {
instagram: instagram.value || undefined,
birthDate: birthDate.value || null,
referrer: referrer.value || undefined,
activityExperience: activityExperience.value || null,
addresses: addresses.value.map((a) => a.trim()).filter(Boolean),
notes: notes.value || undefined,
tags: parseTags(tagsRaw.value),
@@ -570,6 +578,20 @@ onMounted(load);
<a-input v-model:value="referrer" placeholder="نام معرف" />
</a-form-item>
</a-col>
<a-col :xs="24" :md="12">
<a-form-item label="سابقه فعالیت">
<a-select
v-model:value="activityExperience"
allow-clear
placeholder="اختیاری"
style="width: 100%"
:options="[
{ value: '', label: '—' },
...ACTIVITY_EXPERIENCE_OPTIONS.map((value) => ({ value, label: value })),
]"
/>
</a-form-item>
</a-col>
<a-col :xs="24" :md="12">
<a-form-item label="کد ملی">
<a-input v-model:value="nationalId" dir="ltr" placeholder="کد ملی (ته‌حساب)" />
+6
View File
@@ -454,6 +454,7 @@ const infoEmpty = computed(() => {
!p.position &&
!p.website &&
!p.instagram &&
!p.activityExperience &&
!p.birthDate &&
!p.referrer &&
!nationalIdLabel.value &&
@@ -829,6 +830,10 @@ watch(() => route.query.tab, readTab, { immediate: true });
<dt>اینستاگرام</dt>
<dd dir="ltr">{{ person.instagram }}</dd>
</div>
<div v-if="person.activityExperience" class="fact">
<dt>سابقه فعالیت</dt>
<dd>{{ person.activityExperience }}</dd>
</div>
<div v-if="person.addresses?.length" class="fact wide">
<dt>آدرس‌ها</dt>
<dd>
@@ -1145,6 +1150,7 @@ watch(() => route.query.tab, readTab, { immediate: true });
<div><dt>نام قبلی</dt><dd>{{ person.previousFullName || '—' }}</dd></div>
<div><dt>وب‌سایت</dt><dd>{{ person.website || '—' }}</dd></div>
<div><dt>اینستاگرام</dt><dd dir="ltr">{{ person.instagram || '—' }}</dd></div>
<div><dt>سابقه فعالیت</dt><dd>{{ person.activityExperience || '—' }}</dd></div>
<div><dt>معرف</dt><dd>{{ person.referrer || '—' }}</dd></div>
<div>
<dt>کد ملی</dt>
+75
View File
@@ -1491,6 +1491,74 @@ export const PERSON_IMPORT_SOURCE_LABELS: Record<PersonImportSource, string> = {
other: "سایر",
};
/** گزینه‌های ثابت فیلد «سابقه فعالیت» برای لید و مشتری */
export const ACTIVITY_EXPERIENCE_OPTIONS = [
"ندارم",
"1 الی 2 سال",
"2 الی 5 سال",
"بیش از 5 سال",
] as const;
export type ActivityExperience = (typeof ACTIVITY_EXPERIENCE_OPTIONS)[number];
/** نرمال‌سازی جواب فرم/ویرایش به یکی از گزینه‌های ثابت */
export function normalizeActivityExperience(
raw: string | null | undefined,
): ActivityExperience | null {
const text = (raw ?? "")
.trim()
.replace(/[۰-۹]/g, (d) => String("۰۱۲۳۴۵۶۷۸۹".indexOf(d)))
.replace(/[٠-٩]/g, (d) => String("٠١٢٣٤٥٦٧٨٩".indexOf(d)))
.replace(/\s+/g, " ");
if (!text) return null;
const lower = text.replace(/ي/g, "ی").replace(/ك/g, "ک").toLowerCase();
if (
lower === "ندارم" ||
lower === "ندارد" ||
lower.includes("بدون سابقه") ||
lower === "0" ||
lower === "هیچ"
) {
return "ندارم";
}
if (
lower.includes("بیش از 5") ||
lower.includes("بیشتر از 5") ||
lower.includes("بالای 5") ||
lower.includes("+5") ||
lower.includes("5 سال به بالا")
) {
return "بیش از 5 سال";
}
if (
lower.includes("2 الی 5") ||
lower.includes("2 تا 5") ||
lower.includes("۲ الی ۵") ||
lower.includes("2-5") ||
lower.includes("2–5")
) {
return "2 الی 5 سال";
}
if (
lower.includes("1 الی 2") ||
lower.includes("1 تا 2") ||
lower.includes("۱ الی ۲") ||
lower.includes("1-2") ||
lower.includes("1–2")
) {
return "1 الی 2 سال";
}
for (const option of ACTIVITY_EXPERIENCE_OPTIONS) {
if (lower === option.toLowerCase()) return option;
}
return null;
}
/** برچسب سؤال فرم که به فیلد سابقه فعالیت مربوط است */
export function isActivityExperienceLabel(label: string): boolean {
const text = label.trim().replace(/ي/g, "ی").replace(/ك/g, "ک");
return /سابقه\s*فعالیت/.test(text);
}
export interface PersonImportSourceStatDto {
source: PersonImportSource | string;
label: string;
@@ -1520,6 +1588,7 @@ export interface PersonDto {
instagram: string | null;
birthDate: string | null;
referrer: string | null;
activityExperience: string | null;
addresses: string[];
notes: string | null;
mood: PersonMood;
@@ -1555,6 +1624,7 @@ export interface CreatePersonRequest {
instagram?: string;
birthDate?: string | null;
referrer?: string;
activityExperience?: string | null;
addresses?: string[];
notes?: string;
mood?: PersonMood;
@@ -2912,9 +2982,11 @@ export type LeadFormMapTo =
| "lead.city"
| "lead.region"
| "lead.trade"
| "lead.activityExperience"
| "lead.notes"
| "lead.source"
| "lead.gender"
| "person.activityExperience"
| "person.gender"
| "notes"
| "custom";
@@ -6289,6 +6361,7 @@ export interface LeadDto {
addresses: string[];
trade: string | null;
source: string | null;
activityExperience: string | null;
notes: string | null;
estimatedValue: number | null;
stageId: string;
@@ -6330,6 +6403,7 @@ export interface CreateLeadRequest {
addresses?: string[];
trade?: string | null;
source?: string | null;
activityExperience?: string | null;
notes?: string | null;
estimatedValue?: number | null;
stageId?: string;
@@ -6353,6 +6427,7 @@ export interface UpdateLeadRequest {
addresses?: string[];
trade?: string | null;
source?: string | null;
activityExperience?: string | null;
notes?: string | null;
estimatedValue?: number | null;
stageId?: string;