Skip to content

Commit

Permalink
Add notification when credentials are invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
romeovs committed Nov 7, 2024
1 parent 9c23f62 commit dbb1d57
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
15 changes: 12 additions & 3 deletions client/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,20 @@ export function App() {
}, [])

if (route === "login") {
return <Login onClose={handleLoginClose} />
return (
<>
<Login onClose={handleLoginClose} />
<Notifications />
</>
)
}

return <NTS />
return (
<>
<NTS />
<Notifications />
</>
)
}

export function NTS() {
Expand Down Expand Up @@ -371,7 +381,6 @@ export function NTS() {
<Offline hide={!isOffline} />
<Help hide={!isShowingHelp} onHide={() => setIsShowingHelp(false)} />
<Volume volume={preferences.volume} />
<Notifications />
</>
)
}
Expand Down
13 changes: 7 additions & 6 deletions client/login.tsx
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -12,7 +13,9 @@ export function Login(props: LoginProps) {
const { onClose } = props

const handleSubmit = useCallback(
async function (data: FormData) {
async function (evt: FormEvent<HTMLFormElement>) {
evt.preventDefault()
const data = new FormData(evt.target as HTMLFormElement)
const email = data.get("email")?.toString() ?? null
const password = data.get("password")?.toString() ?? null

Expand All @@ -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
<form className={css.login} action={handleSubmit}>
<form className={css.login} onSubmit={handleSubmit}>
<label htmlFor="email">Email</label>
<input id="email" name="email" type="email" required />

Expand Down
1 change: 1 addition & 0 deletions client/notifications/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export function Notifications() {
useEffect(function () {
function handler(evt: CustomEvent<Notification>) {
const notification = evt.detail
console.log("HERE", notification)
setNotifications((notifications) => [...notifications, notification])
}

Expand Down

0 comments on commit dbb1d57

Please sign in to comment.