Files
frontend/src/services/profile-sections.service.ts

122 lines
2.6 KiB
TypeScript
Raw Normal View History

import api from './api';
// Field Types - matching backend enum
export type FieldType =
| 'TEXT'
| 'TEXTAREA'
| 'CHECKBOX'
| 'CHECKBOX_GROUP'
| 'RADIO'
| 'SELECT'
| 'MULTI_SELECT'
| 'RANGE'
| 'NUMBER'
| 'DATE'
2026-01-24 21:06:13 +05:30
| 'TAG_INPUT'
| 'FILE'
2026-01-24 22:31:14 +05:30
| 'FILE_UPLOAD'
| 'REPEATER';
// Types
export interface FieldOption {
value: string;
label: string;
}
export interface RangeConfig {
min: number;
max: number;
step?: number;
unit?: string;
}
export interface FieldValidation {
min?: number;
max?: number;
minLength?: number;
maxLength?: number;
pattern?: string;
2026-01-24 21:06:13 +05:30
allowedFormats?: string[];
maxFileSize?: number;
}
export interface FieldUiConfig {
columns?: number;
showInPreview?: boolean;
helpText?: string;
}
export interface ProfileField {
id: string;
sectionId: string;
name: string;
slug: string;
fieldType: FieldType;
description: string | null;
placeholder: string | null;
defaultValue: string | null;
sortOrder: number;
isActive: boolean;
isRequired: boolean;
isSearchableOnly: boolean;
validation: FieldValidation | null;
options: FieldOption[] | null;
rangeConfig: RangeConfig | null;
uiConfig: FieldUiConfig | null;
}
export interface ProfileSection {
id: string;
name: string;
slug: string;
description: string | null;
icon: string | null;
sortOrder: number;
isActive: boolean;
isGlobal: boolean;
isSystem: boolean;
2026-01-24 21:36:37 +05:30
isRepeatable: boolean;
fields?: ProfileField[];
isRequired?: boolean;
effectiveSortOrder?: number;
hasCustomOrder?: boolean;
}
export interface AgentTypeSectionsResponse {
agentType: {
id: string;
name: string;
description: string | null;
};
sections: ProfileSection[];
}
interface ApiResponse<T> {
success: boolean;
data: T;
message?: string;
}
// Profile Sections Service for Web
class ProfileSectionsService {
private basePath = '/profile-sections';
async getSectionsForAgentType(agentTypeId: string, includeFields = true): Promise<AgentTypeSectionsResponse> {
const url = includeFields
? `${this.basePath}/agent-type/${agentTypeId}`
: `${this.basePath}/agent-type/${agentTypeId}?includeFields=false`;
const response = await api.get<ApiResponse<AgentTypeSectionsResponse>>(url);
return response.data.data;
}
async getAll(includeInactive = false): Promise<ProfileSection[]> {
const url = includeInactive
? `${this.basePath}?includeInactive=true`
: this.basePath;
const response = await api.get<ApiResponse<ProfileSection[]>>(url);
return response.data.data;
}
}
export const profileSectionsService = new ProfileSectionsService();