feat(customers): add optional group assignees with OR visibility for people, companies, and birthdays
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
-- مسئولان اختیاری روی گروههای مشتری
|
||||
CREATE TABLE IF NOT EXISTS "_CustomerGroupAssignees" (
|
||||
"A" TEXT NOT NULL,
|
||||
"B" TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS "_CustomerGroupAssignees_AB_unique" ON "_CustomerGroupAssignees"("A", "B");
|
||||
CREATE INDEX IF NOT EXISTS "_CustomerGroupAssignees_B_index" ON "_CustomerGroupAssignees"("B");
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM pg_constraint WHERE conname = '_CustomerGroupAssignees_A_fkey'
|
||||
) THEN
|
||||
ALTER TABLE "_CustomerGroupAssignees"
|
||||
ADD CONSTRAINT "_CustomerGroupAssignees_A_fkey"
|
||||
FOREIGN KEY ("A") REFERENCES "CustomerGroup"("id")
|
||||
ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
END IF;
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM pg_constraint WHERE conname = '_CustomerGroupAssignees_B_fkey'
|
||||
) THEN
|
||||
ALTER TABLE "_CustomerGroupAssignees"
|
||||
ADD CONSTRAINT "_CustomerGroupAssignees_B_fkey"
|
||||
FOREIGN KEY ("B") REFERENCES "User"("id")
|
||||
ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
END IF;
|
||||
END $$;
|
||||
@@ -306,6 +306,7 @@ model User {
|
||||
ownedInvoices Invoice[] @relation("InvoiceOwner")
|
||||
ownedPeople Person[] @relation("PersonOwner")
|
||||
ownedCompanies Company[] @relation("CompanyOwner")
|
||||
assignedCustomerGroups CustomerGroup[] @relation("CustomerGroupAssignees")
|
||||
financialPartyDocuments FinancialDocument[] @relation("FinancialDocumentParty")
|
||||
ownedProjectCards ProjectCard[] @relation("ProjectCardOwner")
|
||||
activities Activity[] @relation("ActivityAssignee")
|
||||
@@ -576,6 +577,8 @@ model CustomerGroup {
|
||||
children CustomerGroup[] @relation("CustomerGroupTree")
|
||||
people PersonGroupLink[]
|
||||
companies CompanyGroupLink[]
|
||||
/// مسئولان گروه — اختیاری؛ اعضای گروه را مثل مشتریان خود میبینند
|
||||
assignees User[] @relation("CustomerGroupAssignees")
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
|
||||
@@ -135,6 +135,23 @@ function orParts<T>(parts: T[]): T | { OR: T[] } | { id: string } {
|
||||
return parts.length === 1 ? parts[0]! : { OR: parts };
|
||||
}
|
||||
|
||||
/** اعضای گروههایی که کاربر مسئولشان است */
|
||||
function personViaGroupAssignee(userId: string): Prisma.PersonWhereInput {
|
||||
return {
|
||||
groupLinks: {
|
||||
some: { group: { assignees: { some: { id: userId } } } },
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function companyViaGroupAssignee(userId: string): Prisma.CompanyWhereInput {
|
||||
return {
|
||||
groupLinks: {
|
||||
some: { group: { assignees: { some: { id: userId } } } },
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function customersPersonWhere(
|
||||
actor: Pick<Actor, 'userId' | 'role' | 'customersAccess' | 'teamPeerIds'>,
|
||||
): Prisma.PersonWhereInput {
|
||||
@@ -149,6 +166,8 @@ export function customersPersonWhere(
|
||||
});
|
||||
if (w) parts.push(w);
|
||||
}
|
||||
// مسئول گروه: اتحاد با محدودیت نقش (مالک خودم یا عضو گروه تحت مسئولیت)
|
||||
parts.push(personViaGroupAssignee(actor.userId));
|
||||
return orParts(parts);
|
||||
}
|
||||
|
||||
@@ -188,6 +207,7 @@ export function customersCompanyWhere(
|
||||
if (!and.length) continue;
|
||||
parts.push(and.length === 1 ? and[0]! : { AND: and });
|
||||
}
|
||||
parts.push(companyViaGroupAssignee(actor.userId));
|
||||
return orParts(parts);
|
||||
}
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ export function selectMonthBirthdays(people: BirthdayRow[], now = new Date(), pr
|
||||
const upcoming = matched.filter((row) => row.day >= today.jd).sort(byDay);
|
||||
const passed = matched.filter((row) => row.day < today.jd).sort(byDay);
|
||||
return {
|
||||
year: today.jy,
|
||||
month: today.jm,
|
||||
monthName: jalaliMonthName(today.jm),
|
||||
today: today.jd,
|
||||
|
||||
@@ -169,6 +169,7 @@ export class CompaniesService {
|
||||
fromTahesab: Boolean(g.tahesabGid),
|
||||
personCount: 0,
|
||||
companyCount: countMap.get(g.id) ?? 0,
|
||||
assignees: [],
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import { LoyaltyModule } from '../loyalty/loyalty.module';
|
||||
import { AutomationsModule } from '../automations/automations.module';
|
||||
import { MessageAutomationsModule } from '../message-automations/message-automations.module';
|
||||
import { PublicApiModule } from '../public-api/public-api.module';
|
||||
import { NotificationsModule } from '../notifications/notifications.module';
|
||||
import { CompaniesController } from './companies.controller';
|
||||
import { CompaniesService } from './companies.service';
|
||||
import { PeopleController } from './people.controller';
|
||||
@@ -20,6 +21,7 @@ import { CustomerGroupsModule } from '../customer-groups/customer-groups.module'
|
||||
PublicApiModule,
|
||||
BehaviorModule,
|
||||
CustomerGroupsModule,
|
||||
NotificationsModule,
|
||||
],
|
||||
controllers: [PeopleController, CompaniesController],
|
||||
providers: [PeopleService, CompaniesService, ContactsExcelService, SameMobileMergeService],
|
||||
|
||||
@@ -23,6 +23,11 @@ export class BirthdaySmsDto {
|
||||
@MinLength(1)
|
||||
@MaxLength(500)
|
||||
text!: string;
|
||||
|
||||
/** تأیید ارسال مجدد وقتی قبلاً مسئول دیگری تبریک فرستاده */
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
force?: boolean;
|
||||
}
|
||||
|
||||
export class BulkDeletePeopleDto {
|
||||
|
||||
@@ -139,6 +139,7 @@ export class PeopleController {
|
||||
}
|
||||
|
||||
@Get('birthdays')
|
||||
@RequirePermission('customers', { reads: true })
|
||||
birthdays(@CurrentUser() user: Actor) {
|
||||
return this.peopleService.birthdaysThisMonth(user);
|
||||
}
|
||||
@@ -171,7 +172,7 @@ export class PeopleController {
|
||||
@Param('id') id: string,
|
||||
@Body() dto: BirthdaySmsDto,
|
||||
) {
|
||||
return this.peopleService.sendBirthdaySms(user, id, dto.text);
|
||||
return this.peopleService.sendBirthdaySms(user, id, dto.text, Boolean(dto.force));
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
FILTERED_IDS_MAX,
|
||||
PERSON_MOODS,
|
||||
applyPersonGenderTitle,
|
||||
canViewAllRecords,
|
||||
splitPersonHonorific,
|
||||
} from '@mento/shared';
|
||||
import { Prisma } from '@prisma/client';
|
||||
@@ -48,6 +49,7 @@ import {
|
||||
import { actorCanAssignToOthers, assertAssigneeSet } from '../common/assign-access';
|
||||
import { LoyaltyService } from '../loyalty/loyalty.service';
|
||||
import { AutomationsService } from '../automations/automations.service';
|
||||
import { NotificationsService } from '../notifications/notifications.service';
|
||||
import { MessageAutomationsService } from '../message-automations/message-automations.service';
|
||||
import { WebhooksService } from '../public-api/webhooks.service';
|
||||
import { GamificationService } from '../gamification/gamification.service';
|
||||
@@ -157,6 +159,7 @@ export class PeopleService implements OnModuleInit {
|
||||
private readonly outboundSms: OutboundSmsLogService,
|
||||
private readonly behaviorAccess: BehaviorAccessService,
|
||||
private readonly groups: CustomerGroupsService,
|
||||
private readonly notifications: NotificationsService,
|
||||
) {}
|
||||
|
||||
private personListWhere(
|
||||
@@ -349,6 +352,7 @@ export class PeopleService implements OnModuleInit {
|
||||
fromTahesab: Boolean(g.tahesabGid),
|
||||
personCount: countMap.get(g.id) ?? 0,
|
||||
companyCount: 0,
|
||||
assignees: [],
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -684,8 +688,8 @@ export class PeopleService implements OnModuleInit {
|
||||
const rows = await this.prisma.person.findMany({
|
||||
where: {
|
||||
organizationId: actor.organizationId,
|
||||
ownerId: actor.userId,
|
||||
birthDate: { not: null },
|
||||
...customersPersonWhere(actor),
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
@@ -732,13 +736,17 @@ export class PeopleService implements OnModuleInit {
|
||||
};
|
||||
}
|
||||
|
||||
async sendBirthdaySms(actor: Actor, personId: string, text: string) {
|
||||
async sendBirthdaySms(actor: Actor, personId: string, text: string, force = false) {
|
||||
const body = text.trim();
|
||||
if (!body || body.length > 500) {
|
||||
throw new BadRequestException('متن پیامک را تا ۵۰۰ نویسه بنویسید.');
|
||||
}
|
||||
const person = await this.prisma.person.findFirst({
|
||||
where: { id: personId, organizationId: actor.organizationId },
|
||||
where: {
|
||||
id: personId,
|
||||
organizationId: actor.organizationId,
|
||||
...customersPersonWhere(actor),
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
firstName: true,
|
||||
@@ -748,11 +756,29 @@ export class PeopleService implements OnModuleInit {
|
||||
ownerId: true,
|
||||
birthDate: true,
|
||||
company: { select: { name: true } },
|
||||
groupLinks: {
|
||||
select: {
|
||||
group: {
|
||||
select: {
|
||||
assignees: { select: { id: true, fullName: true } },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
if (!person) throw new NotFoundException('مشتری پیدا نشد');
|
||||
if (person.ownerId !== actor.userId) {
|
||||
throw new ForbiddenException('فقط مسئول این مشتری میتواند پیامک تبریک بفرستد.');
|
||||
const assigneeIds = new Set(
|
||||
person.groupLinks.flatMap((link) => link.group.assignees.map((a) => a.id)),
|
||||
);
|
||||
const canSend =
|
||||
canViewAllRecords(actor.role) ||
|
||||
person.ownerId === actor.userId ||
|
||||
assigneeIds.has(actor.userId);
|
||||
if (!canSend) {
|
||||
throw new ForbiddenException(
|
||||
'فقط مالک مشتری یا مسئول گروه او میتواند پیامک تبریک بفرستد.',
|
||||
);
|
||||
}
|
||||
if (!person.birthDate) {
|
||||
throw new BadRequestException('برای این مشتری تاریخ تولد ثبت نشده است.');
|
||||
@@ -774,6 +800,32 @@ export class PeopleService implements OnModuleInit {
|
||||
const mobile = person.mobile || person.phone;
|
||||
if (!mobile) throw new BadRequestException('برای این مشتری شماره موبایل ثبت نشده است.');
|
||||
const fullName = `${person.firstName} ${person.lastName}`.trim();
|
||||
const birthdayKey = `birthday:${inMonth.year}-${inMonth.month}`;
|
||||
if (!force) {
|
||||
const prior = await this.prisma.outboundSmsLog.findFirst({
|
||||
where: {
|
||||
organizationId: actor.organizationId,
|
||||
personId: person.id,
|
||||
status: 'sent',
|
||||
sourceId: birthdayKey,
|
||||
NOT: { actorUserId: actor.userId },
|
||||
},
|
||||
orderBy: { createdAt: 'desc' },
|
||||
select: { actorUserId: true },
|
||||
});
|
||||
if (prior) {
|
||||
const priorUser = prior.actorUserId
|
||||
? await this.prisma.user.findFirst({
|
||||
where: { id: prior.actorUserId },
|
||||
select: { fullName: true },
|
||||
})
|
||||
: null;
|
||||
const who = priorUser?.fullName?.trim() || 'مسئول دیگری';
|
||||
throw new ConflictException(
|
||||
`${who} قبلاً پیامک تبریک این مشتری را فرستاده است. آیا میخواهید دوباره بفرستید؟`,
|
||||
);
|
||||
}
|
||||
}
|
||||
const message = renderSmsText(body, {
|
||||
name: fullName,
|
||||
phone: mobile,
|
||||
@@ -793,6 +845,7 @@ export class PeopleService implements OnModuleInit {
|
||||
mobile,
|
||||
body: message,
|
||||
source: 'manual',
|
||||
sourceId: birthdayKey,
|
||||
status: result.ok ? 'sent' : 'failed',
|
||||
error: result.ok ? null : result.reason,
|
||||
actorUserId: actor.userId,
|
||||
@@ -806,6 +859,28 @@ export class PeopleService implements OnModuleInit {
|
||||
: 'پیامک ارسال نشد. کمی بعد دوباره تلاش کنید.',
|
||||
);
|
||||
}
|
||||
const senderName = (
|
||||
await this.prisma.user.findFirst({
|
||||
where: { id: actor.userId },
|
||||
select: { fullName: true },
|
||||
})
|
||||
)?.fullName?.trim() || 'یکی از مسئولان';
|
||||
const peers = [...assigneeIds].filter((id) => id !== actor.userId);
|
||||
await Promise.all(
|
||||
peers.map((userId) =>
|
||||
this.notifications.create({
|
||||
organizationId: actor.organizationId,
|
||||
userId,
|
||||
type: 'birthday_sms_sent',
|
||||
title: 'پیامک تبریک تولد ارسال شد',
|
||||
body: `${senderName} برای «${fullName}» پیامک تبریک فرستاد. اگر لازم است میتوانید دوباره بفرستید.`,
|
||||
link: `/contacts/people/${person.id}`,
|
||||
entityType: 'person',
|
||||
entityId: person.id,
|
||||
dedupe: false,
|
||||
}),
|
||||
),
|
||||
);
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,14 @@ import {
|
||||
Post,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { IsIn, IsOptional, IsString, MaxLength, MinLength } from 'class-validator';
|
||||
import {
|
||||
IsArray,
|
||||
IsIn,
|
||||
IsOptional,
|
||||
IsString,
|
||||
MaxLength,
|
||||
MinLength,
|
||||
} from 'class-validator';
|
||||
import { CUSTOMER_GROUP_COLORS, type CustomerGroupColor } from '@mento/shared';
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
import { RolesGuard } from '../auth/roles.guard';
|
||||
@@ -26,6 +33,11 @@ class CreateCustomerGroupDto {
|
||||
@IsOptional()
|
||||
@IsIn([...CUSTOMER_GROUP_COLORS])
|
||||
color?: CustomerGroupColor;
|
||||
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@IsString({ each: true })
|
||||
assigneeIds?: string[];
|
||||
}
|
||||
|
||||
class UpdateCustomerGroupDto {
|
||||
@@ -43,6 +55,11 @@ class UpdateCustomerGroupDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
parentId?: string | null;
|
||||
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@IsString({ each: true })
|
||||
assigneeIds?: string[];
|
||||
}
|
||||
|
||||
@Controller('customer-groups')
|
||||
|
||||
@@ -51,26 +51,21 @@ export class CustomerGroupsService {
|
||||
include: {
|
||||
_count: { select: { people: true, companies: true } },
|
||||
parent: { select: { name: true } },
|
||||
assignees: { select: { id: true, fullName: true }, orderBy: { fullName: 'asc' } },
|
||||
},
|
||||
});
|
||||
return rows.map((r) => ({
|
||||
id: r.id,
|
||||
name: r.name,
|
||||
color: r.color,
|
||||
position: r.position,
|
||||
fromTahesab: Boolean(r.tahesabGid),
|
||||
personCount: r._count.people,
|
||||
companyCount: r._count.companies,
|
||||
parentId: r.parentId,
|
||||
parentName: r.parent?.name ?? null,
|
||||
}));
|
||||
return rows.map((r) => this.toDto(r));
|
||||
}
|
||||
|
||||
async create(
|
||||
organizationId: string,
|
||||
dto: { name: string; color?: CustomerGroupColor },
|
||||
dto: { name: string; color?: CustomerGroupColor; assigneeIds?: string[] },
|
||||
): Promise<CustomerGroupDto> {
|
||||
const name = this.cleanName(dto.name);
|
||||
const assigneeIds =
|
||||
dto.assigneeIds !== undefined
|
||||
? await this.validAssigneeIds(organizationId, dto.assigneeIds)
|
||||
: [];
|
||||
const max = await this.prisma.customerGroup.aggregate({
|
||||
where: { organizationId },
|
||||
_max: { position: true },
|
||||
@@ -82,6 +77,9 @@ export class CustomerGroupsService {
|
||||
name,
|
||||
color: this.cleanColor(dto.color),
|
||||
position: (max._max.position ?? -1) + 1,
|
||||
...(assigneeIds.length
|
||||
? { assignees: { connect: assigneeIds.map((id) => ({ id })) } }
|
||||
: {}),
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
@@ -93,7 +91,12 @@ export class CustomerGroupsService {
|
||||
async update(
|
||||
organizationId: string,
|
||||
id: string,
|
||||
dto: { name?: string; color?: CustomerGroupColor; parentId?: string | null },
|
||||
dto: {
|
||||
name?: string;
|
||||
color?: CustomerGroupColor;
|
||||
parentId?: string | null;
|
||||
assigneeIds?: string[];
|
||||
},
|
||||
): Promise<CustomerGroupDto> {
|
||||
await this.require(organizationId, id);
|
||||
const parentId =
|
||||
@@ -101,6 +104,10 @@ export class CustomerGroupsService {
|
||||
if (parentId !== undefined) {
|
||||
await this.assertParent(organizationId, id, parentId);
|
||||
}
|
||||
const assigneeIds =
|
||||
dto.assigneeIds !== undefined
|
||||
? await this.validAssigneeIds(organizationId, dto.assigneeIds)
|
||||
: undefined;
|
||||
try {
|
||||
await this.prisma.customerGroup.update({
|
||||
where: { id },
|
||||
@@ -108,6 +115,9 @@ export class CustomerGroupsService {
|
||||
...(dto.name != null ? { name: this.cleanName(dto.name) } : {}),
|
||||
...(dto.color != null ? { color: this.cleanColor(dto.color) } : {}),
|
||||
...(parentId !== undefined ? { parentId } : {}),
|
||||
...(assigneeIds !== undefined
|
||||
? { assignees: { set: assigneeIds.map((uid) => ({ id: uid })) } }
|
||||
: {}),
|
||||
},
|
||||
});
|
||||
} catch (e) {
|
||||
@@ -317,6 +327,48 @@ export class CustomerGroupsService {
|
||||
return link?.group.name ?? null;
|
||||
}
|
||||
|
||||
private toDto(r: {
|
||||
id: string;
|
||||
name: string;
|
||||
color: string;
|
||||
position: number;
|
||||
tahesabGid: string | null;
|
||||
parentId: string | null;
|
||||
parent?: { name: string } | null;
|
||||
_count: { people: number; companies: number };
|
||||
assignees: Array<{ id: string; fullName: string }>;
|
||||
}): CustomerGroupDto {
|
||||
return {
|
||||
id: r.id,
|
||||
name: r.name,
|
||||
color: r.color,
|
||||
position: r.position,
|
||||
fromTahesab: Boolean(r.tahesabGid),
|
||||
personCount: r._count.people,
|
||||
companyCount: r._count.companies,
|
||||
parentId: r.parentId,
|
||||
parentName: r.parent?.name ?? null,
|
||||
assignees: r.assignees.map((a) => ({ id: a.id, fullName: a.fullName })),
|
||||
};
|
||||
}
|
||||
|
||||
private async validAssigneeIds(organizationId: string, ids: string[]): Promise<string[]> {
|
||||
const unique = [...new Set((ids ?? []).map((id) => id?.trim()).filter(Boolean))];
|
||||
if (!unique.length) return [];
|
||||
const rows = await this.prisma.user.findMany({
|
||||
where: {
|
||||
id: { in: unique },
|
||||
isActive: true,
|
||||
memberships: { some: { organizationId, isActive: true } },
|
||||
},
|
||||
select: { id: true },
|
||||
});
|
||||
if (rows.length !== unique.length) {
|
||||
throw new BadRequestException('یکی از مسئولان انتخابشده معتبر نیست');
|
||||
}
|
||||
return rows.map((r) => r.id);
|
||||
}
|
||||
|
||||
private async require(organizationId: string, id: string) {
|
||||
const row = await this.prisma.customerGroup.findFirst({
|
||||
where: { id, organizationId },
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import { describe, it } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { leadsDeepWhere, resolveSectionAccess } from '../src/common/data-access';
|
||||
import {
|
||||
customersCompanyWhere,
|
||||
customersPersonWhere,
|
||||
leadsDeepWhere,
|
||||
resolveSectionAccess,
|
||||
} from '../src/common/data-access';
|
||||
import {
|
||||
noteAccessWhere,
|
||||
normalizeDataVisibility,
|
||||
@@ -122,3 +127,49 @@ describe('عمق داده وقتی نقش فقط بعضی بخشها را ذ
|
||||
assert.deepEqual(leads.section, { mode: 'rules', rules: [{ owners: ['self'] }] });
|
||||
});
|
||||
});
|
||||
|
||||
describe('مسئول گروه مشتری روی عمق داده', () => {
|
||||
const selfAccess = { mode: 'rules' as const, rules: [{ owners: ['self' as const] }] };
|
||||
|
||||
it('محدودیت self با OR مسئول گروه برای شخص', () => {
|
||||
const where = customersPersonWhere({
|
||||
userId: 'u1',
|
||||
role: 'sales',
|
||||
customersAccess: selfAccess,
|
||||
teamPeerIds: null,
|
||||
});
|
||||
assert.deepEqual(where, {
|
||||
OR: [
|
||||
{ ownerId: 'u1' },
|
||||
{ groupLinks: { some: { group: { assignees: { some: { id: 'u1' } } } } } },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it('محدودیت self با OR مسئول گروه برای شرکت', () => {
|
||||
const where = customersCompanyWhere({
|
||||
userId: 'u1',
|
||||
role: 'sales',
|
||||
customersAccess: selfAccess,
|
||||
teamPeerIds: null,
|
||||
});
|
||||
assert.deepEqual(where, {
|
||||
OR: [
|
||||
{ ownerId: 'u1' },
|
||||
{ groupLinks: { some: { group: { assignees: { some: { id: 'u1' } } } } } },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it('بدون محدودیت عمقی، فیلتر اضافه نمیشود', () => {
|
||||
assert.deepEqual(
|
||||
customersPersonWhere({
|
||||
userId: 'u1',
|
||||
role: 'sales',
|
||||
customersAccess: { mode: 'all', rules: [] },
|
||||
teamPeerIds: null,
|
||||
}),
|
||||
{},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,29 +1,54 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue';
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import axios from 'axios';
|
||||
import type { CustomerGroupColor, CustomerGroupDto } from '@mento/shared';
|
||||
import type { CustomerGroupColor, CustomerGroupDto, OrgUserDto } from '@mento/shared';
|
||||
import { CUSTOMER_GROUP_COLORS } from '@mento/shared';
|
||||
import { api } from '@/lib/api';
|
||||
import { toFaDigits } from '@/lib/jalali';
|
||||
import { normalizeSearchText } from '@/lib/search';
|
||||
import {
|
||||
CUSTOMER_GROUP_COLOR_LABELS,
|
||||
groupSwatch,
|
||||
useCustomerGroups,
|
||||
} from '@/lib/customer-groups';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import { UiButton, UiInput, UiModal } from '@/components/ui';
|
||||
import UiIcon from '@/components/UiIcon.vue';
|
||||
import OrgUserPersonPick from '@/components/OrgUserPersonPick.vue';
|
||||
|
||||
const props = defineProps<{ open: boolean }>();
|
||||
const emit = defineEmits<{ close: []; changed: [] }>();
|
||||
|
||||
const auth = useAuthStore();
|
||||
const canManage = computed(
|
||||
() => auth.user?.role === 'owner' || auth.user?.role === 'admin',
|
||||
);
|
||||
|
||||
const { groups, load } = useCustomerGroups();
|
||||
const users = ref<OrgUserDto[]>([]);
|
||||
const newName = ref('');
|
||||
const newColor = ref<CustomerGroupColor>('teal');
|
||||
const newAssigneeIds = ref<string[]>([]);
|
||||
const editingId = ref<string | null>(null);
|
||||
const editName = ref('');
|
||||
const assigneeDraft = ref<Record<string, string[]>>({});
|
||||
const listQuery = ref('');
|
||||
const busy = ref(false);
|
||||
const error = ref('');
|
||||
|
||||
const filteredGroups = computed(() => {
|
||||
const q = normalizeSearchText(listQuery.value);
|
||||
if (!q) return groups.value;
|
||||
return groups.value.filter((g) => {
|
||||
const assigneeNames = (g.assignees ?? []).map((a) => a.fullName).join(' ');
|
||||
return (
|
||||
normalizeSearchText(g.name).includes(q) ||
|
||||
normalizeSearchText(g.parentName ?? '').includes(q) ||
|
||||
normalizeSearchText(assigneeNames).includes(q)
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
function errorText(e: unknown, fallback: string) {
|
||||
if (axios.isAxiosError(e)) {
|
||||
const msg = (e.response?.data as { message?: string | string[] } | undefined)?.message;
|
||||
@@ -33,12 +58,30 @@ function errorText(e: unknown, fallback: string) {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
async function loadUsers() {
|
||||
try {
|
||||
const { data } = await api.get<OrgUserDto[]>('/users');
|
||||
users.value = data.filter((u) => u.isActive !== false);
|
||||
} catch {
|
||||
users.value = [];
|
||||
}
|
||||
}
|
||||
|
||||
function syncAssigneeDraft() {
|
||||
const next: Record<string, string[]> = {};
|
||||
for (const g of groups.value) {
|
||||
next[g.id] = (g.assignees ?? []).map((a) => a.id);
|
||||
}
|
||||
assigneeDraft.value = next;
|
||||
}
|
||||
|
||||
async function run(task: () => Promise<unknown>, fallback: string) {
|
||||
busy.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
await task();
|
||||
await load(true);
|
||||
syncAssigneeDraft();
|
||||
emit('changed');
|
||||
return true;
|
||||
} catch (e) {
|
||||
@@ -53,10 +96,18 @@ async function create() {
|
||||
const name = newName.value.trim();
|
||||
if (!name) return;
|
||||
const ok = await run(
|
||||
() => api.post('/customer-groups', { name, color: newColor.value }),
|
||||
() =>
|
||||
api.post('/customer-groups', {
|
||||
name,
|
||||
color: newColor.value,
|
||||
assigneeIds: newAssigneeIds.value,
|
||||
}),
|
||||
'ساخت گروه ناموفق بود.',
|
||||
);
|
||||
if (ok) newName.value = '';
|
||||
if (ok) {
|
||||
newName.value = '';
|
||||
newAssigneeIds.value = [];
|
||||
}
|
||||
}
|
||||
|
||||
function startEdit(g: CustomerGroupDto) {
|
||||
@@ -82,6 +133,24 @@ async function setColor(g: CustomerGroupDto, color: CustomerGroupColor) {
|
||||
await run(() => api.patch(`/customer-groups/${g.id}`, { color }), 'تغییر رنگ ناموفق بود.');
|
||||
}
|
||||
|
||||
async function onAssigneesChange(g: CustomerGroupDto, ids: string[]) {
|
||||
assigneeDraft.value = { ...assigneeDraft.value, [g.id]: ids };
|
||||
const prev = (g.assignees ?? []).map((a) => a.id).sort().join(',');
|
||||
const next = [...ids].sort().join(',');
|
||||
if (prev === next) return;
|
||||
await run(
|
||||
() => api.patch(`/customer-groups/${g.id}`, { assigneeIds: ids }),
|
||||
'ذخیره مسئولان گروه ناموفق بود.',
|
||||
);
|
||||
}
|
||||
|
||||
function assigneeLabel(g: CustomerGroupDto) {
|
||||
const names = (g.assignees ?? []).map((a) => a.fullName).filter(Boolean);
|
||||
if (!names.length) return 'بدون مسئول';
|
||||
if (names.length === 1) return names[0]!;
|
||||
return `${names[0]} و ${toFaDigits(names.length - 1)} نفر دیگر`;
|
||||
}
|
||||
|
||||
async function remove(g: CustomerGroupDto) {
|
||||
const used = g.personCount + g.companyCount;
|
||||
const note = used ? ` این گروه از ${toFaDigits(used)} مخاطب برداشته میشود (خود مخاطبها حذف نمیشوند).` : '';
|
||||
@@ -95,9 +164,12 @@ watch(
|
||||
if (!open) return;
|
||||
error.value = '';
|
||||
editingId.value = null;
|
||||
void load(true).catch(() => {
|
||||
error.value = 'بارگذاری گروهها ناموفق بود.';
|
||||
});
|
||||
listQuery.value = '';
|
||||
void Promise.all([load(true), loadUsers()])
|
||||
.then(() => syncAssigneeDraft())
|
||||
.catch(() => {
|
||||
error.value = 'بارگذاری گروهها ناموفق بود.';
|
||||
});
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
@@ -107,34 +179,60 @@ watch(
|
||||
<UiModal :open="open" title="گروههای مشتری" @close="emit('close')">
|
||||
<div class="manager">
|
||||
<p class="lead">
|
||||
هر شخص یا شرکت میتواند چند گروه داشته باشد. گروههایی که از تهحساب میآیند با برچسب
|
||||
«تهحساب» مشخص شدهاند.
|
||||
هر شخص یا شرکت میتواند چند گروه داشته باشد. مسئولان گروه (اختیاری) اعضای آن گروه را مثل
|
||||
مشتریان خود میبینند. گروههای تهحساب با برچسب «تهحساب» مشخص شدهاند.
|
||||
</p>
|
||||
|
||||
<form class="new-row" @submit.prevent="create">
|
||||
<UiInput v-model="newName" placeholder="نام گروه جدید" :maxlength="80" :disabled="busy" />
|
||||
<div class="swatches">
|
||||
<button
|
||||
v-for="c in CUSTOMER_GROUP_COLORS"
|
||||
:key="c"
|
||||
type="button"
|
||||
class="swatch"
|
||||
:class="{ on: newColor === c }"
|
||||
:style="{ background: groupSwatch(c).fg }"
|
||||
:title="CUSTOMER_GROUP_COLOR_LABELS[c]"
|
||||
@click="newColor = c"
|
||||
<form v-if="canManage" class="create-panel" @submit.prevent="create">
|
||||
<header class="create-head">
|
||||
<strong>گروه جدید</strong>
|
||||
<span>نام، رنگ و مسئولان را مشخص کنید و افزودن بزنید.</span>
|
||||
</header>
|
||||
<div class="new-row">
|
||||
<UiInput v-model="newName" placeholder="نام گروه جدید" :maxlength="80" :disabled="busy" />
|
||||
<div class="swatches">
|
||||
<button
|
||||
v-for="c in CUSTOMER_GROUP_COLORS"
|
||||
:key="c"
|
||||
type="button"
|
||||
class="swatch"
|
||||
:class="{ on: newColor === c }"
|
||||
:style="{ background: groupSwatch(c).fg }"
|
||||
:title="CUSTOMER_GROUP_COLOR_LABELS[c]"
|
||||
@click="newColor = c"
|
||||
/>
|
||||
</div>
|
||||
<UiButton type="submit" variant="primary" size="sm" :disabled="busy || !newName.trim()">
|
||||
<UiIcon name="plus" :size="15" />
|
||||
افزودن
|
||||
</UiButton>
|
||||
</div>
|
||||
<div v-if="users.length" class="assignee-field create-assignees">
|
||||
<span class="assignees-label">مسئولان (اختیاری)</span>
|
||||
<OrgUserPersonPick
|
||||
v-model="newAssigneeIds"
|
||||
:users="users"
|
||||
:disabled="busy"
|
||||
empty-label="انتخاب مسئول"
|
||||
/>
|
||||
</div>
|
||||
<UiButton type="submit" variant="primary" size="sm" :disabled="busy || !newName.trim()">
|
||||
<UiIcon name="plus" :size="15" />
|
||||
افزودن
|
||||
</UiButton>
|
||||
</form>
|
||||
|
||||
<p v-if="error" class="error">{{ error }}</p>
|
||||
|
||||
<ul v-if="groups.length" class="list">
|
||||
<li v-for="g in groups" :key="g.id" class="row">
|
||||
<div v-if="canManage || groups.length" class="list-head">
|
||||
<h3 class="list-title">گروههای موجود</h3>
|
||||
<label v-if="groups.length" class="list-search">
|
||||
<UiIcon name="search" :size="15" />
|
||||
<input
|
||||
v-model="listQuery"
|
||||
type="search"
|
||||
placeholder="جستجوی گروه یا مسئول…"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<ul v-if="filteredGroups.length" class="list">
|
||||
<li v-for="g in filteredGroups" :key="g.id" class="row">
|
||||
<div class="name-cell">
|
||||
<form v-if="editingId === g.id" class="edit" @submit.prevent="saveName(g)">
|
||||
<UiInput v-model="editName" :maxlength="80" :disabled="busy" />
|
||||
@@ -152,9 +250,10 @@ watch(
|
||||
<span class="count">
|
||||
{{ toFaDigits(g.personCount) }} شخص · {{ toFaDigits(g.companyCount) }} شرکت
|
||||
</span>
|
||||
<span v-if="!canManage" class="assignee-summary">{{ assigneeLabel(g) }}</span>
|
||||
</template>
|
||||
</div>
|
||||
<div v-if="editingId !== g.id" class="row-actions">
|
||||
<div v-if="editingId !== g.id && canManage" class="row-actions">
|
||||
<div class="swatches">
|
||||
<button
|
||||
v-for="c in CUSTOMER_GROUP_COLORS"
|
||||
@@ -173,8 +272,20 @@ watch(
|
||||
<UiIcon name="trash" :size="14" />
|
||||
</UiButton>
|
||||
</div>
|
||||
<div v-if="canManage && users.length" class="assignee-field">
|
||||
<span class="assignees-label">مسئولان</span>
|
||||
<OrgUserPersonPick
|
||||
:model-value="assigneeDraft[g.id] ?? []"
|
||||
:users="users"
|
||||
:disabled="busy"
|
||||
empty-label="انتخاب مسئول"
|
||||
@update:model-value="(ids) => (assigneeDraft[g.id] = ids)"
|
||||
@change="(ids) => onAssigneesChange(g, ids)"
|
||||
/>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
<p v-else-if="groups.length && listQuery.trim()" class="muted">گروهی با این جستجو پیدا نشد.</p>
|
||||
<p v-else class="muted">هنوز گروهی ساخته نشده است.</p>
|
||||
</div>
|
||||
</UiModal>
|
||||
@@ -200,6 +311,78 @@ watch(
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
.create-panel {
|
||||
display: grid;
|
||||
gap: 0.75rem;
|
||||
padding: 0.85rem 0.95rem;
|
||||
border: 1px solid color-mix(in srgb, var(--accent, #0d9488) 28%, #e2e8f0);
|
||||
border-radius: 12px;
|
||||
background:
|
||||
linear-gradient(180deg, color-mix(in srgb, var(--accent, #0d9488) 8%, #fff) 0%, #fff 72%);
|
||||
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
|
||||
}
|
||||
|
||||
.create-head {
|
||||
display: grid;
|
||||
gap: 0.15rem;
|
||||
}
|
||||
|
||||
.create-head strong {
|
||||
color: var(--accent-deep, #0f766e);
|
||||
font-size: 0.9rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.create-head span {
|
||||
color: #64748b;
|
||||
font-size: 0.78rem;
|
||||
}
|
||||
|
||||
.list-head {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.list-title {
|
||||
margin: 0;
|
||||
color: #475569;
|
||||
font-size: 0.8rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.list-search {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
min-width: min(16rem, 100%);
|
||||
flex: 1 1 12rem;
|
||||
max-width: 18rem;
|
||||
height: 2.25rem;
|
||||
padding: 0 0.65rem;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: var(--radius, 10px);
|
||||
background: #fff;
|
||||
color: #94a3b8;
|
||||
}
|
||||
|
||||
.list-search:focus-within {
|
||||
border-color: #5eead4;
|
||||
}
|
||||
|
||||
.list-search input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
border: 0;
|
||||
outline: none;
|
||||
background: transparent;
|
||||
font: inherit;
|
||||
font-size: 0.85rem;
|
||||
color: #0f172a;
|
||||
}
|
||||
|
||||
.new-row,
|
||||
.edit {
|
||||
display: flex;
|
||||
@@ -282,14 +465,38 @@ watch(
|
||||
padding: 0.05rem 0.4rem;
|
||||
}
|
||||
|
||||
.count {
|
||||
.count,
|
||||
.assignee-summary {
|
||||
color: #94a3b8;
|
||||
font-size: 0.78rem;
|
||||
}
|
||||
|
||||
.assignee-summary {
|
||||
flex: 1 1 100%;
|
||||
}
|
||||
|
||||
.row-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
}
|
||||
|
||||
.assignee-field {
|
||||
flex: 1 1 100%;
|
||||
display: grid;
|
||||
gap: 0.35rem;
|
||||
padding-top: 0.35rem;
|
||||
border-top: 1px dashed #e2e8f0;
|
||||
}
|
||||
|
||||
.create-assignees {
|
||||
border-top: 1px dashed color-mix(in srgb, var(--accent, #0d9488) 22%, #e2e8f0);
|
||||
padding-top: 0.65rem;
|
||||
}
|
||||
|
||||
.assignees-label {
|
||||
font-size: 0.75rem;
|
||||
color: #64748b;
|
||||
font-weight: 600;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -0,0 +1,301 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, ref, watch } from 'vue';
|
||||
import type { OrgUserDto } from '@mento/shared';
|
||||
import { toFaDigits } from '@/lib/jalali';
|
||||
import { normalizeSearchText } from '@/lib/search';
|
||||
import UiIcon from '@/components/UiIcon.vue';
|
||||
import UserAvatar from '@/components/UserAvatar.vue';
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
modelValue: string[];
|
||||
users: Array<Pick<OrgUserDto, 'id' | 'fullName' | 'orgRoleName' | 'hasAvatar'>>;
|
||||
disabled?: boolean;
|
||||
emptyLabel?: string;
|
||||
}>(),
|
||||
{
|
||||
disabled: false,
|
||||
emptyLabel: 'انتخاب مسئول',
|
||||
},
|
||||
);
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [ids: string[]];
|
||||
change: [ids: string[]];
|
||||
}>();
|
||||
|
||||
const open = ref(false);
|
||||
const query = ref('');
|
||||
const searchInput = ref<HTMLInputElement | null>(null);
|
||||
|
||||
const selected = computed(() =>
|
||||
props.modelValue
|
||||
.map((id) => props.users.find((u) => u.id === id))
|
||||
.filter((u): u is NonNullable<typeof u> => Boolean(u)),
|
||||
);
|
||||
|
||||
const label = computed(() => {
|
||||
if (!selected.value.length) return props.emptyLabel;
|
||||
if (selected.value.length === 1) return selected.value[0]!.fullName;
|
||||
return `${selected.value[0]!.fullName} و ${toFaDigits(selected.value.length - 1)} نفر دیگر`;
|
||||
});
|
||||
|
||||
const filtered = computed(() => {
|
||||
const q = normalizeSearchText(query.value);
|
||||
if (!q) return props.users;
|
||||
return props.users.filter(
|
||||
(u) =>
|
||||
normalizeSearchText(u.fullName).includes(q) ||
|
||||
normalizeSearchText(u.orgRoleName ?? '').includes(q),
|
||||
);
|
||||
});
|
||||
|
||||
function toggleMenu() {
|
||||
if (props.disabled) return;
|
||||
open.value = !open.value;
|
||||
if (open.value) {
|
||||
void nextTick(() => searchInput.value?.focus());
|
||||
}
|
||||
}
|
||||
|
||||
function close() {
|
||||
open.value = false;
|
||||
}
|
||||
|
||||
function toggle(userId: string) {
|
||||
if (props.disabled) return;
|
||||
const set = new Set(props.modelValue);
|
||||
if (set.has(userId)) set.delete(userId);
|
||||
else set.add(userId);
|
||||
const next = [...set];
|
||||
emit('update:modelValue', next);
|
||||
emit('change', next);
|
||||
}
|
||||
|
||||
watch(open, (isOpen) => {
|
||||
if (!isOpen) query.value = '';
|
||||
});
|
||||
|
||||
defineExpose({ close });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="wrap" @click.stop>
|
||||
<button
|
||||
class="picker person-pick"
|
||||
type="button"
|
||||
:disabled="disabled"
|
||||
@click="toggleMenu"
|
||||
>
|
||||
<div class="assignee-avatars">
|
||||
<UserAvatar
|
||||
v-for="user in selected.slice(0, 3)"
|
||||
:key="user.id"
|
||||
:name="user.fullName"
|
||||
:user-id="user.id"
|
||||
:has-avatar="user.hasAvatar"
|
||||
:size="28"
|
||||
/>
|
||||
<UserAvatar v-if="!selected.length" name="مسئول" :size="28" />
|
||||
</div>
|
||||
<span :class="{ ghost: !selected.length }">{{ label }}</span>
|
||||
<UiIcon name="chevron" :size="16" />
|
||||
</button>
|
||||
|
||||
<div v-if="open" class="menu person-menu multi-menu" @click.stop>
|
||||
<label class="person-search">
|
||||
<UiIcon name="search" :size="15" />
|
||||
<input
|
||||
ref="searchInput"
|
||||
v-model="query"
|
||||
type="search"
|
||||
placeholder="جستجوی نام یا نقش…"
|
||||
@keydown.esc="close"
|
||||
/>
|
||||
</label>
|
||||
<ul class="person-list">
|
||||
<li v-for="user in filtered" :key="user.id">
|
||||
<button
|
||||
type="button"
|
||||
class="multi-option"
|
||||
:class="{ on: modelValue.includes(user.id) }"
|
||||
@click="toggle(user.id)"
|
||||
>
|
||||
<span class="check" :class="{ on: modelValue.includes(user.id) }">
|
||||
<UiIcon v-if="modelValue.includes(user.id)" name="check-plain" :size="12" />
|
||||
</span>
|
||||
<UserAvatar
|
||||
:name="user.fullName"
|
||||
:user-id="user.id"
|
||||
:has-avatar="user.hasAvatar"
|
||||
:size="28"
|
||||
/>
|
||||
<span class="role-name">{{ user.fullName }}</span>
|
||||
<small v-if="user.orgRoleName" class="role-count">{{ user.orgRoleName }}</small>
|
||||
</button>
|
||||
</li>
|
||||
<li v-if="!filtered.length" class="menu-empty">موردی پیدا نشد.</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.wrap {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
min-width: 12rem;
|
||||
}
|
||||
|
||||
.picker {
|
||||
width: 100%;
|
||||
min-height: var(--control-h, 36px);
|
||||
height: var(--control-h, 36px);
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: var(--radius, 10px);
|
||||
background: #fff;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.6rem;
|
||||
padding: 0.4rem 0.7rem;
|
||||
font: inherit;
|
||||
text-align: start;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.picker:disabled {
|
||||
opacity: 0.65;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.picker .ghost {
|
||||
color: #94a3b8;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.picker :deep(.ico:last-child) {
|
||||
margin-inline-start: auto;
|
||||
color: #94a3b8;
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
.assignee-avatars {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.assignee-avatars :deep(.avatar),
|
||||
.assignee-avatars > * {
|
||||
margin-inline-end: -0.35rem;
|
||||
box-shadow: 0 0 0 2px #fff;
|
||||
}
|
||||
|
||||
.menu {
|
||||
position: absolute;
|
||||
inset-inline: 0;
|
||||
top: calc(100% + 0.25rem);
|
||||
z-index: 40;
|
||||
margin: 0;
|
||||
background: #fff;
|
||||
border-radius: var(--radius, 10px);
|
||||
box-shadow: 0 16px 40px rgba(15, 23, 42, 0.14);
|
||||
}
|
||||
|
||||
.person-menu {
|
||||
max-height: none;
|
||||
overflow: visible;
|
||||
display: grid;
|
||||
gap: 0.35rem;
|
||||
padding: 0.45rem;
|
||||
border: 1px solid #e2e8f0;
|
||||
}
|
||||
|
||||
.person-search {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.45rem;
|
||||
height: 2.4rem;
|
||||
padding: 0 0.7rem;
|
||||
border: 1px solid #e2e8f0;
|
||||
border-radius: var(--radius, 10px);
|
||||
color: #94a3b8;
|
||||
}
|
||||
|
||||
.person-search:focus-within {
|
||||
border-color: #5eead4;
|
||||
}
|
||||
|
||||
.person-search input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
border: 0;
|
||||
outline: none;
|
||||
background: transparent;
|
||||
font: inherit;
|
||||
font-size: 0.88rem;
|
||||
color: #0f172a;
|
||||
}
|
||||
|
||||
.person-list {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
max-height: 15rem;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.multi-menu .multi-option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.55rem;
|
||||
width: 100%;
|
||||
border: 0;
|
||||
background: none;
|
||||
padding: 0.55rem 0.5rem;
|
||||
border-radius: var(--radius, 10px);
|
||||
font: inherit;
|
||||
text-align: start;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.multi-menu .multi-option:hover {
|
||||
background: #f8fafc;
|
||||
}
|
||||
|
||||
.multi-menu .multi-option.on {
|
||||
background: #f0fdfa;
|
||||
}
|
||||
|
||||
.multi-menu .check {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
border: 1.5px solid #cbd5e1;
|
||||
border-radius: 5px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.multi-menu .check.on {
|
||||
background: #14b8a6;
|
||||
border-color: #14b8a6;
|
||||
}
|
||||
|
||||
.multi-menu .role-name {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.multi-menu .role-count {
|
||||
margin-inline-start: auto;
|
||||
color: #94a3b8;
|
||||
font-size: 0.72rem;
|
||||
}
|
||||
|
||||
.menu-empty {
|
||||
padding: 0.6rem;
|
||||
color: #94a3b8;
|
||||
font-size: 0.82rem;
|
||||
}
|
||||
</style>
|
||||
@@ -122,17 +122,27 @@ function apiMessage(e: unknown, fallback: string) {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
async function send() {
|
||||
async function send(force = false) {
|
||||
if (!props.endpoint || busy.value || done.value) return;
|
||||
busy.value = true;
|
||||
error.value = '';
|
||||
try {
|
||||
await api.post(props.endpoint, { text: text.value });
|
||||
await api.post(props.endpoint, { text: text.value, ...(force ? { force: true } : {}) });
|
||||
done.value = 'پیامک ارسال شد.';
|
||||
emit('sent');
|
||||
void loadHistory();
|
||||
} catch (e) {
|
||||
error.value = apiMessage(e, 'ارسال پیامک ناموفق بود.');
|
||||
if (axios.isAxiosError(e) && e.response?.status === 409) {
|
||||
const msg = apiMessage(e, 'قبلاً پیامک تبریک فرستاده شده است. دوباره بفرستیم؟');
|
||||
if (confirm(msg)) {
|
||||
busy.value = false;
|
||||
await send(true);
|
||||
return;
|
||||
}
|
||||
error.value = msg;
|
||||
} else {
|
||||
error.value = apiMessage(e, 'ارسال پیامک ناموفق بود.');
|
||||
}
|
||||
} finally {
|
||||
busy.value = false;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ import { computed, onMounted, ref } from 'vue';
|
||||
import { RouterLink } from 'vue-router';
|
||||
import { api } from '@/lib/api';
|
||||
import { toFaDigits } from '@/lib/jalali';
|
||||
import { hasSectionPermission } from '@/lib/section-permissions';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import UiIcon from '@/components/UiIcon.vue';
|
||||
import { UiModal } from '@/components/ui';
|
||||
import SmsComposeModal from '@/components/SmsComposeModal.vue';
|
||||
@@ -25,9 +27,13 @@ type BirthdayMonth = {
|
||||
items: BirthdayItem[];
|
||||
};
|
||||
|
||||
const auth = useAuthStore();
|
||||
const data = ref<BirthdayMonth | null>(null);
|
||||
const listOpen = ref(false);
|
||||
const smsTarget = ref<BirthdayItem | null>(null);
|
||||
const canSeeCustomers = computed(() =>
|
||||
hasSectionPermission(auth.user?.role, auth.user?.permissions, 'customers'),
|
||||
);
|
||||
|
||||
const groups = computed(() => {
|
||||
const map = new Map<number, BirthdayItem[]>();
|
||||
@@ -44,6 +50,10 @@ function openSms(person: BirthdayItem) {
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
if (!canSeeCustomers.value) {
|
||||
data.value = null;
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const { data: body } = await api.get<BirthdayMonth>('/people/birthdays');
|
||||
data.value = body.total > 0 ? body : null;
|
||||
|
||||
@@ -1324,6 +1324,11 @@ export interface CustomerGroupSummaryDto {
|
||||
source?: "manual" | "tahesab";
|
||||
}
|
||||
|
||||
export interface CustomerGroupAssigneeDto {
|
||||
id: string;
|
||||
fullName: string;
|
||||
}
|
||||
|
||||
export interface CustomerGroupDto {
|
||||
id: string;
|
||||
name: string;
|
||||
@@ -1336,11 +1341,14 @@ export interface CustomerGroupDto {
|
||||
/** گروه اصلی؛ خالی یعنی خودش اصلی است */
|
||||
parentId?: string | null;
|
||||
parentName?: string | null;
|
||||
/** مسئولان گروه (اختیاری) */
|
||||
assignees: CustomerGroupAssigneeDto[];
|
||||
}
|
||||
|
||||
export interface CreateCustomerGroupRequest {
|
||||
name: string;
|
||||
color?: CustomerGroupColor;
|
||||
assigneeIds?: string[];
|
||||
}
|
||||
|
||||
export interface UpdateCustomerGroupRequest {
|
||||
@@ -1348,6 +1356,8 @@ export interface UpdateCustomerGroupRequest {
|
||||
color?: CustomerGroupColor;
|
||||
/** null = برداشتن گروه اصلی */
|
||||
parentId?: string | null;
|
||||
/** جایگزینی کامل فهرست مسئولان */
|
||||
assigneeIds?: string[];
|
||||
}
|
||||
|
||||
export interface CompanySummaryDto {
|
||||
|
||||
Reference in New Issue
Block a user