refactor: remove InvoiceView component and update related email and invoice handling

- Deleted the InvoiceView component to streamline the codebase.
- Updated EmailPreview and SendEmailDialog components to include currency and notes fields.
- Enhanced invoice-form to handle default hourly rates and improved item mapping.
- Refactored email template generation to include notes and currency formatting.
- Adjusted API routers for invoices to calculate totals and handle notes and currency correctly.
This commit is contained in:
2026-04-28 00:34:56 -04:00
parent ad89ad001d
commit 84a5d997b4
12 changed files with 739 additions and 969 deletions
+33 -3
View File
@@ -6,6 +6,7 @@ interface InvoiceEmailTemplateProps {
status: string;
totalAmount: number;
taxRate: number;
currency?: string | null;
notes?: string | null;
client: {
name: string;
@@ -57,10 +58,22 @@ export function generateInvoiceEmailTemplate({
const formatCurrency = (amount: number) => {
return new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",
currency: invoice.currency ?? "USD",
}).format(amount);
};
const escapeHtml = (value: string) =>
value
.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#39;");
const formattedNotes = invoice.notes?.trim()
? escapeHtml(invoice.notes).replace(/\n/g, "<br>")
: "";
const getTimeOfDayGreeting = () => {
const hour = new Date().getHours();
if (hour < 12) return "Good morning";
@@ -459,7 +472,16 @@ export function generateInvoiceEmailTemplate({
</div>
</div>
${
formattedNotes
? `<div class="invoice-card">
<div class="invoice-summary">
<div class="invoice-number" style="font-size: 18px;">Notes</div>
</div>
<div class="message" style="margin-bottom: 0;">${formattedNotes}</div>
</div>`
: ""
}
<div class="attachment-notice">
<div class="attachment-icon"></div>
@@ -540,7 +562,15 @@ Subtotal: ${formatCurrency(subtotal)}${
}
Total: ${formatCurrency(total)}
${
invoice.notes?.trim()
? `
NOTES
═══════════════
${invoice.notes.trim()}
`
: ""
}
ATTACHMENT
═══════════════