Skip to content

feat: add invoice template system with custom branding#262

Open
Jayrodri088 wants to merge 2 commits intodavedumto:mainfrom
Jayrodri088:feat-invoice-templete-system
Open

feat: add invoice template system with custom branding#262
Jayrodri088 wants to merge 2 commits intodavedumto:mainfrom
Jayrodri088:feat-invoice-templete-system

Conversation

@Jayrodri088
Copy link

Summary

Adds an invoice template system so freelancers can customize invoice appearance (logo, colors, footer) and keep branding consistent across invoices, PDFs, and email notifications.

Changes

API

  • GET/POST /api/routes-d/branding/templates – List templates, create template (max 5 per user, first or explicitly set default).
  • GET/PUT/DELETE /api/routes-d/branding/templates/[id] – Get, update, or delete a template; setting isDefault: true clears default on others.
  • POST /api/routes-d/branding/logo-upload – Upload branding logo (images only, max 2MB). Returns path stored on template.
  • GET /api/routes-d/branding/logo?path=userId/filename – Authenticated serve for logo files (used by editor preview and PDF).

Database

  • New InvoiceTemplate model: id, userId, name, isDefault, logoUrl, primaryColor, accentColor, showLogo, showFooter, footerText, layout (modern | classic | minimal), timestamps. Index on (userId, isDefault).
  • User has new relation invoiceTemplates.

Frontend

  • components/settings/TemplateEditor.tsx – Template list, create/edit form, hex color pickers for primary/accent, logo file upload, live invoice-style preview, set default, delete. Resolves /branding-logos/ logo URLs via authenticated fetch for preview.

PDF & email

  • lib/invoice-renderer.tsx – Branded invoice PDF with template config (logo, colors, layout, footer). Re-exported from lib/pdf.tsx for backward compatibility.
  • Invoice PDF route uses default template (or BrandingSettings fallback); resolves /branding-logos/ to absolute path for server-side rendering.
  • Invoice-created and invoice auto-cancelled emails accept optional branding (primary/accent/footerText/logoUrl) and use default template when available (subscription cron, bulk invoices, cancel-overdue cron).

Other

  • lib/file-storage.tsvalidateLogoFile, storeBrandingLogoFile, getBrandingLogoAbsolutePath for branding logos under uploads/branding-logos/.
  • lib/email-templates/invoice-auto-cancelled.tsx – Optional branding prop for logo and colors.

Acceptance criteria (from spec)

  • Users can upload custom logo (max 2MB).
  • Hex color picker for primary/accent.
  • Live preview of invoice template.
  • Set default template (applies to new invoices / PDF / emails).
  • Max 5 templates per user.
  • Templates apply to email notifications.
  • Export invoice as branded PDF.

How to test

  1. npm install, npx prisma generate, npx prisma migrate dev --name add-invoice-templates, npm run dev.
  2. Mount <TemplateEditor /> on a settings/branding page, log in, create a template, upload a logo, set default.
  3. Create an invoice and open /api/routes-d/invoices/[id]/pdf (or use existing PDF action) – PDF should use template logo/colors/footer.
  4. Trigger invoice-created or auto-cancelled flows and confirm emails use template branding when a default template exists.

Notes

  • Logo in emails only displays if logoUrl is a full public URL; stored /branding-logos/ paths are used for in-app preview and PDF only.
  • Existing BrandingSettings remains supported as fallback when no invoice template exists.

Closes: #240

@vercel
Copy link

vercel bot commented Feb 25, 2026

@Jayrodri088 is attempting to deploy a commit to the david's projects Team on Vercel.

A member of the Team first needs to authorize it.

@davedumto
Copy link
Owner

HI @Jayrodri088 FIX THE CI ERRORS

@Jayrodri088
Copy link
Author

@davedumto errors fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add invoice template system with custom branding

2 participants