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: add Radix UI Accordion to invoice form for improved section organization (#56)
Vlad Sazonauac5a6f451057
diff --git a/package.json b/package.jsonindex c169670..5f1627d 100644--- a/package.json+++ b/package.json@@ -15,6 +15,7 @@"dependencies": {"@hookform/resolvers": "3.9.0","@openpanel/nextjs": "1.0.7",+ "@radix-ui/react-accordion": "1.2.3","@radix-ui/react-alert-dialog": "1.1.6","@radix-ui/react-dialog": "1.1.6","@radix-ui/react-label": "2.1.2",diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex bb08675..3ecf8cd 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -14,6 +14,9 @@ importers:'@openpanel/nextjs':specifier: 1.0.7version: 1.0.7([email protected]([email protected]([email protected]))([email protected]))([email protected]([email protected]))([email protected])+ '@radix-ui/react-accordion':+ specifier: 1.2.3+ version: 1.2.3(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])'@radix-ui/react-alert-dialog':specifier: 1.1.6version: 1.1.6(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])@@ -297,6 +300,19 @@ packages:'@radix-ui/[email protected]':resolution: {integrity: sha512-SJ31y+Q/zAyShtXJc8x83i9TYdbAfHZ++tUZnvjJJqFjzsdUnKsxPL6IEtBlxKkU7yzer//GQtZSV4GbldL3YA==}+ '@radix-ui/[email protected]':+ resolution: {integrity: sha512-RIQ15mrcvqIkDARJeERSuXSry2N8uYnxkdDetpfmalT/+0ntOXLkFOsh9iwlAsCv+qcmhZjbdJogIm6WBa6c4A==}+ peerDependencies:+ '@types/react': '*'+ '@types/react-dom': '*'+ react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ peerDependenciesMeta:+ '@types/react':+ optional: true+ '@types/react-dom':+ optional: true+'@radix-ui/[email protected]':resolution: {integrity: sha512-p4XnPqgej8sZAAReCAKgz1REYZEBLR8hU9Pg27wFnCWIMc8g1ccCs0FjBcy05V15VTu8pAePw/VDYeOm/uZ6yQ==}peerDependencies:@@ -323,6 +339,32 @@ packages:'@types/react-dom':optional: true+ '@radix-ui/[email protected]':+ resolution: {integrity: sha512-jFSerheto1X03MUC0g6R7LedNW9EEGWdg9W1+MlpkMLwGkgkbUXLPBH/KIuWKXUoeYRVY11llqbTBDzuLg7qrw==}+ peerDependencies:+ '@types/react': '*'+ '@types/react-dom': '*'+ react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ peerDependenciesMeta:+ '@types/react':+ optional: true+ '@types/react-dom':+ optional: true++ '@radix-ui/[email protected]':+ resolution: {integrity: sha512-9z54IEKRxIa9VityapoEYMuByaG42iSy1ZXlY2KcuLSEtq8x4987/N6m15ppoMffgZX72gER2uHe1D9Y6Unlcw==}+ peerDependencies:+ '@types/react': '*'+ '@types/react-dom': '*'+ react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ peerDependenciesMeta:+ '@types/react':+ optional: true+ '@types/react-dom':+ optional: true+'@radix-ui/[email protected]':resolution: {integrity: sha512-Y9VzoRDSJtgFMUCoiZBDVo084VQ5hfpXxVE+NgkdNsjiDBByiImMZKKhxMwCbdHvhlENG6a833CbFkOQvTricw==}peerDependencies:@@ -354,6 +396,15 @@ packages:'@types/react-dom':optional: true+ '@radix-ui/[email protected]':+ resolution: {integrity: sha512-BUuBvgThEiAXh2DWu93XsT+a3aWrGqolGlqqw5VU1kG7p/ZH2cuDlM1sRLNnY3QcBS69UIz2mcKhMxDsdewhjg==}+ peerDependencies:+ '@types/react': '*'+ react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc+ peerDependenciesMeta:+ '@types/react':+ optional: true+'@radix-ui/[email protected]':resolution: {integrity: sha512-E4TywXY6UsXNRhFrECa5HAvE5/4BFcGyfTyK36gP+pAW1ed7UTK4vKwdr53gAJYwqbfCWC6ATvJa3J3R/9+Qrg==}peerDependencies:@@ -2443,6 +2494,23 @@ snapshots:'@radix-ui/[email protected]': {}+ '@radix-ui/[email protected](@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])':+ dependencies:+ '@radix-ui/primitive': 1.1.1+ '@radix-ui/react-collapsible': 1.1.3(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])+ '@radix-ui/react-collection': 1.1.2(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])+ '@radix-ui/react-compose-refs': 1.1.1(@types/[email protected])([email protected])+ '@radix-ui/react-context': 1.1.1(@types/[email protected])([email protected])+ '@radix-ui/react-direction': 1.1.0(@types/[email protected])([email protected])+ '@radix-ui/react-id': 1.1.0(@types/[email protected])([email protected])+ '@radix-ui/react-primitive': 2.0.2(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])+ '@radix-ui/react-use-controllable-state': 1.1.0(@types/[email protected])([email protected])+ react: 18.3.1+ react-dom: 18.3.1([email protected])+ optionalDependencies:+ '@types/react': 18.3.12+ '@types/react-dom': 18.3.1+'@radix-ui/[email protected](@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])':dependencies:'@radix-ui/primitive': 1.1.1@@ -2466,6 +2534,34 @@ snapshots:'@types/react': 18.3.12'@types/react-dom': 18.3.1+ '@radix-ui/[email protected](@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])':+ dependencies:+ '@radix-ui/primitive': 1.1.1+ '@radix-ui/react-compose-refs': 1.1.1(@types/[email protected])([email protected])+ '@radix-ui/react-context': 1.1.1(@types/[email protected])([email protected])+ '@radix-ui/react-id': 1.1.0(@types/[email protected])([email protected])+ '@radix-ui/react-presence': 1.1.2(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])+ '@radix-ui/react-primitive': 2.0.2(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])+ '@radix-ui/react-use-controllable-state': 1.1.0(@types/[email protected])([email protected])+ '@radix-ui/react-use-layout-effect': 1.1.0(@types/[email protected])([email protected])+ react: 18.3.1+ react-dom: 18.3.1([email protected])+ optionalDependencies:+ '@types/react': 18.3.12+ '@types/react-dom': 18.3.1++ '@radix-ui/[email protected](@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])':+ dependencies:+ '@radix-ui/react-compose-refs': 1.1.1(@types/[email protected])([email protected])+ '@radix-ui/react-context': 1.1.1(@types/[email protected])([email protected])+ '@radix-ui/react-primitive': 2.0.2(@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])+ '@radix-ui/react-slot': 1.1.2(@types/[email protected])([email protected])+ react: 18.3.1+ react-dom: 18.3.1([email protected])+ optionalDependencies:+ '@types/react': 18.3.12+ '@types/react-dom': 18.3.1+dependencies:react: 18.3.1@@ -2500,6 +2596,12 @@ snapshots:'@types/react': 18.3.12'@types/react-dom': 18.3.1+ dependencies:+ react: 18.3.1+ optionalDependencies:+ '@types/react': 18.3.12+'@radix-ui/[email protected](@types/[email protected])(@types/[email protected])([email protected]([email protected]))([email protected])':dependencies:'@radix-ui/primitive': 1.1.1diff --git a/src/app/components/invoice-form.tsx b/src/app/components/invoice-form.tsxindex a3eb865..bc04cdb 100644--- a/src/app/components/invoice-form.tsx+++ b/src/app/components/invoice-form.tsx@@ -31,6 +31,12 @@ import { Controller, useFieldArray, useForm, useWatch } from "react-hook-form";import { toast } from "sonner";import { useDebouncedCallback } from "use-debounce";import { z } from "zod";+import {+ Accordion,+ AccordionContent,+ AccordionItem,+ AccordionTrigger,+} from "@/components/ui/accordion";export const PDF_DATA_LOCAL_STORAGE_KEY = "EASY_INVOICE_PDF_DATA";export const PDF_DATA_FORM_ID = "pdfInvoiceForm";@@ -38,6 +44,16 @@ export const DEBOUNCE_TIMEOUT = 500;export const LOADING_BUTTON_TIMEOUT = 400;export const LOADING_BUTTON_TEXT = "Generating Document...";+const DEFAULT_ACCORDION_VALUES = ["seller", "buyer", "invoiceItems"] as const;++const ACCORDION_SELLER = DEFAULT_ACCORDION_VALUES[0];+const ACCORDION_BUYER = DEFAULT_ACCORDION_VALUES[1];+const ACCORDION_ITEMS = DEFAULT_ACCORDION_VALUES[2];++type NonReadonly<T> = {+ -readonly [P in keyof T]: T[P] extends object ? NonReadonly<T[P]> : T[P];+};+const checkIfDateOnInvoiceIsInCurrentMonth = (date: string) => {const today = dayjs();@@ -580,1049 +596,1113 @@ export function InvoiceForm({)}</div>- {/* Seller Information */}- <fieldset className="rounded-lg border p-4 shadow">- <Legend>Seller Information</Legend>+ <Accordion+ type="multiple"+ // we need to cast to non-readonly to avoid type error+ defaultValue={+ DEFAULT_ACCORDION_VALUES as NonReadonly<+ typeof DEFAULT_ACCORDION_VALUES+ >+ }+ className="space-y-4"+ >+ {/* Seller Information */}+ <AccordionItem+ value={ACCORDION_SELLER}+ className="rounded-lg border shadow"+ >+ <AccordionTrigger className="px-4 py-3">+ <Legend>Seller Information</Legend>+ </AccordionTrigger>+ <AccordionContent className="px-4 pb-4">+ <div className="relative flex items-end justify-end gap-2">+ <SellerManagement+ setValue={setValue}+ invoiceData={invoiceData}+ />+ </div>+ <div className="space-y-4">+ <div>+ <Label htmlFor="sellerName" className="mb-1">+ Name+ </Label>+ <Controller+ name="seller.name"+ control={control}+ render={({ field }) => (+ <Textarea+ {...field}+ id="sellerName"+ rows={3}+ className=""+ />+ )}+ />+ {errors.seller?.name && (+ <ErrorMessage>{errors.seller.name.message}</ErrorMessage>+ )}+ </div>- {/* Seller Select */}- <div className="relative bottom-3 flex items-end justify-end gap-2">- <SellerManagement setValue={setValue} invoiceData={invoiceData} />- </div>+ <div>+ <Label htmlFor="sellerAddress" className="mb-1">+ Address+ </Label>+ <Controller+ name="seller.address"+ control={control}+ render={({ field }) => (+ <Textarea+ {...field}+ id="sellerAddress"+ rows={3}+ className=""+ />+ )}+ />+ {errors.seller?.address && (+ <ErrorMessage>{errors.seller.address.message}</ErrorMessage>+ )}+ </div>- {/* Seller Information Form */}- <div className="space-y-4">- <div>- <Label htmlFor="sellerName" className="mb-1">- Name- </Label>- <Controller- name="seller.name"- control={control}- render={({ field }) => (- <Textarea {...field} id="sellerName" rows={3} className="" />- )}- />- {errors.seller?.name && (- <ErrorMessage>{errors.seller.name.message}</ErrorMessage>- )}- </div>+ <div>+ <div className="relative mb-2 flex items-center justify-between">+ <Label htmlFor="sellerVatNo" className="">+ VAT Number+ </Label>- <div>- <Label htmlFor="sellerAddress" className="mb-1">- Address- </Label>- <Controller- name="seller.address"- control={control}- render={({ field }) => (- <Textarea- {...field}- id="sellerAddress"- rows={3}- className=""+ {/* Show/hide Seller VAT Number field in PDF switch */}+ <div className="inline-flex items-center gap-2">+ <Controller+ name={`seller.vatNoFieldIsVisible`}+ control={control}+ render={({ field: { value, onChange, ...field } }) => (+ <Switch+ {...field}+ id={`sellerVatNoFieldIsVisible`}+ 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={`sellerVatNoFieldIsVisible`}>+ Show in PDF+ </Label>+ }+ content='Show/Hide the "Seller VAT Number" Field in the PDF'+ />+ </div>+ </div>+ <Controller+ name="seller.vatNo"+ control={control}+ render={({ field }) => (+ <Input+ {...field}+ id="sellerVatNo"+ type="text"+ className=""+ />+ )}/>- )}- />- {errors.seller?.address && (- <ErrorMessage>{errors.seller.address.message}</ErrorMessage>- )}- </div>+ {errors.seller?.vatNo && (+ <ErrorMessage>{errors.seller.vatNo.message}</ErrorMessage>+ )}+ </div>- <div>- <div className="relative mb-2 flex items-center justify-between">- <Label htmlFor="sellerVatNo" className="">- VAT Number- </Label>+ <div>+ <Label htmlFor="sellerEmail" className="mb-1">+ </Label>+ <Controller+ name="seller.email"+ control={control}+ render={({ field }) => (+ <Input+ {...field}+ id="sellerEmail"+ type="email"+ className=""+ />+ )}+ />+ {errors.seller?.email && (+ <ErrorMessage>{errors.seller.email.message}</ErrorMessage>+ )}+ </div>++ {/* Account Number */}+ <div>+ <div className="relative mb-2 flex items-center justify-between">+ <Label htmlFor="sellerAccountNumber" className="">+ Account Number+ </Label>- {/* Show/hide Seller VAT Number field in PDF switch */}- <div className="inline-flex items-center gap-2">+ {/* Show/hide Account Number field in PDF switch */}+ <div className="inline-flex items-center gap-2">+ <Controller+ name={`seller.accountNumberFieldIsVisible`}+ control={control}+ render={({ field: { value, onChange, ...field } }) => (+ <Switch+ {...field}+ id={`sellerAccountNumberFieldIsVisible`}+ 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={`sellerAccountNumberFieldIsVisible`}>+ Show in PDF+ </Label>+ }+ content='Show/Hide the "Account Number" Field in the PDF'+ />+ </div>+ </div><Controller- name={`seller.vatNoFieldIsVisible`}+ name="seller.accountNumber"control={control}- render={({ field: { value, onChange, ...field } }) => (- <Switch+ render={({ field }) => (+ <Textarea{...field}- id={`sellerVatNoFieldIsVisible`}- 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"+ id="sellerAccountNumber"+ rows={3}+ className=""/>)}/>- <CustomTooltip- trigger={- <Label htmlFor={`sellerVatNoFieldIsVisible`}>- Show in PDF- </Label>- }- content='Show/Hide the "Seller VAT Number" Field in the PDF'+ {errors.seller?.accountNumber && (+ <ErrorMessage>+ {errors.seller.accountNumber.message}+ </ErrorMessage>+ )}+ </div>++ {/* SWIFT/BIC */}+ <div>+ <div className="relative mb-2 flex items-center justify-between">+ <Label htmlFor="sellerSwiftBic" className="">+ SWIFT/BIC+ </Label>++ {/* Show/hide SWIFT/BIC field in PDF switch */}+ <div className="inline-flex items-center gap-2">+ <Controller+ name={`seller.swiftBicFieldIsVisible`}+ control={control}+ render={({ field: { value, onChange, ...field } }) => (+ <Switch+ {...field}+ id={`sellerSwiftBicFieldIsVisible`}+ 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={`sellerSwiftBicFieldIsVisible`}>+ Show in PDF+ </Label>+ }+ content='Show/Hide the "SWIFT/BIC" Field in the PDF'+ />+ </div>+ </div>++ <Controller+ name="seller.swiftBic"+ control={control}+ render={({ field }) => (+ <Textarea+ {...field}+ id="sellerSwiftBic"+ rows={3}+ className=""+ />+ )}/>+ {errors.seller?.swiftBic && (+ <ErrorMessage>+ {errors.seller.swiftBic.message}+ </ErrorMessage>+ )}</div></div>- <Controller- name="seller.vatNo"- control={control}- render={({ field }) => (- <Input {...field} id="sellerVatNo" type="text" className="" />- )}- />- {errors.seller?.vatNo && (- <ErrorMessage>{errors.seller.vatNo.message}</ErrorMessage>- )}- </div>+ </AccordionContent>+ </AccordionItem>- <div>- <Label htmlFor="sellerEmail" className="mb-1">- </Label>- <Controller- name="seller.email"- control={control}- render={({ field }) => (- <Input- {...field}- id="sellerEmail"- type="email"- className=""+ {/* Buyer Information */}+ <AccordionItem+ value={ACCORDION_BUYER}+ className="rounded-lg border shadow"+ >+ <AccordionTrigger className="px-4 py-3">+ <Legend>Buyer Information</Legend>+ </AccordionTrigger>+ <AccordionContent className="px-4 pb-4">+ <div className="space-y-4">+ <div>+ <Label htmlFor="buyerName" className="mb-1">+ Name+ </Label>+ <Controller+ name="buyer.name"+ control={control}+ render={({ field }) => (+ <Textarea+ {...field}+ id="buyerName"+ rows={3}+ className=""+ />+ )}/>- )}- />- {errors.seller?.email && (- <ErrorMessage>{errors.seller.email.message}</ErrorMessage>- )}- </div>+ {errors.buyer?.name && (+ <ErrorMessage>{errors.buyer.name.message}</ErrorMessage>+ )}+ </div>- {/* Account Number */}- <div>- <div className="relative mb-2 flex items-center justify-between">- <Label htmlFor="sellerAccountNumber" className="">- Account Number- </Label>+ <div>+ <Label htmlFor="buyerAddress" className="mb-1">+ Address+ </Label>+ <Controller+ name="buyer.address"+ control={control}+ render={({ field }) => (+ <Textarea+ {...field}+ id="buyerAddress"+ rows={3}+ className=""+ />+ )}+ />+ {errors.buyer?.address && (+ <ErrorMessage>{errors.buyer.address.message}</ErrorMessage>+ )}+ </div>++ {/* Buyer VAT Number */}+ <div>+ <div className="relative mb-2 flex items-center justify-between">+ <Label htmlFor="buyerVatNo" className="">+ VAT Number+ </Label>++ {/* Show/hide Buyer VAT Number field in PDF switch */}+ <div className="inline-flex items-center gap-2">+ <Controller+ name={`buyer.vatNoFieldIsVisible`}+ control={control}+ render={({ field: { value, onChange, ...field } }) => (+ <Switch+ {...field}+ id={`buyerVatNoFieldIsVisible`}+ 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={`buyerVatNoFieldIsVisible`}>+ Show in PDF+ </Label>+ }+ content='Show/Hide the "Buyer VAT Number" Field in the PDF'+ />+ </div>+ </div>- {/* Show/hide Account Number field in PDF switch */}- <div className="inline-flex items-center gap-2"><Controller- name={`seller.accountNumberFieldIsVisible`}+ name="buyer.vatNo"control={control}- render={({ field: { value, onChange, ...field } }) => (- <Switch+ render={({ field }) => (+ <Textarea{...field}- id={`sellerAccountNumberFieldIsVisible`}- 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"+ id="buyerVatNo"+ rows={3}+ className=""/>)}/>- <CustomTooltip- trigger={- <Label htmlFor={`sellerAccountNumberFieldIsVisible`}>- Show in PDF- </Label>- }- content='Show/Hide the "Account Number" Field in the PDF'+ {errors.buyer?.vatNo && (+ <ErrorMessage>{errors.buyer.vatNo.message}</ErrorMessage>+ )}+ </div>++ <div>+ <Label htmlFor="buyerEmail" className="mb-1">+ </Label>+ <Controller+ name="buyer.email"+ control={control}+ render={({ field }) => (+ <Input+ {...field}+ id="buyerEmail"+ type="email"+ className=""+ />+ )}/>+ {errors.buyer?.email && (+ <ErrorMessage>{errors.buyer.email.message}</ErrorMessage>+ )}</div></div>- <Controller- name="seller.accountNumber"- control={control}- render={({ field }) => (- <Textarea- {...field}- id="sellerAccountNumber"- rows={3}- className=""- />- )}- />- {errors.seller?.accountNumber && (- <ErrorMessage>- {errors.seller.accountNumber.message}- </ErrorMessage>- )}- </div>+ </AccordionContent>+ </AccordionItem>- {/* SWIFT/BIC */}- <div>- <div className="relative mb-2 flex items-center justify-between">- <Label htmlFor="sellerSwiftBic" className="">- SWIFT/BIC- </Label>+ {/* Invoice Items */}+ <AccordionItem+ value={ACCORDION_ITEMS}+ className="rounded-lg border shadow"+ >+ <AccordionTrigger className="px-4 py-3">+ <Legend>Invoice Items</Legend>+ </AccordionTrigger>+ <AccordionContent className="px-4 pb-4">+ <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>- {/* Show/hide SWIFT/BIC field in PDF switch */}- <div className="inline-flex items-center gap-2"><Controller- name={`seller.swiftBicFieldIsVisible`}+ name={`items.0.invoiceItemNumberIsVisible`}control={control}render={({ field: { value, onChange, ...field } }) => (<Switch{...field}- id={`sellerSwiftBicFieldIsVisible`}+ 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"/>)}/>- <CustomTooltip- trigger={- <Label htmlFor={`sellerSwiftBicFieldIsVisible`}>- Show in PDF- </Label>- }- content='Show/Hide the "SWIFT/BIC" Field in the PDF'- /></div>- </div>-- <Controller- name="seller.swiftBic"- control={control}- render={({ field }) => (- <Textarea- {...field}- id="sellerSwiftBic"- rows={3}- className=""- />- )}- />- {errors.seller?.swiftBic && (- <ErrorMessage>{errors.seller.swiftBic.message}</ErrorMessage>- )}- </div>- {/* TODO: add button that opens dialog to save seller with prefilled data from the form- <div className="flex justify-end">- <Button- type="button"- _variant="outline"- onClick={() => {- }}- >- Save seller- </Button>- </div> */}- </div>- </fieldset>- {/* Buyer Information */}- <fieldset className="rounded-lg border p-4 shadow">- <Legend>Buyer Information</Legend>- <div className="space-y-4">- <div>- <Label htmlFor="buyerName" className="mb-1">- Name- </Label>- <Controller- name="buyer.name"- control={control}- render={({ field }) => (- <Textarea {...field} id="buyerName" rows={3} className="" />- )}- />- {errors.buyer?.name && (- <ErrorMessage>{errors.buyer.name.message}</ErrorMessage>- )}- </div>-- <div>- <Label htmlFor="buyerAddress" className="mb-1">- Address- </Label>- <Controller- name="buyer.address"- control={control}- render={({ field }) => (- <Textarea- {...field}- id="buyerAddress"- rows={3}- className=""- />- )}- />- {errors.buyer?.address && (- <ErrorMessage>{errors.buyer.address.message}</ErrorMessage>- )}- </div>-- {/* Buyer VAT Number */}- <div>- <div className="relative mb-2 flex items-center justify-between">- <Label htmlFor="buyerVatNo" className="">- VAT Number- </Label>+ {/* 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>- {/* Show/hide Buyer VAT Number field in PDF switch */}- <div className="inline-flex items-center gap-2"><Controller- name={`buyer.vatNoFieldIsVisible`}+ name={`vatTableSummaryIsVisible`}control={control}render={({ field: { value, onChange, ...field } }) => (<Switch{...field}- id={`buyerVatNoFieldIsVisible`}+ 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"/>)}/>- <CustomTooltip- trigger={- <Label htmlFor={`buyerVatNoFieldIsVisible`}>- Show in PDF- </Label>- }- content='Show/Hide the "Buyer VAT Number" Field in the PDF'- /></div></div>- <Controller- name="buyer.vatNo"- control={control}- render={({ field }) => (- <Textarea {...field} id="buyerVatNo" rows={3} className="" />- )}- />- {errors.buyer?.vatNo && (- <ErrorMessage>{errors.buyer.vatNo.message}</ErrorMessage>- )}- </div>-- <div>- <Label htmlFor="buyerEmail" className="mb-1">- </Label>- <Controller- name="buyer.email"- control={control}- render={({ field }) => (- <Input {...field} id="buyerEmail" type="email" className="" />- )}- />- {errors.buyer?.email && (- <ErrorMessage>{errors.buyer.email.message}</ErrorMessage>- )}- </div>- </div>- </fieldset>-- {/* Invoice Items */}- <fieldset className="rounded-lg border p-4 shadow">- <Legend>Invoice Items</Legend>-- <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>-- {fields.map((field, index) => {- const isNotFirstItem = index > 0;- const isFirstItem = index === 0;-- return (- <fieldset- key={field.id}- className="relative mb-4 rounded-lg border p-4 shadow"- >- {/* Delete invoice item button */}- {isNotFirstItem ? (- <div className="absolute -right-3 -top-10">- <button- type="button"- onClick={() => handleRemoveItem(index)}- className="flex items-center justify-center rounded-full bg-red-600 p-2 transition-colors hover:bg-red-700"- title="Delete invoice item"- >- <Trash2 className="h-4 w-4 text-white" />- </button>- </div>- ) : null}- <Legend>Item {index + 1}</Legend>- <div className="relative mb-8 space-y-4">- <div>- {/* Invoice Item Name */}- <div className="mb-2 flex items-center justify-between">- <Label htmlFor={`itemName${index}`} className="">- Name- </Label>-- {/* Show/hide Name field in PDF switch */}- {isFirstItem ? (- <div className="inline-flex items-center gap-2">- <Controller- name={`items.${index}.nameFieldIsVisible`}- control={control}- render={({- field: { value, onChange, ...field },- }) => (- <Switch- {...field}- id={`itemNameFieldIsVisible${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"+ {fields.map((field, index) => {+ const isNotFirstItem = index > 0;+ const isFirstItem = index === 0;++ return (+ <fieldset+ key={field.id}+ className="relative mb-4 rounded-lg border p-4 shadow"+ >+ {/* Delete invoice item button */}+ {isNotFirstItem ? (+ <div className="absolute -right-3 -top-10">+ <CustomTooltip+ trigger={+ <button+ type="button"+ onClick={() => handleRemoveItem(index)}+ className="flex items-center justify-center rounded-full bg-red-600 p-2 transition-colors hover:bg-red-700"+ >+ <Trash2 className="h-4 w-4 text-white" />+ </button>+ }+ content={`Delete Invoice Item ${index + 1}`}+ />+ </div>+ ) : null}+ <Legend>Item {index + 1}</Legend>+ <div className="relative mb-8 space-y-4">+ <div>+ {/* Invoice Item Name */}+ <div className="mb-2 flex items-center justify-between">+ <Label htmlFor={`itemName${index}`} className="">+ Name+ </Label>++ {/* Show/hide Name field in PDF switch */}+ {isFirstItem ? (+ <div className="inline-flex items-center gap-2">+ <Controller+ name={`items.${index}.nameFieldIsVisible`}+ control={control}+ render={({+ field: { value, onChange, ...field },+ }) => (+ <Switch+ {...field}+ id={`itemNameFieldIsVisible${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={`itemNameFieldIsVisible${index}`}>- Show in PDF- </Label>- }- content="Show/hide the 'Name of Goods/Service' Column in the PDF"- />+ <CustomTooltip+ trigger={+ <Label+ htmlFor={`itemNameFieldIsVisible${index}`}+ >+ Show in PDF+ </Label>+ }+ content="Show/hide the 'Name of Goods/Service' Column in the PDF"+ />+ </div>+ ) : null}</div>- ) : null}- </div>- {/* Name input */}- <Controller- name={`items.${index}.name`}- control={control}- render={({ field }) => (- <Textarea- {...field}- rows={4}- id={`itemName${index}`}- className=""+ {/* Name input */}+ <Controller+ name={`items.${index}.name`}+ control={control}+ render={({ field }) => (+ <Textarea+ {...field}+ rows={4}+ id={`itemName${index}`}+ className=""+ />+ )}/>- )}- />- {errors.items?.[index]?.name && (- <ErrorMessage>- {errors.items[index]?.name?.message}- </ErrorMessage>- )}- </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>-- {/* 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"+ {errors.items?.[index]?.name && (+ <ErrorMessage>+ {errors.items[index]?.name?.message}+ </ErrorMessage>+ )}+ </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>++ {/* 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'- />+ <CustomTooltip+ trigger={+ <Label+ htmlFor={`itemTypeOfGTUFieldIsVisible${index}`}+ >+ Show in PDF+ </Label>+ }+ content='Show/hide the "Type of GTU" Column in the PDF'+ />+ </div>+ ) : null}</div>- ) : null}- </div>- {/* Type of GTU input */}- <Controller- name={`items.${index}.typeOfGTU`}- control={control}- render={({ field }) => (- <Input- {...field}- id={`itemTypeOfGTU${index}`}- className=""- type="text"+ {/* 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>- )}- </div>-- {/* Invoice Item Amount */}- <div>- <div className="mb-2 flex items-center justify-between">- <Label htmlFor={`itemAmount${index}`} className="">- Amount- </Label>+ {errors.items?.[index]?.typeOfGTU && (+ <ErrorMessage>+ {errors.items[index]?.typeOfGTU?.message}+ </ErrorMessage>+ )}+ </div>++ {/* Invoice Item Amount */}+ <div>+ <div className="mb-2 flex items-center justify-between">+ <Label htmlFor={`itemAmount${index}`} className="">+ Amount+ </Label>++ {/* Show/hide Amount field in PDF switch */}+ {isFirstItem ? (+ <div className="inline-flex items-center gap-2">+ <Controller+ name={`items.${index}.amountFieldIsVisible`}+ control={control}+ render={({+ field: { value, onChange, ...field },+ }) => (+ <Switch+ {...field}+ id={`itemAmountFieldIsVisible${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={`itemAmountFieldIsVisible${index}`}+ >+ Show in PDF+ </Label>+ }+ content='Show/hide the "Amount" Column in the PDF'+ />+ </div>+ ) : null}+ </div>- {/* Show/hide Amount field in PDF switch */}- {isFirstItem ? (- <div className="inline-flex items-center gap-2">- <Controller- name={`items.${index}.amountFieldIsVisible`}- control={control}- render={({- field: { value, onChange, ...field },- }) => (- <Switch- {...field}- id={`itemAmountFieldIsVisible${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"+ {/* Amount input */}+ <Controller+ name={`items.${index}.amount`}+ control={control}+ render={({ field }) => {+ const fieldValueNumber = Number(field.value) || 0;+ const previewFormattedValue =+ fieldValueNumber.toLocaleString("en-US", {+ style: "decimal",+ maximumFractionDigits: 3,+ });++ return (+ <>+ <Input+ {...field}+ id={`itemAmount${index}`}+ type="number"+ step="0.01"+ min="0"+ className=""+ />+ {!errors.items?.[index]?.amount && (+ <InputHelperMessage>+ Preview: {previewFormattedValue}+ </InputHelperMessage>+ )}+ </>+ );+ }}+ />+ {errors.items?.[index]?.amount && (+ <ErrorMessage>+ {errors.items[index].amount.message}+ </ErrorMessage>+ )}+ </div>++ {/* Invoice Item Unit */}+ <div>+ <div className="mb-2 flex items-center justify-between">+ <Label htmlFor={`itemUnit${index}`} className="">+ Unit+ </Label>++ {/* Show/hide Unit field in PDF switch */}+ {isFirstItem ? (+ <div className="inline-flex items-center gap-2">+ <Controller+ name={`items.${index}.unitFieldIsVisible`}+ control={control}+ render={({+ field: { value, onChange, ...field },+ }) => (+ <Switch+ {...field}+ id={`itemUnitFieldIsVisible${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={`itemAmountFieldIsVisible${index}`}- >- Show in PDF- </Label>- }- content='Show/hide the "Amount" Column in the PDF'- />+ <CustomTooltip+ trigger={+ <Label+ htmlFor={`itemUnitFieldIsVisible${index}`}+ >+ Show in PDF+ </Label>+ }+ content='Show/hide the "Unit" Column in the PDF'+ />+ </div>+ ) : null}</div>- ) : null}- </div>- {/* Amount input */}- <Controller- name={`items.${index}.amount`}- control={control}- render={({ field }) => {- const fieldValueNumber = Number(field.value) || 0;- const previewFormattedValue =- fieldValueNumber.toLocaleString("en-US", {- style: "decimal",- maximumFractionDigits: 3,- });-- return (- <>+ {/* Unit input */}+ <Controller+ name={`items.${index}.unit`}+ control={control}+ render={({ field }) => (<Input{...field}- id={`itemAmount${index}`}- type="number"- step="0.01"- min="0"- className=""+ id={`itemUnit${index}`}+ type="text"/>- {!errors.items?.[index]?.amount && (- <InputHelperMessage>- Preview: {previewFormattedValue}- </InputHelperMessage>- )}- </>- );- }}- />- {errors.items?.[index]?.amount && (- <ErrorMessage>- {errors.items[index].amount.message}- </ErrorMessage>- )}- </div>-- {/* Invoice Item Unit */}- <div>- <div className="mb-2 flex items-center justify-between">- <Label htmlFor={`itemUnit${index}`} className="">- Unit- </Label>-- {/* Show/hide Unit field in PDF switch */}- {isFirstItem ? (- <div className="inline-flex items-center gap-2">- <Controller- name={`items.${index}.unitFieldIsVisible`}- control={control}- render={({- field: { value, onChange, ...field },- }) => (- <Switch- {...field}- id={`itemUnitFieldIsVisible${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"+ )}+ />+ {errors.items?.[index]?.unit && (+ <ErrorMessage>+ {errors.items[index].unit.message}+ </ErrorMessage>+ )}+ </div>++ {/* Invoice Item Net Price */}+ <div>+ <div className="mb-2 flex items-center justify-between">+ <Label htmlFor={`itemNetPrice${index}`} className="">+ Net Price+ </Label>++ {/* Show/hide Net Price field in PDF switch */}+ {isFirstItem ? (+ <div className="inline-flex items-center gap-2">+ <Controller+ name={`items.${index}.netPriceFieldIsVisible`}+ control={control}+ render={({+ field: { value, onChange, ...field },+ }) => (+ <Switch+ {...field}+ id={`itemNetPriceFieldIsVisible${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={`itemUnitFieldIsVisible${index}`}>- Show in PDF- </Label>- }- content='Show/hide the "Unit" Column in the PDF'- />+ <CustomTooltip+ trigger={+ <Label+ htmlFor={`itemNetPriceFieldIsVisible${index}`}+ >+ Show in PDF+ </Label>+ }+ content='Show/hide the "Net Price" Column in the PDF'+ />+ </div>+ ) : null}</div>- ) : null}- </div>-- {/* Unit input */}- <Controller- name={`items.${index}.unit`}- control={control}- render={({ field }) => (- <Input {...field} id={`itemUnit${index}`} type="text" />- )}- />- {errors.items?.[index]?.unit && (- <ErrorMessage>- {errors.items[index].unit.message}- </ErrorMessage>- )}- </div>-- {/* Invoice Item Net Price */}- <div>- <div className="mb-2 flex items-center justify-between">- <Label htmlFor={`itemNetPrice${index}`} className="">- Net Price- </Label>- {/* Show/hide Net Price field in PDF switch */}- {isFirstItem ? (- <div className="inline-flex items-center gap-2">+ {/* Net price input */}+ <div className="flex items-center gap-2"><Controller- name={`items.${index}.netPriceFieldIsVisible`}+ name={`items.${index}.netPrice`}control={control}- render={({- field: { value, onChange, ...field },- }) => (- <Switch- {...field}- id={`itemNetPriceFieldIsVisible${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={`itemNetPriceFieldIsVisible${index}`}- >- Show in PDF- </Label>- }- content='Show/hide the "Net Price" Column in the PDF'+ render={({ field }) => {+ const fieldValueNumber = Number(field.value) || 0;++ const previewFormattedValue =+ fieldValueNumber.toLocaleString("en-US", {+ style: "currency",+ currency: currency,+ minimumFractionDigits: 2,+ maximumFractionDigits: 2,+ });++ const previewAmountInWords = getAmountInWords({+ amount: fieldValueNumber,+ language,+ });++ const previewNumberFractionalPart =+ getNumberFractionalPart(fieldValueNumber);++ return (+ <div className="flex w-full flex-col">+ <MoneyInput+ {...field}+ id={`itemNetPrice${index}`}+ currency={currency}+ type="number"+ step="0.01"+ min="0"+ className="w-full"+ />+ {!errors.items?.[index]?.netPrice && (+ <InputHelperMessage>+ Preview: {previewFormattedValue} (+ {previewAmountInWords} {currency}{" "}+ {previewNumberFractionalPart}/100)+ </InputHelperMessage>+ )}+ </div>+ );+ }}/></div>- ) : null}- </div>-- {/* Net price input */}- <div className="flex items-center gap-2">- <Controller- name={`items.${index}.netPrice`}- control={control}- render={({ field }) => {- const fieldValueNumber = Number(field.value) || 0;-- const previewFormattedValue =- fieldValueNumber.toLocaleString("en-US", {- style: "currency",- currency: currency,- minimumFractionDigits: 2,- maximumFractionDigits: 2,- });-- const previewAmountInWords = getAmountInWords({- amount: fieldValueNumber,- language,- });-- const previewNumberFractionalPart =- getNumberFractionalPart(fieldValueNumber);-- return (- <div className="flex w-full flex-col">- <MoneyInput- {...field}- id={`itemNetPrice${index}`}- currency={currency}- type="number"- step="0.01"- min="0"- className="w-full"+ {errors.items?.[index]?.netPrice && (+ <ErrorMessage>+ {errors.items[index].netPrice.message}+ </ErrorMessage>+ )}+ </div>++ {/* Invoice Item VAT */}+ <div>+ <div className="mb-2 flex items-center justify-between">+ <Label htmlFor={`itemVat${index}`} className="">+ VAT+ </Label>++ {/* Show/hide VAT field in PDF switch */}+ {isFirstItem ? (+ <div className="inline-flex items-center gap-2">+ <Controller+ name={`items.${index}.vatFieldIsVisible`}+ control={control}+ render={({+ field: { value, onChange, ...field },+ }) => (+ <Switch+ {...field}+ id={`itemVatFieldIsVisible${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={`itemVatFieldIsVisible${index}`}+ >+ Show in PDF+ </Label>+ }+ content='Show/hide the "VAT" Column in the PDF'/>- {!errors.items?.[index]?.netPrice && (- <InputHelperMessage>- Preview: {previewFormattedValue} (- {previewAmountInWords} {currency}{" "}- {previewNumberFractionalPart}/100)- </InputHelperMessage>- )}</div>- );- }}- />- </div>- {errors.items?.[index]?.netPrice && (- <ErrorMessage>- {errors.items[index].netPrice.message}- </ErrorMessage>- )}- </div>+ ) : null}+ </div>- {/* Invoice Item VAT */}- <div>- <div className="mb-2 flex items-center justify-between">- <Label htmlFor={`itemVat${index}`} className="">- VAT- </Label>+ {/* VAT input */}+ <Controller+ name={`items.${index}.vat`}+ control={control}+ render={({ field }) => (+ <Input+ {...field}+ id={`itemVat${index}`}+ type="text"+ className=""+ />+ )}+ />- {/* Show/hide VAT field in PDF switch */}- {isFirstItem ? (- <div className="inline-flex items-center gap-2">- <Controller- name={`items.${index}.vatFieldIsVisible`}- control={control}- render={({- field: { value, onChange, ...field },- }) => (- <Switch- {...field}- id={`itemVatFieldIsVisible${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"+ {errors.items?.[index]?.vat ? (+ <ErrorMessage>+ {errors.items[index].vat.message}+ </ErrorMessage>+ ) : (+ <InputHelperMessage>+ Enter NP, OO or percentage value (0-100)+ </InputHelperMessage>+ )}+ </div>++ {/* Invoice Item Net Amount */}+ <div>+ <div className="mb-2 flex items-center justify-between">+ <Label htmlFor={`itemNetAmount${index}`} className="">+ Net Amount+ </Label>++ {/* Show/hide Net Amount field in PDF switch */}+ {isFirstItem ? (+ <div className="inline-flex items-center gap-2">+ <Controller+ name={`items.${index}.netAmountFieldIsVisible`}+ control={control}+ render={({+ field: { value, onChange, ...field },+ }) => (+ <Switch+ {...field}+ id={`itemNetAmountFieldIsVisible${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={`itemVatFieldIsVisible${index}`}>- Show in PDF- </Label>- }- content='Show/hide the "VAT" Column in the PDF'- />+ <CustomTooltip+ trigger={+ <Label+ htmlFor={`itemNetAmountFieldIsVisible${index}`}+ >+ Show in PDF+ </Label>+ }+ content='Show/hide the "Net Amount" Column in the PDF'+ />+ </div>+ ) : null}</div>- ) : null}- </div>- {/* VAT input */}- <Controller- name={`items.${index}.vat`}- control={control}- render={({ field }) => (- <Input- {...field}- id={`itemVat${index}`}- type="text"- className=""+ {/* Invoice Item Net Amount (calculated automatically) */}+ <Controller+ name={`items.${index}.netAmount`}+ control={control}+ render={({ field }) => {+ return (+ <ReadOnlyMoneyInput+ {...field}+ id={`itemNetAmount${index}`}+ currency={currency}+ value={field.value.toLocaleString("en-US", {+ minimumFractionDigits: 2,+ maximumFractionDigits: 2,+ })}+ />+ );+ }}/>- )}- />-- {errors.items?.[index]?.vat ? (- <ErrorMessage>- {errors.items[index].vat.message}- </ErrorMessage>- ) : (- <InputHelperMessage>- Enter NP, OO or percentage value (0-100)- </InputHelperMessage>- )}- </div>- {/* Invoice Item Net Amount */}- <div>- <div className="mb-2 flex items-center justify-between">- <Label htmlFor={`itemNetAmount${index}`} className="">- Net Amount- </Label>-- {/* Show/hide Net Amount field in PDF switch */}- {isFirstItem ? (- <div className="inline-flex items-center gap-2">- <Controller- name={`items.${index}.netAmountFieldIsVisible`}- control={control}- render={({- field: { value, onChange, ...field },- }) => (- <Switch- {...field}- id={`itemNetAmountFieldIsVisible${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"+ {errors.items?.[index]?.netAmount ? (+ <ErrorMessage>+ {errors.items[index].netAmount.message}+ </ErrorMessage>+ ) : (+ <InputHelperMessage>+ Calculated automatically based on Amount and Net+ Price+ </InputHelperMessage>+ )}+ </div>++ {/* Invoice Item VAT Amount (calculated automatically) */}+ <div>+ <div className="mb-2 flex items-center justify-between">+ <Label htmlFor={`itemVatAmount${index}`} className="">+ VAT Amount+ </Label>++ {/* Show/hide VAT Amount field in PDF switch */}+ {isFirstItem ? (+ <div className="inline-flex items-center gap-2">+ <Controller+ name={`items.${index}.vatAmountFieldIsVisible`}+ control={control}+ render={({+ field: { value, onChange, ...field },+ }) => (+ <Switch+ {...field}+ id={`itemVatAmountFieldIsVisible${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={`itemNetAmountFieldIsVisible${index}`}- >- Show in PDF- </Label>- }- content='Show/hide the "Net Amount" Column in the PDF'- />+ <CustomTooltip+ trigger={+ <Label+ htmlFor={`itemVatAmountFieldIsVisible${index}`}+ >+ Show in PDF+ </Label>+ }+ content='Show/hide the "VAT Amount" Column in the PDF'+ />+ </div>+ ) : null}</div>- ) : null}- </div>- {/* Invoice Item Net Amount (calculated automatically) */}- <Controller- name={`items.${index}.netAmount`}- control={control}- render={({ field }) => {- return (- <ReadOnlyMoneyInput- {...field}- id={`itemNetAmount${index}`}- currency={currency}- value={field.value.toLocaleString("en-US", {- minimumFractionDigits: 2,- maximumFractionDigits: 2,- })}- />- );- }}- />-- {errors.items?.[index]?.netAmount ? (- <ErrorMessage>- {errors.items[index].netAmount.message}- </ErrorMessage>- ) : (- <InputHelperMessage>- Calculated automatically based on Amount and Net Price- </InputHelperMessage>- )}- </div>-- {/* Invoice Item VAT Amount (calculated automatically) */}- <div>- <div className="mb-2 flex items-center justify-between">- <Label htmlFor={`itemVatAmount${index}`} className="">- VAT Amount- </Label>+ {/* VAT amount input */}+ <Controller+ name={`items.${index}.vatAmount`}+ control={control}+ render={({ field }) => (+ <ReadOnlyMoneyInput+ {...field}+ id={`itemVatAmount${index}`}+ currency={currency}+ value={field.value.toLocaleString("en-US", {+ minimumFractionDigits: 2,+ maximumFractionDigits: 2,+ })}+ />+ )}+ />- {/* Show/hide VAT Amount field in PDF switch */}- {isFirstItem ? (- <div className="inline-flex items-center gap-2">- <Controller- name={`items.${index}.vatAmountFieldIsVisible`}- control={control}- render={({- field: { value, onChange, ...field },- }) => (- <Switch- {...field}- id={`itemVatAmountFieldIsVisible${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"+ {errors.items?.[index]?.vatAmount ? (+ <ErrorMessage>+ {errors.items[index].vatAmount.message}+ </ErrorMessage>+ ) : (+ <InputHelperMessage>+ Calculated automatically based on Net Amount and VAT+ </InputHelperMessage>+ )}+ </div>++ {/* Pre-tax Amount field */}+ <div>+ <div className="mb-2 flex items-center justify-between">+ <Label+ htmlFor={`itemPreTaxAmount${index}`}+ className=""+ >+ Pre-tax Amount+ </Label>++ {/* Show/hide Pre-tax Amount field in PDF switch */}+ {isFirstItem ? (+ <div className="inline-flex items-center gap-2">+ <Controller+ name={`items.${index}.preTaxAmountFieldIsVisible`}+ control={control}+ render={({+ field: { value, onChange, ...field },+ }) => (+ <Switch+ {...field}+ id={`itemPreTaxAmountFieldIsVisible${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={`itemVatAmountFieldIsVisible${index}`}- >- Show in PDF- </Label>- }- content='Show/hide the "VAT Amount" Column in the PDF'- />+ <CustomTooltip+ trigger={+ <Label+ htmlFor={`itemPreTaxAmountFieldIsVisible${index}`}+ >+ Show in PDF+ </Label>+ }+ content='Show/hide the "Pre-tax Amount" Column in the PDF'+ />+ </div>+ ) : null}</div>- ) : null}- </div>- {/* VAT amount input */}- <Controller- name={`items.${index}.vatAmount`}- control={control}- render={({ field }) => (- <ReadOnlyMoneyInput- {...field}- id={`itemVatAmount${index}`}- currency={currency}- value={field.value.toLocaleString("en-US", {- minimumFractionDigits: 2,- maximumFractionDigits: 2,- })}+ {/* Pre-tax amount input */}+ <Controller+ name={`items.${index}.preTaxAmount`}+ control={control}+ render={({ field }) => (+ <ReadOnlyMoneyInput+ {...field}+ id={`itemPreTaxAmount${index}`}+ currency={currency}+ value={field.value.toLocaleString("en-US", {+ minimumFractionDigits: 2,+ maximumFractionDigits: 2,+ })}+ />+ )}/>- )}- />-- {errors.items?.[index]?.vatAmount ? (- <ErrorMessage>- {errors.items[index].vatAmount.message}- </ErrorMessage>- ) : (- <InputHelperMessage>- Calculated automatically based on Net Amount and VAT- </InputHelperMessage>- )}- </div>- {/* Pre-tax Amount field */}- <div>- <div className="mb-2 flex items-center justify-between">- <Label htmlFor={`itemPreTaxAmount${index}`} className="">- Pre-tax Amount- </Label>-- {/* Show/hide Pre-tax Amount field in PDF switch */}- {isFirstItem ? (- <div className="inline-flex items-center gap-2">- <Controller- name={`items.${index}.preTaxAmountFieldIsVisible`}- control={control}- render={({- field: { value, onChange, ...field },- }) => (- <Switch- {...field}- id={`itemPreTaxAmountFieldIsVisible${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={`itemPreTaxAmountFieldIsVisible${index}`}- >- Show in PDF- </Label>- }- content='Show/hide the "Pre-tax Amount" Column in the PDF'- />- </div>- ) : null}+ {errors.items?.[index]?.preTaxAmount ? (+ <ErrorMessage>+ {errors.items[index].preTaxAmount.message}+ </ErrorMessage>+ ) : (+ <InputHelperMessage>+ Calculated automatically based on Net Amount and VAT+ </InputHelperMessage>+ )}+ </div></div>+ </fieldset>+ );+ })}- {/* Pre-tax amount input */}- <Controller- name={`items.${index}.preTaxAmount`}- control={control}- render={({ field }) => (- <ReadOnlyMoneyInput- {...field}- id={`itemPreTaxAmount${index}`}- currency={currency}- value={field.value.toLocaleString("en-US", {- minimumFractionDigits: 2,- maximumFractionDigits: 2,- })}- />- )}- />-- {errors.items?.[index]?.preTaxAmount ? (- <ErrorMessage>- {errors.items[index].preTaxAmount.message}- </ErrorMessage>- ) : (- <InputHelperMessage>- Calculated automatically based on Net Amount and VAT- </InputHelperMessage>- )}- </div>- </div>- </fieldset>- );- })}-- <button- type="button"- onClick={() => {- // analytics track event- openPanel.track("add_invoice_item");-- append({- invoiceItemNumberIsVisible: true,- name: "",- nameFieldIsVisible: true,- amount: 1,- amountFieldIsVisible: true,- unit: "",- unitFieldIsVisible: true,- netPrice: 0,- netPriceFieldIsVisible: true,- vat: "NP",- vatFieldIsVisible: true,- netAmount: 0,- netAmountFieldIsVisible: true,- vatAmount: 0,- vatAmountFieldIsVisible: true,- preTaxAmount: 0,- preTaxAmountFieldIsVisible: true,- typeOfGTU: "",- typeOfGTUFieldIsVisible: true,- });- }}- className="mb-1 flex items-center text-sm font-medium text-gray-700 hover:text-black"- >- <Plus className="mr-2 h-4 w-4" />- Add invoice item- </button>- </fieldset>+ <button+ type="button"+ onClick={() => {+ // analytics track event+ openPanel.track("add_invoice_item");++ append({+ invoiceItemNumberIsVisible: true,+ name: "",+ nameFieldIsVisible: true,+ amount: 1,+ amountFieldIsVisible: true,+ unit: "",+ unitFieldIsVisible: true,+ netPrice: 0,+ netPriceFieldIsVisible: true,+ vat: "NP",+ vatFieldIsVisible: true,+ netAmount: 0,+ netAmountFieldIsVisible: true,+ vatAmount: 0,+ vatAmountFieldIsVisible: true,+ preTaxAmount: 0,+ preTaxAmountFieldIsVisible: true,+ typeOfGTU: "",+ typeOfGTUFieldIsVisible: true,+ });+ }}+ className="mb-1 flex items-center text-sm font-medium text-gray-700 hover:text-black"+ >+ <Plus className="mr-2 h-4 w-4" />+ Add invoice item+ </button>+ </AccordionContent>+ </AccordionItem>+ </Accordion>{/* Total field (with currency) */}<div className="">diff --git a/src/components/ui/accordion.tsx b/src/components/ui/accordion.tsxnew file mode 100644index 0000000..cd5e887--- /dev/null+++ b/src/components/ui/accordion.tsx@@ -0,0 +1,64 @@+"use client";++import * as React from "react";+import * as AccordionPrimitive from "@radix-ui/react-accordion";+import { ChevronDown } from "lucide-react";++import { cn } from "@/lib/utils";+import { CustomTooltip } from "./tooltip";++const Accordion = AccordionPrimitive.Root;++const AccordionItem = React.forwardRef<+ React.ElementRef<typeof AccordionPrimitive.Item>,+ React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Item>+>(({ className, ...props }, ref) => (+ <AccordionPrimitive.Item+ ref={ref}+ className={cn("border-b", className)}+ {...props}+ />+));+AccordionItem.displayName = "AccordionItem";++const AccordionTrigger = React.forwardRef<+ React.ElementRef<typeof AccordionPrimitive.Trigger>,+ React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Trigger>+>(({ className, children, ...props }, ref) => (+ <AccordionPrimitive.Header className="flex">+ <AccordionPrimitive.Trigger+ ref={ref}+ className={cn(+ "flex flex-1 items-center justify-between py-4 font-medium transition-all [&[data-state=open]>svg]:rotate-180",+ className+ )}+ {...props}+ >+ {children}+ <CustomTooltip+ trigger={+ <ChevronDown className="h-6 w-6 shrink-0 rounded-full p-1 transition-all duration-200 hover:bg-gray-200" />+ }+ content="Expand/Collapse Section"+ />+ </AccordionPrimitive.Trigger>+ </AccordionPrimitive.Header>+));+AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName;++const AccordionContent = React.forwardRef<+ React.ElementRef<typeof AccordionPrimitive.Content>,+ React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Content>+>(({ className, children, ...props }, ref) => (+ <AccordionPrimitive.Content+ ref={ref}+ className="overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down"+ {...props}+ >+ <div className={cn("pb-4 pt-0", className)}>{children}</div>+ </AccordionPrimitive.Content>+));++AccordionContent.displayName = AccordionPrimitive.Content.displayName;++export { Accordion, AccordionItem, AccordionTrigger, AccordionContent };diff --git a/tailwind.config.ts b/tailwind.config.tsindex 364f230..8aa97f2 100644--- a/tailwind.config.ts+++ b/tailwind.config.ts@@ -18,6 +18,28 @@ const config: Config = {md: "calc(var(--radius) - 2px)",sm: "calc(var(--radius) - 4px)",},+ keyframes: {+ "accordion-down": {+ from: {+ height: "0",+ },+ to: {+ height: "var(--radix-accordion-content-height)",+ },+ },+ "accordion-up": {+ from: {+ height: "var(--radix-accordion-content-height)",+ },+ to: {+ height: "0",+ },+ },+ },+ animation: {+ "accordion-down": "accordion-down 0.2s ease-out",+ "accordion-up": "accordion-up 0.2s ease-out",+ },},},plugins: [require("tailwindcss-animate")],