Skip to content

Commit

Permalink
feat: ✨ changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dfrnoch committed Dec 17, 2023
1 parent 3fd0917 commit 1803de5
Show file tree
Hide file tree
Showing 24 changed files with 376 additions and 181 deletions.
Binary file modified bun.lockb
Binary file not shown.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,19 @@
"@tauri-apps/plugin-http": "github:tauri-apps/tauri-plugin-http#v2",
"@tauri-apps/plugin-os": "github:tauri-apps/tauri-plugin-os#v2",
"@tauri-apps/plugin-process": "github:tauri-apps/tauri-plugin-process#v2",
"@tauri-apps/plugin-shell": "github:tauri-apps/tauri-plugin-shell#v2",
"@tauri-apps/plugin-store": "github:tauri-apps/tauri-plugin-store#v2",
"@tauri-apps/plugin-updater": "github:tauri-apps/tauri-plugin-updater#v2",
"@tauri-apps/plugin-shell": "github:tauri-apps/tauri-plugin-shell#v2",
"@unocss/reset": "^0.58.0",
"solid-chartjs": "^1.3.8",
"solid-headless": "^0.13.1",
"solid-icons": "^1.1.0",
"solid-js": "^1.8.7",
"solid-toast": "^0.5.0"
"solid-toast": "^0.5.0",
"xml2js": "^0.6.2"
},
"devDependencies": {
"@types/xml2js": "^0.4.14",
"@biomejs/biome": "1.4",
"@tauri-apps/cli": "2.0.0-alpha.18",
"@types/node": "^20.10",
Expand Down
48 changes: 6 additions & 42 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,52 +1,16 @@
import type { Component } from "solid-js";
import { Show, type ParentComponent } from "solid-js";
import { I18nProvider, locale } from "@/i18n";
import { Toaster } from "solid-toast";
import { Show, createEffect, createSignal, lazy } from "solid-js";
import { checkDb } from "@/bindings";
import { StoreProvider } from "@/store";

const Dashboard = lazy(() => import("./screens/Dashboard"));
const SetupWizard = lazy(() => import("./screens/Setup"));

enum Screen {
Dashboard = "dashboard",
Setup = "setup",
Loading = "loading",
}

const App: Component = () => {
const [screen, setScreen] = createSignal<Screen>(Screen.Loading);

const startup = async () => {
const data = await checkDb();

if (data === 200) {
return setScreen(Screen.Dashboard);
}
return setScreen(Screen.Setup);
};

createEffect(() => {
startup();
});

const App: ParentComponent = (props) => {
return (
<I18nProvider locale={locale()}>
<Show when={screen() === Screen.Dashboard}>
<StoreProvider>
<Dashboard />
</StoreProvider>
</Show>
<Show when={screen() === Screen.Setup}>
<SetupWizard />
</Show>
<Show when={screen() === Screen.Loading}>
<div class="flex justify-center items-center h-screen">
<div class="flex flex-col justify-center items-center">
<h1 class="text-4xl font-bold">Loading...</h1>
</div>
</div>
{/* When in developement enviroment show text */}
<Show when={import.meta.env.DEV}>
<div class="absolute bottom-0 right-0 p-2 text-danger text-xs font-medium ">Developement enviroment</div>
</Show>
<StoreProvider>{props.children}</StoreProvider>
<Toaster />
</I18nProvider>
);
Expand Down
28 changes: 28 additions & 0 deletions src/Loader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { ParentComponent } from "solid-js";
import { checkDb } from "@/bindings";
import { useNavigate } from "@solidjs/router";

const Loader: ParentComponent = (props) => {
const navigate = useNavigate();
const startup = async () => {
const data = await checkDb();

if (data === 200) {
navigate("/setup");
return;
}
navigate("/setup");
};

startup();

return (
<div class="flex justify-center items-center h-screen">
<div class="flex flex-col justify-center items-center">
<h1 class="text-4xl font-bold">Loading...</h1>
</div>
</div>
);
};

export default Loader;
22 changes: 15 additions & 7 deletions src/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,33 @@ export function getCompany(id: number | null) {
return invoke<Company | null>("get_company", { id });
}

export function createPost(data: CreateCompanyData) {
return invoke<number>("create_company", data);
export function createCompany(data: CreateCompanyData) {
return invoke<number>("create_company", { data });
}

export function migrateAndPopulate() {
return invoke("migrate_and_populate");
}

export type CreateCompanyData = { name: string };
export type Test = { id: number; name: string };
export type CreateCompanyData = {
name: string;
cin: string;
vatId: string;
streetAddress: string;
city: string;
postalCode: string;
phoneNumber: string;
email: string;
};

export type Company = {
id: number;
name: string;
email: string;
cin: string | null;
vatId: string | null;
streetAddress: string;
street: string;
city: string;
postalCode: string;
phoneNumber: string | null;
website: string | null;
email: string | null;
};
12 changes: 11 additions & 1 deletion src/i18n/dict/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"welcome": "Vítejte",
"get_started": "Začít",
"continue": "Pokračovat",
"finalize": "Dokončit",
"step1": {
"select_language": "Vyberte jazyk",
"select_currency": "Vyberte měnu",
Expand All @@ -13,7 +14,16 @@
"step2": {
"create_company": "Pojďme vytvořit firmu",
"company_name": "Název firmy / podnikatele",
"CIN": "IČO"
"CIN": "IČO",
"vatID": "DIČ",
"street": "Ulice",
"city": "Město",
"zip": "PSČ",
"email": "Email",
"phone": "Telefon",
"help": {
"retrieve_by_cin": "Po zadání správného IČA se načte zbytek údajů automaticky"
}
}
},
"sidebar": {
Expand Down
12 changes: 11 additions & 1 deletion src/i18n/dict/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"welcome": "Welcome to the app",
"get_started": "Get started",
"continue": "Continue",
"finalize": "Finalize",
"step1": {
"select_language": "Select your language",
"select_currency": "Select your currency",
Expand All @@ -13,7 +14,16 @@
"step2": {
"create_company": "Let's create your company",
"company_name": "Company name",
"CIN": "CIN"
"CIN": "CIN",
"vatID": "VAT ID",
"street": "Street",
"city": "City",
"zip": "ZIP",
"email": "Email",
"phone": "Phone",
"help": {
"retrieve_by_cin": "After entering your CIN, we will try to retrieve your company information from the government database."
}
}
},
"sidebar": {
Expand Down
36 changes: 34 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,48 @@
import { lazy } from "solid-js";

import "./styles/index.css";
import "@unocss/reset/tailwind-compat.css";
import "uno.css";

const Overview = lazy(() => import("./screens/Dashboard/pages"));
const Invoices = lazy(() => import("./screens/Dashboard/pages/Sales/Invoices"));
const Expenses = lazy(() => import("./screens/Dashboard/pages/Purchase/Expenses"));
const Clients = lazy(() => import("./screens/Dashboard/pages/Other/Clients"));
const Reports = lazy(() => import("./screens/Dashboard/pages/Other"));
const Settings = lazy(() => import("./screens/Dashboard/pages/Settings"));
const Dashboard = lazy(() => import("./screens/Dashboard"));
const Setup = lazy(() => import("./screens/Setup"));
const App = lazy(() => import("./App"));

import { render } from "solid-js/web";

import App from "./App";
import { Theme, getTheme, setTheme } from "./utils/theme";
import { Navigate, Route, Router } from "@solidjs/router";

setTheme(getTheme());
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", (e) => e.matches && setTheme(Theme.Dark));
window
.matchMedia("(prefers-color-scheme: light)")
.addEventListener("change", (e) => e.matches && setTheme(Theme.Light));

render(() => <App />, document.getElementById("root") as HTMLElement);
render(
() => (
<Router root={App}>
<Route path="/" component={() => <Navigate href={"/setup"} />} />
<Route path="/loader" component={App} />
<Route path="/setup" component={Setup} />
<Route path="/dashboard" component={Dashboard}>
<Route path="/" component={Overview} />
<Route path="/sales">
<Route path="/invoices" component={Invoices} />
</Route>
<Route path="/other/clients" component={Clients} />
<Route path="/other/reports" component={Reports} />
<Route path="/purchase/expenses" component={Expenses} />
<Route path="/settings" component={Settings} />
<Route path="*" component={Overview} />
</Route>
</Router>
),
document.getElementById("root") as HTMLElement,
);
6 changes: 3 additions & 3 deletions src/screens/Dashboard/components/Sidebar/Section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ interface ISidebarSectionProps {

const SidebarSection: ParentComponent<ISidebarSectionProps> = (props) => {
return (
<div class="mt-5">
<div class="text-xs font-medium text-grey">{props.title}</div>
<>
<div class="mt-4 text-xs font-medium text-grey">{props.title}</div>
<div class="">{props.children}</div>
</div>
</>
);
};

Expand Down
19 changes: 10 additions & 9 deletions src/screens/Dashboard/components/Sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import SidebarSection from "./Section";
import { useSelector } from "@/store";
import { useI18n } from "@/i18n";
import { FiDollarSign, FiFileText, FiHome, FiPaperclip, FiSettings, FiUsers } from "solid-icons/fi";
import { Hr } from "@/shared/components/Menu/Hr";

const Sidebar: Component = () => {
const [t] = useI18n();
Expand All @@ -15,43 +16,43 @@ const Sidebar: Component = () => {
return (
<div class="flex relative flex-col justify-between px-2.5 lg:px-4 pt-14 pb-4 w-1/5 h-screen lg:max-w-[220px] min-w-[140px] shrink-0 text-primary border-r dark:border-black/90 border-zinc-400/70">
<div>
<SidebarButton notInSection target="/" icon={<FiHome />}>
<SidebarButton notInSection target="/dashboard/" icon={<FiHome />}>
{t("sidebar.button.overview")}
</SidebarButton>

<SidebarSection title={t("sidebar.section.sales")}>
<SidebarButton target="sales/invoices" icon={<FiFileText />}>
<SidebarButton target="/dashboard/sales/invoices" icon={<FiFileText />}>
{t("sidebar.button.invoices")}
</SidebarButton>
</SidebarSection>
<SidebarSection title={t("sidebar.section.purchase")}>
<SidebarButton target="/purchase/expenses" icon={<FiDollarSign />}>
<SidebarButton target="/dashboard/purchase/expenses" icon={<FiDollarSign />}>
{t("sidebar.button.expenses")}
</SidebarButton>
</SidebarSection>

<SidebarSection title={t("sidebar.section.other")}>
<SidebarButton target="/other/clients" icon={<FiUsers />}>
<SidebarButton target="/dashboard/other/clients" icon={<FiUsers />}>
{t("sidebar.button.clients")}
</SidebarButton>
<SidebarButton target="/other/reports" icon={<FiPaperclip />}>
<SidebarButton target="/dashboard/other/reports" icon={<FiPaperclip />}>
{t("sidebar.button.reports")}
</SidebarButton>
</SidebarSection>
</div>

{/* profile */}
<div class="flex flex-col gap-4">
<SidebarButton target="/settings" icon={<FiSettings />} notInSection>
<SidebarButton target="/dashboard/settings" icon={<FiSettings />} notInSection>
{t("sidebar.button.settings")}
</SidebarButton>
<hr class="border-black/10" />
<Hr />
<div class="flex flex-row gap-2.5 justify-start items-center lg:gap-4">
<div class="flex justify-center items-center w-8 h-8 lg:w-10 lg:h-10">
<img
src="https://cdn.discordapp.com/avatars/724579978921902114/a71691117b6ea1d85fd2cd2b21506f63.webp?size=4096"
src="https://cdn.discordapp.com/avatars/724579978921902114/a0050fed75bf9ecbdc3dbcc23ecb6d8e.webp?size=2048"
alt="pfp"
class="rounded-full"
class="rounded"
/>
</div>
<div class="flex flex-col">
Expand Down
23 changes: 3 additions & 20 deletions src/screens/Dashboard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
import { Route, Router } from "@solidjs/router";
import type { Component } from "solid-js";
import type { Component, ParentComponent } from "solid-js";
import { createEffect, lazy } from "solid-js";
import { getCompany } from "../../bindings";
import TitleBar from "./components/TitleBar";
import Sidebar from "./components/Sidebar";
import { useSelector } from "@/store";

const Overview = lazy(() => import("./pages"));
const Invoices = lazy(() => import("./pages/Sales/Invoices"));
const Expenses = lazy(() => import("./pages/Purchase/Expenses"));
const Clients = lazy(() => import("./pages/Other/Clients"));
const Reports = lazy(() => import("./pages/Other"));
const Settings = lazy(() => import("./pages/Settings"));

const Dashboard: Component = () => {
const Dashboard: ParentComponent = (props) => {
const {
companyService: { updateCompany },
stateService: { state, updateState },
Expand All @@ -40,17 +33,7 @@ const Dashboard: Component = () => {
<div class="flex flex-row items-start w-screen">
<Sidebar />
<div class="overflow-y-auto px-4 pt-14 mx-auto w-full h-screen no-scrollbar bg-secondary text-primary">
<div class="container">
<Router>
<Route path="/" component={Overview} />
<Route path="/sales/invoices" component={Invoices} />
<Route path="/other/clients" component={Clients} />
<Route path="/other/reports" component={Reports} />
<Route path="/purchase/expenses" component={Expenses} />
<Route path="/settings" component={Settings} />
<Route path="*" component={Overview} />
</Router>
</div>
<div class="container">{props.children}</div>
</div>
</div>
</>
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Dashboard/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const Overview: Component = () => {

return (
<div class="grid grid-cols-3 grid-rows-5 gap-3 lg:gap-4 w-full h-screen">
<div class="col-span-3">
<div class="col-span-2">
<div class="flex flex-row gap-3 lg:gap-4 justify-between items-center w-full h-full">
<StatBox title={t("home.stats.purchase")} value="$8657.32" last={6804.52} />
<StatBox title={t("home.stats.sales")} value="100$" />
Expand Down
13 changes: 13 additions & 0 deletions src/screens/Setup/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ParentComponent } from "solid-js";

export const Button: ParentComponent<{ onClick?: (e: MouseEvent) => void; class?: string }> = (props) => {
return (
<button
class={`py-1.5 px-8 bg-primary rounded-md text-secondary font-medium text-sm ${props.class}`}
type="button"
onClick={props.onClick}
>
{props.children}
</button>
);
};
2 changes: 1 addition & 1 deletion src/screens/Setup/components/LanguageBox.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Accessor, For, ParentComponent } from "solid-js";
import { ParentComponent } from "solid-js";

const LangaugeBox: ParentComponent<{ onClick: () => void; active?: boolean }> = (props) => {
return (
Expand Down
Loading

0 comments on commit 1803de5

Please sign in to comment.