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
attempt to fix android pdf preview (#115)
Vlad Sazonaud8099a9eb910
diff --git a/next.config.mjs b/next.config.mjsindex f6bf906..d54e2de 100644--- a/next.config.mjs+++ b/next.config.mjs@@ -129,6 +129,10 @@ const nextConfig = {fullUrl: true,},},+ webpack: (config) => {+ config.resolve.alias.canvas = false;+ return config;+ },async rewrites() {return [{diff --git a/package.json b/package.jsonindex f43567b..3820afd 100644--- a/package.json+++ b/package.json@@ -67,6 +67,7 @@"react-dom": "18.3.1","react-hook-form": "7.53.1","react-intersection-observer": "9.16.0",+ "react-pdf": "9.2.1","resend": "4.2.0","sonner": "1.7.4","tailwind-merge": "2.6.0",diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 8abca64..7293f46 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -130,6 +130,9 @@ importers:react-intersection-observer:specifier: 9.16.0+ react-pdf:+ specifier: 9.2.1resend:specifier: 4.2.0@@ -4756,6 +4759,13 @@ packages:integrity: sha512-3qtRjw/HQSMlDWf+X79N206fepf4SOOU6SQLMaq/0KkZLmSjPxAkBOQQ+FxbHKfHmYLZFfdWsO3KA90ceHPSnw==,}+ resolution:+ {+ integrity: sha512-tTj3CqqukVJ9NgSahykNwtGda7V33VLObwrHfzT0vqJXu7J4d4C/7kQQW3fOEGDfZZoILPut5H00gOjyttPGyg==,+ }+ engines: { node: ^18.12.0 || >= 20.9.0 }+resolution:{@@ -4791,6 +4801,12 @@ packages:}engines: { node: ">= 14.16.0" }+ resolution:+ {+ integrity: sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg==,+ }+resolution:{@@ -5107,6 +5123,20 @@ packages:integrity: sha512-8vDa8Qxvr/+d94hSh5P3IJwI5t8/c0KsMp+g8bNw9cY2icONa5aPfvKeieW1WlG0WQYwwhJ7mjui2xtiePQSXw==,}+ resolution:+ {+ integrity: sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ==,+ }+ engines: { node: ">=10" }++ resolution:+ {+ integrity: sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==,+ }+ engines: { node: ">=4.0.0" }+resolution:{@@ -5154,6 +5184,13 @@ packages:}engines: { node: ">= 0.8" }+ resolution:+ {+ integrity: sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==,+ }+ engines: { node: ">=6" }+resolution:{@@ -5286,6 +5323,12 @@ packages:}engines: { node: ">= 0.8" }+ resolution:+ {+ integrity: sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==,+ }+resolution:{@@ -5648,6 +5691,13 @@ packages:}engines: { node: ">=16.17" }+ resolution:+ {+ integrity: sha512-XYfuKMvj4O35f/pOXLObndIRvyQ+/+6AhODh+OKWj9S9498pHHn/IMszH+gt0fBCRWMNfk1ZSp5x3AifmnI2vg==,+ }+ engines: { node: ">=6" }+resolution:{@@ -5852,6 +5902,12 @@ packages:}engines: { node: ">= 0.8" }+ resolution:+ {+ integrity: sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==,+ }+resolution:{@@ -5962,6 +6018,12 @@ packages:integrity: sha512-kGzZ3LWWQcGIAmg6iWvXn0ei6WDtV26wzHRMwDSzmAbcXrTEXxHy6IehI6/4eT6VRKyMP1eF1VqwrVUmE/LR7A==,}+ resolution:+ {+ integrity: sha512-SyHy3T1v2NUXn29OsWdxmK6RwHD+vkj3v8en8AOBZ1wBQ/hCAQ5bAQTD02kW4W9tUp/3Qh6J8r9EvntiyCmOOw==,+ }+resolution:{@@ -6266,6 +6328,12 @@ packages:integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==,}+ resolution:+ {+ integrity: sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==,+ }+resolution:{@@ -6893,6 +6961,18 @@ packages:}engines: { node: ">=12" }+ resolution:+ {+ integrity: sha512-GCXh3bq/WuMbS+Ky4JBPW1hYTOU+znU+Q5m9Pu+pI8EoUqIHk9+tviOKC6/qhHh8C4/As3tzJ69IF32kdz85ww==,+ }++ resolution:+ {+ integrity: sha512-iDwf7mA03WPiR8QxvcVHmVWEPfMY1RZXerDVNCRYW7dUr2ppH3J58Rwb39/WG39yTZdRSxr3x+2v22tvI0VEvA==,+ }+resolution:{@@ -6936,6 +7016,17 @@ packages:}engines: { node: ">=18" }+ resolution:+ {+ integrity: sha512-nqXPXbso+1dcKDpPCXvwZyJILz+vSLqGGOnDrYHQYE+B8n9JTCekVLC65AfCpR4ggVyA/45Y0iR9LDyS2iI+zA==,+ }+ peerDependencies:+ "@types/react": ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0+ peerDependenciesMeta:+ "@types/react":+ optional: true+resolution:{@@ -7005,6 +7096,13 @@ packages:}engines: { node: ">=18" }+ resolution:+ {+ integrity: sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ==,+ }+ engines: { node: ">=10" }+resolution:{@@ -7045,6 +7143,12 @@ packages:}engines: { node: ">=16 || 14 >=14.17" }+ resolution:+ {+ integrity: sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A==,+ }+resolution:{@@ -7078,6 +7182,12 @@ packages:engines: { node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1 }hasBin: true+ resolution:+ {+ integrity: sha512-GEbrYkbfF7MoNaoh2iGG84Mnf/WZfB0GdGEsM8wz7Expx/LlWf5U8t9nvJKXSp3qr5IsEbK04cBGhol/KwOsWA==,+ }+resolution:{@@ -7162,6 +7272,19 @@ packages:sass:optional: true+ resolution:+ {+ integrity: sha512-OhYaY5sDsIka7H7AtijtI9jwGYLyl29eQn/W623DiN/MIv5sUqc4g7BIDThX+gb7di9f6xK02nkp8sdfFWZLTg==,+ }+ engines: { node: ">=10" }++ resolution:+ {+ integrity: sha512-5m3bsyrjFWE1xf7nz7YXdN4udnVtXK6/Yfgn5qnahL6bCkf2yKt4k3nuTKAtT4r3IG8JNR2ncsIMdZuAzJjHQQ==,+ }+resolution:{@@ -7430,6 +7553,13 @@ packages:}engines: { node: ">=16" }+ resolution:+ {+ integrity: sha512-+vnG6S4dYcYxZd+CZxzXCNKdELYZSKfohrk98yajCo1PtRoDgCTrrwOvK1GT0UoAdVszagDVllQc0U1vaX4NUQ==,+ }+ engines: { node: ">=6" }+resolution:{@@ -7437,6 +7567,13 @@ packages:}engines: { node: ">=6.8.1" }+ resolution:+ {+ integrity: sha512-IHZsA4T7YElCKNNXtiLgqScw4zPd3pG9do8UrznC757gMd7UPeHSL2qwNNMJo4r79fl8oj1Xx+1nh2YkzdMpLQ==,+ }+ engines: { node: ">=18" }+resolution:{@@ -7632,6 +7769,14 @@ packages:}engines: { node: ">=0.10.0" }+ resolution:+ {+ integrity: sha512-8Mf2cbV7x1cXPUILADGI3wuhfqWvtiLA1iclTDbFRZkgRQS0NqsPZphna9V+HyTEadheuPmjaJMsbzKQFOzLug==,+ }+ engines: { node: ">=10" }+ hasBin: true+resolution:{@@ -7752,6 +7897,12 @@ packages:integrity: sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==,}+ resolution:+ {+ integrity: sha512-tUPXtzlGM8FE3P0ZL6DVs/3P58k9nk8/jZeQCurTJylQA8qFYzHFfhBJkuqyE0FifOsQ0uKWekiZ5g8wtr28cw==,+ }+resolution:{@@ -7798,6 +7949,13 @@ packages:}engines: { node: ">= 0.8" }+ resolution:+ {+ integrity: sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==,+ }+ hasBin: true+resolution:{@@ -7859,6 +8017,19 @@ packages:integrity: sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==,}+ resolution:+ {+ integrity: sha512-AJt0lAIkItWEZRA5d/mO+Om4nPCuTiQ0saA+qItO967DTjmGjnhmF+Bi2tL286mOTfBlF5CyLzJ35KTMaDoH+A==,+ }+ peerDependencies:+ "@types/react": ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0+ react: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0+ react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0+ peerDependenciesMeta:+ "@types/react":+ optional: true+resolution:{@@ -8315,6 +8486,18 @@ packages:}engines: { node: ">=14" }+ resolution:+ {+ integrity: sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q==,+ }++ resolution:+ {+ integrity: sha512-brv7p5WgH0jmQJr1ZDDfKDOSeWWg+OVypG99A/5vYGPqJ6pxiaHLy8nxtFjBA7oMa01ebA9gfh1uMCFqOuXxvA==,+ }+resolution:{@@ -8527,6 +8710,13 @@ packages:}engines: { node: ">=12" }+ resolution:+ {+ integrity: sha512-4gB8na07fecVVkOI6Rs4e7T6NOTki5EmL7TUduTs6bu3EdnSycntVJ4re8kgZA+wx9IueI2Y11bfbgwtzuE0KQ==,+ }+ engines: { node: ">=0.10.0" }+resolution:{@@ -8637,6 +8827,19 @@ packages:}engines: { node: ">=6" }+ resolution:+ {+ integrity: sha512-EsaAXwxmx8UB7FRKqeozqEPop69DXcmYwTQwXvyAPF352HJsPdkVhvTaDPYqfNgruveJIJy3TA2l+2zj8LJIJA==,+ }++ resolution:+ {+ integrity: sha512-ujeqbceABgwMZxEJnk2HDY2DlnUZ+9oEcb1KzTVfYHio0UE6dG71n60d8D2I4qNvleWrrXpmjpt7vZeF1LnMZQ==,+ }+ engines: { node: ">=6" }+resolution:{@@ -8683,6 +8886,12 @@ packages:integrity: sha512-pkY1fj1cKHb2seWDy0B16HeWyczlJA9/WW3u3c4z/NiWDsO3DOU5D7nhTLE9CF0yXv/QZFY7sEJmj24dK+Rrqw==,}+ resolution:+ {+ integrity: sha512-+FbBPE1o9QAYvviau/qC5SE3caw21q3xkvWKBtja5vgqOWIHHJ3ioaq1VPfn/Szqctz2bU/oYeKd9/z5BL+PVg==,+ }+resolution:{@@ -8737,6 +8946,12 @@ packages:integrity: sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==,}+ resolution:+ {+ integrity: sha512-McnNiV1l8RYeY8tBgEpuodCC1mLUdbSN+CYBL7kJsJNInOP8UjDDEwdk6Mw60vdLLrr5NHKZhMAOSrR2NZuQ+w==,+ }+resolution:{@@ -8967,6 +9182,12 @@ packages:integrity: sha512-9YlCL/ynK3CTlrSRrDxZvUauLzAswPCrsaCgilqFevUYpeEW0/3ScEjaa3kbW/T0ghhkEr7mv+fpjqn1Y1YuTA==,}+ resolution:+ {+ integrity: sha512-rpJyN222KWIvHJ/F53XSZv0Zl/accqHR8et1kpaMTD/fLCRxtV8iX8czMzY7sVZupTI3zcUTg8eycS2kNF9l6w==,+ }+resolution:{@@ -12711,6 +12932,12 @@ snapshots:+ dependencies:+ node-addon-api: 7.1.1+ prebuild-install: 7.1.3+ optional: true+dependencies:ansi-styles: 4.3.0@@ -12739,6 +12966,9 @@ snapshots:dependencies:readdirp: 4.1.2+ optional: true+@@ -12884,6 +13114,14 @@ snapshots:+ dependencies:+ mimic-response: 3.1.0+ optional: true++ optional: true+@@ -12908,6 +13146,8 @@ snapshots:+ [email protected]: {}+@@ -12969,6 +13209,11 @@ snapshots:+ dependencies:+ once: 1.4.0+ optional: true+@@ -13366,6 +13611,9 @@ snapshots:signal-exit: 4.1.0strip-final-newline: 3.0.0+ optional: true+dependencies:express: 5.1.0@@ -13523,6 +13771,9 @@ snapshots:+ optional: true+@@ -13600,6 +13851,9 @@ snapshots:dependencies:resolve-pkg-maps: 1.0.0+ optional: true+dependencies:is-glob: 4.0.3@@ -13798,6 +14052,9 @@ snapshots:+ optional: true+dependencies:es-errors: 1.3.0@@ -14173,6 +14430,10 @@ snapshots:dependencies:"@jridgewell/sourcemap-codec": 1.5.0+ [email protected]: {}++ [email protected]: {}+@@ -14188,6 +14449,10 @@ snapshots:+ [email protected](@types/[email protected]):+ optionalDependencies:+ "@types/react": 18.3.12+@@ -14215,6 +14480,9 @@ snapshots:+ optional: true+dependencies:brace-expansion: 1.1.11@@ -14233,6 +14501,9 @@ snapshots:+ optional: true+@@ -14247,6 +14518,9 @@ snapshots:+ optional: true+@@ -14319,6 +14593,14 @@ snapshots:- "@babel/core"- babel-plugin-macros+ dependencies:+ semver: 7.7.1+ optional: true++ optional: true+@@ -14472,6 +14754,9 @@ snapshots:+ optional: true+dependencies:debug: 3.2.7@@ -14479,6 +14764,11 @@ snapshots:transitivePeerDependencies:- supports-color+ optionalDependencies:+ canvas: 3.1.0+ path2d: 0.2.2+@@ -14570,6 +14860,22 @@ snapshots:dependencies:xtend: 4.0.2+ dependencies:+ detect-libc: 2.0.3+ expand-template: 2.0.3+ github-from-package: 0.0.0+ minimist: 1.2.8+ mkdirp-classic: 0.5.3+ napi-build-utils: 2.0.0+ node-abi: 3.75.0+ pump: 3.0.2+ rc: 1.2.8+ simple-get: 4.0.1+ tar-fs: 2.1.2+ tunnel-agent: 0.6.0+ optional: true+@@ -14599,6 +14905,12 @@ snapshots:+ dependencies:+ end-of-stream: 1.4.4+ once: 1.4.0+ optional: true+@@ -14624,6 +14936,14 @@ snapshots:iconv-lite: 0.6.3unpipe: 1.0.0+ dependencies:+ deep-extend: 0.6.0+ ini: 1.3.8+ minimist: 1.2.8+ strip-json-comments: 2.0.1+ optional: true+dependencies:"@internationalized/date": 3.8.0@@ -14751,6 +15071,21 @@ snapshots:+ [email protected](@types/[email protected])([email protected]([email protected]))([email protected]):+ dependencies:+ clsx: 2.1.1+ dequal: 2.0.3+ make-cancellable-promise: 1.3.2+ make-event-props: 1.6.2+ merge-refs: 1.3.0(@types/[email protected])+ pdfjs-dist: 4.8.69+ react: 18.3.1+ react-dom: 18.3.1([email protected])+ tiny-invariant: 1.3.3+ warning: 4.0.3+ optionalDependencies:+ "@types/react": 18.3.12+dependencies:fast-deep-equal: 2.0.1@@ -15134,6 +15469,16 @@ snapshots:+ optional: true++ dependencies:+ decompress-response: 6.0.0+ once: 1.4.0+ simple-concat: 1.0.1+ optional: true+dependencies:is-arrayish: 0.3.2@@ -15294,6 +15639,9 @@ snapshots:+ optional: true+@@ -15369,6 +15717,23 @@ snapshots:+ dependencies:+ chownr: 1.1.4+ mkdirp-classic: 0.5.3+ pump: 3.0.2+ tar-stream: 2.2.0+ optional: true++ dependencies:+ bl: 4.1.0+ end-of-stream: 1.4.4+ fs-constants: 1.0.0+ inherits: 2.0.4+ readable-stream: 3.6.2+ optional: true+dependencies:"@jridgewell/trace-mapping": 0.3.25@@ -15395,6 +15760,8 @@ snapshots:+ [email protected]: {}+dependencies:fdir: 6.4.3([email protected])@@ -15423,6 +15790,11 @@ snapshots:+ dependencies:+ safe-buffer: 5.2.1+ optional: true+dependencies:prelude-ls: 1.2.1@@ -15578,6 +15950,10 @@ snapshots:+ dependencies:+ loose-envify: 1.4.0+dependencies:glob-to-regexp: 0.4.1diff --git a/src/app/components/android-pdf-viewer.tsx b/src/app/components/android-pdf-viewer.tsxnew file mode 100644index 0000000..18ed740--- /dev/null+++ b/src/app/components/android-pdf-viewer.tsx@@ -0,0 +1,79 @@+import { BlobProvider } from "@react-pdf/renderer/lib/react-pdf.browser";+import { Document, Page, pdfjs } from "react-pdf";+import type { InvoiceData } from "../schema";+import { InvoicePdfTemplate } from "./invoice-pdf-template";++import "react-pdf/dist/esm/Page/AnnotationLayer.css";+import "react-pdf/dist/esm/Page/TextLayer.css";++// https://github.com/wojtekmaj/react-pdf/issues/1822#issuecomment-2233334169+pdfjs.GlobalWorkerOptions.workerSrc = `//unpkg.com/pdfjs-dist@${pdfjs.version}/build/pdf.worker.min.mjs`;++export const AndroidPdfViewer = ({+ invoiceData,+}: {+ invoiceData: InvoiceData;+}) => {+ // On mobile, we need to use the BlobProvider to generate a PDF preview+ // This is because the PDF viewer is not supported on Android Chrome devices+ // https://github.com/diegomura/react-pdf/issues/714+ return (+ <BlobProvider document={<InvoicePdfTemplate invoiceData={invoiceData} />}>+ {({ url, loading, error }) => {+ if (error) {+ return (+ <div className="flex h-[580px] w-full items-center justify-center border border-gray-200 bg-gray-200 lg:h-[620px] 2xl:h-[700px]">+ <div className="text-center">+ <p className="text-red-600">Error generating PDF preview</p>+ <p className="mt-2 text-sm text-gray-600">+ Something went wrong. Please try again or contact support.+ </p>+ </div>+ </div>+ );+ }++ if (loading) {+ return (+ <div className="flex h-full w-full items-center justify-center border border-gray-200 bg-gray-200">+ <div className="text-center">+ <div className="mx-auto mb-4 h-8 w-8 animate-spin rounded-full border-4 border-blue-500 border-t-transparent" />+ <p className="text-gray-600">Loading PDF viewer...</p>+ </div>+ </div>+ );+ }++ return (+ <Document+ file={url}+ className="h-[480px] w-[650px] overflow-auto"+ loading={+ <div className="flex h-[480px] w-full items-center justify-center border border-gray-200 bg-gray-200 lg:h-[620px] 2xl:h-[700px]">+ <div className="text-center">+ <div className="mx-auto mb-4 h-8 w-8 animate-spin rounded-full border-4 border-blue-500 border-t-transparent" />+ <p className="text-gray-600">Loading PDF viewer...</p>+ </div>+ </div>+ }+ >+ <Page+ pageNumber={1}+ error={"Something went wrong"}+ loading={+ <div className="flex h-[480px] w-full items-center justify-center border border-gray-200 bg-gray-200 lg:h-[620px] 2xl:h-[700px]">+ <div className="text-center">+ <div className="mx-auto mb-4 h-8 w-8 animate-spin rounded-full border-4 border-blue-500 border-t-transparent" />+ <p className="text-gray-600">Loading PDF viewer...</p>+ </div>+ </div>+ }+ height={450}+ width={650}+ />+ </Document>+ );+ }}+ </BlobProvider>+ );+};diff --git a/src/app/components/index.tsx b/src/app/components/index.tsxindex 4aea330..0ba0d6d 100644--- a/src/app/components/index.tsx+++ b/src/app/components/index.tsx@@ -1,29 +1,66 @@+import { Button } from "@/components/ui/button";import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";+import { CustomTooltip } from "@/components/ui/tooltip";import { FileTextIcon, PencilIcon } from "lucide-react";import dynamic from "next/dynamic";+import type { InvoiceData } from "../schema";import { InvoiceForm } from "./invoice-form";import { InvoicePDFDownloadLink } from "./invoice-pdf-download-link";import { InvoicePdfTemplate } from "./invoice-pdf-template";-import type { InvoiceData } from "../schema";-import { CustomTooltip } from "@/components/ui/tooltip";-import { Button } from "@/components/ui/button";+import { useDeviceContext } from "@/contexts/device-context";++const DesktopPDFViewerModuleLoading = () => (+ <div className="flex h-[580px] w-full items-center justify-center border border-gray-200 bg-gray-200 lg:h-[620px] 2xl:h-[700px]">+ <div className="text-center">+ <div className="mx-auto mb-4 h-8 w-8 animate-spin rounded-full border-4 border-blue-500 border-t-transparent" />+ <p className="text-gray-600">Loading PDF viewer...</p>+ </div>+ </div>+);++const AndroidPDFViewerModuleLoading = () => (+ <div className="flex h-full w-full items-center justify-center border border-gray-200 bg-gray-200">+ <div className="text-center">+ <div className="mx-auto mb-4 h-8 w-8 animate-spin rounded-full border-4 border-blue-500 border-t-transparent" />+ <p className="text-gray-600">Loading PDF viewer...</p>+ </div>+ </div>+);const InvoicePDFViewer = dynamic(() => import("./invoice-pdf-viewer").then((mod) => mod.InvoicePDFViewer),{ssr: false,- loading: () => (- <div className="flex h-[580px] w-full items-center justify-center border border-gray-200 bg-gray-200 lg:h-[620px] 2xl:h-[700px]">- <div className="text-center">- <div className="mx-auto mb-4 h-8 w-8 animate-spin rounded-full border-4 border-blue-500 border-t-transparent" />- <p className="text-gray-600">Loading PDF viewer...</p>- </div>- </div>- ),+ loading: () => <DesktopPDFViewerModuleLoading />,});+const AndroidPDFViewer = dynamic(+ () => import("./android-pdf-viewer").then((mod) => mod.AndroidPdfViewer),+ {+ ssr: false,+ loading: () => <AndroidPDFViewerModuleLoading />,+ }+);++const PdfViewer = ({ invoiceData }: { invoiceData: InvoiceData }) => {+ const { isAndroid } = useDeviceContext();++ // we only show the Android PDF viewer on Android devices due to the limitations of the PDF viewer+ // https://github.com/diegomura/react-pdf/issues/714+ if (isAndroid) {+ return <AndroidPDFViewer invoiceData={invoiceData} />;+ }++ // Desktop version+ return (+ <InvoicePDFViewer>+ <InvoicePdfTemplate invoiceData={invoiceData} />+ </InvoicePDFViewer>+ );+};+const TABS_VALUES = ["invoice-form", "invoice-preview"] as const;const TAB_INVOICE_FORM = TABS_VALUES[0];@@ -68,14 +105,12 @@ export function InvoiceClientPage({</div></TabsContent><TabsContent value={TAB_INVOICE_PREVIEW} className="mt-1">- <div className="h-[480px] w-full">- <InvoicePDFViewer>- <InvoicePdfTemplate invoiceData={invoiceDataState} />- </InvoicePDFViewer>+ <div className="flex h-[480px] w-full items-center justify-center">+ <PdfViewer invoiceData={invoiceDataState} /></div></TabsContent></Tabs>- <div className="sticky bottom-0 mt-2 flex flex-col items-center justify-center gap-3 rounded-lg border border-t border-gray-200 bg-white px-3 py-3 shadow-[0_-4px_6px_-1px_rgba(0,0,0,0.1),0_-2px_4px_-2px_rgba(0,0,0,0.05)]">+ <div className="sticky bottom-0 z-50 mt-2 flex flex-col items-center justify-center gap-3 rounded-lg border border-t border-gray-200 bg-white px-3 py-3 shadow-[0_-4px_6px_-1px_rgba(0,0,0,0.1),0_-2px_4px_-2px_rgba(0,0,0,0.05)]"><CustomTooltiptrigger={<Button@@ -103,9 +138,7 @@ export function InvoiceClientPage({</div></div><div className="col-span-8 h-[620px] w-full max-w-full 2xl:h-[700px]">- <InvoicePDFViewer>- <InvoicePdfTemplate invoiceData={invoiceDataState} />- </InvoicePDFViewer>+ <PdfViewer invoiceData={invoiceDataState} /></div></>)}diff --git a/src/app/layout.tsx b/src/app/layout.tsxindex 408af58..b936311 100644--- a/src/app/layout.tsx+++ b/src/app/layout.tsx@@ -133,12 +133,16 @@ export default async function RootLayout({}: Readonly<{children: React.ReactNode;}>) {- const { isDesktop: isDesktopServer } = await checkDeviceUserAgent();+ const { isDesktop: isDesktopServer, isAndroid } =+ await checkDeviceUserAgent();return (<html lang="en"><body>- <DeviceContextProvider isDesktop={isDesktopServer}>+ <DeviceContextProvider+ isDesktop={isDesktopServer}+ isAndroid={isAndroid}+ ><NextIntlClientProvider>{/* React-scan is a tool for detecting and fixing issues with Reactcomponents https://github.com/aidenybai/react-scan#readme Uncommentdiff --git a/src/contexts/device-context.tsx b/src/contexts/device-context.tsxindex bb4c796..3f1af0f 100644--- a/src/contexts/device-context.tsx+++ b/src/contexts/device-context.tsx@@ -5,12 +5,14 @@ import { createContext, useContext, useEffect, useState } from "react";interface DeviceContextType {isDesktop: boolean;+ isAndroid: boolean;}const DeviceContext = createContext<DeviceContextType | null>(null);export function useDeviceContext() {const context = useContext(DeviceContext);+if (!context) {throw new Error("useDeviceContext must be used within a DeviceProvider");}@@ -20,6 +22,7 @@ export function useDeviceContext() {export function DeviceContextProvider({children,isDesktop,+ isAndroid,}: DeviceContextType & { children: React.ReactNode }) {const [isDesktopClient, setIsDesktopClient] = useState(isDesktop);@@ -37,7 +40,7 @@ export function DeviceContextProvider({}, [isMediaQueryDesktop]);return (- <DeviceContext.Provider value={{ isDesktop: isDesktopClient }}>+ <DeviceContext.Provider value={{ isDesktop: isDesktopClient, isAndroid }}>{children}</DeviceContext.Provider>);diff --git a/src/lib/check-device.server.ts b/src/lib/check-device.server.tsindex dceda2b..fded41f 100644--- a/src/lib/check-device.server.ts+++ b/src/lib/check-device.server.ts@@ -31,8 +31,11 @@ export const checkDeviceUserAgent = async () => {// Detect mobile phonesconst isMobile = device.type === "mobile";+ // Detect Android specifically+ const isAndroid = os.name === "Android";+// Desktop is when it's neither tablet nor mobileconst isDesktop = !isTablet && !isMobile;- return { isDesktop };+ return { isDesktop, isAndroid };};