Skip to content

Free & Open-Source Invoice Generator - No Sign-Up, No Ads, Instant PDF Export, 100% In-Browser, and Fully Customizable Templates.

feat: Add mobile-friendly tabs for invoice form and PDF preview (#64)

Vlad Sazonau1dac29c12405
diff --git a/package.json b/package.json
index 5f1627d..fecd82d 100644
--- a/package.json
+++ b/package.json
@@ -21,12 +21,15 @@
"@radix-ui/react-label": "2.1.2",
"@radix-ui/react-slot": "1.1.2",
"@radix-ui/react-switch": "1.1.3",
+ "@radix-ui/react-tabs": "1.1.3",
"@radix-ui/react-tooltip": "1.1.8",
"@react-pdf/layout": "4.2.2",
"@react-pdf/renderer": "4.2.1",
"class-variance-authority": "0.7.1",
"clsx": "2.1.1",
"dayjs": "1.11.13",
+ "file-saver": "2.0.5",
+ "jszip": "3.10.1",
"lucide-react": "0.475.0",
"lz-string": "1.5.0",
"n2words": "1.21.0",
@@ -42,6 +45,7 @@
"zod": "3.24.1"
},
"devDependencies": {
+ "@types/file-saver": "2.0.7",
"@types/node": "22.8.1",
"@types/react": "18.3.12",
"@types/react-dom": "18.3.1",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 3ecf8cd..072e371 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -32,6 +32,9 @@ importers:
'@radix-ui/react-switch':
specifier: 1.1.3
+ '@radix-ui/react-tabs':
+ specifier: 1.1.3
'@radix-ui/react-tooltip':
specifier: 1.1.8
@@ -50,6 +53,12 @@ importers:
dayjs:
specifier: 1.11.13
version: 1.11.13
+ file-saver:
+ specifier: 2.0.5
+ version: 2.0.5
+ jszip:
+ specifier: 3.10.1
+ version: 3.10.1
lucide-react:
specifier: 0.475.0
version: 0.475.0([email protected])
@@ -90,6 +99,9 @@ importers:
specifier: 3.24.1
version: 3.24.1
devDependencies:
+ '@types/file-saver':
+ specifier: 2.0.7
+ version: 2.0.7
'@types/node':
specifier: 22.8.1
version: 22.8.1
@@ -514,6 +526,19 @@ packages:
'@types/react-dom':
optional: true
+ '@radix-ui/[email protected]':
+ resolution: {integrity: sha512-zgMQWkNO169GtGqRvYrzb0Zf8NhMHS2DuEB/TiEmVnpr5OqPU3i8lfbxaAmC2J/KYuIQxyoQQ6DxepyXp61/xw==}
+ 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-YAKxaiGsSQJ38VzKH86/BPRC4rh+b1Jpa+JneA5LRE7skmLPNAyeG8kPJj/oo4STLvlrs8vkf/iYyc3A5stYCQ==}
peerDependencies:
@@ -536,6 +561,19 @@ packages:
'@types/react-dom':
optional: true
+ '@radix-ui/[email protected]':
+ resolution: {integrity: sha512-9mFyI30cuRDImbmFF6O2KUJdgEOsGh9Vmx9x/Dh9tOhL7BngmQPQfwW4aejKm5OHpfWIdmeV6ySyuxoOGjtNng==}
+ 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-YAA2cu48EkJZdAMHC0dqo9kialOcRStbtiY4nJPaht7Ptrhcvpo+eDChaM6BIs8kL6a8Z5l5poiqLnXcNduOkA==}
peerDependencies:
@@ -686,6 +724,9 @@ packages:
resolution: {integrity: sha512-KGYxvIOXcceOAbEk4bi/dVLEK9z8sZ0uBB3Il5b1rhfClSpcX0yfRO0KmTkqR2cnQDymwLB+25ZyMzICg/cm/A==}
+ '@types/[email protected]':
+ resolution: {integrity: sha512-dNKVfHd/jk0SkR/exKGj2ggkB45MAkzvWCaqLUUgkyjITkGNzH8H+yUwr+BLJUBjZOe9w8X3wgmXhZDRg1ED6A==}
+
resolution: {integrity: sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==}
@@ -951,6 +992,9 @@ packages:
resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==}
+ resolution: {integrity: sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==}
+
resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==}
engines: {node: '>= 8'}
@@ -1222,6 +1266,9 @@ packages:
resolution: {integrity: sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==}
engines: {node: ^10.12.0 || >=12.0.0}
+ resolution: {integrity: sha512-P9bmyZ3h/PRG+Nzga+rbdI4OEpNDzAVyy74uVO9ATgzLK6VtAsYybF/+TOCvrc0MO793d6+42lLyZTw7/ArVzA==}
+
resolution: {integrity: sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==}
engines: {node: '>=8'}
@@ -1357,6 +1404,9 @@ packages:
resolution: {integrity: sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==}
engines: {node: '>= 4'}
+ resolution: {integrity: sha512-XXOFtyqDjNDAQxVfYxuF7g9Il/IbWmmlQg2MYKOH8ExIT1qg6xc4zyS3HaEEATgs1btfzxq15ciUiY7gjSXRGQ==}
+
resolution: {integrity: sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==}
engines: {node: '>=6'}
@@ -1498,6 +1548,9 @@ packages:
resolution: {integrity: sha512-LvIm3/KWzS9oRFHugab7d+M/GcBXuXX5xZkzPmN+NxihdQlZUQ4dWuSV1xR/sq6upL1TJEDrfBgRepHFdBtSNQ==}
engines: {node: '>= 0.4'}
+ resolution: {integrity: sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==}
+
resolution: {integrity: sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==}
@@ -1546,6 +1599,9 @@ packages:
resolution: {integrity: sha512-ZZow9HBI5O6EPgSJLUb8n2NKgmVWTwCvHGwFuJlMjvLFqlGG6pjirPhtdsseaLZjSibD8eegzmYpUZwoIlj2cQ==}
engines: {node: '>=4.0'}
+ resolution: {integrity: sha512-xXDvecyTpGLrqFrvkrUSoxxfJI5AH7U8zxxtVclpsUtMCq4JQ290LY8AW5c7Ggnr/Y/oK+bQMbqK2qmtk3pN4g==}
+
resolution: {integrity: sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==}
@@ -1560,6 +1616,9 @@ packages:
resolution: {integrity: sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==}
engines: {node: '>= 0.8.0'}
+ resolution: {integrity: sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==}
+
resolution: {integrity: sha512-utWOt/GHzuUxnLKxB6dk81RoOeoNeHgbrXiuGk4yyF5qlRz+iIVWu56E2fqGHFrXz0QNUhLB/8nKqvRH66JKGQ==}
engines: {node: '>=10'}
@@ -1901,6 +1960,9 @@ packages:
engines: {node: '>=14'}
hasBin: true
+ resolution: {integrity: sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==}
+
resolution: {integrity: sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==}
@@ -1965,6 +2027,9 @@ packages:
resolution: {integrity: sha512-Owdv/Ft7IjOgm/i0xvNDZ1LrRANRfew4b2prF3OWMQLxLfu3bS8FVhCsrSCMK4lR56Y9ya+AThoTpDCTxCmpRA==}
+ resolution: {integrity: sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==}
+
resolution: {integrity: sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==}
engines: {node: '>=8.10.0'}
@@ -2018,6 +2083,9 @@ packages:
resolution: {integrity: sha512-vj6RsCsWBCf19jIeHEfkRMw8DPiBb+DMXklQ/1SGDHOMlHdPUkZXFQ2YdplS23zESTijAcurb1aSgJA3AgMu1Q==}
engines: {node: '>=0.4'}
+ resolution: {integrity: sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==}
+
resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==}
@@ -2048,6 +2116,9 @@ packages:
resolution: {integrity: sha512-7PGFlmtwsEADb0WYyvCMa1t+yke6daIG4Wirafur5kcf+MhUnPms1UeR0CKQdTZD81yESwMHbtn+TR+dMviakQ==}
engines: {node: '>= 0.4'}
+ resolution: {integrity: sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA==}
+
resolution: {integrity: sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==}
engines: {node: '>=8'}
@@ -2115,6 +2186,9 @@ packages:
resolution: {integrity: sha512-UXSH262CSZY1tfu3G3Secr6uGLCFVPMhIqHjlgCUtCCcgihYc/xKs9djMTMUOb2j1mVSeU8EU6NWc/iQKU6Gfg==}
engines: {node: '>= 0.4'}
+ resolution: {integrity: sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==}
+
resolution: {integrity: sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==}
@@ -2695,6 +2769,23 @@ snapshots:
'@types/react': 18.3.12
'@types/react-dom': 18.3.1
+ dependencies:
+ '@radix-ui/primitive': 1.1.1
+ '@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-callback-ref': 1.1.0(@types/[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
+
dependencies:
'@radix-ui/react-compose-refs': 1.1.1(@types/[email protected])([email protected])
@@ -2717,6 +2808,22 @@ snapshots:
'@types/react': 18.3.12
'@types/react-dom': 18.3.1
+ dependencies:
+ '@radix-ui/primitive': 1.1.1
+ '@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-roving-focus': 1.1.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
+
dependencies:
'@radix-ui/primitive': 1.1.1
@@ -2912,6 +3019,8 @@ snapshots:
'@swc/counter': 0.1.3
tslib: 2.8.1
+ '@types/[email protected]': {}
+
'@types/[email protected]': {}
@@ -3224,6 +3333,8 @@ snapshots:
+
dependencies:
path-key: 3.1.1
@@ -3661,6 +3772,8 @@ snapshots:
dependencies:
flat-cache: 3.2.0
+
dependencies:
to-regex-range: 5.0.1
@@ -3816,6 +3929,8 @@ snapshots:
+
dependencies:
parent-module: 1.0.1
@@ -3947,6 +4062,8 @@ snapshots:
call-bind: 1.0.7
get-intrinsic: 1.2.4
+
@@ -4000,6 +4117,13 @@ snapshots:
object.assign: 4.1.5
object.values: 1.2.0
+ dependencies:
+ lie: 3.3.0
+ pako: 1.0.11
+ readable-stream: 2.3.8
+ setimmediate: 1.0.5
+
dependencies:
json-buffer: 3.0.1
@@ -4015,6 +4139,10 @@ snapshots:
prelude-ls: 1.2.1
type-check: 0.4.0
+ dependencies:
+ immediate: 3.0.6
+
@@ -4271,6 +4399,8 @@ snapshots:
+
dependencies:
loose-envify: 1.4.0
@@ -4332,6 +4462,16 @@ snapshots:
dependencies:
pify: 2.3.0
+ dependencies:
+ core-util-is: 1.0.3
+ inherits: 2.0.4
+ isarray: 1.0.0
+ process-nextick-args: 2.0.1
+ safe-buffer: 5.1.2
+ string_decoder: 1.1.1
+ util-deprecate: 1.0.2
+
dependencies:
picomatch: 2.3.1
@@ -4392,6 +4532,8 @@ snapshots:
has-symbols: 1.0.3
isarray: 2.0.5
+
@@ -4426,6 +4568,8 @@ snapshots:
functions-have-names: 1.2.3
has-property-descriptors: 1.0.2
+
dependencies:
shebang-regex: 3.0.0
@@ -4515,6 +4659,10 @@ snapshots:
define-properties: 1.2.1
es-object-atoms: 1.0.0
+ dependencies:
+ safe-buffer: 5.1.2
+
dependencies:
safe-buffer: 5.2.1
diff --git a/src/app/components/invoice-form.tsx b/src/app/components/invoice-form.tsx
index f89a522..4f9772e 100644
--- a/src/app/components/invoice-form.tsx
+++ b/src/app/components/invoice-form.tsx
@@ -1,4 +1,6 @@
import {
+ ACCORDION_STATE_LOCAL_STORAGE_KEY,
+ accordionSchema,
invoiceItemSchema,
invoiceSchema,
SUPPORTED_CURRENCIES,
@@ -8,6 +10,12 @@ import {
type InvoiceItemData,
} from "@/app/schema";
import { SellerManagement } from "@/components/seller-management";
+import {
+ Accordion,
+ AccordionContent,
+ AccordionItem,
+ AccordionTrigger,
+} from "@/components/ui/accordion";
import { ButtonHelper } from "@/components/ui/button-helper";
import { Input } from "@/components/ui/input";
import { InputHelperMessage } from "@/components/ui/input-helper-message";
@@ -21,23 +29,17 @@ import { SelectNative } from "@/components/ui/select-native";
import { Switch } from "@/components/ui/switch";
import { Textarea } from "@/components/ui/textarea";
import { CustomTooltip } from "@/components/ui/tooltip";
+import { umamiTrackEvent } from "@/lib/umami-analytics-track-event";
import { getAmountInWords, getNumberFractionalPart } from "@/lib/utils";
import { zodResolver } from "@hookform/resolvers/zod";
import { useOpenPanel } from "@openpanel/nextjs";
import dayjs from "dayjs";
import { AlertTriangle, Plus, Trash2 } from "lucide-react";
-import React, { useCallback, useEffect } from "react";
+import React, { useCallback, useEffect, useState } from "react";
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";
-import { umamiTrackEvent } from "@/lib/umami-analytics-track-event";
export const PDF_DATA_LOCAL_STORAGE_KEY = "EASY_INVOICE_PDF_DATA";
export const PDF_DATA_FORM_ID = "pdfInvoiceForm";
@@ -115,6 +117,12 @@ const AlertIcon = () => {
return <AlertTriangle className="mr-1 inline-block h-3 w-3 text-amber-500" />;
};
+type AccordionKeys = Array<(typeof DEFAULT_ACCORDION_VALUES)[number]>;
+
+type Prettify<T> = {
+ [K in keyof T]: T[K];
+} & {};
+
interface InvoiceFormProps {
invoiceData: InvoiceData;
onInvoiceDataChange: (updatedData: InvoiceData) => void;
@@ -276,6 +284,65 @@ export function InvoiceForm({
onInvoiceDataChange(data);
};
+ /**
+ * All open accordion sections will be in the array of strings
+ * ['general', 'seller', 'invoiceItems'] -> means that general, seller and invoiceItems accordion sections are open
+ * [] -> means that all accordion sections are closed
+ */
+ const [accordionValues, setAccordionValues] = useState<
+ Prettify<AccordionKeys>
+ >(() => {
+ // Try to load from localStorage
+ try {
+ const savedState = localStorage.getItem(
+ ACCORDION_STATE_LOCAL_STORAGE_KEY
+ );
+
+ if (savedState) {
+ const parsedState = JSON.parse(savedState);
+
+ const validatedState = accordionSchema.safeParse(parsedState);
+
+ if (validatedState.success) {
+ const arrayOfOpenSections = Object.entries(validatedState.data)
+ .filter(([_, isOpen]) => isOpen)
+ .map(([section]) => section) as Prettify<AccordionKeys>;
+
+ return arrayOfOpenSections;
+ }
+ }
+ } catch (error) {
+ console.error("Error loading accordion state:", error);
+ }
+
+ // Default to all sections open if no valid state found
+ return DEFAULT_ACCORDION_VALUES as NonReadonly<
+ typeof DEFAULT_ACCORDION_VALUES
+ >;
+ });
+
+ // Save accordion state changes to localStorage
+ const handleAccordionValueChange = (value: Prettify<AccordionKeys>) => {
+ setAccordionValues(value);
+
+ try {
+ // parse the value to the accordion schema
+ const stateToSave = accordionSchema.parse({
+ general: value.includes(ACCORDION_GENERAL),
+ seller: value.includes(ACCORDION_SELLER),
+ buyer: value.includes(ACCORDION_BUYER),
+ invoiceItems: value.includes(ACCORDION_ITEMS),
+ });
+
+ localStorage.setItem(
+ ACCORDION_STATE_LOCAL_STORAGE_KEY,
+ JSON.stringify(stateToSave)
+ );
+ } catch (error) {
+ console.error("Error saving accordion state:", error);
+ }
+ };
+
return (
<>
<form
@@ -342,11 +409,8 @@ export function InvoiceForm({
>
<Accordion
type="multiple"
- defaultValue={
- DEFAULT_ACCORDION_VALUES as NonReadonly<
- typeof DEFAULT_ACCORDION_VALUES
- >
- }
+ value={accordionValues}
+ onValueChange={handleAccordionValueChange}
className="space-y-4"
>
{/* General Information */}
@@ -1745,113 +1809,135 @@ export function InvoiceForm({
</AccordionItem>
</Accordion>
- {/* Total field (with currency) */}
- <div className="">
- <div className="mt-5" />
- <Label htmlFor="total" className="mb-1">
- Total
- </Label>
- <div className="relative mt-1 rounded-md shadow-sm">
- <Controller
- name="total"
- control={control}
- render={({ field }) => (
- <ReadOnlyMoneyInput
- {...field}
- id="total"
- currency={currency}
- value={field.value.toLocaleString("en-US", {
- minimumFractionDigits: 2,
- maximumFractionDigits: 2,
- })}
- />
- )}
- />
- </div>
- {errors.total ? (
- <ErrorMessage>{errors.total.message}</ErrorMessage>
- ) : (
- <InputHelperMessage>
- Calculated automatically based on (Net Amount + VAT Amount) *
- Number of invoice items
- </InputHelperMessage>
- )}
- </div>
-
- {/* Payment Method */}
- <div>
- <div className="relative mb-2 mt-6 flex items-center justify-between">
- <Label htmlFor="paymentMethod" className="">
- Payment Method
+ {/* Final section */}
+ <div className="space-y-4">
+ <div className="">
+ {/* Total field (with currency) */}
+ <div className="mt-5" />
+ <Label htmlFor="total" className="mb-1">
+ Total
</Label>
-
- {/* Show/hide Payment Method field in PDF switch */}
- <div className="inline-flex items-center gap-2">
+ <div className="relative mt-1 rounded-md shadow-sm">
<Controller
- name={`paymentMethodFieldIsVisible`}
+ name="total"
control={control}
- render={({ field: { value, onChange, ...field } }) => (
- <Switch
+ render={({ field }) => (
+ <ReadOnlyMoneyInput
{...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"
+ id="total"
+ currency={currency}
+ value={field.value.toLocaleString("en-US", {
+ minimumFractionDigits: 2,
+ maximumFractionDigits: 2,
+ })}
/>
)}
/>
- <CustomTooltip
- trigger={
- <Label htmlFor={`paymentMethodFieldIsVisible`}>
- Show in PDF
- </Label>
- }
- content='Show/Hide the "Payment Method" Field in the PDF'
- />
</div>
+ {errors.total ? (
+ <ErrorMessage>{errors.total.message}</ErrorMessage>
+ ) : (
+ <InputHelperMessage>
+ Calculated automatically based on (Net Amount + VAT Amount) *
+ Number of invoice items
+ </InputHelperMessage>
+ )}
</div>
- <Controller
- name="paymentMethod"
- control={control}
- render={({ field }) => (
- <Input
- {...field}
- id="paymentMethod"
- type="text"
- className="mt-1"
- />
- )}
- />
- {errors.paymentMethod && (
- <ErrorMessage>{errors.paymentMethod.message}</ErrorMessage>
- )}
- </div>
+ {/* Payment Method */}
+ <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'
+ />
+ </div>
+ </div>
- {/* Payment Due */}
- <div>
- <div className="mb-6">
- <Label htmlFor="paymentDue" className="mb-1">
- Payment Due
- </Label>
<Controller
- name="paymentDue"
+ name="paymentMethod"
control={control}
render={({ field }) => (
- <Input {...field} id="paymentDue" type="date" className="" />
+ <Input
+ {...field}
+ id="paymentMethod"
+ type="text"
+ className="mt-1"
+ />
)}
/>
- {errors.paymentDue && (
- <ErrorMessage>{errors.paymentDue.message}</ErrorMessage>
+ {errors.paymentMethod && (
+ <ErrorMessage>{errors.paymentMethod.message}</ErrorMessage>
)}
- {!errors.paymentDue && isPaymentDueBeforeDateOfIssue ? (
- <InputHelperMessage>
- <span className="flex items-center text-balance">
- <AlertIcon />
- Payment due date is before date of issue (
- {dayjs(dateOfIssue).format("DD.MM.YYYY")})
- </span>
+ </div>
+
+ {/* Payment Due */}
+ <div>
+ <div className="mb-6">
+ <Label htmlFor="paymentDue" className="mb-1">
+ Payment Due
+ </Label>
+ <Controller
+ name="paymentDue"
+ control={control}
+ render={({ field }) => (
+ <Input {...field} id="paymentDue" type="date" className="" />
+ )}
+ />
+ {errors.paymentDue && (
+ <ErrorMessage>{errors.paymentDue.message}</ErrorMessage>
+ )}
+ {!errors.paymentDue && isPaymentDueBeforeDateOfIssue ? (
+ <InputHelperMessage>
+ <span className="flex items-center text-balance">
+ <AlertIcon />
+ Payment due date is before date of issue (
+ {dayjs(dateOfIssue).format("DD.MM.YYYY")})
+ </span>
+ <ButtonHelper
+ onClick={() => {
+ const newPaymentDue = dayjs(dateOfIssue)
+ .add(14, "days")
+ .format("YYYY-MM-DD");
+
+ setValue("paymentDue", newPaymentDue);
+ }}
+ >
+ Click to set payment due date 14 days after the date of
+ issue (
+ {dayjs(dateOfIssue).add(14, "days").format("DD/MM/YYYY")})
+ </ButtonHelper>
+ </InputHelperMessage>
+ ) : null}
+ {/* If there are no errors and the payment due date is not before the date of issue and the payment due date is not 14 days after the date of issue, show the button to set the payment due date to 14 days after the date of issue (probably a bit better UX) */}
+ {!errors.paymentDue &&
+ !isPaymentDueBeforeDateOfIssue &&
+ !isPaymentDue14DaysFromDateOfIssue ? (
<ButtonHelper
+ className="whitespace-normal"
onClick={() => {
const newPaymentDue = dayjs(dateOfIssue)
.add(14, "days")
@@ -1863,115 +1949,97 @@ export function InvoiceForm({
Click to set payment due date 14 days after the date of issue
({dayjs(dateOfIssue).add(14, "days").format("DD/MM/YYYY")})
</ButtonHelper>
- </InputHelperMessage>
- ) : null}
- {/* If there are no errors and the payment due date is not before the date of issue and the payment due date is not 14 days after the date of issue, show the button to set the payment due date to 14 days after the date of issue (probably a bit better UX) */}
- {!errors.paymentDue &&
- !isPaymentDueBeforeDateOfIssue &&
- !isPaymentDue14DaysFromDateOfIssue ? (
- <ButtonHelper
- className="whitespace-normal"
- onClick={() => {
- const newPaymentDue = dayjs(dateOfIssue)
- .add(14, "days")
- .format("YYYY-MM-DD");
-
- setValue("paymentDue", newPaymentDue);
- }}
- >
- Click to set payment due date 14 days after the date of issue (
- {dayjs(dateOfIssue).add(14, "days").format("DD/MM/YYYY")})
- </ButtonHelper>
- ) : null}
- </div>
- </div>
-
- {/* Notes */}
- <div className="">
- <div className="relative mb-2 flex items-center justify-between">
- <Label htmlFor="notes" className="">
- Notes
- </Label>
-
- {/* Show/hide Notes field in PDF switch */}
- <div className="inline-flex items-center gap-2">
- <Controller
- name={`notesFieldIsVisible`}
- control={control}
- render={({ field: { value, onChange, ...field } }) => (
- <Switch
- {...field}
- id={`notesFieldIsVisible`}
- 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={`notesFieldIsVisible`}>Show in PDF</Label>
- }
- content='Show/Hide the "Notes" Field in the PDF'
- />
+ ) : null}
</div>
</div>
- <Controller
- name="notes"
- control={control}
- render={({ field }) => (
- <Textarea {...field} id="notes" rows={3} className="" />
- )}
- />
- {errors?.notes && (
- <ErrorMessage>{errors?.notes?.message}</ErrorMessage>
- )}
- </div>
- <div>
- <div className="relative mt-5 space-y-4">
- {/* Show/hide Person Authorized to Receive field in PDF switch */}
- <div className="flex items-center justify-between">
- <Label htmlFor={`personAuthorizedToReceiveFieldIsVisible`}>
- Show &quot;Person Authorized to Receive&quot; Signature Field in
- the PDF
+ {/* Notes */}
+ <div className="">
+ <div className="relative mb-2 flex items-center justify-between">
+ <Label htmlFor="notes" className="">
+ Notes
</Label>
- <Controller
- name={`personAuthorizedToReceiveFieldIsVisible`}
- control={control}
- render={({ field: { value, onChange, ...field } }) => (
- <Switch
- {...field}
- id={`personAuthorizedToReceiveFieldIsVisible`}
- 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"
- />
- )}
- />
+ {/* Show/hide Notes field in PDF switch */}
+ <div className="inline-flex items-center gap-2">
+ <Controller
+ name={`notesFieldIsVisible`}
+ control={control}
+ render={({ field: { value, onChange, ...field } }) => (
+ <Switch
+ {...field}
+ id={`notesFieldIsVisible`}
+ 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={`notesFieldIsVisible`}>Show in PDF</Label>
+ }
+ content='Show/Hide the "Notes" Field in the PDF'
+ />
+ </div>
</div>
+ <Controller
+ name="notes"
+ control={control}
+ render={({ field }) => (
+ <Textarea {...field} id="notes" rows={3} className="" />
+ )}
+ />
+ {errors?.notes && (
+ <ErrorMessage>{errors?.notes?.message}</ErrorMessage>
+ )}
+ </div>
- {/* Show/hide Person Authorized to Issue field in PDF switch */}
- <div className="flex items-center justify-between">
- <Label htmlFor={`personAuthorizedToIssueFieldIsVisible`}>
- Show &quot;Person Authorized to Issue&quot; Signature Field in
- the PDF
- </Label>
+ <div>
+ <div className="relative mt-5 space-y-4">
+ {/* Show/hide Person Authorized to Receive field in PDF switch */}
+ <div className="flex items-center justify-between">
+ <Label htmlFor={`personAuthorizedToReceiveFieldIsVisible`}>
+ Show &quot;Person Authorized to Receive&quot; Signature Field
+ in the PDF
+ </Label>
+
+ <Controller
+ name={`personAuthorizedToReceiveFieldIsVisible`}
+ control={control}
+ render={({ field: { value, onChange, ...field } }) => (
+ <Switch
+ {...field}
+ id={`personAuthorizedToReceiveFieldIsVisible`}
+ 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>
- <Controller
- name={`personAuthorizedToIssueFieldIsVisible`}
- control={control}
- render={({ field: { value, onChange, ...field } }) => (
- <Switch
- {...field}
- id={`personAuthorizedToIssueFieldIsVisible`}
- 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"
- />
- )}
- />
+ {/* Show/hide Person Authorized to Issue field in PDF switch */}
+ <div className="flex items-center justify-between">
+ <Label htmlFor={`personAuthorizedToIssueFieldIsVisible`}>
+ Show &quot;Person Authorized to Issue&quot; Signature Field in
+ the PDF
+ </Label>
+
+ <Controller
+ name={`personAuthorizedToIssueFieldIsVisible`}
+ control={control}
+ render={({ field: { value, onChange, ...field } }) => (
+ <Switch
+ {...field}
+ id={`personAuthorizedToIssueFieldIsVisible`}
+ 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>
</div>
diff --git a/src/app/components/invoice-pdf-download-link.tsx b/src/app/components/invoice-pdf-download-link.tsx
index 5d5343e..afd29f0 100644
--- a/src/app/components/invoice-pdf-download-link.tsx
+++ b/src/app/components/invoice-pdf-download-link.tsx
@@ -36,7 +36,7 @@ export function InvoicePDFDownloadLink({
if (pdfLoading) {
setIsLoading(true);
} else {
- // wait for 0.5 second before hiding the loader
+ // wait before hiding the loader to avoid flickering
const timer = setTimeout(() => {
setIsLoading(false);
}, LOADING_BUTTON_TIMEOUT);
@@ -87,6 +87,9 @@ export function InvoicePDFDownloadLink({
openPanel.track("download_invoice");
umamiTrackEvent("download_invoice");
+ // dismiss any existing toast for better UX
+ toast.dismiss();
+
// Show donation toast after 3 seconds
setTimeout(() => {
toast("Consider Supporting Us!", {
diff --git a/src/app/page.tsx b/src/app/page.tsx
index ac35a78..859bc59 100644
--- a/src/app/page.tsx
+++ b/src/app/page.tsx
@@ -23,6 +23,8 @@ import { INITIAL_INVOICE_DATA } from "./constants";
import { useOpenPanel } from "@openpanel/nextjs";
import { isLocalStorageAvailable } from "@/lib/check-local-storage";
import { umamiTrackEvent } from "@/lib/umami-analytics-track-event";
+import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/ui/tabs";
+import { FileTextIcon, PencilIcon } from "lucide-react";
const InvoicePDFViewer = dynamic(
() =>
@@ -43,6 +45,11 @@ const InvoicePDFViewer = dynamic(
}
);
+const TABS_VALUES = ["form", "preview"] as const;
+
+const TAB_FORM = TABS_VALUES[0];
+const TAB_PREVIEW = TABS_VALUES[1];
+
export default function Home() {
const router = useRouter();
const searchParams = useSearchParams();
@@ -199,13 +206,13 @@ export default function Home() {
<div className="flex min-h-screen flex-col items-center justify-center bg-gray-100 sm:p-4">
<div className="mb-4 w-full max-w-7xl bg-white p-3 shadow-lg sm:mb-0 sm:rounded-lg sm:p-6">
<div className="flex w-full flex-row flex-wrap items-center justify-between lg:flex-nowrap">
- <h1 className="mb-6 mt-6 w-full text-balance text-center text-xl font-bold sm:mb-4 sm:mt-0 sm:text-2xl lg:text-left">
+ <h1 className="mb-6 mt-6 w-full text-balance text-center text-xl font-bold sm:mb-4 sm:mt-0 sm:text-2xl lg:mr-5 lg:text-left">
Free Invoice PDF Generator with Live Preview
</h1>
<div className="mb-1 flex w-full flex-wrap justify-center gap-3 lg:flex-nowrap lg:justify-end">
<Button
- className="w-full bg-blue-500 text-white transition-all hover:scale-105 hover:bg-blue-600 hover:no-underline lg:w-auto"
+ className="mx-2 w-full bg-blue-500 text-white transition-all hover:scale-105 hover:bg-blue-600 hover:no-underline lg:mx-0 lg:w-auto"
_variant="link"
onClick={() => {
window.open(
@@ -229,7 +236,7 @@ export default function Home() {
<Button
onClick={handleShareInvoice}
_variant="outline"
- className="w-full lg:w-auto"
+ className="mx-2 mb-2 w-full lg:mx-0 lg:mb-0 lg:w-auto"
>
Generate a link to invoice
</Button>
@@ -242,59 +249,63 @@ export default function Home() {
</div>
</div>
<div className="mb-4 flex flex-row items-center justify-center lg:mb-0 lg:justify-start">
- <span className="relative bottom-0 text-center text-sm text-gray-900 lg:bottom-3">
- Made by{" "}
- <a
- href="https://dub.sh/vldzn.me"
- className="underline transition-colors hover:text-blue-600"
- target="_blank"
- >
- Vlad Sazonau
- </a>
- {" | "}
- <a
- href="https://github.com/VladSez/pdf-invoice-generator"
- target="_blank"
- rel="noopener noreferrer"
- className="group inline-flex items-center gap-2"
- title="View on GitHub"
- >
- <span className="transition-all group-hover:text-blue-600 group-hover:underline">
- Open Source
- </span>
- <GithubIcon />
- </a>
- {" | "}
- <a
- href="https://dub.sh/easy-invoice-pdf-feedback"
- className="transition-colors hover:text-blue-600 hover:underline"
- target="_blank"
- >
- Share your feedback
- </a>
- </span>
+ <ProjectInfo />
</div>
<div className="grid grid-cols-1 gap-4 lg:grid-cols-12">
- <div className="lg:col-span-4">
- <div className="h-[400px] overflow-auto p-3 lg:h-[580px] lg:pl-0">
+ {/* Mobile View with Tabs */}
+ <div className="block w-full lg:hidden">
+ <Tabs defaultValue={TAB_FORM} className="w-full">
+ <TabsList className="w-full">
+ <TabsTrigger value={TAB_FORM} className="flex-1">
+ <span className="flex items-center gap-1">
+ <PencilIcon className="h-4 w-4" />
+ Edit Invoice
+ </span>
+ </TabsTrigger>
+ <TabsTrigger value={TAB_PREVIEW} className="flex-1">
+ <span className="flex items-center gap-1">
+ <FileTextIcon className="h-4 w-4" />
+ Preview PDF
+ </span>
+ </TabsTrigger>
+ </TabsList>
+ <TabsContent value={TAB_FORM} className="mt-4">
+ <div className="h-[400px] overflow-auto rounded-lg border-b px-3 shadow-sm">
+ <InvoiceForm
+ invoiceData={invoiceDataState}
+ onInvoiceDataChange={handleInvoiceDataChange}
+ />
+ </div>
+ </TabsContent>
+ <TabsContent value={TAB_PREVIEW} className="mt-4">
+ <div className="h-[580px] w-full">
+ <InvoicePDFViewer>
+ <InvoicePdfTemplate invoiceData={invoiceDataState} />
+ </InvoicePDFViewer>
+ </div>
+ </TabsContent>
+ {/* Action buttons visible in both tabs */}
+ <div className="sticky bottom-0 mt-4 flex flex-col gap-3 bg-white pb-2">
+ <RegenerateInvoiceButton invoiceData={invoiceDataState} />
+ <InvoicePDFDownloadLink invoiceData={invoiceDataState} />
+ </div>
+ </Tabs>
+ </div>
+
+ {/* Desktop View - Side by Side */}
+ <div className="hidden lg:col-span-4 lg:block">
+ <div className="h-[580px] overflow-auto px-3 pl-0">
<InvoiceForm
invoiceData={invoiceDataState}
onInvoiceDataChange={handleInvoiceDataChange}
/>
</div>
-
<div className="flex flex-col gap-3">
<RegenerateInvoiceButton invoiceData={invoiceDataState} />
- {/* We show the pdf download link here only on mobile/tables */}
- {isDesktop ? null : (
- <InvoicePDFDownloadLink invoiceData={invoiceDataState} />
- )}
</div>
-
- <hr className="my-2 block w-full lg:hidden" />
</div>
- <div className="h-[580px] w-full max-w-full lg:col-span-8">
+ <div className="hidden h-[580px] w-full max-w-full lg:col-span-8 lg:block">
<InvoicePDFViewer>
<InvoicePdfTemplate invoiceData={invoiceDataState} />
</InvoicePDFViewer>
@@ -306,7 +317,45 @@ export default function Home() {
);
}
-const GithubIcon = () => {
+function ProjectInfo() {
+ return (
+ <>
+ <span className="relative bottom-0 text-center text-sm text-gray-900 lg:bottom-3">
+ Made by{" "}
+ <a
+ href="https://dub.sh/vldzn.me"
+ className="underline transition-colors hover:text-blue-600"
+ target="_blank"
+ >
+ Vlad Sazonau
+ </a>
+ {" | "}
+ <a
+ href="https://github.com/VladSez/pdf-invoice-generator"
+ target="_blank"
+ rel="noopener noreferrer"
+ className="group inline-flex items-center gap-2"
+ title="View on GitHub"
+ >
+ <span className="transition-all group-hover:text-blue-600 group-hover:underline">
+ Open Source
+ </span>
+ <GithubIcon />
+ </a>
+ {" | "}
+ <a
+ href="https://dub.sh/easy-invoice-pdf-feedback"
+ className="transition-colors hover:text-blue-600 hover:underline"
+ target="_blank"
+ >
+ Share your feedback
+ </a>
+ </span>
+ </>
+ );
+}
+
+function GithubIcon() {
return (
<svg
role="img"
@@ -318,4 +367,4 @@ const GithubIcon = () => {
<path d="M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12" />
</svg>
);
-};
+}
diff --git a/src/app/schema/index.ts b/src/app/schema/index.ts
index 09d9b53..1a5cd83 100644
--- a/src/app/schema/index.ts
+++ b/src/app/schema/index.ts
@@ -5,6 +5,11 @@ export const SUPPORTED_CURRENCIES = ["EUR", "USD", "GBP", "PLN"] as const;
export const SUPPORTED_LANGUAGES = ["en", "pl"] as const;
export type SupportedLanguages = (typeof SUPPORTED_LANGUAGES)[number];
+export const LANGUAGE_TO_LABEL = {
+ en: "English",
+ pl: "Polish",
+} as const satisfies Record<SupportedLanguages, string>;
+
export const SUPPORTED_DATE_FORMATS = [
"YYYY-MM-DD", // 2024-03-20
"DD/MM/YYYY", // 20/03/2024
@@ -16,22 +21,6 @@ export const SUPPORTED_DATE_FORMATS = [
"YYYY.MM.DD", // 2024.03.20
] as const;
-export const DEFAULT_SELLER_DATA = {
- name: "Seller name",
- address: "Seller address",
-
- vatNo: "Seller vat number",
- vatNoFieldIsVisible: true,
-
- email: "[email protected]",
-
- accountNumber: "Seller account number",
- accountNumberFieldIsVisible: true,
-
- swiftBic: "Seller swift bic",
- swiftBicFieldIsVisible: true,
-} as const satisfies SellerData;
-
export type SupportedDateFormat = (typeof SUPPORTED_DATE_FORMATS)[number];
export const invoiceItemSchema = z
@@ -244,3 +233,41 @@ export type InvoiceData = z.infer<typeof invoiceSchema>;
// })
// .transform((value) => (value === null ? 0 : Number(value)))
// .pipe(zodPipe);
+
+export const DEFAULT_SELLER_DATA = {
+ name: "Seller name",
+ address: "Seller address",
+
+ vatNo: "Seller vat number",
+ vatNoFieldIsVisible: true,
+
+ email: "[email protected]",
+
+ accountNumber: "Seller account number",
+ accountNumberFieldIsVisible: true,
+
+ swiftBic: "Seller swift bic",
+ swiftBicFieldIsVisible: true,
+} as const satisfies SellerData;
+
+/**
+ * Accordion state schema
+ *
+ * This schema is used to store the state of the accordion in the local storage
+ *
+ * The accordion is used to collapse/expand the sections of the invoice form
+ *
+ *
+ */
+export const accordionSchema = z
+ .object({
+ general: z.boolean(),
+ seller: z.boolean(),
+ buyer: z.boolean(),
+ invoiceItems: z.boolean(),
+ })
+ .strict();
+
+export type AccordionState = z.infer<typeof accordionSchema>;
+
+export const ACCORDION_STATE_LOCAL_STORAGE_KEY = "EASY_INVOICE_ACCORDION_STATE";
diff --git a/src/components/ui/tabs.tsx b/src/components/ui/tabs.tsx
new file mode 100644
index 0000000..82628fd
--- /dev/null
+++ b/src/components/ui/tabs.tsx
@@ -0,0 +1,66 @@
+"use client";
+
+import * as TabsPrimitive from "@radix-ui/react-tabs";
+import * as React from "react";
+
+import { cn } from "@/lib/utils";
+
+function Tabs({
+ className,
+ ...props
+}: React.ComponentProps<typeof TabsPrimitive.Root>) {
+ return (
+ <TabsPrimitive.Root
+ data-slot="tabs"
+ className={cn("flex flex-col gap-2", className)}
+ {...props}
+ />
+ );
+}
+
+function TabsList({
+ className,
+ ...props
+}: React.ComponentProps<typeof TabsPrimitive.List>) {
+ return (
+ <TabsPrimitive.List
+ data-slot="tabs-list"
+ className={cn(
+ "inline-flex w-fit items-center justify-center gap-2 rounded-md bg-slate-200 p-1 text-slate-700 dark:bg-slate-800 dark:text-slate-300",
+ className
+ )}
+ {...props}
+ />
+ );
+}
+
+function TabsTrigger({
+ className,
+ ...props
+}: React.ComponentProps<typeof TabsPrimitive.Trigger>) {
+ return (
+ <TabsPrimitive.Trigger
+ data-slot="tabs-trigger"
+ className={cn(
+ "inline-flex items-center justify-center whitespace-nowrap rounded-[4px] px-3 py-1.5 text-sm font-medium ring-offset-white transition-all hover:bg-slate-100 hover:text-slate-900 focus-visible:border-indigo-500 focus-visible:ring focus-visible:ring-indigo-200 focus-visible:ring-opacity-50 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-white data-[state=active]:text-slate-950 data-[state=active]:shadow-sm dark:ring-offset-slate-950 dark:hover:bg-slate-800 dark:hover:text-slate-50 dark:focus-visible:ring-slate-300 dark:data-[state=active]:bg-slate-950 dark:data-[state=active]:text-slate-50",
+ className
+ )}
+ {...props}
+ />
+ );
+}
+
+function TabsContent({
+ className,
+ ...props
+}: React.ComponentProps<typeof TabsPrimitive.Content>) {
+ return (
+ <TabsPrimitive.Content
+ data-slot="tabs-content"
+ className={cn("flex-1 outline-none", className)}
+ {...props}
+ />
+ );
+}
+
+export { Tabs, TabsContent, TabsList, TabsTrigger };