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
feat: stripe template improvements (Template-aware UI, etc) (#137)
Vlad Sazonau8e36e79a9f50
diff --git a/e2e/invoice-form.test.ts b/e2e/invoice-form.test.tsindex cb64232..c816af2 100644--- a/e2e/invoice-form.test.ts+++ b/e2e/invoice-form.test.ts@@ -433,6 +433,15 @@ test.describe("Invoice Generator Page", () => {invoiceItemsSection.getByRole("switch", { name: /Show in PDF/i }).nth(5),).toBeChecked();+ // Verify VAT helper text is displayed+ await expect(+ invoiceItemsSection+ .getByTestId(`itemVat0`)+ .getByText(+ 'Enter "NP" (not applicable), "OO" (out of scope), or a percentage value (0-100)',+ ),+ ).toBeVisible();+// Net Amount field (read-only) and visibility toggleawait expect(invoiceItemsSection.getByRole("textbox", {@@ -976,7 +985,9 @@ test.describe("Invoice Generator Page", () => {await vatInput.fill("abc");await expect(- page.getByText("Must be a valid number (0-100) or NP or OO"),+ page.getByText(+ `Must be a valid number (0-100), "NP" (not applicable), or "OO" (out of scope)`,+ ),).toBeVisible();// Try valid values@@ -985,12 +996,16 @@ test.describe("Invoice Generator Page", () => {await vatInput.fill("NP");await expect(- page.getByText("Must be a valid number (0-100) or NP or OO"),+ page.getByText(+ `Must be a valid number (0-100), "NP" (not applicable), or "OO" (out of scope)`,+ ),).toBeHidden();await vatInput.fill("OO");await expect(- page.getByText("Must be a valid number (0-100) or NP or OO"),+ page.getByText(+ `Must be a valid number (0-100), "NP" (not applicable), or "OO" (out of scope)`,+ ),).toBeHidden();});diff --git a/e2e/stripe-invoice-template/template.test.ts b/e2e/stripe-invoice-template/template.test.tsindex 0ae38b6..454247a 100644--- a/e2e/stripe-invoice-template/template.test.ts+++ b/e2e/stripe-invoice-template/template.test.ts@@ -1,6 +1,7 @@import {PDF_DATA_LOCAL_STORAGE_KEY,STRIPE_DEFAULT_DATE_FORMAT,+ SUPPORTED_DATE_FORMATS,type InvoiceData,} from "@/app/schema";import { expect, test } from "@playwright/test";@@ -193,213 +194,6 @@ test.describe("Stripe Invoice Template", () => {).toBeHidden();});- test("Invoice Type field and signature fields only appear for default template", async ({- page,- }) => {- // Verify default template is selected by default- await expect(page).toHaveURL("/?template=default");-- const generalInfoSection = page.getByTestId("general-information-section");- const finalSection = page.getByTestId("final-section");-- // Initially default template - Invoice Type field should be visible- await expect(- generalInfoSection.getByRole("textbox", { name: "Invoice Type" }),- ).toBeVisible();-- // Invoice Type visibility switch should be visible- await expect(- generalInfoSection.getByRole("switch", { name: "Show in PDF" }),- ).toBeVisible();-- // Signature fields should be visible for default template- await expect(- finalSection.getByRole("switch", {- name: 'Show "Person Authorized to Receive" Signature Field in the PDF',- }),- ).toBeVisible();-- await expect(- finalSection.getByRole("switch", {- name: 'Show "Person Authorized to Issue" Signature Field in the PDF',- }),- ).toBeVisible();-- // Switch to Stripe template- await page- .getByRole("combobox", { name: "Invoice Template" })- .selectOption("stripe");-- // Wait for URL to be updated- await page.waitForURL("/?template=stripe");-- await expect(page).toHaveURL("/?template=stripe");-- // Invoice Type field should now be hidden- await expect(- generalInfoSection.getByRole("textbox", { name: "Invoice Type" }),- ).toBeHidden();-- // Signature fields should be hidden for Stripe template- await expect(- finalSection.getByRole("switch", {- name: 'Show "Person Authorized to Receive" Signature Field in the PDF',- }),- ).toBeHidden();-- await expect(- finalSection.getByRole("switch", {- name: 'Show "Person Authorized to Issue" Signature Field in the PDF',- }),- ).toBeHidden();-- // Switch back to default template- await page- .getByRole("combobox", { name: "Invoice Template" })- .selectOption("default");-- // Invoice Type field should be visible again- await expect(- generalInfoSection.getByRole("textbox", { name: "Invoice Type" }),- ).toBeVisible();-- // Invoice Type visibility switch should be visible again- await expect(- generalInfoSection.getByRole("switch", { name: "Show in PDF" }),- ).toBeVisible();-- // Signature fields should be visible again for default template- await expect(- finalSection.getByRole("switch", {- name: 'Show "Person Authorized to Receive" Signature Field in the PDF',- }),- ).toBeVisible();-- await expect(- finalSection.getByRole("switch", {- name: 'Show "Person Authorized to Issue" Signature Field in the PDF',- }),- ).toBeVisible();- });-- test("signature field switches work correctly in default template", async ({- page,- }) => {- // Verify default template is selected by default- await expect(page).toHaveURL("/?template=default");-- const finalSection = page.getByTestId("final-section");-- // Get the signature field switches- const personAuthorizedToReceiveSwitch = finalSection.getByRole("switch", {- name: 'Show "Person Authorized to Receive" Signature Field in the PDF',- });-- const personAuthorizedToIssueSwitch = finalSection.getByRole("switch", {- name: 'Show "Person Authorized to Issue" Signature Field in the PDF',- });-- // Verify both switches are visible and enabled- await expect(personAuthorizedToReceiveSwitch).toBeVisible();- await expect(personAuthorizedToReceiveSwitch).toBeEnabled();- await expect(personAuthorizedToIssueSwitch).toBeVisible();- await expect(personAuthorizedToIssueSwitch).toBeEnabled();-- // Verify initial state (should be checked by default based on initial data)- await expect(personAuthorizedToReceiveSwitch).toBeChecked();- await expect(personAuthorizedToIssueSwitch).toBeChecked();-- // Toggle the switches- await personAuthorizedToReceiveSwitch.click();- await personAuthorizedToIssueSwitch.click();-- // Verify switches are now unchecked- await expect(personAuthorizedToReceiveSwitch).not.toBeChecked();- await expect(personAuthorizedToIssueSwitch).not.toBeChecked();-- // Toggle them back- await personAuthorizedToReceiveSwitch.click();- await personAuthorizedToIssueSwitch.click();-- // Verify switches are checked again- await expect(personAuthorizedToReceiveSwitch).toBeChecked();- await expect(personAuthorizedToIssueSwitch).toBeChecked();-- // Switch to Stripe template to verify switches become hidden- await page- .getByRole("combobox", { name: "Invoice Template" })- .selectOption("stripe");-- await page.waitForURL("/?template=stripe");-- // Verify switches are now hidden- await expect(personAuthorizedToReceiveSwitch).toBeHidden();- await expect(personAuthorizedToIssueSwitch).toBeHidden();- });-- test("Invoice Type field works correctly in default template", async ({- page,- }) => {- // Verify default template is selected by default- await expect(page).toHaveURL("/?template=default");-- const generalInfoSection = page.getByTestId("general-information-section");-- // Get the Invoice Type field and its visibility switch- const invoiceTypeField = generalInfoSection.getByRole("textbox", {- name: "Invoice Type",- });- const invoiceTypeVisibilitySwitch = generalInfoSection.getByRole("switch", {- name: "Show in PDF",- });-- // Verify field and switch are visible and enabled- await expect(invoiceTypeField).toBeVisible();- await expect(invoiceTypeField).toBeEnabled();- await expect(invoiceTypeVisibilitySwitch).toBeVisible();- await expect(invoiceTypeVisibilitySwitch).toBeEnabled();-- // Verify initial state (should be checked by default)- await expect(invoiceTypeVisibilitySwitch).toBeChecked();-- // Test filling in the Invoice Type field- await invoiceTypeField.fill("Test Invoice Type");- await expect(invoiceTypeField).toHaveValue("Test Invoice Type");-- // Test toggling the visibility switch- await invoiceTypeVisibilitySwitch.click();- await expect(invoiceTypeVisibilitySwitch).not.toBeChecked();-- // Toggle it back- await invoiceTypeVisibilitySwitch.click();- await expect(invoiceTypeVisibilitySwitch).toBeChecked();-- // Clear the field and verify it's empty- await invoiceTypeField.clear();- await expect(invoiceTypeField).toHaveValue("");-- // Switch to Stripe template to verify field becomes hidden- await page- .getByRole("combobox", { name: "Invoice Template" })- .selectOption("stripe");-- await page.waitForURL("/?template=stripe");-- // Verify Invoice Type field is now hidden- await expect(invoiceTypeField).toBeHidden();-- // Switch back to default template- await page- .getByRole("combobox", { name: "Invoice Template" })- .selectOption("default");-- // Verify field is visible again and data persists- await expect(invoiceTypeField).toBeVisible();- await expect(invoiceTypeField).toHaveValue(""); // Should be empty as we cleared it- await expect(invoiceTypeVisibilitySwitch).toBeVisible();- await expect(invoiceTypeVisibilitySwitch).toBeChecked(); // Should maintain its state- });-test("validates file types and shows error for invalid files", async ({page,}) => {@@ -735,4 +529,437 @@ test.describe("Stripe Invoice Template", () => {generalInfoSection.getByAltText("Company logo preview"),).toBeVisible();});++ test("Signature fields only appears for default template", async ({+ page,+ }) => {+ // Verify default template is selected by default+ await expect(page).toHaveURL("/?template=default");++ const finalSection = page.getByTestId("final-section");++ // Get the signature field switches+ const personAuthorizedToReceiveSwitch = finalSection.getByRole("switch", {+ name: 'Show "Person Authorized to Receive" Signature Field in the PDF',+ });++ const personAuthorizedToIssueSwitch = finalSection.getByRole("switch", {+ name: 'Show "Person Authorized to Issue" Signature Field in the PDF',+ });++ // Verify both switches are visible and enabled+ await expect(personAuthorizedToReceiveSwitch).toBeVisible();+ await expect(personAuthorizedToReceiveSwitch).toBeEnabled();+ await expect(personAuthorizedToIssueSwitch).toBeVisible();+ await expect(personAuthorizedToIssueSwitch).toBeEnabled();++ // Verify initial state (should be checked by default based on initial data)+ await expect(personAuthorizedToReceiveSwitch).toBeChecked();+ await expect(personAuthorizedToIssueSwitch).toBeChecked();++ // Switch to Stripe template to verify switches become hidden+ await page+ .getByRole("combobox", { name: "Invoice Template" })+ .selectOption("stripe");++ await page.waitForURL("/?template=stripe");++ // Verify switches are now hidden+ await expect(personAuthorizedToReceiveSwitch).toBeHidden();+ await expect(personAuthorizedToIssueSwitch).toBeHidden();+ });++ test("Invoice Type field only appears for default template", async ({+ page,+ }) => {+ // Verify default template is selected by default+ await expect(page).toHaveURL("/?template=default");++ const generalInfoSection = page.getByTestId("general-information-section");++ // Get the Invoice Type field and its visibility switch+ const invoiceTypeField = generalInfoSection.getByRole("textbox", {+ name: "Invoice Type",+ });+ const invoiceTypeVisibilitySwitch = generalInfoSection.getByRole("switch", {+ name: "Show in PDF",+ });++ // Verify field and switch are visible and enabled+ await expect(invoiceTypeField).toBeVisible();+ await expect(invoiceTypeField).toBeEnabled();+ await expect(invoiceTypeVisibilitySwitch).toBeVisible();+ await expect(invoiceTypeVisibilitySwitch).toBeEnabled();++ // Verify initial state (should be checked by default)+ await expect(invoiceTypeVisibilitySwitch).toBeChecked();++ // Test filling in the Invoice Type field+ await invoiceTypeField.fill("Test Invoice Type");+ await expect(invoiceTypeField).toHaveValue("Test Invoice Type");++ // Test toggling the visibility switch+ await invoiceTypeVisibilitySwitch.click();+ await expect(invoiceTypeVisibilitySwitch).not.toBeChecked();++ // Toggle it back+ await invoiceTypeVisibilitySwitch.click();+ await expect(invoiceTypeVisibilitySwitch).toBeChecked();++ // Clear the field and verify it's empty+ await invoiceTypeField.clear();+ await expect(invoiceTypeField).toHaveValue("");++ // Switch to Stripe template to verify field becomes hidden+ await page+ .getByRole("combobox", { name: "Invoice Template" })+ .selectOption("stripe");++ await page.waitForURL("/?template=stripe");++ // Verify Invoice Type field is now hidden+ await expect(invoiceTypeField).toBeHidden();++ // Switch back to default template+ await page+ .getByRole("combobox", { name: "Invoice Template" })+ .selectOption("default");++ // Verify field is visible again and data persists+ await expect(invoiceTypeField).toBeVisible();+ await expect(invoiceTypeField).toHaveValue(""); // Should be empty as we cleared it+ await expect(invoiceTypeVisibilitySwitch).toBeVisible();+ await expect(invoiceTypeVisibilitySwitch).toBeChecked(); // Should maintain its state+ });++ test("Invoice items fields and switches only appear for default template", async ({+ page,+ }) => {+ // Verify default template is selected by default+ await expect(page).toHaveURL("/?template=default");++ const invoiceItemsSection = page.getByTestId("invoice-items-section");++ // =============== GLOBAL SWITCHES TESTING ===============++ // 1. Show Number Column switch+ const showNumberColumnSwitch = invoiceItemsSection.getByRole("switch", {+ name: 'Show "Number" Column in the Invoice Items Table',+ });++ await expect(showNumberColumnSwitch).toBeVisible();+ await expect(showNumberColumnSwitch).toBeEnabled();+ await expect(showNumberColumnSwitch).toBeChecked(); // Should be checked by default++ // 2. Show VAT Table Summary switch+ const showVatTableSummarySwitch = invoiceItemsSection.getByRole("switch", {+ name: 'Show "VAT Table Summary" in the PDF',+ });++ await expect(showVatTableSummarySwitch).toBeVisible();+ await expect(showVatTableSummarySwitch).toBeEnabled();+ await expect(showVatTableSummarySwitch).toBeChecked(); // Should be checked by default++ // =============== ITEM FIELD SWITCHES TESTING ===============++ // Get all "Show in PDF" switches for individual fields (these are the ones that only show for first item)+ const nameFieldSwitch = invoiceItemsSection+ .getByRole("switch", { name: /Show in PDF/i })+ .nth(0);+ const typeOfGTUFieldSwitch = invoiceItemsSection+ .getByRole("switch", { name: /Show in PDF/i })+ .nth(1);+ const amountFieldSwitch = invoiceItemsSection+ .getByRole("switch", { name: /Show in PDF/i })+ .nth(2);+ const unitFieldSwitch = invoiceItemsSection+ .getByRole("switch", { name: /Show in PDF/i })+ .nth(3);+ const netPriceFieldSwitch = invoiceItemsSection+ .getByRole("switch", { name: /Show in PDF/i })+ .nth(4);+ const vatFieldSwitch = invoiceItemsSection+ .getByRole("switch", { name: /Show in PDF/i })+ .nth(5);+ const netAmountFieldSwitch = invoiceItemsSection+ .getByRole("switch", { name: /Show in PDF/i })+ .nth(6);+ const vatAmountFieldSwitch = invoiceItemsSection+ .getByRole("switch", { name: /Show in PDF/i })+ .nth(7);+ const preTaxAmountFieldSwitch = invoiceItemsSection+ .getByRole("switch", { name: /Show in PDF/i })+ .nth(8);++ // Verify all field switches are visible and enabled+ const fieldSwitches = [+ nameFieldSwitch,+ typeOfGTUFieldSwitch,+ amountFieldSwitch,+ unitFieldSwitch,+ netPriceFieldSwitch,+ vatFieldSwitch,+ netAmountFieldSwitch,+ vatAmountFieldSwitch,+ preTaxAmountFieldSwitch,+ ] as const;++ for (const switchElement of fieldSwitches) {+ await expect(switchElement).toBeVisible();+ await expect(switchElement).toBeEnabled();+ }++ // Check initial states (some switches should be checked by default, some not)+ await expect(nameFieldSwitch).toBeChecked();+ await expect(typeOfGTUFieldSwitch).not.toBeChecked(); // Type of GTU is not shown by default+ await expect(amountFieldSwitch).toBeChecked();+ await expect(unitFieldSwitch).toBeChecked();+ await expect(netPriceFieldSwitch).toBeChecked();+ await expect(vatFieldSwitch).toBeChecked();+ await expect(netAmountFieldSwitch).toBeChecked();+ await expect(vatAmountFieldSwitch).toBeChecked();+ await expect(preTaxAmountFieldSwitch).toBeChecked();++ // =============== TYPE OF GTU FIELD TESTING ===============++ // Type of GTU field should be visible+ const typeOfGTUField = invoiceItemsSection.getByRole("textbox", {+ name: "Type of GTU",+ });+ await expect(typeOfGTUField).toBeVisible();++ // =============== TOGGLE TESTING ===============++ // Test toggling the global switches+ await showNumberColumnSwitch.click();+ await expect(showNumberColumnSwitch).not.toBeChecked();+ await showNumberColumnSwitch.click();+ await expect(showNumberColumnSwitch).toBeChecked();++ await showVatTableSummarySwitch.click();+ await expect(showVatTableSummarySwitch).not.toBeChecked();+ await showVatTableSummarySwitch.click();+ await expect(showVatTableSummarySwitch).toBeChecked();++ // Test toggling some field switches+ await typeOfGTUFieldSwitch.click();+ await expect(typeOfGTUFieldSwitch).toBeChecked();+ await typeOfGTUFieldSwitch.click();+ await expect(typeOfGTUFieldSwitch).not.toBeChecked();++ await nameFieldSwitch.click();+ await expect(nameFieldSwitch).not.toBeChecked();+ await nameFieldSwitch.click();+ await expect(nameFieldSwitch).toBeChecked();++ // =============== STRIPE TEMPLATE TESTING ===============++ // Switch to Stripe template+ await page+ .getByRole("combobox", { name: "Invoice Template" })+ .selectOption("stripe");++ // Wait for URL to be updated+ await page.waitForURL("/?template=stripe");++ // All switches and Type of GTU field should now be hidden+ await expect(showNumberColumnSwitch).toBeHidden();+ await expect(showVatTableSummarySwitch).toBeHidden();+ await expect(typeOfGTUField).toBeHidden();++ for (const switchElement of fieldSwitches) {+ await expect(switchElement).toBeHidden();+ }++ // =============== BACK TO DEFAULT TEMPLATE TESTING ===============++ // Switch back to default template+ await page+ .getByRole("combobox", { name: "Invoice Template" })+ .selectOption("default");++ // All switches and Type of GTU field should be visible again+ await expect(showNumberColumnSwitch).toBeVisible();+ await expect(showVatTableSummarySwitch).toBeVisible();+ await expect(typeOfGTUField).toBeVisible();++ for (const switchElement of fieldSwitches) {+ await expect(switchElement).toBeVisible();+ }++ // Verify states are maintained after switching back+ await expect(showNumberColumnSwitch).toBeChecked();+ await expect(showVatTableSummarySwitch).toBeChecked();+ await expect(nameFieldSwitch).toBeChecked();+ await expect(typeOfGTUFieldSwitch).not.toBeChecked();+ });++ test("Payment Method field only appears for default template", async ({+ page,+ }) => {+ // Verify default template is selected by default+ await expect(page).toHaveURL("/?template=default");++ const finalSection = page.getByTestId("final-section");++ // Get the Payment Method field and its visibility switch+ const paymentMethodField = finalSection.getByRole("textbox", {+ name: "Payment Method",+ });+ const paymentMethodVisibilitySwitch = finalSection.getByTestId(+ "paymentMethodFieldIsVisible",+ );++ // Verify field and switch are visible and enabled for default template+ await expect(paymentMethodField).toBeVisible();+ await expect(paymentMethodField).toBeEnabled();+ await expect(paymentMethodVisibilitySwitch).toBeVisible();+ await expect(paymentMethodVisibilitySwitch).toBeEnabled();++ // Verify initial state (should be checked by default)+ await expect(paymentMethodVisibilitySwitch).toBeChecked();++ // Test filling in the Payment Method field+ await paymentMethodField.fill("Bank Transfer");+ await expect(paymentMethodField).toHaveValue("Bank Transfer");++ // Test toggling the visibility switch+ await paymentMethodVisibilitySwitch.click();+ await expect(paymentMethodVisibilitySwitch).not.toBeChecked();++ // Toggle it back+ await paymentMethodVisibilitySwitch.click();+ await expect(paymentMethodVisibilitySwitch).toBeChecked();++ // Switch to Stripe template to verify field becomes hidden+ await page+ .getByRole("combobox", { name: "Invoice Template" })+ .selectOption("stripe");++ await page.waitForURL("/?template=stripe");++ // Verify Payment Method field is now hidden+ await expect(paymentMethodField).toBeHidden();+ await expect(paymentMethodVisibilitySwitch).toBeHidden();++ // Switch back to default template+ await page+ .getByRole("combobox", { name: "Invoice Template" })+ .selectOption("default");++ // Verify field is visible again and data persists+ await expect(paymentMethodField).toBeVisible();+ await expect(paymentMethodField).toHaveValue("Bank Transfer");+ await expect(paymentMethodVisibilitySwitch).toBeVisible();+ await expect(paymentMethodVisibilitySwitch).toBeChecked(); // Should maintain its state+ });++ test("automatically enables VAT field visibility and sets date format when switching to Stripe template", async ({+ page,+ }) => {+ // Verify default template is selected by default+ await expect(page).toHaveURL("/?template=default");++ const invoiceItemsSection = page.getByTestId("invoice-items-section");++ // Get the VAT field switch (5th "Show in PDF" switch)+ const vatFieldSwitch = invoiceItemsSection+ .getByRole("switch", { name: /Show in PDF/i })+ .nth(5);++ // Verify VAT switch is visible and checked by default+ await expect(vatFieldSwitch).toBeVisible();+ await expect(vatFieldSwitch).toBeEnabled();+ await expect(vatFieldSwitch).toBeChecked();++ // SCENARIO: User disables VAT field visibility in default template+ await vatFieldSwitch.click();+ await expect(vatFieldSwitch).not.toBeChecked();++ // Set VAT to a numeric value to make Tax column potentially visible in Stripe+ const vatInput = invoiceItemsSection.getByRole("textbox", {+ name: "VAT",+ exact: true,+ });+ await vatInput.clear();+ await vatInput.fill("20");++ // Wait a moment for form state to update+ // eslint-disable-next-line playwright/no-wait-for-timeout+ await page.waitForTimeout(600);++ // Switch to Stripe template+ await page+ .getByRole("combobox", { name: "Invoice Template" })+ .selectOption("stripe");++ // Wait for URL to be updated+ await page.waitForURL("/?template=stripe");++ // VAT field switch should now be hidden (since most switches are hidden in Stripe)+ await expect(vatFieldSwitch).toBeHidden();++ // BUT the VAT field visibility should be automatically enabled+ // Let's verify this by checking the localStorage data+ const storedData = (await page.evaluate((key) => {+ return localStorage.getItem(key);+ }, PDF_DATA_LOCAL_STORAGE_KEY)) as string;++ expect(storedData).toBeTruthy();+ const parsedData = JSON.parse(storedData) as InvoiceData;++ // The VAT field should be automatically enabled for Stripe template+ expect(parsedData.items[0].vatFieldIsVisible).toBe(true);++ // The date format should be automatically set to Stripe default format+ expect(parsedData.dateFormat).toBe(STRIPE_DEFAULT_DATE_FORMAT);++ // Generate PDF to verify Tax column is visible+ const downloadPromise = page.waitForEvent("download");+ const downloadButton = page.getByRole("link", {+ name: "Download PDF in English",+ });++ await expect(downloadButton).toBeVisible();+ await downloadButton.click();++ const download = await downloadPromise;+ const suggestedFilename = download.suggestedFilename();+ const tmpPath = path.join(downloadDir, suggestedFilename);+ await download.saveAs(tmpPath);++ // Read and verify PDF content+ const dataBuffer = await fs.promises.readFile(tmpPath);+ const pdfData = await pdf(dataBuffer);++ // Verify that Tax column is visible in the Stripe template PDF+ expect(pdfData.text).toContain("DescriptionQtyUnit PriceTaxAmount");+ expect(pdfData.text).toContain("20%"); // The VAT percentage should be visible++ // Switch back to default template+ await page+ .getByRole("combobox", { name: "Invoice Template" })+ .selectOption("default");++ // Wait for URL to be updated+ await page.waitForURL("/?template=default");++ // VAT switch should be visible again and should maintain the enabled state+ await expect(vatFieldSwitch).toBeVisible();+ await expect(vatFieldSwitch).toBeChecked(); // Should be re-enabled due to Stripe template logic++ // Verify VAT input still has the numeric value+ await expect(vatInput).toHaveValue("20");++ // Verify that date format is restored to default template format+ const finalStoredData = (await page.evaluate((key) => {+ return localStorage.getItem(key);+ }, PDF_DATA_LOCAL_STORAGE_KEY)) as string;++ expect(finalStoredData).toBeTruthy();+ const finalParsedData = JSON.parse(finalStoredData) as InvoiceData;++ // The date format should be restored to default format+ expect(finalParsedData.dateFormat).toBe(SUPPORTED_DATE_FORMATS[0]);+ });});diff --git a/src/app/(app)/components/invoice-form/index.tsx b/src/app/(app)/components/invoice-form/index.tsxindex 0c7b649..6d62af0 100644--- a/src/app/(app)/components/invoice-form/index.tsx+++ b/src/app/(app)/components/invoice-form/index.tsx@@ -427,6 +427,7 @@ export const InvoiceForm = memo(function InvoiceForm({currency={currency}language={language}append={append}+ template={template}/></AccordionContent></AccordionItem>@@ -467,55 +468,58 @@ export const InvoiceForm = memo(function InvoiceForm({)}</div>- {/* Payment Method */}- <div>- <div className="relative mb-2 mt-6 flex items-center justify-between">- <Label htmlFor={`paymentMethod`} className="">- Payment Method- </Label>+ {/* Payment Method (Only show for default template) */}+ {template === "default" && (+ <div>+ <div className="relative mb-2 mt-6 flex items-center justify-between">+ <Label htmlFor={`paymentMethod`} className="">+ Payment Method+ </Label>- {/* Show/hide Payment Method field in PDF switch */}- <div className="inline-flex items-center gap-2">- <Controller- name={`paymentMethodFieldIsVisible`}- control={control}- render={({ field: { value, onChange, ...field } }) => (- <Switch- {...field}- id={`paymentMethodFieldIsVisible`}- checked={value}- onCheckedChange={onChange}- className="h-5 w-8 [&_span]:size-4 [&_span]:data-[state=checked]:translate-x-3 rtl:[&_span]:data-[state=checked]:-translate-x-3"- />- )}- />- <CustomTooltip- trigger={- <Label htmlFor={`paymentMethodFieldIsVisible`}>- Show in PDF- </Label>- }- content='Show/Hide the "Payment Method" Field in the PDF'- />+ {/* Show/hide Payment Method field in PDF switch */}+ <div className="inline-flex items-center gap-2">+ <Controller+ name={`paymentMethodFieldIsVisible`}+ control={control}+ render={({ field: { value, onChange, ...field } }) => (+ <Switch+ {...field}+ id={`paymentMethodFieldIsVisible`}+ checked={value}+ onCheckedChange={onChange}+ className="h-5 w-8 [&_span]:size-4 [&_span]:data-[state=checked]:translate-x-3 rtl:[&_span]:data-[state=checked]:-translate-x-3"+ data-testid="paymentMethodFieldIsVisible"+ />+ )}+ />+ <CustomTooltip+ trigger={+ <Label htmlFor={`paymentMethodFieldIsVisible`}>+ Show in PDF+ </Label>+ }+ content='Show/Hide the "Payment Method" Field in the PDF'+ />+ </div></div>- </div>- <Controller- name="paymentMethod"- control={control}- render={({ field }) => (- <Input- {...field}- id={`paymentMethod`}- type="text"- className="mt-1"- />+ <Controller+ name="paymentMethod"+ control={control}+ render={({ field }) => (+ <Input+ {...field}+ id={`paymentMethod`}+ type="text"+ className="mt-1"+ />+ )}+ />+ {errors.paymentMethod && (+ <ErrorMessage>{errors.paymentMethod.message}</ErrorMessage>)}- />- {errors.paymentMethod && (- <ErrorMessage>{errors.paymentMethod.message}</ErrorMessage>- )}- </div>+ </div>+ )}{/* Payment Due */}<div>diff --git a/src/app/(app)/components/invoice-form/sections/general-information.tsx b/src/app/(app)/components/invoice-form/sections/general-information.tsxindex a607bed..02a3e5c 100644--- a/src/app/(app)/components/invoice-form/sections/general-information.tsx+++ b/src/app/(app)/components/invoice-form/sections/general-information.tsx@@ -160,6 +160,9 @@ export const GeneralInformation = memo(function GeneralInformation({if (template === "stripe") {// Set date format to "MMMM D, YYYY" when template is StripesetValue("dateFormat", STRIPE_DEFAULT_DATE_FORMAT);++ // Always enable VAT field visibility for Stripe template (because we don't show Switches for items in Stripe template and we want to make sure the Tax column is visible in the PDF)+ setValue("items.0.vatFieldIsVisible", true);} else {// Clear Stripe-specific fields when not using Stripe templateif (errors.stripePayOnlineUrl) {diff --git a/src/app/(app)/components/invoice-form/sections/invoice-items.tsx b/src/app/(app)/components/invoice-form/sections/invoice-items.tsxindex 38354d3..178683c 100644--- a/src/app/(app)/components/invoice-form/sections/invoice-items.tsx+++ b/src/app/(app)/components/invoice-form/sections/invoice-items.tsx@@ -40,6 +40,7 @@ interface InvoiceItemsSettingsProps {errors: FieldErrors<InvoiceData>;currency: SupportedCurrencies;language: SupportedLanguages;+ template: InvoiceData["template"];}export const InvoiceItems = memo(function InvoiceItems({@@ -50,52 +51,56 @@ export const InvoiceItems = memo(function InvoiceItems({currency,language,append,+ template,}: InvoiceItemsSettingsProps) {return (<>- <div className="mb-3 space-y-4">- {/* Show Number column on PDF switch */}- <div className="relative flex items-center justify-between">- <Label htmlFor={`itemInvoiceItemNumberIsVisible0`}>- Show "Number" Column in the Invoice Items Table- </Label>-- <Controller- name={`items.0.invoiceItemNumberIsVisible`}- control={control}- render={({ field: { value, onChange, ...field } }) => (- <Switch- {...field}- id={`itemInvoiceItemNumberIsVisible0`}- checked={value}- onCheckedChange={onChange}- className="h-5 w-8 [&_span]:size-4 [&_span]:data-[state=checked]:translate-x-3 rtl:[&_span]:data-[state=checked]:-translate-x-3"- />- )}- />- </div>-- {/* Show VAT Table Summary in PDF switch */}- <div className="relative flex items-center justify-between">- <Label htmlFor={`vatTableSummaryIsVisible`}>- Show "VAT Table Summary" in the PDF- </Label>-- <Controller- name={`vatTableSummaryIsVisible`}- control={control}- render={({ field: { value, onChange, ...field } }) => (- <Switch- {...field}- id={`vatTableSummaryIsVisible`}- checked={value}- onCheckedChange={onChange}- className="h-5 w-8 [&_span]:size-4 [&_span]:data-[state=checked]:translate-x-3 rtl:[&_span]:data-[state=checked]:-translate-x-3"- />- )}- />+ {/** we only want to show these settings for default template */}+ {template === "default" && (+ <div className="mb-3 space-y-4">+ {/* Show Number column on PDF switch */}+ <div className="relative flex items-center justify-between">+ <Label htmlFor={`itemInvoiceItemNumberIsVisible0`}>+ Show "Number" Column in the Invoice Items Table+ </Label>++ <Controller+ name={`items.0.invoiceItemNumberIsVisible`}+ control={control}+ render={({ field: { value, onChange, ...field } }) => (+ <Switch+ {...field}+ id={`itemInvoiceItemNumberIsVisible0`}+ checked={value}+ onCheckedChange={onChange}+ className="h-5 w-8 [&_span]:size-4 [&_span]:data-[state=checked]:translate-x-3 rtl:[&_span]:data-[state=checked]:-translate-x-3"+ />+ )}+ />+ </div>++ {/* Show VAT Table Summary in PDF switch */}+ <div className="relative flex items-center justify-between">+ <Label htmlFor={`vatTableSummaryIsVisible`}>+ Show "VAT Table Summary" in the PDF+ </Label>++ <Controller+ name={`vatTableSummaryIsVisible`}+ control={control}+ render={({ field: { value, onChange, ...field } }) => (+ <Switch+ {...field}+ id={`vatTableSummaryIsVisible`}+ checked={value}+ onCheckedChange={onChange}+ className="h-5 w-8 [&_span]:size-4 [&_span]:data-[state=checked]:translate-x-3 rtl:[&_span]:data-[state=checked]:-translate-x-3"+ />+ )}+ />+ </div></div>- </div>+ )}{fields.map((field, index) => {const isNotFirstItem = index > 0;const isFirstItem = index === 0;@@ -142,8 +147,8 @@ export const InvoiceItems = memo(function InvoiceItems({Name</Label>- {/* Show/hide Name field in PDF switch */}- {isFirstItem ? (+ {/* Show/hide Name field in PDF switch (Only show for default template) */}+ {isFirstItem && template === "default" ? (<div className="inline-flex items-center gap-2"><Controllername={`items.${index}.nameFieldIsVisible`}@@ -190,62 +195,66 @@ export const InvoiceItems = memo(function InvoiceItems({)}</div>- {/* Invoice Item Type of GTU */}- <div>- <div className="mb-2 flex items-center justify-between">- <Label htmlFor={`itemTypeOfGTU${index}`} className="">- Type of GTU- </Label>+ {/* Invoice Item Type of GTU - Only show for default template */}+ {template === "default" && (+ <div>+ <div className="mb-2 flex items-center justify-between">+ <Label htmlFor={`itemTypeOfGTU${index}`} className="">+ Type of GTU+ </Label>++ {/* Show/hide Type of GTU field in PDF switch */}+ {isFirstItem ? (+ <div className="inline-flex items-center gap-2">+ <Controller+ name={`items.${index}.typeOfGTUFieldIsVisible`}+ control={control}+ render={({+ field: { value, onChange, ...field },+ }) => (+ <Switch+ {...field}+ id={`itemTypeOfGTUFieldIsVisible${index}`}+ checked={value}+ onCheckedChange={onChange}+ className="h-5 w-8 [&_span]:size-4 [&_span]:data-[state=checked]:translate-x-3 rtl:[&_span]:data-[state=checked]:-translate-x-3"+ />+ )}+ />+ <CustomTooltip+ trigger={+ <Label+ htmlFor={`itemTypeOfGTUFieldIsVisible${index}`}+ >+ Show in PDF+ </Label>+ }+ content='Show/hide the "Type of GTU" Column in the PDF'+ />+ </div>+ ) : null}+ </div>- {/* Show/hide Type of GTU field in PDF switch */}- {isFirstItem ? (- <div className="inline-flex items-center gap-2">- <Controller- name={`items.${index}.typeOfGTUFieldIsVisible`}- control={control}- render={({ field: { value, onChange, ...field } }) => (- <Switch- {...field}- id={`itemTypeOfGTUFieldIsVisible${index}`}- checked={value}- onCheckedChange={onChange}- className="h-5 w-8 [&_span]:size-4 [&_span]:data-[state=checked]:translate-x-3 rtl:[&_span]:data-[state=checked]:-translate-x-3"- />- )}- />- <CustomTooltip- trigger={- <Label- htmlFor={`itemTypeOfGTUFieldIsVisible${index}`}- >- Show in PDF- </Label>- }- content='Show/hide the "Type of GTU" Column in the PDF'+ {/* Type of GTU input */}+ <Controller+ name={`items.${index}.typeOfGTU`}+ control={control}+ render={({ field }) => (+ <Input+ {...field}+ id={`itemTypeOfGTU${index}`}+ className=""+ type="text"/>- </div>- ) : null}- </div>-- {/* Type of GTU input */}- <Controller- name={`items.${index}.typeOfGTU`}- control={control}- render={({ field }) => (- <Input- {...field}- id={`itemTypeOfGTU${index}`}- className=""- type="text"- />+ )}+ />+ {errors.items?.[index]?.typeOfGTU && (+ <ErrorMessage>+ {errors.items[index]?.typeOfGTU?.message}+ </ErrorMessage>)}- />- {errors.items?.[index]?.typeOfGTU && (- <ErrorMessage>- {errors.items[index]?.typeOfGTU?.message}- </ErrorMessage>- )}- </div>+ </div>+ )}{/* Invoice Item Amount */}<div>@@ -254,8 +263,8 @@ export const InvoiceItems = memo(function InvoiceItems({Amount (Quantity)</Label>- {/* Show/hide Amount field in PDF switch */}- {isFirstItem ? (+ {/* Show/hide Amount field in PDF switch (Only show for default template) */}+ {isFirstItem && template === "default" ? (<div className="inline-flex items-center gap-2"><Controllername={`items.${index}.amountFieldIsVisible`}@@ -327,8 +336,8 @@ export const InvoiceItems = memo(function InvoiceItems({Unit</Label>- {/* Show/hide Unit field in PDF switch */}- {isFirstItem ? (+ {/* Show/hide Unit field in PDF switch (Only show for default template) */}+ {isFirstItem && template === "default" ? (<div className="inline-flex items-center gap-2"><Controllername={`items.${index}.unitFieldIsVisible`}@@ -377,8 +386,8 @@ export const InvoiceItems = memo(function InvoiceItems({Net Price (Rate or Unit Price)</Label>- {/* Show/hide Net Price field in PDF switch */}- {isFirstItem ? (+ {/* Show/hide Net Price field in PDF switch (Only show for default template) */}+ {isFirstItem && template === "default" ? (<div className="inline-flex items-center gap-2"><Controllername={`items.${index}.netPriceFieldIsVisible`}@@ -462,14 +471,14 @@ export const InvoiceItems = memo(function InvoiceItems({</div>{/* Invoice Item VAT */}- <div>+ <div data-testid={`itemVat${index}`}><div className="mb-2 flex items-center justify-between"><Label htmlFor={`itemVat${index}`} className="">VAT</Label>- {/* Show/hide VAT field in PDF switch */}- {isFirstItem ? (+ {/* Show/hide VAT field in PDF switch (Only show for default template) */}+ {isFirstItem && template === "default" ? (<div className="inline-flex items-center gap-2"><Controllername={`items.${index}.vatFieldIsVisible`}@@ -514,7 +523,8 @@ export const InvoiceItems = memo(function InvoiceItems({<ErrorMessage>{errors.items[index].vat.message}</ErrorMessage>) : (<InputHelperMessage>- Enter NP, OO or percentage value (0-100)+ Enter "NP" (not applicable), "OO" (out+ of scope), or a percentage value (0-100)</InputHelperMessage>)}</div>@@ -526,8 +536,8 @@ export const InvoiceItems = memo(function InvoiceItems({Net Amount</Label>- {/* Show/hide Net Amount field in PDF switch */}- {isFirstItem ? (+ {/* Show/hide Net Amount field in PDF switch (Only show for default template) */}+ {isFirstItem && template === "default" ? (<div className="inline-flex items-center gap-2"><Controllername={`items.${index}.netAmountFieldIsVisible`}@@ -594,8 +604,8 @@ export const InvoiceItems = memo(function InvoiceItems({VAT Amount</Label>- {/* Show/hide VAT Amount field in PDF switch */}- {isFirstItem ? (+ {/* Show/hide VAT Amount field in PDF switch (Only show for default template) */}+ {isFirstItem && template === "default" ? (<div className="inline-flex items-center gap-2"><Controllername={`items.${index}.vatAmountFieldIsVisible`}@@ -662,8 +672,8 @@ export const InvoiceItems = memo(function InvoiceItems({Pre-tax Amount</Label>- {/* Show/hide Pre-tax Amount field in PDF switch */}- {isFirstItem ? (+ {/* Show/hide Pre-tax Amount field in PDF switch (Only show for default template) */}+ {isFirstItem && template === "default" ? (<div className="inline-flex items-center gap-2"><Controllername={`items.${index}.preTaxAmountFieldIsVisible`}diff --git a/src/app/schema/index.ts b/src/app/schema/index.tsindex 50b9fe9..08a431b 100644--- a/src/app/schema/index.ts+++ b/src/app/schema/index.ts@@ -255,10 +255,10 @@ export const invoiceItemSchema = zz.any().refine((val) => val !== "", {- message: "VAT is required (0-100 or NP or OO)",+ message: `VAT is required. Enter a percentage (0-100), "NP" (not applicable), or "OO" (out of scope)`,}).refine((val) => !isNaN(Number(val)), {- message: "Must be a valid number (0-100) or NP or OO",+ message: `Must be a valid number (0-100), "NP" (not applicable), or "OO" (out of scope)`,}).transform(Number).refine((val) => val >= 0 && val <= 100, {diff --git a/src/components/ui/input-helper-message.tsx b/src/components/ui/input-helper-message.tsxindex dde7475..809bdff 100644--- a/src/components/ui/input-helper-message.tsx+++ b/src/components/ui/input-helper-message.tsx@@ -7,7 +7,7 @@ export const InputHelperMessage = memo(function InputHelperMessage({}) {return (<p- className="mt-1 text-balance text-xs text-zinc-700/90"+ className="mt-1 text-pretty text-xs text-zinc-700/90"role="region"aria-live="polite">