From 746774750856b497712b0ff0a0b46845ef8c3fb0 Mon Sep 17 00:00:00 2001 From: lnxcz Date: Tue, 26 Mar 2024 10:45:07 +0100 Subject: [PATCH] feat: :sparkles: account switching --- .DS_Store | Bin 6148 -> 8196 bytes .github/.DS_Store | Bin 0 -> 6148 bytes src-tauri/.DS_Store | Bin 6148 -> 8196 bytes src/.DS_Store | Bin 0 -> 8196 bytes src/bindings.ts | 2 +- src/i18n/dict/index.ts | 12 +- src/i18n/index.ts | 2 +- src/screens/Dashboard/components/Box.tsx | 2 +- .../Dashboard/components/Popup/Popup.tsx | 2 +- .../Dashboard/components/Sidebar/Button.tsx | 2 +- .../components/Sidebar/Profile/Button.tsx | 2 +- .../Dashboard/components/Sidebar/Section.tsx | 2 +- .../Dashboard/components/Sidebar/index.tsx | 69 +++++----- src/screens/Dashboard/components/StatBox.tsx | 2 +- .../components/Table/ActionButton.tsx | 2 +- .../Dashboard/components/Table/Pagination.tsx | 2 +- .../Dashboard/components/Table/Row.tsx | 2 +- .../Dashboard/components/Table/index.tsx | 2 +- src/screens/Dashboard/components/TitleBar.tsx | 2 +- src/screens/Setup/index.tsx | 126 ++++++++++-------- src/store/index.tsx | 2 +- src/store/services/companyService.ts | 2 +- src/store/services/stateService.ts | 2 +- 23 files changed, 128 insertions(+), 111 deletions(-) create mode 100644 .github/.DS_Store create mode 100644 src/.DS_Store diff --git a/.DS_Store b/.DS_Store index d9e54e6697733aca76f714aabcf1e0b9116c7677..1842f5ad837474d320a6bc5146929378c1af6ebb 100644 GIT binary patch literal 8196 zcmeHMziSjh6#m96dSZ%G3xg*G6gIy3k-ImyyN6XG_y%UaVcz%leS8~cZZ-ha(y(0v764SJ zYpfolp`huw?zwiztt=8M%15$VYqru}KgW~>aX=gp2gCt!Kpgm29H28>w@S&mZ=*7b z1LDAc>44rJLh2eLhnYpQb@6p+iL$WfTX*fxH8Yv=rbHR?)?VcYjYh7kI3fHX3n~ z#P%PyN>R<$Kr0dOX%dPdUriV|KBCRCGy?|6WwT zNlL~suHosA;B$P#y%(3u-6)ECb?v4)k4M%4+(*yMhDgxCfICt>_wEr)EU_xdElYwvEp{_ypg@y6xxs`;o_FBs{1M{PY^#0DOa1MBFv2dyMd(?p+^ z1z~1RaQ5nZZB7A;%iK9#d;7&&RLGpXyxB}9KREwzBCvuILi&=kFHuH%H`e;Cp{bg{@` TW|1P)Dk_S3~8%Vf<9JVp>JM(0I8A}C_FwkjC VP?`lq134fsfPBTUIi6<@GXSP1D`fxx diff --git a/.github/.DS_Store b/.github/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..35ef5352024c6f7c66c510c294fa98495be2ee91 GIT binary patch literal 6148 zcmeHKy-ve05I&cJ649X}5=&m8Pk^ZcFVGi&($WeN61AYRAZ20aL6BIO*x7g*Ha5OH zTP1(Mf)GM?(fM=EcfQLPD~^fC46h~wqCOD?P{vM(rbT$1wILmE=>d(*aY@T$HW-~` zY2NTw!(U{8-`y4+(-PN|8t*T^uaBo$9FLQ1414f&9X`D7J?}StCg1wx^YS_=Fa>SW z1!bsVT3luY;Z1yvp?~ z-tKO0t<=*pU%9TYJ*)LeW^I%KWk4DDDF(1-vjp1?wN(a`0cBv#0Dm7MD5LdQIFwHZ z8aV<0yD*EOFaJ`&hz&sNv2X|r#JEtP3pM_TVO%)uk@vG63x_V8jAX_aY96@fkC4$yim9Kr(89|5638)e{E8F&Y}2XDIo literal 0 HcmV?d00001 diff --git a/src-tauri/.DS_Store b/src-tauri/.DS_Store index c1b1fb3c56d9a13e4451896b278f933883e58eba..88872726c902d35c8b6dc52f077d998798898964 100644 GIT binary patch literal 8196 zcmeHMO=}ZT6ur+TLx>ez$+!?E2+~c3bWy~Gj%A9tl9IL1CQZ{qk{OyRF6Upwji9?$ zcU`%3<3a+0l>Pwy2SVM7=Y7z5Z$7N6w$S_Fy%XNOch1RSK5{2SBvxK-wuyWqYG6vd zc^ym1ka0N+Uad8HzOk}mDg5OWW+PZRf@!i@-gmASUQx6clb z|9n&W{*j+){h$02-E;7*Ph&@A^ZgVmO~lqTn?KnWGo|S?nkgto9lqvg9F*#CrAIN1 zbI$k=2X55n{do7$^6l@6*Qy`I8FzVx!|%V#@xSWqj)(DB^2!^tM+wfN9h%UHHXJ|5 zd!CQm>W)r+wUXE7OtOw)>#NFf6za!E)7C+Ya0_RXt4F+mp3*#9*PF+yTZd1Tu8Q2u zzq4{(odM`^eoWw3&rw!C-p?YomJdHWzi0YtGj+B*#i+yQsVmIG6{WB9KJ8howLA6o zTVQqKHuus&d(qctPcA3>{#7}aj@rV505ll<{MSD4$_`wV19O_#m;L{0_51&elE=L4 z06TCF4v1RRiB>>ldg}tE?6m{Tbxb*AUaC=*U{UQjP_^U0(?1OHIY6qc2@R$iv4g=s N1e6WDumk7nz+Y%v7li-- delta 188 zcmZp1XfcprU|?W$DortDU=RQ@Ie-{MGjdEU6q~50D9j4tfW?Z-f{XHU^7GOs7OrGu zoopi{E6&VN%uvLToRe-CoSdIq094Arz}DzId4aGPo7iKut#@oE?-7=OF>eV=F;3W6 zSj4uNor6P=8LXN?fE!4=f-Kxv_?>w&zl@~wxd!wdi` CFe9%3 diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..4d4a5226945552a0aa476b66e8b30ece95a1741e GIT binary patch literal 8196 zcmeHMJ#Q015SrwnVn;ZV?Td(wlm^`opx_@M zL`y-z4{$?=pma)VnpD*AW_ESAdmkVgM8vGM`>dTeyU*|Le4aBAnXUP-L$pCeEp*27 z=P*<>j&m=y6*m(B4f2U*bU1$6=?#*}L5Zys>VP_+4yXg_fI9FmIDmULw^q%4-$r#* z2h@T8(gFT{h|n2hhp9#R>cAi+0I-2+X?Tx1Kyo67vBT7&q+(55Js6j2T!~?9I^q%2 zfw9BXqD?1b)5*A-Xl}VtkTxySw9L z7xS$jpWZFL-uQU0%o+Zcb1?Fs6UbG&P6JA43MDfrnwHhjP3%;`@->Y%FHRp1MN=g+ zSN3aWg}w&uQ-^NTGGvI^?=pr8%yZeds8txOH88$fCZ6_um$emdDNqkCFRO z%?S7JV*~zup!a_^LYq2piX1p&wQg|zf4~0u|0()JDpeg&2maIn)9CiPTgY;?bt#`~ v?FhY(&W(AgMM=RR4N~VK?il("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 {