A lead can carry the same honorific as a person, and a form that asks gender writes it onto the lead. Co-authored-by: Cursor <cursoragent@cursor.com>
299 lines
4.7 KiB
TypeScript
299 lines
4.7 KiB
TypeScript
import {
|
|
ArrayMaxSize,
|
|
IsArray,
|
|
IsBoolean,
|
|
IsIn,
|
|
IsObject,
|
|
IsOptional,
|
|
IsString,
|
|
MaxLength,
|
|
MinLength,
|
|
ValidateNested,
|
|
} from 'class-validator';
|
|
import { Type } from 'class-transformer';
|
|
import { LEAD_FORM_FIELD_TYPES } from '@mento/shared';
|
|
|
|
const MAP_TO = [
|
|
'person.firstName',
|
|
'person.lastName',
|
|
'person.fullName',
|
|
'person.email',
|
|
'person.mobile',
|
|
'person.phone',
|
|
'person.position',
|
|
'deal.title',
|
|
'deal.notes',
|
|
'lead.title',
|
|
'lead.contactName',
|
|
'lead.mobile',
|
|
'lead.phone',
|
|
'lead.city',
|
|
'lead.region',
|
|
'lead.trade',
|
|
'lead.notes',
|
|
'lead.source',
|
|
'lead.gender',
|
|
'person.gender',
|
|
'notes',
|
|
'custom',
|
|
] as const;
|
|
|
|
const DUPLICATE_MODES = ['skip', 'update', 'activity'] as const;
|
|
|
|
export class LeadFormFieldInputDto {
|
|
@IsOptional()
|
|
@IsString()
|
|
@MaxLength(64)
|
|
key?: string;
|
|
|
|
@IsString()
|
|
@MinLength(1)
|
|
@MaxLength(120)
|
|
label!: string;
|
|
|
|
@IsIn([...LEAD_FORM_FIELD_TYPES])
|
|
fieldType!: (typeof LEAD_FORM_FIELD_TYPES)[number];
|
|
|
|
@IsOptional()
|
|
@IsBoolean()
|
|
required?: boolean;
|
|
|
|
@IsIn(MAP_TO)
|
|
mapTo!: (typeof MAP_TO)[number];
|
|
|
|
@IsOptional()
|
|
position?: number;
|
|
|
|
@IsOptional()
|
|
@IsString()
|
|
@MaxLength(160)
|
|
placeholder?: string | null;
|
|
|
|
@IsOptional()
|
|
@IsArray()
|
|
@IsString({ each: true })
|
|
@ArrayMaxSize(40)
|
|
options?: string[];
|
|
}
|
|
|
|
export class CreateLeadFormDto {
|
|
@IsString()
|
|
@MinLength(2)
|
|
@MaxLength(120)
|
|
name!: string;
|
|
|
|
@IsOptional()
|
|
@IsString()
|
|
@MaxLength(400)
|
|
description?: string | null;
|
|
|
|
@IsOptional()
|
|
@IsBoolean()
|
|
createLead?: boolean;
|
|
|
|
@IsOptional()
|
|
@IsBoolean()
|
|
createPerson?: boolean;
|
|
|
|
@IsOptional()
|
|
@IsBoolean()
|
|
createDeal?: boolean;
|
|
|
|
@IsOptional()
|
|
@IsString()
|
|
pipelineId?: string | null;
|
|
|
|
@IsOptional()
|
|
@IsString()
|
|
leadStageId?: string | null;
|
|
|
|
@IsOptional()
|
|
@IsIn(DUPLICATE_MODES)
|
|
duplicateMode?: (typeof DUPLICATE_MODES)[number];
|
|
|
|
@IsOptional()
|
|
@IsString()
|
|
@MaxLength(80)
|
|
source?: string | null;
|
|
|
|
@IsOptional()
|
|
@IsString()
|
|
@MaxLength(500)
|
|
thankYouMessage?: string | null;
|
|
|
|
@IsOptional()
|
|
@IsString()
|
|
@MaxLength(500)
|
|
redirectUrl?: string | null;
|
|
|
|
@IsOptional()
|
|
@IsArray()
|
|
@IsString({ each: true })
|
|
@ArrayMaxSize(50)
|
|
assigneeIds?: string[];
|
|
|
|
@IsOptional()
|
|
@IsString()
|
|
@MaxLength(80)
|
|
submitLabel?: string;
|
|
|
|
@IsOptional()
|
|
@IsString()
|
|
@MaxLength(20)
|
|
submitColor?: string;
|
|
|
|
@IsOptional()
|
|
@IsArray()
|
|
@ValidateNested({ each: true })
|
|
@Type(() => LeadFormFieldInputDto)
|
|
@ArrayMaxSize(40)
|
|
fields?: LeadFormFieldInputDto[];
|
|
}
|
|
|
|
export class UpdateLeadFormDto {
|
|
@IsOptional()
|
|
@IsString()
|
|
@MinLength(2)
|
|
@MaxLength(120)
|
|
name?: string;
|
|
|
|
@IsOptional()
|
|
@IsString()
|
|
@MaxLength(400)
|
|
description?: string | null;
|
|
|
|
@IsOptional()
|
|
@IsBoolean()
|
|
isActive?: boolean;
|
|
|
|
@IsOptional()
|
|
@IsBoolean()
|
|
createLead?: boolean;
|
|
|
|
@IsOptional()
|
|
@IsBoolean()
|
|
createPerson?: boolean;
|
|
|
|
@IsOptional()
|
|
@IsBoolean()
|
|
createDeal?: boolean;
|
|
|
|
@IsOptional()
|
|
@IsString()
|
|
pipelineId?: string | null;
|
|
|
|
@IsOptional()
|
|
@IsString()
|
|
leadStageId?: string | null;
|
|
|
|
@IsOptional()
|
|
@IsIn(DUPLICATE_MODES)
|
|
duplicateMode?: (typeof DUPLICATE_MODES)[number];
|
|
|
|
@IsOptional()
|
|
@IsString()
|
|
@MaxLength(80)
|
|
source?: string | null;
|
|
|
|
@IsOptional()
|
|
@IsString()
|
|
@MaxLength(500)
|
|
thankYouMessage?: string | null;
|
|
|
|
@IsOptional()
|
|
@IsString()
|
|
@MaxLength(500)
|
|
redirectUrl?: string | null;
|
|
|
|
@IsOptional()
|
|
@IsArray()
|
|
@IsString({ each: true })
|
|
@ArrayMaxSize(50)
|
|
assigneeIds?: string[];
|
|
|
|
@IsOptional()
|
|
@IsString()
|
|
@MaxLength(80)
|
|
submitLabel?: string;
|
|
|
|
@IsOptional()
|
|
@IsString()
|
|
@MaxLength(20)
|
|
submitColor?: string;
|
|
|
|
@IsOptional()
|
|
@IsArray()
|
|
@ValidateNested({ each: true })
|
|
@Type(() => LeadFormFieldInputDto)
|
|
@ArrayMaxSize(40)
|
|
fields?: LeadFormFieldInputDto[];
|
|
}
|
|
|
|
export class LeadFormUtmDto {
|
|
@IsOptional()
|
|
@IsString()
|
|
@MaxLength(120)
|
|
source?: string;
|
|
|
|
@IsOptional()
|
|
@IsString()
|
|
@MaxLength(120)
|
|
medium?: string;
|
|
|
|
@IsOptional()
|
|
@IsString()
|
|
@MaxLength(160)
|
|
campaign?: string;
|
|
|
|
@IsOptional()
|
|
@IsString()
|
|
@MaxLength(160)
|
|
term?: string;
|
|
|
|
@IsOptional()
|
|
@IsString()
|
|
@MaxLength(160)
|
|
content?: string;
|
|
|
|
@IsOptional()
|
|
@IsString()
|
|
@MaxLength(500)
|
|
landingPage?: string;
|
|
|
|
@IsOptional()
|
|
@IsString()
|
|
@MaxLength(500)
|
|
referrer?: string;
|
|
}
|
|
|
|
export class SubmitLeadFormDto {
|
|
@IsObject()
|
|
values!: Record<string, string>;
|
|
|
|
@IsOptional()
|
|
@ValidateNested()
|
|
@Type(() => LeadFormUtmDto)
|
|
utm?: LeadFormUtmDto;
|
|
|
|
@IsOptional()
|
|
@IsString()
|
|
@MaxLength(1000)
|
|
pageUrl?: string;
|
|
|
|
@IsOptional()
|
|
@IsString()
|
|
@MaxLength(1000)
|
|
referrer?: string;
|
|
|
|
/** honeypot */
|
|
@IsOptional()
|
|
@IsString()
|
|
@MaxLength(200)
|
|
website?: string;
|
|
}
|
|
|
|
export class LeadFormPublicEventDto {
|
|
@IsIn(['view', 'start'])
|
|
type!: 'view' | 'start';
|
|
}
|