Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/aliabb01/invoify
Browse files Browse the repository at this point in the history
  • Loading branch information
al1abb committed Dec 6, 2023
2 parents e2b7208 + e568a76 commit a429717
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 72 deletions.
2 changes: 2 additions & 0 deletions app/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import NewInvoiceAlert from "./modals/alerts/NewInvoiceAlert";
========================= */
// Invoice templates
import DynamicInvoiceTemplate from "./templates/invoice-pdf/DynamicInvoiceTemplate";
import InvoiceLayout from "./templates/invoice-pdf/InvoiceLayout";
import InvoiceTemplate1 from "./templates/invoice-pdf/InvoiceTemplate1";
import InvoiceTemplate2 from "./templates/invoice-pdf/InvoiceTemplate2";

Expand Down Expand Up @@ -134,6 +135,7 @@ export {
SignatureFontSelector,
NewInvoiceAlert,
DynamicInvoiceTemplate,
InvoiceLayout,
InvoiceTemplate1,
InvoiceTemplate2,
SendPdfEmail,
Expand Down
49 changes: 49 additions & 0 deletions app/components/templates/invoice-pdf/InvoiceLayout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { ReactNode } from "react";

import { InvoiceType } from "@/app/types/types";

type InvoiceLayoutProps = {
data: InvoiceType;
children: ReactNode;
};

export default function InvoiceLayout({ data, children }: InvoiceLayoutProps) {
const { sender, receiver, details } = data;

// Instead of fetching all fonts, get the specific one user selected
const fontHref = details.signature?.fontFamily
? `https://fonts.googleapis.com/css2?family=${details?.signature?.fontFamily}&display=swap`
: "";

const head = (
<>
{/* //! NOTE: This causes performance issues in production. (Estimated saving 1.38s) */}
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css"
rel="stylesheet"
/>

{details.signature?.fontFamily && (
<>
<link
rel="preconnect"
href="https://fonts.googleapis.com"
/>
<link
rel="preconnect"
href="https://fonts.gstatic.com"
crossOrigin="anonymous"
/>
<link href={fontHref} rel="stylesheet" />
</>
)}
</>
);

return (
<>
{head}
{children}
</>
);
}
41 changes: 6 additions & 35 deletions app/components/templates/invoice-pdf/InvoiceTemplate1.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import React from "react";

// Components
import { InvoiceLayout } from "@/app/components";

// Helpers
import { formatNumberWithCommas, isDataUrl } from "@/lib/helpers";

Expand All @@ -12,38 +15,8 @@ import { DATE_OPTIONS } from "@/lib/variables";
const InvoiceTemplate = (data: InvoiceType) => {
const { sender, receiver, details } = data;

// Instead of fetching all fonts, get the specific one user selected
const fontHref = details.signature?.fontFamily
? `https://fonts.googleapis.com/css2?family=${details?.signature?.fontFamily}&display=swap`
: "";

const heading = (
<>
{/* //! NOTE: This causes performance issues in production. (Estimated saving 1.38s) */}
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css"
rel="stylesheet"
/>

{details.signature?.fontFamily && (
<>
<link
rel="preconnect"
href="https://fonts.googleapis.com"
/>
<link
rel="preconnect"
href="https://fonts.gstatic.com"
crossOrigin="anonymous"
/>
<link href={fontHref} rel="stylesheet" />
</>
)}
</>
);
const content = (
<>
{heading}
return (
<InvoiceLayout data={data}>
<div
style={{
position: "relative",
Expand Down Expand Up @@ -348,10 +321,8 @@ const InvoiceTemplate = (data: InvoiceType) => {
) : null}
</div>
</div>
</>
</InvoiceLayout>
);

return <>{content}</>;
};

export default InvoiceTemplate;
45 changes: 8 additions & 37 deletions app/components/templates/invoice-pdf/InvoiceTemplate2.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import React from "react";

// Components
import { InvoiceLayout } from "@/app/components";

// Helpers
import { formatNumberWithCommas, isDataUrl } from "@/lib/helpers";

Expand All @@ -9,40 +12,10 @@ import { InvoiceType } from "@/app/types/types";
// Variables
import { DATE_OPTIONS } from "@/lib/variables";

const InvoiceTemplate2 = ({ sender, receiver, details }: InvoiceType) => {
// const ReactDOMServer = (await import("react-dom/server")).default;

// Instead of fetching all fonts, get the specific one user selected
const fontHref = details.signature?.fontFamily
? `https://fonts.googleapis.com/css2?family=${details?.signature?.fontFamily}&display=swap`
: "";

const heading = (
<>
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css"
rel="stylesheet"
/>

{details.signature?.fontFamily && (
<>
<link
rel="preconnect"
href="https://fonts.googleapis.com"
/>
<link
rel="preconnect"
href="https://fonts.gstatic.com"
crossOrigin="anonymous"
/>
<link href={fontHref} rel="stylesheet" />
</>
)}
</>
);
const content = (
<>
{heading}
const InvoiceTemplate2 = (data: InvoiceType) => {
const { sender, receiver, details } = data;
return (
<InvoiceLayout data={data}>
<div
style={{
position: "relative",
Expand Down Expand Up @@ -349,10 +322,8 @@ const InvoiceTemplate2 = ({ sender, receiver, details }: InvoiceType) => {
) : null}
</div>
</div>
</>
</InvoiceLayout>
);

return <>{content}</>;
};

export default InvoiceTemplate2;

0 comments on commit a429717

Please sign in to comment.