Skip to content

Commit

Permalink
feat: ✨ template, tailwind hack
Browse files Browse the repository at this point in the history
  • Loading branch information
dfrnoch committed Aug 11, 2024
1 parent 8d6a05d commit a17174a
Show file tree
Hide file tree
Showing 14 changed files with 54,099 additions and 124 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"@solid-primitives/i18n": "^2.1.1",
"@solid-primitives/storage": "3.8.0",
"@solidjs/router": "0.14.1",
"@tanstack/solid-form": "^0.26.4",
"@tanstack/zod-form-adapter": "^0.26.4",
"@tanstack/solid-form": "0.28.0",
"@tanstack/zod-form-adapter": "0.28.0",
"@tauri-apps/api": "2.0.0-beta.15",
"@tauri-apps/plugin-os": "github:tauri-apps/tauri-plugin-os#v2",
"@tauri-apps/plugin-shell": "github:tauri-apps/tauri-plugin-shell#v2",
Expand All @@ -43,7 +43,7 @@
"@types/xml2js": "^0.4.14",
"@biomejs/biome": "1.8.3",
"@tauri-apps/cli": "2.0.0-beta.22",
"@types/node": "20.14.11",
"@types/node": "22.2.0",
"@unocss/preset-uno": "0.61.5",
"@unocss/transformer-variant-group": "0.61.5",
"@unocss/vite": "0.61.5",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ tauri-plugin-os = { git = "https://github.com/tauri-apps/plugins-workspace", bra
tauri-plugin-shell = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
pretty_env_logger = "0.5.0"
log = "0.4"
thiserror = "1.0.61"
thiserror = "1.0.63"
platform-dirs = "0.3.0"
anyhow = "1.0.86"
bcrypt = "0.15.1"
Expand Down
Binary file modified src/.DS_Store
Binary file not shown.
115 changes: 115 additions & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,118 @@ export enum LANG {
EN = "en-US",
CS = "cs-CZ",
}

export const templatesHtml = {
cz: {
1: `
<div class="bg-white p-8">
<div class="flex justify-between mb-8">
<div>
<h1 class="text-2xl font-bold">{{ company.name }}</h1>
<p>{{ company.website }}</p>
<p>{{ company.email }}</p>
<p>{{ company.phone }}</p>
</div>
<div class="text-right">
<p>{{ company.address }}</p>
<p>{{ company.city }}, {{ company.state }} - {{ company.zip }}</p>
<p>TAX ID {{ company.vatId }}</p>
</div>
</div>
<div class="flex justify-between mb-8">
<div>
<h2 class="font-bold mb-2">Billed to</h2>
<p>{{ client.name }}</p>
<p>{{ client.address }}</p>
<p>{{ client.city }}, {{ client.country }} - {{ client.zip }}</p>
<p>{{ client.phone }}</p>
</div>
<div class="text-right">
<div class="mb-4">
<h2 class="font-bold">Invoice number</h2>
<p>{{ number }}</p>
</div>
<div>
<h2 class="font-bold">Reference</h2>
<p>INV-057</p>
</div>
</div>
</div>
<div class="flex justify-between mb-8">
<div>
<h2 class="font-bold mb-2">Subject</h2>
<p>Design System</p>
</div>
<div class="text-right">
<h2 class="font-bold text-3xl text-orange-500">{{ items | map: 'price' | sum }}.00</h2>
<p>Invoice of ({{ currency.code }})</p>
</div>
</div>
<div class="flex justify-between mb-8">
<div>
<h2 class="font-bold">Invoice date</h2>
<p>{{ issueDate }}</p>
</div>
<div class="text-right">
<h2 class="font-bold">Due date</h2>
<p>{{ dueDate }}</p>
</div>
</div>
<table class="w-full mb-8">
<thead>
<tr class="bg-gray-100">
<th class="px-4 py-2 text-left">ITEM DETAIL</th>
<th class="px-4 py-2 text-right">QTY</th>
<th class="px-4 py-2 text-right">RATE</th>
<th class="px-4 py-2 text-right">AMOUNT</th>
</tr>
</thead>
<tbody>
{% for item in items %}
<tr>
<td class="border-b px-4 py-2">
<p class="font-bold">{{ item.description }}</p>
<p class="text-gray-600">Item description</p>
</td>
<td class="border-b px-4 py-2 text-right">{{ item.quantity }}</td>
<td class="border-b px-4 py-2 text-right">{{ item.price }}.00</td>
<td class="border-b px-4 py-2 text-right">{{ item.quantity | times: item.price }}.00</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="flex justify-end">
<div class="w-1/2">
<div class="flex justify-between mb-2">
<span>Subtotal</span>
<span>{{ items | map: 'price' | sum }}.00</span>
</div>
<div class="flex justify-between mb-2">
<span>Tax (10%)</span>
<span>{{ items | map: 'price' | sum | times: 0.1 }}.00</span>
</div>
<div class="flex justify-between font-bold">
<span>Total</span>
<span>{{ items | map: 'price' | sum | plus: items | map: 'price' | sum | times: 0.1 }}.00</span>
</div>
</div>
</div>
<div class="mt-8">
<p>Thanks for the business.</p>
</div>
<div class="mt-8">
<h2 class="font-bold mb-2">Terms & Conditions</h2>
<p>Please pay within 15 days of receiving this invoice.</p>
</div>
</div>
`,
},
};
3 changes: 2 additions & 1 deletion src/i18n/dict/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@
"save": "Uložit",
"dataHints": "Nápověda dat",
"sections": {
"information": "Informace o šabloně"
"information": "Informace o šabloně",
"selectTemplate": "Vyberte šablonu"
},
"name": "Název",
"namePlaceholder": "Faktura",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/dict/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
"save": "Save",
"dataHints": "Data Hints",
"sections": {
"information": "Template Information"
"information": "Template Information",
"selectTemplate": "Select Template"
},
"name": "Name",
"namePlaceholder": "Invoice",
Expand Down
129 changes: 23 additions & 106 deletions src/screens/Dashboard/pages/Other/Templates/ManageTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
type Component,
Show,
type ParentComponent,
For,
} from "solid-js";
import PageHeader from "@/screens/Dashboard/components/PageHeader";
import { useI18n } from "@/i18n";
Expand All @@ -28,6 +29,8 @@ import Section from "@/shared/components/Form/Section";
import Input from "@/shared/components/Form/Input";
import PdfRenderer from "@/shared/components/PdfRenderer";
import Dropdown from "@/shared/components/Form/Dropdown";
import Box from "@/shared/components/Box";
import { templatesHtml } from "@/constants";

const ManageTemplate: Component = () => {
const params = useParams<{ readonly id?: string }>();
Expand All @@ -37,108 +40,13 @@ const ManageTemplate: Component = () => {
const [showHints, setShowHints] = createSignal(false);
const [showPreview, setShowPreview] = createSignal(false);

const mockData = {
number: "INV-123",
issueDate: "2023-01-01T00:00:00.000Z",
dueDate: "2023-01-15T00:00:00.000Z",
client: {
name: "John Doe",
cin: "123456789",
vatId: "US12345678",
address: "123 Main St",
city: "Metropolis",
zip: "12345",
email: "[email protected]",
phone: "+1234567890",
bankAccount: "123456789012345",
IBAN: "US123456789012345",
},
company: {
name: "Example Corp",
cin: "987654321",
vatId: "US98765432",
address: "456 Elsewhere St",
city: "Gotham",
zip: "54321",
email: "[email protected]",
phone: "+0987654321",
bankAccount: "543210987654321",
IBAN: "US543210987654321",
},
items: [
{ description: "Product 1", quantity: 2, price: 19.99 },
{ description: "Service 1", quantity: 5, price: 49.99 },
],
currency: { code: "USD" },
template: {
html: `
<div class="bg-white p-8 rounded shadow">
<h1 class="text-2xl font-bold mb-4">Invoice</h1>
<div class="mb-8">
<p class="text-gray-600">Invoice Number: {{ number }}</p>
<p class="text-gray-600">Issue Date: {{ issueDate }}</p>
<p class="text-gray-600">Due Date: {{ dueDate }}</p>
</div>
<div class="grid grid-cols-2 gap-8 mb-8">
<div>
<h2 class="text-xl font-bold mb-2">Client Details</h2>
<p>{{ client.name }}</p>
<p>CIN: {{ client.cin }}</p>
<p>VAT ID: {{ client.vatId }}</p>
<p>{{ client.address }}</p>
<p>{{ client.city }}, {{ client.zip }}</p>
<p>Email: {{ client.email }}</p>
<p>Phone: {{ client.phone }}</p>
<p>Bank Account: {{ client.bankAccount }}</p>
<p>IBAN: {{ client.IBAN }}</p>
</div>
<div>
<h2 class="text-xl font-bold mb-2">Company Details</h2>
<p>{{ company.name }}</p>
<p>CIN: {{ company.cin }}</p>
<p>VAT ID: {{ company.vatId }}</p>
<p>{{ company.address }}</p>
<p>{{ company.city }}, {{ company.zip }}</p>
<p>Email: {{ company.email }}</p>
<p>Phone: {{ company.phone }}</p>
<p>Bank Account: {{ company.bankAccount }}</p>
<p>IBAN: {{ company.IBAN }}</p>
</div>
</div>
<table class="w-full mb-8">
<thead>
<tr class="bg-gray-100">
<th class="px-4 py-2">Description</th>
<th class="px-4 py-2">Quantity</th>
<th class="px-4 py-2">Price</th>
<th class="px-4 py-2">Total</th>
</tr>
</thead>
<tbody>
{% for item in items %}
<tr>
<td class="border px-4 py-2">{{ item.description }}</td>
<td class="border px-4 py-2">{{ item.quantity }}</td>
<td class="border px-4 py-2">{{ item.price }} {{ currency.code }}</td>
<td class="border px-4 py-2">{{ item.quantity | times: item.price }} {{ currency.code }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="text-right">
<p class="text-xl font-bold">Total: {{ items | map: 'price' | sum }} {{ currency.code }}</p>
</div>
</div>
`,
},
};
const templates = [
{ id: 1, name: t("setup.step2.template.basic"), icon: "📄" },
{ id: 2, name: t("setup.step2.template.modern"), icon: "📊" },
{ id: 3, name: t("setup.step2.template.creative"), icon: "🎨" },
];

const [templateCode, setTemplateCode] = createSignal(mockData.template.html);
const [templateCode, setTemplateCode] = createSignal("");

const form = createForm<{
name: string;
Expand Down Expand Up @@ -200,9 +108,9 @@ const ManageTemplate: Component = () => {
<HeaderButton buttonType="secondary" onClick={() => setShowHints(!showHints())}>
<FiList />
</HeaderButton>,
<HeaderButton buttonType="secondary" onClick={() => setShowPreview(!showPreview())}>
<FiEye />
</HeaderButton>,
// <HeaderButton buttonType="secondary" onClick={() => setShowPreview(!showPreview())}>
// <FiEye />
// </HeaderButton>,
<Show when={params.id}>
<HeaderButton
buttonType="secondary"
Expand Down Expand Up @@ -257,16 +165,25 @@ const ManageTemplate: Component = () => {
)}
</form.Field>
</Section>
<Section title={t("pages.other.templates.sections.selectTemplate")} columns={1}>
<For each={templates}>
{(template) => (
<Box onClick={() => setTemplateCode(templatesHtml.cz[1])} icon={template.icon}>
{template.name}
</Box>
)}
</For>
</Section>
</Form>
</SidePopup>
</div>
<Show when={showPreview()}>
{/* <Show when={showPreview()}>
<div class="absolute top-0 left-0 w-full h-full flex items-center justify-center ">
<div class="bg-white rounded max-w-4xl p-4 shadow-xl w-full max-h-full overflow-auto">
<PdfRenderer data={mockData} />
</div>
</div>
</Show>
</Show> */}
</>
);
};
Expand Down
1 change: 1 addition & 0 deletions src/screens/Print/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getPrintDocument } from "@/bindings";
import PdfRenderer from "@/shared/components/PdfRenderer";
import { useParams } from "@solidjs/router";
import "@/styles/tw.css";
import { Show, Suspense, createResource, type Component } from "solid-js";

const Print: Component = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Setup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { createForm } from "@tanstack/solid-form";
import { zodValidator } from "@tanstack/zod-form-adapter";
import Form from "@/shared/components/Form";
import Input from "@/shared/components/Form/Input";
import Box from "./components/Box";
import Box from "../../shared/components/Box";
import Button from "@/shared/components/Button";
import { Title } from "./components/Title";
import { z } from "zod";
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions src/shared/components/PdfRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { type Component, createSignal, onMount } from "solid-js";
import { Liquid } from "liquidjs";
import type { GetPrintDocumentResult } from "@/bindings";
import { format } from "date-fns";
import "@/styles/print.css";

interface PdfRendererProps {
data: GetPrintDocumentResult | undefined;
Expand Down
12 changes: 1 addition & 11 deletions src/styles/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,4 @@ input[type=number] {
tr td:last-child {
border-top-right-radius: 6px;
border-bottom-right-radius: 6px;
} */

.print {
width: 21cm !important;
height: 296mm !important;
padding: 2rem;
margin: 0;
color: black;
background-color: white;
print-color-adjust: exact !important;
}
} */
9 changes: 9 additions & 0 deletions src/styles/print.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.print {
width: 21cm !important;
height: 296mm !important;
padding: 2rem;
margin: 0;
color: black;
background-color: white;
print-color-adjust: exact !important;
}
Loading

0 comments on commit a17174a

Please sign in to comment.