diff --git a/src/bindings.ts b/src/bindings.ts index 46342b6..5f8b2f8 100644 --- a/src/bindings.ts +++ b/src/bindings.ts @@ -29,6 +29,7 @@ export enum DocumentType { INVOICE = "INVOICE", PROFORMA = "PROFORMA", RECIEVE = "RECIEVE", + TEMPLATE = "TEMPLATE", } export function getDocuments(documentType: DocumentType, indicies: Indicies) { @@ -38,6 +39,7 @@ export function getDocuments(documentType: DocumentType, indicies: Indicies) { indicies, }); } + export function getDocument(id: number) { return invoke("get_document", { id }); } diff --git a/src/i18n/dict/cs.json b/src/i18n/dict/cs.json index 77a35d8..7ba24e4 100644 --- a/src/i18n/dict/cs.json +++ b/src/i18n/dict/cs.json @@ -22,7 +22,9 @@ "help": { "retrieve_by_cin": "Po zadání správného IČA se načte zbytek údajů automaticky" } - } + }, + "error_creating_ompany": "Při vytváření firmy došlo k chybě. Zkuste to prosím znovu.", + "company_created": "Firma byla úspěšně vytvořena" }, "table": { "all": "Vše" diff --git a/src/i18n/dict/en.json b/src/i18n/dict/en.json index 6e11377..f1045d7 100644 --- a/src/i18n/dict/en.json +++ b/src/i18n/dict/en.json @@ -24,7 +24,9 @@ "help": { "retrieve_by_cin": "After entering your CIN, we will try to retrieve your company information from the government database." } - } + }, + "error_creating_ompany": "Error creating company", + "company_created": "Company created" }, "table": { "all": "All" diff --git a/src/screens/Dashboard/components/Form/index.tsx b/src/screens/Dashboard/components/Form/index.tsx deleted file mode 100644 index ae6f210..0000000 --- a/src/screens/Dashboard/components/Form/index.tsx +++ /dev/null @@ -1,9 +0,0 @@ -import type { FormApi } from "@tanstack/solid-form"; -import type { ParentComponent } from "solid-js"; - -// div beacuse form causes issues with dropdown menu -// biome-ignore lint/suspicious/noExplicitAny: idk what the form type is -const Form: ParentComponent<{ form: FormApi; class?: string }> = (props) => { - return
{props.children}
; -}; -export default Form; diff --git a/src/screens/Dashboard/index.tsx b/src/screens/Dashboard/index.tsx index d07f8b9..83f5d76 100644 --- a/src/screens/Dashboard/index.tsx +++ b/src/screens/Dashboard/index.tsx @@ -29,7 +29,6 @@ const Dashboard: ParentComponent = (props) => { <>
- {/* px 4 pt-50px */}
{props.children} diff --git a/src/screens/Dashboard/pages/Other/Clients/ManageClient.tsx b/src/screens/Dashboard/pages/Other/Clients/ManageClient.tsx index 3ffa318..b3f3e89 100644 --- a/src/screens/Dashboard/pages/Other/Clients/ManageClient.tsx +++ b/src/screens/Dashboard/pages/Other/Clients/ManageClient.tsx @@ -3,31 +3,18 @@ import Container from "@/screens/Dashboard/components/Container"; import PageHeader from "@/screens/Dashboard/components/PageHeader"; import HeaderButton from "@/screens/Dashboard/components/PageHeader/HeaderButton"; import { useNavigate, useParams } from "@solidjs/router"; -import { For, Show, onMount, type Component } from "solid-js"; +import { Show, onMount, type Component } from "solid-js"; import { createForm } from "@tanstack/solid-form"; -import Input from "@/screens/Dashboard/components/Form/Input"; -import Dropdown from "@/screens/Dashboard/components/Form/Dropdown"; +import Input from "@/shared/components/Form/Input"; +import Dropdown from "@/shared/components/Form/Dropdown"; import { type Client, createClient, deleteClient, getClient, updateClient } from "@/bindings"; -import Form from "@/screens/Dashboard/components/Form"; +import Form from "@/shared/components/Form"; import { zodValidator } from "@tanstack/zod-form-adapter"; import { z } from "zod"; -import Section from "@/screens/Dashboard/components/Form/Section"; +import Section from "@/shared/components/Form/Section"; import toast from "solid-toast"; import { FiTrash } from "solid-icons/fi"; -const schema = z.object({ - id: z.number(), - name: z.string().min(20), - clientType: z.enum(["BOTH", "SUPPLIER", "CUSTOMER"]), - email: z.string().optional(), - cin: z.string(), - vatId: z.string(), - address: z.string(), - city: z.string(), - zip: z.string(), - phone: z.string(), -}); - const ManageClient: Component = () => { const params = useParams<{ readonly id?: string }>(); const [t] = useI18n(); @@ -46,9 +33,6 @@ const ManageClient: Component = () => { phone: "", } as Client, validatorAdapter: zodValidator, - validators: { - onSubmit: schema, - }, onSubmitInvalid: (e) => { console.log("invalid", e.formApi.state.errors); }, @@ -104,19 +88,17 @@ const ManageClient: Component = () => { , ]} /> -
+
- + {(field) => ( - <> - field().handleChange(data)} - errors={field().state.meta.touchedErrors} - /> - + field().handleChange(data)} + errors={field().state.meta.touchedErrors} + /> )} { /> )} - + {(field) => ( field().handleChange(data)} + errors={field().state.meta.touchedErrors} /> )} - + {(field) => ( field().handleChange(data)} + errors={field().state.meta.touchedErrors} /> )}
-
- +
+ {(field) => ( field().handleChange(data)} + errors={field().state.meta.touchedErrors} /> )} - + {(field) => ( field().handleChange(data)} + errors={field().state.meta.touchedErrors} /> )} - + {(field) => ( field().handleChange(data)} + errors={field().state.meta.touchedErrors} /> )} - + {(field) => ( field().handleChange(data)} + errors={field().state.meta.touchedErrors} /> )} diff --git a/src/screens/Dashboard/pages/Sales/Invoices/ManageInvoice.tsx b/src/screens/Dashboard/pages/Sales/Invoices/ManageInvoice.tsx index 55fe54b..72ff2c9 100644 --- a/src/screens/Dashboard/pages/Sales/Invoices/ManageInvoice.tsx +++ b/src/screens/Dashboard/pages/Sales/Invoices/ManageInvoice.tsx @@ -5,11 +5,11 @@ import HeaderButton from "@/screens/Dashboard/components/PageHeader/HeaderButton import { useNavigate, useParams } from "@solidjs/router"; import { For, Show, onMount, type Component } from "solid-js"; import { createForm } from "@tanstack/solid-form"; -import Input from "@/screens/Dashboard/components/Form/Input"; -import Dropdown from "@/screens/Dashboard/components/Form/Dropdown"; +import Input from "@/shared/components/Form/Input"; +import Dropdown from "@/shared/components/Form/Dropdown"; import { createDocument, deleteDocument, getDocument, updateDocument, type Document } from "@/bindings"; -import Form from "@/screens/Dashboard/components/Form"; -import Section from "@/screens/Dashboard/components/Form/Section"; +import Form from "@/shared/components/Form"; +import Section from "@/shared/components/Form/Section"; import toast from "solid-toast"; import { FiTrash } from "solid-icons/fi"; diff --git a/src/screens/Setup/components/LanguageBox.tsx b/src/screens/Setup/components/LanguageBox.tsx index 3033e5b..0301491 100644 --- a/src/screens/Setup/components/LanguageBox.tsx +++ b/src/screens/Setup/components/LanguageBox.tsx @@ -1,4 +1,4 @@ -import { ParentComponent } from "solid-js"; +import type { ParentComponent } from "solid-js"; const LangaugeBox: ParentComponent<{ onClick: () => void; active?: boolean }> = (props) => { return ( diff --git a/src/screens/Setup/components/Progress.tsx b/src/screens/Setup/components/Progress.tsx index a7cb839..a9910da 100644 --- a/src/screens/Setup/components/Progress.tsx +++ b/src/screens/Setup/components/Progress.tsx @@ -1,21 +1,18 @@ -import { Component, For } from "solid-js"; +import { type Component, For } from "solid-js"; // https://macos-tailwind.netlify.app/?path=/docs/controls-progress-bar--docs const ProgressDots: Component<{ count: number; active: number }> = (props) => { return ( - // add blur and -
- {/*
*/} +
{(_, index) => (
)} - {/*
*/}
); }; diff --git a/src/screens/Setup/components/Title.tsx b/src/screens/Setup/components/Title.tsx index f29efbf..139911e 100644 --- a/src/screens/Setup/components/Title.tsx +++ b/src/screens/Setup/components/Title.tsx @@ -1,4 +1,4 @@ -import { ParentComponent } from "solid-js"; +import type { ParentComponent } from "solid-js"; export const Title: ParentComponent<{ class?: string }> = (props) => { return

{props.children}

; diff --git a/src/screens/Setup/index.tsx b/src/screens/Setup/index.tsx index be9025e..fc2d104 100644 --- a/src/screens/Setup/index.tsx +++ b/src/screens/Setup/index.tsx @@ -1,35 +1,31 @@ import { locale, setLocale, useI18n } from "@/i18n"; -import { createSignal, type Component, Show, createEffect } from "solid-js"; +import { createSignal, type Component, Show, onMount } from "solid-js"; import ProgressDots from "./components/Progress"; import { createCompany, migrateAndPopulate } from "@/bindings"; -import Input from "@/shared/components/Menu/Input"; -import { createStore } from "solid-js/store"; -import LanguageBox from "./components/LanguageBox"; import { LANG } from "@/constants"; import { open } from "@tauri-apps/plugin-shell"; -import { getDataByCIN } from "@/utils/getDataByCIN"; -import InputList from "@/shared/components/Menu/InputList"; -import { Hr } from "@/shared/components/Menu/Hr"; -import { Button } from "@/shared/components/Button"; -import { Title } from "./components/Title"; import { useNavigate } from "@solidjs/router"; import { useSelector } from "@/store"; +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 LanguageBox from "./components/LanguageBox"; +import Button from "@/shared/components/Button"; +import { Title } from "./components/Title"; +import { z } from "zod"; +import toast from "solid-toast"; +import Section from "@/shared/components/Form/Section"; interface UserData { companyName: string; cin: string; vatID: string; - userName: string; - userEmail: string; - contact: { - email: string; - phone: string; - }; - address: { - street: string; - city: string; - zip: string; - }; + email: string; + phone: string; + street: string; + city: string; + zip: string; } const SetupWizard: Component = () => { @@ -37,148 +33,190 @@ const SetupWizard: Component = () => { const [currentStep, setCurrentStep] = createSignal(0); const stateService = useSelector((state) => state.stateService); const navigate = useNavigate(); - const [userData, setUserData] = createStore({ - companyName: "", - cin: "", - vatID: "", - userName: "", - userEmail: "", - contact: { + + const form = createForm(() => ({ + defaultValues: { + companyName: "", + cin: "", + vatID: "", email: "", phone: "", - }, - address: { street: "", city: "", zip: "", + } as UserData, + validatorAdapter: zodValidator, + onSubmitInvalid: (e) => { + console.log("invalid", e.formApi.state.errors); }, - }); - - createEffect(async () => { - if (userData.cin.length === 8) { - const data = await getDataByCIN(userData.cin); - if (data) { - setUserData({ - companyName: data.company, - vatID: data.dic, + onSubmit: async (userData) => { + try { + const result = await createCompany({ + cin: userData.value.cin, + name: userData.value.companyName, + vatId: userData.value.vatID, + email: userData.value.email, + phoneNumber: userData.value.phone, + city: userData.value.city, + postalCode: userData.value.zip, + streetAddress: userData.value.street, }); - } - } - }); - const handleCreateCompany = async () => { - try { - const result = await createCompany({ - cin: userData.cin, - name: userData.companyName, - vatId: userData.vatID, - email: userData.contact.email, - phoneNumber: userData.contact.phone, - city: userData.address.city, - postalCode: userData.address.zip, - streetAddress: userData.address.street, - }); + stateService.updateState({ companyId: result.id }); + toast.success(t("setup.company_created")); + navigate("/"); + } catch (error) { + console.error("Error creating company:", error); + toast.error(t("setup.error_creating_ompany")); + } + }, + })); - stateService.updateState({ companyId: result.id }); - navigate("/"); - } catch (error) { - console.error("Error creating company:", error); - } - }; + onMount(() => { + migrateAndPopulate(); + }); return ( -
-
- - - {t("setup.welcome")} - - +
+
+ +
+ +
+ + + {t("setup.welcome")} + + - - {t("setup.step1.select_language")} -
-
- setLocale(LANG.CS)} active={locale() === LANG.CS}> - 🇨🇿 - - setLocale(LANG.EN)} active={locale() === LANG.EN}> - 🇬🇧 - + + {t("setup.step1.select_language")} +
+
+ setLocale(LANG.CS)} active={locale() === LANG.CS}> + 🇨🇿 + + setLocale(LANG.EN)} active={locale() === LANG.EN}> + 🇬🇧 + +
+

open("https://github.com/dfrnoch/accounting")} + > + {t("setup.step1.improve")} +

-

open("https://github.com")} - > - {t("setup.step1.improve")} -

-
- - + + - -
-
+ +
{t("setup.step2.create_company")} - - setUserData("companyName", e.currentTarget.value)} - /> + + {(field) => ( + field().handleChange(data)} + errors={field().state.meta.touchedErrors} + /> + )} + +
+ + {(field) => ( setUserData("cin", e.currentTarget.value)} + defaultValue={field().state.value} + onChange={(data) => field().handleChange(data)} + errors={field().state.meta.touchedErrors} /> + )} + + + {(field) => ( setUserData("vatID", e.currentTarget.value)} + defaultValue={field().state.value} + onChange={(data) => field().handleChange(data)} + errors={field().state.meta.touchedErrors} /> -
+ )} +
+ + {(field) => ( setUserData("address", "street", e.currentTarget.value)} + defaultValue={field().state.value} + onChange={(data) => field().handleChange(data)} + errors={field().state.meta.touchedErrors} /> + )} + + + {(field) => ( setUserData("address", "city", e.currentTarget.value)} + defaultValue={field().state.value} + onChange={(data) => field().handleChange(data)} + errors={field().state.meta.touchedErrors} /> + )} + + + {(field) => ( setUserData("address", "zip", e.currentTarget.value)} + defaultValue={field().state.value} + onChange={(data) => field().handleChange(data)} + errors={field().state.meta.touchedErrors} /> -
+ )} +
+ + {(field) => ( setUserData("contact", "email", e.currentTarget.value)} + defaultValue={field().state.value} + onChange={(data) => field().handleChange(data)} + errors={field().state.meta.touchedErrors} /> + )} + + + {(field) => ( setUserData("contact", "phone", e.currentTarget.value)} + defaultValue={field().state.value} + onChange={(data) => field().handleChange(data)} + errors={field().state.meta.touchedErrors} /> - - -
-
-
+ )} + + + +
); diff --git a/src/shared/components/Button.tsx b/src/shared/components/Button.tsx index 11c3cef..4adbbff 100644 --- a/src/shared/components/Button.tsx +++ b/src/shared/components/Button.tsx @@ -13,3 +13,5 @@ export const Button: ParentComponent<{ onClick?: (e: MouseEvent) => void; class? ); }; + +export default Button; diff --git a/src/screens/Dashboard/components/Form/Dropdown.tsx b/src/shared/components/Form/Dropdown.tsx similarity index 100% rename from src/screens/Dashboard/components/Form/Dropdown.tsx rename to src/shared/components/Form/Dropdown.tsx diff --git a/src/screens/Dashboard/components/Form/Input.tsx b/src/shared/components/Form/Input.tsx similarity index 97% rename from src/screens/Dashboard/components/Form/Input.tsx rename to src/shared/components/Form/Input.tsx index 9ff14c3..9a0a5df 100644 --- a/src/screens/Dashboard/components/Form/Input.tsx +++ b/src/shared/components/Form/Input.tsx @@ -36,7 +36,7 @@ const Input: Component = (props) => { {props.label} 0 : false, "border-default": !props.errors || props.errors.length === 0, diff --git a/src/screens/Dashboard/components/Form/Section.tsx b/src/shared/components/Form/Section.tsx similarity index 100% rename from src/screens/Dashboard/components/Form/Section.tsx rename to src/shared/components/Form/Section.tsx diff --git a/src/screens/Dashboard/components/Form/Table.tsx b/src/shared/components/Form/Table.tsx similarity index 100% rename from src/screens/Dashboard/components/Form/Table.tsx rename to src/shared/components/Form/Table.tsx diff --git a/src/shared/components/Form/index.tsx b/src/shared/components/Form/index.tsx new file mode 100644 index 0000000..b55abc7 --- /dev/null +++ b/src/shared/components/Form/index.tsx @@ -0,0 +1,7 @@ +import type { ParentComponent } from "solid-js"; + +// div beacuse form causes issues with dropdown menu +const Form: ParentComponent<{ class?: string }> = (props) => { + return
{props.children}
; +}; +export default Form;