- Replace stale TanStack Router scaffold with working react-router-dom app - Add all 9 page components + cyber theme CSS - Remove routeTree.gen.ts, add index.css, query.ts
24 lines
1.1 KiB
TypeScript
24 lines
1.1 KiB
TypeScript
import { useState } from "react";
|
|
import { useMutation } from "@tanstack/react-query";
|
|
import { api } from "../lib/api";
|
|
|
|
export default function LoginPage() {
|
|
const [mailbox, setMailbox] = useState("");
|
|
const [pin, setPin] = useState("");
|
|
const [error, setError] = useState("");
|
|
const login = useMutation({ mutationFn: () => api.login(mailbox, pin) });
|
|
const submit = (e: React.FormEvent) => { e.preventDefault(); setError(""); login.mutate(undefined, { onSuccess: () => { window.location.href = "/"; }, onError: (err) => setError((err as Error).message) }); };
|
|
return (
|
|
<div className="wrap">
|
|
<div className="card">
|
|
{error && <div className="err">{error}</div>}
|
|
<form onSubmit={submit}>
|
|
<label>Mailbox number</label><input value={mailbox} onChange={(e) => setMailbox(e.target.value)} inputMode="numeric" />
|
|
<label>PIN</label><input type="password" value={pin} onChange={(e) => setPin(e.target.value)} inputMode="numeric" />
|
|
<div className="row"><button type="submit" className="primary">Log in</button></div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|