Skip to content

Commit

Permalink
feat: ✨ im the best
Browse files Browse the repository at this point in the history
  • Loading branch information
dfrnoch committed Jul 24, 2024
1 parent 860da95 commit a6ba6c0
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 61 deletions.
3 changes: 3 additions & 0 deletions src/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ export type ManageCompanyData = {

bankAccount?: string;
bankIban?: string;

password?: string;
passwordConfirmation?: string;
};

export interface Document {
Expand Down
18 changes: 17 additions & 1 deletion src/i18n/dict/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"improve": "Pomozte nám zlepšit"
},
"step2": {
"backToLogin": "Zpět na přihlášení",
"create_company": "Pojďme vytvořit firmu",
"company_name": "Název firmy / podnikatele",
"CIN": "IČO",
Expand All @@ -20,10 +21,14 @@
"zip": "PSČ",
"email": "Email",
"phone": "Telefon",
"password": "Heslo",
"passwordMatch": "Hesla se neshodují",
"passwordConfirm": "Potvrzení hesla",
"sections": {
"details": "Detaily",
"bank": "Bankovní účet",
"contact": "Kontakt"
"contact": "Kontakt",
"password": "Heslo (Volitelné)"
},
"account": "Číslo účtu",
"iban": "IBAN",
Expand Down Expand Up @@ -96,6 +101,17 @@
},

"pages": {
"login": {
"manageAccounts": "Správa účtů",
"switchAccountsDescription": "Přepínejte mezi účty nebo se přihlašte a odhlašte.",
"invalidPassword": "Neplatné heslo",
"switchedCompany": "Firma změněna",
"password": "Heslo",
"enterPassword": "Zadejte heslo",
"validating": "Ověřování...",
"logIn": "Přihlásit se",
"addAccount": "Přidat účet"
},
"other": {
"templates": {
"table": {
Expand Down
18 changes: 17 additions & 1 deletion src/i18n/dict/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"improve": "Help us improve"
},
"step2": {
"backToLogin": "Back to login",
"create_company": "Let's create your company",
"company_name": "Company name",
"CIN": "CIN",
Expand All @@ -20,11 +21,15 @@
"zip": "ZIP",
"email": "Email",
"phone": "Phone",
"password": "Password",
"passwordMatch": "Passwords do not match",
"passwordConfirm": "Confirm password",

"sections": {
"details": "Details",
"bank": "Bank details",
"contact": "Contact details"
"contact": "Contact details",
"password": "Password (Optional)"
},
"account": "Account number",
"iban": "IBAN",
Expand All @@ -43,6 +48,17 @@
"new": "New Entry"
},
"pages": {
"login": {
"manageAccounts": "Manage Accounts",
"switchAccountsDescription": "Switch accounts or sign in and sign out.",
"invalidPassword": "Invalid password",
"switchedCompany": "Switched company",
"password": "Password",
"enterPassword": "Enter password",
"validating": "Validating...",
"logIn": "Log in",
"addAccount": "Add an account"
},
"other": {
"templates": {
"table": {
Expand Down
4 changes: 2 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ render(
<Router root={App}>
<Route path="/" component={Loader} />
<Route path="/print/:id" component={Print} />
<Route path="/setup" component={Setup} />
<Route path="/setup/:step?" component={Setup} />
<Route path="/login" component={Login} />
<Route path="/dashboard" component={Dashboard}>
<Route path="/" component={Overview} />
Expand Down Expand Up @@ -80,7 +80,7 @@ render(
</Route>
</Route>
<Route path="/settings" component={Settings} />
<Route path="*" component={() => <Navigate href={"/login"} />} />
<Route path="*" component={() => <Navigate href={"/dashboard"} />} />
</Route>
</Router>
),
Expand Down
Binary file modified src/screens/.DS_Store
Binary file not shown.
51 changes: 18 additions & 33 deletions src/screens/Dashboard/components/Sidebar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import { type Component, For, type JSX, createSignal, onMount } from "solid-js";
import { type Component, For, type JSX } from "solid-js";
import SidebarButton from "./Button";
import SidebarSection from "./Section";
import { useI18n } from "@/i18n";
import {
FiCheck,
FiBriefcase,
FiClipboard,
FiDollarSign,
FiFileMinus,
FiFileText,
FiHome,
FiInbox,
FiPlus,
FiSettings,
FiUsers,
} from "solid-icons/fi";
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";
import toast from "solid-toast";
import { useSelector } from "@/store";

interface SidebarButtonData {
Expand All @@ -38,20 +34,6 @@ const Sidebar: Component = () => {
const company = useSelector((state) => state.companyService.company);
const stateService = useSelector((state) => state.stateService);

const [companies, setCompanies] = createSignal<Company[]>([]);
const [selected, setSelected] = createSignal<Company>(company);

onMount(async () => {
const data = await getCompanies(stateService.state.companyId || undefined);
setCompanies([company, ...data]);
});

const setCompany = (company: Company) => {
stateService.updateState({ companyId: company.id });
toast.success("Switched company");
navigate("/");
};

const sidebarSections: SidebarSectionData[] = [
{
title: t("sidebar.section.sales"),
Expand Down Expand Up @@ -102,16 +84,19 @@ const Sidebar: Component = () => {
{t("sidebar.button.settings")}
</SidebarButton>
<Hr />
<Listbox value={selected()} onSelectChange={setSelected} defaultOpen={false}>
<ListboxButton class="text-sm flex flex-row items-center justify-start gap-2.5 lg:gap-4 hover:bg-[#AFAEAF]/20 dark:hover:bg-neutral-100/15 bg-transparent rounded-[5px] px-2 py-[3px] w-full">
<div class="flex h-8 w-8 items-center justify-center lg:h-10 lg:w-10 rounded-full bg-secondary opacity-50">
<FiUsers class="w-5 h-5 text-primary" />
</div>
<span class="block truncate">{company.name}</span>
</ListboxButton>
<div class="flex flex-col w-full">
<div class="relative">
<DisclosureStateChild>
{/* <Listbox value={selected()} onSelectChange={setSelected} defaultOpen={false}> */}
<div
class="text-sm flex flex-row items-center justify-start gap-2.5 lg:gap-4 hover:bg-[#AFAEAF]/20 dark:hover:bg-neutral-100/15 bg-transparent rounded-[5px] px-2 py-[3px] w-full cursor-pointer"
onClick={() => navigate("/login")}
>
<div class="flex h-8 w-8 items-center justify-center lg:h-10 lg:w-10 rounded-full bg-secondary opacity-50">
<FiBriefcase class="w-5 h-5 text-primary" />
</div>
<span class="block truncate">{company.name}</span>
</div>
{/* <div class="flex flex-col w-full">
<div class="relative"> */}
{/* <DisclosureStateChild>
{({ isOpen }): JSX.Element => (
<Transition
show={isOpen()}
Expand Down Expand Up @@ -197,10 +182,10 @@ const Sidebar: Component = () => {
</ListboxOptions>
</Transition>
)}
</DisclosureStateChild>
</div>
</DisclosureStateChild> */}
{/* </div>
</div>
</Listbox>
</Listbox> */}
</div>
</div>
);
Expand Down
26 changes: 14 additions & 12 deletions src/screens/Login/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type Company, getCompanies, validateCompanyPassword } from "@/bindings";
import { useI18n } from "@/i18n";
import Button from "@/shared/components/Button";
import Input from "@/shared/components/Form/Input";
import { useSelector } from "@/store";
Expand All @@ -15,6 +16,7 @@ const Login: Component = () => {
const [isValidating, setIsValidating] = createSignal<boolean>(false);
const [passwordError, setPasswordError] = createSignal<string | null>(null);
const navigate = useNavigate();
const [t] = useI18n();
const stateService = useSelector((state) => state.stateService);

onMount(async () => {
Expand All @@ -29,14 +31,14 @@ const Login: Component = () => {
const isValid = await validateCompanyPassword(company.id, password());
setIsValidating(false);
if (!isValid) {
setPasswordError("Invalid password");
toast.error("Invalid password");
setPasswordError(t("pages.login.invalidPassword"));
toast.error(t("pages.login.invalidPassword"));
return;
}
}
stateService.updateState({ companyId: company.id });
toast.success("Switched company");
navigate("/");
toast.success(t("pages.login.switchedCompany"));
navigate("/dashboard");
};

const handleCompanyClick = (companyId: number) => {
Expand All @@ -48,8 +50,8 @@ const Login: Component = () => {
return (
<div class="w-screen h-screen flex flex-col justify-center items-center" data-tauri-drag-region>
<div class="w-96 bg-primary rounded-lg shadow-xl flex flex-col items-center justify-between p-6 gap-4">
<h2 class="text-2xl font-bold text-primary">Manage Accounts</h2>
<p class="text-sm text-secondary -mt-2">Switch accounts or sign in and sign out.</p>
<h2 class="text-2xl font-bold text-primary">{t("pages.login.manageAccounts")}</h2>
<p class="text-sm text-secondary -mt-2">{t("pages.login.switchAccountsDescription")}</p>
<div class="overflow-y-auto w-full max-h-80 space-y-3 shadow-inner rounded-lg p-2">
<For each={companies()}>
{(company) => (
Expand Down Expand Up @@ -87,15 +89,15 @@ const Login: Component = () => {
<Show when={company.isProtected}>
<Input
type="password"
label="Password"
placeholder="Enter password"
label={t("pages.login.password")}
placeholder={t("pages.login.enterPassword")}
onChange={(value) => setPassword(value)}
errors={passwordError() ? [passwordError()] : undefined}
class="w-full"
/>
</Show>
<Button class="w-full" onClick={() => setCompany(company)} disabled={isValidating()}>
{isValidating() ? "Validating..." : "Log in"}
<Button class="w-2/3" onClick={() => setCompany(company)} disabled={isValidating()}>
{isValidating() ? t("pages.login.validating") : t("pages.login.logIn")}
</Button>
</Motion.div>
)}
Expand All @@ -104,8 +106,8 @@ const Login: Component = () => {
)}
</For>
</div>
<Button class="w-full" onClick={() => navigate("/setup")}>
Add an account
<Button class="w-full" onClick={() => navigate("/setup/2")}>
{t("pages.login.addAccount")}
</Button>
</div>
</div>
Expand Down
Loading

0 comments on commit a6ba6c0

Please sign in to comment.