Appearance
Templates System
Overview
The templates system provides a simple, type-safe way to manage predefined configurations for forms and HTML blocks. Templates are stored as TypeScript enums and can be easily extended without modifying multiple files. The system works across multiple components and is fully extensible.
Architecture
1. Template Definition (types.ts)
Templates are defined as an enum with human-readable display names:
typescript
export enum FormTemplate {
LEADGEN = 'Lead Gen',
CONTEST = 'Contest',
SURVEY = 'Survey',
CONTACT = 'Contact',
EMPTY = 'Empty Form',
}The enum value serves dual purpose:
- Registry key: Used to look up template generators
- Display label: Shown directly in the UI
2. Template Registry (src/templates/index.ts)
Each template is registered with its enum value as the key:
typescript
export const templateRegistry: TemplateRegistry = {
[FormTemplate.LEADGEN]: leadGenFormTemplate,
[FormTemplate.CONTEST]: contestFormTemplate,
[FormTemplate.SURVEY]: surveyFormTemplate,
[FormTemplate.CONTACT]: contactFormTemplate,
[FormTemplate.EMPTY]: emptyFormTemplate,
}3. Template Retrieval (templateHelper.ts)
Simple helper to get template data:
typescript
export const getFormTemplate = (templateName: FormTemplate) => getTemplate(templateName)4. Component Usage (FormConfiguration.vue)
- Track current template in
data()ascurrentTemplate - Use
computedproperties to derive selected value and label - Update on selection via
handleTemplateSelect()
typescript
data() {
return {
currentTemplate: FormTemplate.EMPTY,
}
},
computed: {
selectedTemplateValue() {
return this.currentTemplate
},
selectedTemplateLabel() {
return this.currentTemplate // Value IS the label!
},
},
methods: {
async handleTemplateSelect(value: FormTemplate) {
this.currentTemplate = value
await this.applyTemplate(value)
},
}Adding a New Template
Form Template
Add to enum in
src/pages/Chatbots/components/BuilderVisuals/Blocks/data/types.ts:typescriptNEWSLETTER = 'Newsletter',Create template file in
src/templates/form/:typescriptexport const newsletterFormTemplate = () => ({ // template structure... })Register template in
src/templates/index.ts:typescriptimport { newsletterFormTemplate } from './form/newsletterForm' export const templateRegistry: TemplateRegistry = { // ... existing templates [FormTemplate.NEWSLETTER]: newsletterFormTemplate, }
HTML Template
Add to enum in
src/pages/Chatbots/components/BuilderVisuals/Blocks/data/types.ts:typescriptexport enum HtmlTemplate { CUSTOM = 'Custom HTML', // Add new templates here }Create template file in
src/templates/html/:typescriptexport const customHtmlTemplate = () => ({ blockType: 'htmlProperties', html: '<div>Your HTML here</div>', // ... other properties })Register template in
src/templates/index.ts:typescriptimport { customHtmlTemplate } from './html/customHtml' export const templateRegistry: TemplateRegistry = { // ... existing templates [HtmlTemplate.CUSTOM]: customHtmlTemplate, }Done! The new template is automatically available in the UI and works across all components that use HTML blocks.
Key Benefits
- ✅ Single source of truth: Enum values are both keys and labels
- ✅ No duplication: No separate label maps needed
- ✅ Type-safe: Full TypeScript support
- ✅ Scalable: Add new templates without modifying existing code
- ✅ Simple: Minimal boilerplate, easy to understand
- ✅ Reactive: Computed properties ensure UI stays in sync
File Structure
src/
├── templates/
│ ├── index.ts # Central registry for all templates
│ ├── form/
│ │ ├── index.ts # Form template exports
│ │ ├── leadGenForm.ts
│ │ ├── contestForm.ts
│ │ ├── surveyForm.ts
│ │ ├── contactForm.ts
│ │ └── emptyForm.ts
│ └── html/
│ ├── index.ts # HTML template exports
│ ├── defaultHtml.ts
│ ├── emptyHtml.ts
│ ├── flexHtml.ts
│ ├── gridHtml.ts
│ └── ... (other HTML templates)
└── pages/Chatbots/components/BuilderVisuals/
├── Blocks/data/
│ └── types.ts # FormTemplate & HtmlTemplate enums
└── Configuration/
├── helpers/templateHelper.ts
├── configs/
│ ├── FormConfiguration.vue
│ └── HtmlConfiguration.vue
└── components/TemplateButton.vue