Free & Open-Source Invoice Generator - No Sign-Up, No Ads, Instant PDF Export, 100% In-Browser, and Fully Customizable Templates.
TypeScript fintechinvoiceinvoice-generatorinvoice-pdfinvoice-templateinvoicesnextjsopen-sourcequotesreactreact-pdf-rendererself-hostedshadcn-uitailwindcsstypescript
fix: fix i18n issue with generating pdf via api + other improvements (#181)
Vlad Sazonaub407d39731f1
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.ymlindex a5eb186..8438879 100644--- a/.github/workflows/lint.yml+++ b/.github/workflows/lint.yml@@ -57,9 +57,6 @@ jobs:body: |Linting for ${{ github.repository }} has failed.- Branch: ${{ github.ref_name }}- Commit: ${{ github.sha }}-For more details, please check:- GitHub Actions run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}${{ steps.pr-url.outputs.pr_url && format('- Pull Request: {0}', steps.pr-url.outputs.pr_url) }}diff --git a/.github/workflows/type-check.yml b/.github/workflows/type-check.ymlindex 62ba023..8040e6d 100644--- a/.github/workflows/type-check.yml+++ b/.github/workflows/type-check.yml@@ -57,9 +57,6 @@ jobs:body: |Type check for ${{ github.repository }} has failed.- Branch: ${{ github.ref_name }}- Commit: ${{ github.sha }}-For more details, please check:- GitHub Actions run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}${{ steps.pr-url.outputs.pr_url && format('- Pull Request: {0}', steps.pr-url.outputs.pr_url) }}diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.ymlindex 06e552f..1b79b8e 100644--- a/.github/workflows/unit-tests.yml+++ b/.github/workflows/unit-tests.yml@@ -58,9 +58,6 @@ jobs:body: |Unit tests for ${{ github.repository }} have failed.- Branch: ${{ github.ref_name }}- Commit: ${{ github.sha }}-For more details, please check:- GitHub Actions run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}${{ steps.pr-url.outputs.pr_url && format('- Pull Request: {0}', steps.pr-url.outputs.pr_url) }}diff --git a/e2e/invoice-form.test.ts b/e2e/invoice-form.test.tsindex 8777a9d..56b0053 100644--- a/e2e/invoice-form.test.ts+++ b/e2e/invoice-form.test.ts@@ -22,13 +22,8 @@ test.describe("Invoice Generator Page", () => {});test("should redirect from /:locale/app to /", async ({ page }) => {- // listener starts FIRST- // navigation starts SECOND- // should eliminate flakiness- await Promise.all([- page.waitForURL("**/?template=default"),- page.goto("/en/app"),- ]);+ await page.goto("/en/app");+ await page.waitForURL("**/?template=default");// wait for the app page to loadconst downloadPDFButton = page.getByRole("link", {@@ -39,6 +34,20 @@ test.describe("Invoice Generator Page", () => {await expect(downloadPDFButton).toBeEnabled();});+ test("returns permanent redirect from /:locale/app to /", async ({+ request,+ }) => {+ const response = await request.get("/en/app", {+ maxRedirects: 0, // IMPORTANT+ });++ // this is a Next.js permanent redirect defined in next.config.mjs+ expect(response.status()).toBe(308); // Next.js permanent redirect+ expect(response.statusText()).toBe("Permanent Redirect");+ // we expect the redirect to the root URL+ expect(response.headers().location).toBe("/");+ });+test("displays correct OG meta tags for default template", async ({page,}) => {diff --git a/e2e/stripe-invoice-template/stripe-invoice-template.test.ts b/e2e/stripe-invoice-template/stripe-invoice-template.test.tsindex 849f9bb..18a1b1b 100644--- a/e2e/stripe-invoice-template/stripe-invoice-template.test.ts+++ b/e2e/stripe-invoice-template/stripe-invoice-template.test.ts@@ -617,6 +617,7 @@ test.describe("Stripe Invoice Template", () => {// NOTE: Unit field switch is visible in stripe templateawait expect(unitFieldSwitch).toBeVisible();+ await expect(unitFieldSwitch).not.toBeChecked(); // should be unchecked by default to match stripe template behaviour (and for backwards compatibility)await expect(netPriceFieldSwitch).toBeHidden();diff --git a/package.json b/package.jsonindex d34b86c..0badd96 100644--- a/package.json+++ b/package.json@@ -3,9 +3,6 @@"version": "1.0.1","private": true,"packageManager": "[email protected]+sha512.3590e550d5384caa39bd5c7c739f72270234b2f6059e13018f975c313b1eb9fefcc09714048765d4d9efe961382c312e624572c0420762bdc5d5940cdf9be73a",- "engines": {- "node": ">=20.0.0"- },"scripts": {"dev": "next dev","build": "next build",diff --git a/src/app/(app)/components/invoice-form/sections/general-information.tsx b/src/app/(app)/components/invoice-form/sections/general-information.tsxindex d6c7d48..45b0131 100644--- a/src/app/(app)/components/invoice-form/sections/general-information.tsx+++ b/src/app/(app)/components/invoice-form/sections/general-information.tsx@@ -184,7 +184,7 @@ export const GeneralInformation = memo(function GeneralInformation({// Set date format to "MMMM D, YYYY" when template is StripesetValue("dateFormat", STRIPE_DEFAULT_DATE_FORMAT);- // Set unit field to be hidden by default for Stripe template (backwards compatibility)+ // Set unit field to be HIDDEN by default for Stripe template (matches stripe template behaviour)setValue("items.0.unitFieldIsVisible", false);} else {// DEFAULT TEMPLATE@@ -201,6 +201,9 @@ export const GeneralInformation = memo(function GeneralInformation({// Set date format to "YYYY-MM-DD" when template is defaultsetValue("dateFormat", DEFAULT_DATE_FORMAT);++ // Set unit field to be VISIBLE for default template+ setValue("items.0.unitFieldIsVisible", true);}}}>diff --git a/src/app/(app)/components/invoice-form/sections/invoice-items.tsx b/src/app/(app)/components/invoice-form/sections/invoice-items.tsxindex bb6d36f..01b99bf 100644--- a/src/app/(app)/components/invoice-form/sections/invoice-items.tsx+++ b/src/app/(app)/components/invoice-form/sections/invoice-items.tsx@@ -862,7 +862,7 @@ function DeleteInvoiceItemConfirmationDialog({<AlertDialogContent><AlertDialogHeader><AlertDialogTitle>Delete Invoice Item</AlertDialogTitle>- <AlertDialogDescription>+ <AlertDialogDescription className="text-balance">Are you sure you want to delete the invoice item{" "}<strong>"{itemName}"</strong>? This action cannot beundone.diff --git a/src/app/api/generate-invoice/render-pdf-on-server.tsx b/src/app/api/generate-invoice/render-pdf-on-server.tsxindex c18ff35..b488e4e 100644--- a/src/app/api/generate-invoice/render-pdf-on-server.tsx+++ b/src/app/api/generate-invoice/render-pdf-on-server.tsx@@ -169,4 +169,12 @@ export const POLISH_INVOICE_REAL_DATA = {label: translateInvoiceNumberLabel({ language: "pl" }),value: INVOICE_DEFAULT_NUMBER_VALUE,},+ buyer: {+ ...ENGLISH_INVOICE_REAL_DATA.buyer,+ vatNoLabelText: "NIP", // on polish invoices, we use "NIP" instead of "VAT"+ },+ seller: {+ ...ENGLISH_INVOICE_REAL_DATA.seller,+ vatNoLabelText: "NIP", // on polish invoices, we use "NIP" instead of "VAT"+ },} as const satisfies InvoiceData;diff --git a/src/app/api/generate-invoice/route.tsx b/src/app/api/generate-invoice/route.tsxindex 3f1d7d4..a7f6e2a 100644--- a/src/app/api/generate-invoice/route.tsx+++ b/src/app/api/generate-invoice/route.tsx@@ -58,13 +58,17 @@ export async function GET(req: NextRequest) {);}+ // only send email if the query parameter "sendEmail" is not "false" (for backwards compatibility), we want to send email by default, but allow to disable it for testing purposes+ const shouldSendEmail =+ req.nextUrl.searchParams.get("sendEmail") !== "false";+const GENERATED_ENGLISH_INVOICE_PDF_DOCUMENT = renderToBuffer(<InvoicePdfTemplateToRenderOnBackendinvoiceData={ENGLISH_INVOICE_REAL_DATA}/>,).catch((err) => {console.error(- "\n\n_________________________Error during `renderToBuffer` for English invoice:",+ "\n\n_________________________[generate-invoice] Error during `renderToBuffer` for ENGLISH invoice:",err,);@@ -77,7 +81,7 @@ export async function GET(req: NextRequest) {/>,).catch((err) => {console.error(- "\n\n_________________________Error during `renderToBuffer` for Polish invoice:",+ "\n\n_________________________[generate-invoice] Error during `renderToBuffer` for POLISH invoice:",err,);@@ -134,7 +138,7 @@ export async function GET(req: NextRequest) {if (!ATTACHMENTS.length) {return NextResponse.json(- { error: "No attachments found" },+ { error: "[generate-invoice] No attachments found" },{ status: 400 },);}@@ -188,12 +192,14 @@ export async function GET(req: NextRequest) {if (failedUploads.length > 0) {console.error(- "Some files failed to upload to Google Drive:",+ "[generate-invoice] Some files failed to upload to Google Drive:",failedUploads,);return NextResponse.json(- { error: "Failed to upload invoices to Google Drive" },+ {+ error: "[generate-invoice] Failed to upload invoices to Google Drive",+ },{ status: 500 },);}@@ -211,8 +217,7 @@ export async function GET(req: NextRequest) {// *___________SEND NOTIFICATIONS___________*// Send notifications in parallel- const notificationResults = await Promise.allSettled([- // Send Telegram notification with PDFs+ const notifications: Promise<unknown>[] = [sendTelegramMessage({message: `π *Invoices for ${monthAndYear}*@@ -235,13 +240,15 @@ EasyInvoicePDF.com`,buffer: Buffer.from(attachment.content),})),}),-- // Send email with PDF attachment- resend.emails.send({- from: "Vlad from EasyInvoicePDF.com <[email protected]>",- to: env.INVOICE_EMAIL_RECIPIENT,- subject: `π Invoices for ${monthAndYear}`,- html: `<p>Hello,</p>+ ];++ if (shouldSendEmail) {+ notifications.push(+ resend.emails.send({+ from: "Vlad from EasyInvoicePDF.com <[email protected]>",+ to: env.INVOICE_EMAIL_RECIPIENT,+ subject: `π Invoices for ${monthAndYear}`,+ html: `<p>Hello,</p><span>Invoice No. of: <b>${invoiceNumberValue}</b><br/>Date: <b>${dayjs().format("MMMM D, YYYY")}</b><br/>@@ -262,18 +269,41 @@ EasyInvoicePDF.com`,Have a nice day!<br/><br/>Best regards,<br/>EasyInvoicePDF.com</span>`,- attachments: ATTACHMENTS,- }),- ]);+ attachments: ATTACHMENTS,+ }),+ );+ }++ const notificationResults = await Promise.allSettled(notifications);const failedNotifications = notificationResults.filter((result): result is PromiseRejectedResult => result.status === "rejected",);if (failedNotifications.length > 0) {- console.error("Some notifications failed to send:", failedNotifications);+ const errorMessage = `Some notifications failed to send:\n${JSON.stringify(+ failedNotifications,+ null,+ 2,+ )}`;++ console.error("[generate-invoice] Error in route:", errorMessage);++ // Send error to Telegram+ try {+ await sendTelegramMessage({+ message: `π¨ Error in generate-invoice API route\n\n${errorMessage}`,+ });+ } catch (telegramError) {+ console.error(+ "Failed to send error notification to Telegram:",+ telegramError,+ );+ }- throw new Error("Failed to send some notifications");+ throw new Error("[generate-invoice] Failed to send notifications", {+ cause: errorMessage,+ });}return NextResponse.json(@@ -281,10 +311,10 @@ EasyInvoicePDF.com`,{ status: 200 },);} catch (error) {- console.error("Error in generate-invoice route:", error);+ console.error("[generate-invoice] Error in route:", error);return NextResponse.json(- { error: "Failed to generate and send invoice" },+ { error: "[generate-invoice] Failed to generate and send invoice" },{ status: 500 },);}