122 lines
2.6 KiB
TypeScript
122 lines
2.6 KiB
TypeScript
import api from './api';
|
|
|
|
// Field Types - matching backend enum
|
|
export type FieldType =
|
|
| 'TEXT'
|
|
| 'TEXTAREA'
|
|
| 'CHECKBOX'
|
|
| 'CHECKBOX_GROUP'
|
|
| 'RADIO'
|
|
| 'SELECT'
|
|
| 'MULTI_SELECT'
|
|
| 'RANGE'
|
|
| 'NUMBER'
|
|
| 'DATE'
|
|
| 'TAG_INPUT'
|
|
| 'FILE'
|
|
| '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;
|
|
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;
|
|
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();
|