diff --git a/.DS_Store b/.DS_Store index d9e54e6..1842f5a 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/.github/.DS_Store b/.github/.DS_Store new file mode 100644 index 0000000..35ef535 Binary files /dev/null and b/.github/.DS_Store differ diff --git a/src-tauri/.DS_Store b/src-tauri/.DS_Store index c1b1fb3..8887272 100644 Binary files a/src-tauri/.DS_Store and b/src-tauri/.DS_Store differ diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000..4d4a522 Binary files /dev/null and b/src/.DS_Store differ diff --git a/src/bindings.ts b/src/bindings.ts index 8bbbc77..5825647 100644 --- a/src/bindings.ts +++ b/src/bindings.ts @@ -13,7 +13,7 @@ export function getCompany(id: number | null) { } export function createCompany(data: CreateCompanyData) { - return invoke("create_company", { data }); + return invoke("create_company", { data }); } export function migrateAndPopulate() { diff --git a/src/i18n/dict/index.ts b/src/i18n/dict/index.ts index a994c34..da2fba5 100644 --- a/src/i18n/dict/index.ts +++ b/src/i18n/dict/index.ts @@ -1,11 +1,11 @@ -import { Flatten } from '@solid-primitives/i18n' -import { LANG } from '@/constants' -import en from './en.json' -import cs from './cs.json' +import type { Flatten } from "@solid-primitives/i18n"; +import { LANG } from "@/constants"; +import en from "./en.json"; +import cs from "./cs.json"; -export type Dict = Flatten +export type Dict = Flatten; export default { [LANG.EN]: en, [LANG.CS]: cs, -} \ No newline at end of file +}; diff --git a/src/i18n/index.ts b/src/i18n/index.ts index e6ae4b0..3f30591 100644 --- a/src/i18n/index.ts +++ b/src/i18n/index.ts @@ -3,7 +3,7 @@ import * as i18n from "@solid-primitives/i18n"; import { makePersisted } from "@solid-primitives/storage"; import { createSignal } from "solid-js"; import { LANG } from "@/constants"; -import dict, { Dict } from "./dict"; +import dict, { type Dict } from "./dict"; export const [locale, setLocale] = makePersisted( createSignal(Reflect.has(dict, navigator.language) ? (navigator.language as LANG) : LANG.EN), diff --git a/src/screens/Dashboard/components/Box.tsx b/src/screens/Dashboard/components/Box.tsx index c8dad97..63005a0 100644 --- a/src/screens/Dashboard/components/Box.tsx +++ b/src/screens/Dashboard/components/Box.tsx @@ -1,4 +1,4 @@ -import { ParentComponent } from "solid-js"; +import type { ParentComponent } from "solid-js"; const Box: ParentComponent = (props) => { return ( diff --git a/src/screens/Dashboard/components/Popup/Popup.tsx b/src/screens/Dashboard/components/Popup/Popup.tsx index ecddc80..170cb07 100644 --- a/src/screens/Dashboard/components/Popup/Popup.tsx +++ b/src/screens/Dashboard/components/Popup/Popup.tsx @@ -1,4 +1,4 @@ -import { ParentComponent } from "solid-js"; +import type { ParentComponent } from "solid-js"; const Popup: ParentComponent<{}> = (props) => { return
{props.children}
; diff --git a/src/screens/Dashboard/components/Sidebar/Button.tsx b/src/screens/Dashboard/components/Sidebar/Button.tsx index f2ecda8..fcc1b4e 100644 --- a/src/screens/Dashboard/components/Sidebar/Button.tsx +++ b/src/screens/Dashboard/components/Sidebar/Button.tsx @@ -1,5 +1,5 @@ import { A } from "@solidjs/router"; -import { JSX, ParentComponent } from "solid-js"; +import type { JSX, ParentComponent } from "solid-js"; const SidebarButton: ParentComponent<{ icon?: JSX.Element; diff --git a/src/screens/Dashboard/components/Sidebar/Profile/Button.tsx b/src/screens/Dashboard/components/Sidebar/Profile/Button.tsx index 1fd6d74..e8c8fd7 100644 --- a/src/screens/Dashboard/components/Sidebar/Profile/Button.tsx +++ b/src/screens/Dashboard/components/Sidebar/Profile/Button.tsx @@ -1,4 +1,4 @@ -import { ParentComponent } from "solid-js"; +import type { ParentComponent } from "solid-js"; interface IProfileButtonProps { onClick: () => void; diff --git a/src/screens/Dashboard/components/Sidebar/Section.tsx b/src/screens/Dashboard/components/Sidebar/Section.tsx index 62fa28d..caf018f 100644 --- a/src/screens/Dashboard/components/Sidebar/Section.tsx +++ b/src/screens/Dashboard/components/Sidebar/Section.tsx @@ -1,4 +1,4 @@ -import { ParentComponent } from "solid-js"; +import type { ParentComponent } from "solid-js"; interface ISidebarSectionProps { title: string; diff --git a/src/screens/Dashboard/components/Sidebar/index.tsx b/src/screens/Dashboard/components/Sidebar/index.tsx index f0a3391..661a25b 100644 --- a/src/screens/Dashboard/components/Sidebar/index.tsx +++ b/src/screens/Dashboard/components/Sidebar/index.tsx @@ -18,20 +18,39 @@ import { import { Hr } from "@/shared/components/Menu/Hr"; import { DisclosureStateChild, Listbox, ListboxButton, ListboxOption, ListboxOptions, Transition } from "terracotta"; import { type Company, getCompanies } from "@/bindings"; +import { useNavigate } from "@solidjs/router"; + +interface SidebarButtonData { + target: string; + icon: JSX.Element; + label: string; +} + +interface SidebarSectionData { + title: string; + buttons: SidebarButtonData[]; +} const Sidebar: Component = () => { const [t] = useI18n(); + const navigate = useNavigate(); const company = useSelector((state) => state.companyService.company); - const [companies, setCompanies] = createSignal([company]); + const stateService = useSelector((state) => state.stateService); + + const [companies, setCompanies] = createSignal([]); + const [selected, setSelected] = createSignal(company); onMount(async () => { - const data = await getCompanies(company.id); - setCompanies((prev) => [...prev, ...data]); + const data = await getCompanies(stateService.state.companyId || undefined); + setCompanies([company, ...data]); }); - const [selected, setSelected] = createSignal(companies()[0]); + const setCompany = (company: Company) => { + stateService.updateState({ companyId: company.id }); + navigate("/"); + }; - const sidebarSections = [ + const sidebarSections: SidebarSectionData[] = [ { title: t("sidebar.section.sales"), buttons: [ @@ -80,7 +99,7 @@ const Sidebar: Component = () => { {t("sidebar.button.settings")}
- +
{ class="rounded-full" />
- { - console.log(companies()); - }} - > - {company.name} - + {company.name}
@@ -117,7 +129,11 @@ const Sidebar: Component = () => { > {(company): JSX.Element => ( - + setCompany(company)} + > {({ isActive, isSelected }): JSX.Element => (
{ > {company.name} - {isSelected() ? ( + {isSelected() && ( { > - ) : null} + )}
)}
)}
- {/* Option to create company */} - console.log("create company")} - > - {({ isActive, isSelected }): JSX.Element => ( + navigate("/setup")}> + {({ isActive }): JSX.Element => (
{ > - - {t("sidebar.button.company.create")} - + {t("sidebar.button.company.create")}
)}
diff --git a/src/screens/Dashboard/components/StatBox.tsx b/src/screens/Dashboard/components/StatBox.tsx index da50a24..6f195c6 100644 --- a/src/screens/Dashboard/components/StatBox.tsx +++ b/src/screens/Dashboard/components/StatBox.tsx @@ -1,4 +1,4 @@ -import { Component, Show } from "solid-js"; +import { type Component, Show } from "solid-js"; // import { Platform } from "@tauri-apps/plugin-os"; const StatBox: Component<{ diff --git a/src/screens/Dashboard/components/Table/ActionButton.tsx b/src/screens/Dashboard/components/Table/ActionButton.tsx index 6dbb660..683ecbd 100644 --- a/src/screens/Dashboard/components/Table/ActionButton.tsx +++ b/src/screens/Dashboard/components/Table/ActionButton.tsx @@ -1,4 +1,4 @@ -import { Component } from "solid-js"; +import type { Component } from "solid-js"; import { Dynamic } from "solid-js/web"; interface ActionButtonProps { diff --git a/src/screens/Dashboard/components/Table/Pagination.tsx b/src/screens/Dashboard/components/Table/Pagination.tsx index 378997d..6a416a3 100644 --- a/src/screens/Dashboard/components/Table/Pagination.tsx +++ b/src/screens/Dashboard/components/Table/Pagination.tsx @@ -1,4 +1,4 @@ -import { For, Component } from "solid-js"; +import { For, type Component } from "solid-js"; interface PaginationProps { currentPage: number; diff --git a/src/screens/Dashboard/components/Table/Row.tsx b/src/screens/Dashboard/components/Table/Row.tsx index 5ebaf81..fb8027a 100644 --- a/src/screens/Dashboard/components/Table/Row.tsx +++ b/src/screens/Dashboard/components/Table/Row.tsx @@ -1,4 +1,4 @@ -import { Component, For, Show } from "solid-js"; +import { type Component, For, Show } from "solid-js"; import ActionButton from "./ActionButton"; interface TableRowProps { diff --git a/src/screens/Dashboard/components/Table/index.tsx b/src/screens/Dashboard/components/Table/index.tsx index df99b96..572a9da 100644 --- a/src/screens/Dashboard/components/Table/index.tsx +++ b/src/screens/Dashboard/components/Table/index.tsx @@ -1,4 +1,4 @@ -import { createSignal, createEffect, For, JSX, Component } from "solid-js"; +import { createSignal, createEffect, For, type JSX, type Component } from "solid-js"; import Pagination from "./Pagination"; import TableHead from "./TableHeader"; import TableRow from "./Row"; diff --git a/src/screens/Dashboard/components/TitleBar.tsx b/src/screens/Dashboard/components/TitleBar.tsx index 124bf70..358d304 100644 --- a/src/screens/Dashboard/components/TitleBar.tsx +++ b/src/screens/Dashboard/components/TitleBar.tsx @@ -1,4 +1,4 @@ -import { Component, For, Show, createMemo } from "solid-js"; +import { type Component, For, Show, createMemo } from "solid-js"; import { useLocation } from "@solidjs/router"; import { useI18n } from "@/i18n"; import { FiBell, FiSearch } from "solid-icons/fi"; diff --git a/src/screens/Setup/index.tsx b/src/screens/Setup/index.tsx index a91605e..575bb2f 100644 --- a/src/screens/Setup/index.tsx +++ b/src/screens/Setup/index.tsx @@ -4,7 +4,7 @@ import ProgressDots from "./components/Progress"; import { createCompany, migrateAndPopulate } from "@/bindings"; import Input from "@/shared/components/Menu/Input"; import { createStore } from "solid-js/store"; -import LangaugeBox from "./components/LanguageBox"; +import LanguageBox from "./components/LanguageBox"; import { LANG } from "@/constants"; import { open } from "@tauri-apps/plugin-shell"; import { getDataByCIN } from "@/utils/getDataByCIN"; @@ -13,12 +13,31 @@ 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"; + +interface UserData { + companyName: string; + cin: string; + vatID: string; + userName: string; + userEmail: string; + contact: { + email: string; + phone: string; + }; + address: { + street: string; + city: string; + zip: string; + }; +} const SetupWizard: Component = () => { const [t] = useI18n(); const [currentStep, setCurrentStep] = createSignal(0); + const stateService = useSelector((state) => state.stateService); const navigate = useNavigate(); - const [userData, setUserData] = createStore({ + const [userData, setUserData] = createStore({ companyName: "", cin: "", vatID: "", @@ -35,23 +54,41 @@ const SetupWizard: Component = () => { }, }); - createEffect(() => { + createEffect(async () => { if (userData.cin.length === 8) { - getDataByCIN(userData.cin).then((data) => { - if (data) { - console.log(data); - setUserData({ - companyName: data.company, - vatID: data.dic, - }); - } + const data = await getDataByCIN(userData.cin); + if (data) { + setUserData({ + companyName: data.company, + vatID: data.dic, + }); + } + } + }); + + 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 }); + navigate("/"); + } catch (error) { + console.error("Error creating company:", error); } - }, [userData.cin]); + }; return ( -
-
+
+
{t("setup.welcome")} @@ -69,18 +106,16 @@ const SetupWizard: Component = () => { {t("setup.step1.select_language")}
- setLocale(LANG.CS)} active={locale() === LANG.CS}> + setLocale(LANG.CS)} active={locale() === LANG.CS}> 🇨🇿 - - setLocale(LANG.EN)} active={locale() === LANG.EN}> + + setLocale(LANG.EN)} active={locale() === LANG.EN}> 🇬🇧 - +

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

@@ -89,77 +124,56 @@ const SetupWizard: Component = () => { -
-
+
+
{t("setup.step2.create_company")} setUserData("companyName", e.target.value)} + onChange={(e) => setUserData("companyName", e.currentTarget.value)} /> setUserData("cin", e.target.value)} + onChange={(e) => setUserData("cin", e.currentTarget.value)} /> setUserData("vatID", e.target.value)} + onChange={(e) => setUserData("vatID", e.currentTarget.value)} />
setUserData("address", "street", e.target.value)} + onChange={(e) => setUserData("address", "street", e.currentTarget.value)} /> setUserData("address", "city", e.target.value)} + onChange={(e) => setUserData("address", "city", e.currentTarget.value)} /> setUserData("address", "zip", e.target.value)} + onChange={(e) => setUserData("address", "zip", e.currentTarget.value)} />
setUserData("contact", "email", e.target.value)} + onChange={(e) => setUserData("contact", "email", e.currentTarget.value)} /> setUserData("contact", "phone", e.target.value)} + onChange={(e) => setUserData("contact", "phone", e.currentTarget.value)} />
-
diff --git a/src/store/index.tsx b/src/store/index.tsx index 87f0ffc..17104cf 100644 --- a/src/store/index.tsx +++ b/src/store/index.tsx @@ -1,4 +1,4 @@ -import { createContext, createSignal, ParentComponent, useContext } from "solid-js"; +import { createContext, createSignal, type ParentComponent, useContext } from "solid-js"; import { CompanyService } from "./services/companyService"; import { StateService } from "./services/stateService"; diff --git a/src/store/services/companyService.ts b/src/store/services/companyService.ts index 583c529..fa90451 100644 --- a/src/store/services/companyService.ts +++ b/src/store/services/companyService.ts @@ -1,4 +1,4 @@ -import { Company } from "@/bindings"; +import type { Company } from "@/bindings"; import { onMount } from "solid-js"; import { createStore } from "solid-js/store"; diff --git a/src/store/services/stateService.ts b/src/store/services/stateService.ts index 5926725..1335786 100644 --- a/src/store/services/stateService.ts +++ b/src/store/services/stateService.ts @@ -1,5 +1,5 @@ import { onMount } from "solid-js"; -import { StoreSetter, createStore } from "solid-js/store"; +import { type StoreSetter, createStore } from "solid-js/store"; // import { Store } from "@tauri-apps/plugin-store"; interface StateService {