Free & Open-Source Invoice Generator - No Sign-Up, No Ads, Instant PDF Export, 100% In-Browser, and Fully Customizable Templates.
TypeScript fintechinvoiceinvoice-generatorinvoice-pdfinvoice-templateinvoicesnextjsopen-sourcequotesreactreact-pdf-rendererself-hostedshadcn-uitailwindcsstypescript
fix: improve invoice form payment due date UX and PDF download error handling + PDF download bug fix (#41)
Vlad Sazonaua0776d1db354
diff --git a/src/app/components/invoice-form.tsx b/src/app/components/invoice-form.tsxindex ca35497..263c11c 100644--- a/src/app/components/invoice-form.tsx+++ b/src/app/components/invoice-form.tsx@@ -142,6 +142,11 @@ export function InvoiceForm({dayjs(dateOfIssue));+ // payment due date is 14 days after the date of issue or the same day+ const isPaymentDue14DaysFromDateOfIssue =+ dayjs(paymentDue).isAfter(dayjs(dateOfIssue).add(14, "days")) ||+ dayjs(paymentDue).isSame(dayjs(dateOfIssue).add(14, "days"));+const extractInvoiceMonthAndYear = invoiceNumber?.split("/")?.[1];const isInvoiceNumberInCurrentMonth =@@ -1662,6 +1667,23 @@ export function InvoiceForm({</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+ 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>{/* Notes */}diff --git a/src/app/components/invoice-pdf-download-link.tsx b/src/app/components/invoice-pdf-download-link.tsxindex 66ea2b9..dcf4daa 100644--- a/src/app/components/invoice-pdf-download-link.tsx+++ b/src/app/components/invoice-pdf-download-link.tsx@@ -8,6 +8,7 @@ import { loglib } from "@loglib/tracker";import { cn } from "@/lib/utils";import { Loader2 } from "lucide-react";import { LOADING_BUTTON_TEXT, LOADING_TIMEOUT } from "./invoice-form";+import { toast } from "sonner";export function InvoicePDFDownloadLink({invoiceData,@@ -18,12 +19,16 @@ export function InvoicePDFDownloadLink({invoiceData.language}-${invoiceData.invoiceNumber.replace("/", "-")}.pdf`;- const [{ loading: pdfLoading, url }] = usePDF({- document: <InvoicePdfTemplate invoiceData={invoiceData} />,- });+ const [{ loading: pdfLoading, url, error }, updatePdfInstance] = usePDF();const [isLoading, setIsLoading] = useState(false);+ // https://github.com/diegomura/react-pdf/pull/2247/files+ // allow the pdf to be updated correctly when the invoice data changes+ useEffect(() => {+ updatePdfInstance(<InvoicePdfTemplate invoiceData={invoiceData} />);+ }, [invoiceData, updatePdfInstance]);+useEffect(() => {if (pdfLoading) {setIsLoading(true);@@ -36,6 +41,12 @@ export function InvoicePDFDownloadLink({}}, [pdfLoading]);+ useEffect(() => {+ if (error) {+ toast.error("Error generating document link");+ }+ }, [error]);+return (<><a