-
Notifications
You must be signed in to change notification settings - Fork 514
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
302 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function Editor() { | ||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
export * from "./template/invoice"; | ||
export * from "./templates/html"; | ||
export * from "./templates/pdf"; | ||
export * from "./editor"; | ||
|
||
export { renderToStream } from "@react-pdf/renderer"; |
13 changes: 13 additions & 0 deletions
13
packages/invoice/src/templates/html/components/editor-content.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { formatEditorToHtml } from "../../../utils/format"; | ||
|
||
export function EditorContent({ content }: { content?: JSON }) { | ||
if (!content) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className="font-mono text-[11px] leading-5"> | ||
{formatEditorToHtml(content)} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import Image from "next/image"; | ||
|
||
type Props = { | ||
logo: string; | ||
customerName: string; | ||
}; | ||
|
||
export function Logo({ logo, customerName }: Props) { | ||
return <Image src={logo} alt={customerName} width={78} height={78} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import type { Template } from "@midday/invoice/types"; | ||
import { format } from "date-fns"; | ||
|
||
type Props = { | ||
template: Template; | ||
invoiceNumber: string; | ||
issueDate: string; | ||
dueDate: string; | ||
}; | ||
|
||
export function Meta({ template, invoiceNumber, issueDate, dueDate }: Props) { | ||
return ( | ||
<div className="grid grid-cols-3 gap-4 items-center"> | ||
<div className="flex space-x-1 items-center"> | ||
<div className="flex items-center flex-shrink-0 space-x-1"> | ||
<span className="truncate font-mono text-[11px] text-[#878787]"> | ||
{template.invoice_no_label}: | ||
</span> | ||
<span className="text-[11px] font-mono flex-shrink-0"> | ||
{invoiceNumber} | ||
</span> | ||
</div> | ||
</div> | ||
|
||
<div> | ||
<div> | ||
<div className="flex space-x-1 items-center"> | ||
<div className="flex items-center flex-shrink-0 space-x-1"> | ||
<span className="truncate font-mono text-[11px] text-[#878787]"> | ||
{template.issue_date_label}: | ||
</span> | ||
<span className="text-[11px] font-mono flex-shrink-0"> | ||
{format(new Date(issueDate), template.date_format)} | ||
</span> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div> | ||
<div> | ||
<div className="flex space-x-1 items-center"> | ||
<div className="flex items-center flex-shrink-0 space-x-1"> | ||
<span className="truncate font-mono text-[11px] text-[#878787]"> | ||
{template.due_date_label}: | ||
</span> | ||
<span className="text-[11px] font-mono flex-shrink-0"> | ||
{format(new Date(dueDate), template.date_format)} | ||
</span> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { ScrollArea } from "@midday/ui/scroll-area"; | ||
import type { TemplateProps } from "../types"; | ||
import { CustomerDetails } from "./components/customer-details"; | ||
import { EditorContent } from "./components/editor-content"; | ||
import { FromDetails } from "./components/from-details"; | ||
import { Logo } from "./components/logo"; | ||
import { Meta } from "./components/meta"; | ||
|
||
export function HtmlTemplate({ | ||
invoice_number, | ||
issue_date, | ||
due_date, | ||
template, | ||
line_items, | ||
customer_details, | ||
from_details, | ||
payment_details, | ||
note_details, | ||
currency, | ||
customer_name, | ||
vat, | ||
tax, | ||
amount, | ||
size = "a4", | ||
}: TemplateProps) { | ||
const width = size === "letter" ? 816 : 595; | ||
const height = size === "letter" ? 1056 : 842; | ||
|
||
return ( | ||
<ScrollArea | ||
className="bg-background border border-border shadow-2xl" | ||
style={{ width, height }} | ||
hideScrollbar | ||
> | ||
<div className="p-8 h-full flex flex-col"> | ||
<div className="flex flex-col"> | ||
{template.logo_url && ( | ||
<Logo logo={template.logo_url} customerName={customer_name || ""} /> | ||
)} | ||
</div> | ||
|
||
<div className="mt-8"> | ||
<Meta | ||
template={template} | ||
invoiceNumber={invoice_number} | ||
issueDate={issue_date} | ||
dueDate={due_date} | ||
/> | ||
</div> | ||
|
||
<div className="grid grid-cols-2 gap-6 mt-8"> | ||
<div> | ||
<p className="text-[11px] text-[#878787] font-mono mb-2 block"> | ||
{template.from_label} | ||
</p> | ||
<EditorContent content={from_details} /> | ||
</div> | ||
<div> | ||
<p className="text-[11px] text-[#878787] font-mono mb-2 block"> | ||
{template.customer_label} | ||
</p> | ||
<EditorContent content={customer_details} /> | ||
</div> | ||
</div> | ||
</div> | ||
</ScrollArea> | ||
); | ||
} |
4 changes: 2 additions & 2 deletions
4
...invoice/src/components/editor-content.tsx → ...mplates/pdf/components/editor-content.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { View } from "@react-pdf/renderer"; | ||
import { formatEditorContent } from "../utils/format"; | ||
import { formatEditorToPdf } from "../../../utils/format"; | ||
|
||
export function EditorContent({ content }: { content?: JSON }) { | ||
if (!content) { | ||
return null; | ||
} | ||
|
||
return <View style={{ marginTop: 10 }}>{formatEditorContent(content)}</View>; | ||
return <View style={{ marginTop: 10 }}>{formatEditorToPdf(content)}</View>; | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
export type Template = { | ||
logo_url?: string; | ||
from_label: string; | ||
customer_label: string; | ||
invoice_no_label: string; | ||
issue_date_label: string; | ||
due_date_label: string; | ||
date_format: string; | ||
payment_label: string; | ||
note_label: string; | ||
description_label: string; | ||
quantity_label: string; | ||
price_label: string; | ||
total_label: string; | ||
tax_label: string; | ||
vat_label: string; | ||
}; | ||
|
||
export type LineItem = { | ||
name: string; | ||
quantity: number; | ||
price: number; | ||
invoice_number?: string; | ||
issue_date?: string; | ||
due_date?: string; | ||
}; | ||
|
||
export type TemplateProps = { | ||
invoice_number: string; | ||
issue_date: string; | ||
due_date: string; | ||
template: Template; | ||
line_items: LineItem[]; | ||
customer_details?: JSON; | ||
payment_details?: JSON; | ||
from_details?: JSON; | ||
note_details?: JSON; | ||
currency: string; | ||
amount: number; | ||
customer_name?: string; | ||
vat?: number; | ||
tax?: number; | ||
size?: "letter" | "a4"; | ||
}; |
Oops, something went wrong.