From dbb1d57b6e053b47aff41a8f4427a68be5941395 Mon Sep 17 00:00:00 2001 From: Romeo Van Snick Date: Thu, 7 Nov 2024 20:12:57 +1100 Subject: [PATCH] Add notification when credentials are invalid --- client/app.tsx | 15 ++++++++++++--- client/login.tsx | 13 +++++++------ client/notifications/index.tsx | 1 + 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/client/app.tsx b/client/app.tsx index 7b79654..f03bd64 100644 --- a/client/app.tsx +++ b/client/app.tsx @@ -52,10 +52,20 @@ export function App() { }, []) if (route === "login") { - return + return ( + <> + + + + ) } - return + return ( + <> + + + + ) } export function NTS() { @@ -371,7 +381,6 @@ export function NTS() { setIsShowingHelp(false)} /> - ) } diff --git a/client/login.tsx b/client/login.tsx index 316d807..91284a6 100644 --- a/client/login.tsx +++ b/client/login.tsx @@ -1,8 +1,9 @@ -import { useCallback } from "react" +import { type FormEvent, useCallback } from "react" import { electron } from "./electron" import css from "./login.module.css" +import { notify } from "./notifications" type LoginProps = { onClose: () => void @@ -12,7 +13,9 @@ export function Login(props: LoginProps) { const { onClose } = props const handleSubmit = useCallback( - async function (data: FormData) { + async function (evt: FormEvent) { + evt.preventDefault() + const data = new FormData(evt.target as HTMLFormElement) const email = data.get("email")?.toString() ?? null const password = data.get("password")?.toString() ?? null @@ -24,16 +27,14 @@ export function Login(props: LoginProps) { await electron.invoke("login-credentials", { email, password }) onClose() } catch (err) { - // TODO: show error - console.log("HERE", err) + notify({ message: "invalid credentials", ttl: 4000, type: "error" }) } }, [onClose], ) return ( - // @ts-expect-error: form action type is not a string -
+ diff --git a/client/notifications/index.tsx b/client/notifications/index.tsx index c271aba..3a99933 100644 --- a/client/notifications/index.tsx +++ b/client/notifications/index.tsx @@ -39,6 +39,7 @@ export function Notifications() { useEffect(function () { function handler(evt: CustomEvent) { const notification = evt.detail + console.log("HERE", notification) setNotifications((notifications) => [...notifications, notification]) }