Repository navigation
feat: Multi-Template Support - #5
maheshrijal wants to merge 4 commits into
Conversation
Adds template registry, selector UI, default module, and minimalist template.
Deploying rebill with
|
| Latest commit: |
ccf990d
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://a50b34d2.rebill.pages.dev |
| Branch Preview URL: | https://feat-multi-template-support.rebill.pages.dev |
Greptile SummaryThis PR successfully implements a multi-template system for invoice generation with a clean, extensible architecture. The implementation moves PDF generation logic from a monolithic Key Changes:
Architecture: Issues Addressed: Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant UI as index.html
participant Main as main.js
participant Form as form.js
participant Invoice as invoice.js
participant PDF as pdf.js
participant Registry as template-registry.js
participant Template as Template Module
User->>UI: Select template from dropdown
UI->>Main: Change event on templateId
Main->>Form: syncFromForm({ render: true })
Form->>Form: getDataFromForm()
Form->>Form: Collect templateId from form
Form->>Invoice: renderInvoice(data)
Invoice->>Invoice: Extract templateId from settings
Invoice->>Invoice: Update CSS class to invoice-template-{id}
Invoice->>UI: Update DOM with preview
User->>UI: Click "Download PDF"
UI->>PDF: downloadPDF()
PDF->>Form: getDataFromForm()
Form-->>PDF: Return data with templateId
PDF->>PDF: generateDocumentDefinition(data)
PDF->>Registry: getTemplate(templateId)
Registry->>Registry: Find template by id
Registry-->>PDF: Return template strategy
PDF->>Template: template.generateDocumentDefinition(data)
Template->>Template: Build pdfmake document definition
Template-->>PDF: Return docDefinition
PDF->>PDF: pdfMake.createPdf(docDefinition)
PDF->>User: Download PDF file
|
|
|
||
| import { getDataFromForm } from './form.js'; | ||
| import { formatCurrency, formatDate } from './formatters.js'; | ||
| import { getTemplate } from './templates/template-registry.js'; |
There was a problem hiding this comment.
syntax: missing import for getDataFromForm which is used on lines 34 and 67
| import { getTemplate } from './templates/template-registry.js'; | |
| import { getDataFromForm } from './form.js'; | |
| import { getTemplate } from './templates/template-registry.js'; |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/js/modules/pdf.js
Line: 6:6
Comment:
**syntax:** missing import for `getDataFromForm` which is used on lines 34 and 67
```suggestion
import { getDataFromForm } from './form.js';
import { getTemplate } from './templates/template-registry.js';
```
How can I resolve this? If you propose a fix, please make it concise.| const templates = [ | ||
| { id: 'default', name: 'Default Standard' }, | ||
| { id: 'minimal', name: 'Minimalist' } | ||
| ]; |
There was a problem hiding this comment.
logic: returns plain objects without generateDocumentDefinition method, but pdf.js:16 calls template.generateDocumentDefinition(data) causing runtime error
| const templates = [ | |
| { id: 'default', name: 'Default Standard' }, | |
| { id: 'minimal', name: 'Minimalist' } | |
| ]; | |
| import defaultTemplate from './default.js'; | |
| import minimalTemplate from './minimal.js'; | |
| const templates = [ | |
| defaultTemplate, | |
| minimalTemplate | |
| ]; |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/js/modules/templates/template-registry.js
Line: 6:9
Comment:
**logic:** returns plain objects without `generateDocumentDefinition` method, but `pdf.js:16` calls `template.generateDocumentDefinition(data)` causing runtime error
```suggestion
import defaultTemplate from './default.js';
import minimalTemplate from './minimal.js';
const templates = [
defaultTemplate,
minimalTemplate
];
```
How can I resolve this? If you propose a fix, please make it concise.
Playwright test resultsDetails
Failed testschromium › advanced-features.spec.js › Advanced Invoice Features › should calculate tax and discount correctly in preview and PDF |
Moved template selector near Generate button and added explicit change listener for instant preview update.
Summary
Implements support for multiple invoice templates.
Changes
template-registry.jsand modularized PDF generation.Verification