feat: Implement dynamic agent profile editing by introducing new services and dynamic UI components.
This commit is contained in:
115
src/services/profile-sections.service.ts
Normal file
115
src/services/profile-sections.service.ts
Normal file
@@ -0,0 +1,115 @@
|
||||
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';
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
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;
|
||||
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();
|
||||
Reference in New Issue
Block a user