mirror of
https://github.com/aaronleetw/savage-tracking.git
synced 2024-11-14 11:01:39 -08:00
fixed structure, added dashboard header format
This commit is contained in:
parent
4fd2900f5b
commit
af65bb7191
3 changed files with 65 additions and 53 deletions
|
@ -3,7 +3,7 @@ import { useRouter } from "next/navigation";
|
|||
import { useEffect } from "react";
|
||||
import { api } from "~/utils/api";
|
||||
|
||||
export default function DashboardHeader() {
|
||||
export default function DashboardHeader({ url }: { url: string }) {
|
||||
const { push } = useRouter();
|
||||
const session = api.admin.session.useQuery();
|
||||
const logout = api.admin.logout.useMutation();
|
||||
|
@ -15,49 +15,70 @@ export default function DashboardHeader() {
|
|||
}, [logout.isSuccess])
|
||||
|
||||
return (
|
||||
<div className="text-3xl md:text-5xl font-bold bg-indigo-100 p-5 pb-0">
|
||||
<div className="flex items-center w-full mb-3">
|
||||
<img className="h-16 md:h-24 m-2" src="/favicon.png" alt="" />
|
||||
<div>
|
||||
<h1 className="mb-2">Savage Tracking</h1>
|
||||
<h2 className="text-2xl">Hi, {session?.data?.name} ({session?.data?.grade} {session?.data?.class})</h2>
|
||||
<div className="text-3xl md:text-5xl font-bold bg-indigo-100">
|
||||
<div className="p-5 pb-0">
|
||||
<div className="flex items-center w-full mb-3">
|
||||
<img className="h-16 md:h-24 m-2" src="/favicon.png" alt="" />
|
||||
<div>
|
||||
<h1 className="mb-2">Savage Tracking</h1>
|
||||
<h2 className="text-2xl">Hi, {session?.data?.name} ({session?.data?.grade} {session?.data?.class})</h2>
|
||||
</div>
|
||||
<button className="text-2xl ml-10 bg-indigo-600 px-3 py-2 rounded text-white focus:ring focus:ring-indigo-200 focus:ring-opacity-70 disabled:bg-indigo-400" disabled={logout.isLoading} onClick={() => logout.mutate()}>
|
||||
Logout
|
||||
</button>
|
||||
</div>
|
||||
<div className="flex items-center w-full gap-3">
|
||||
<Link href="/dash">
|
||||
<button className={[
|
||||
"text-xl px-3 py-2 rounded-lg rounded-b-none focus:ring focus:ring-sky-200 focus:ring-opacity-70",
|
||||
url == "/dash" ? "bg-sky-600 text-white" : "bg-sky-300 text-black"
|
||||
].join(" ")}>
|
||||
Time Selection
|
||||
</button>
|
||||
</Link>
|
||||
<Link href="/dash/chgPassword">
|
||||
<button className={[
|
||||
"text-xl px-3 py-2 rounded-lg rounded-b-none focus:ring focus:ring-sky-200 focus:ring-opacity-70",
|
||||
url == "/dash/chgPassword" ? "bg-sky-600 text-white" : "bg-sky-300 text-black"
|
||||
].join(" ")}>
|
||||
Change Password
|
||||
</button>
|
||||
</Link>
|
||||
{
|
||||
session?.data?.isAdmin && (
|
||||
<>
|
||||
<Link href="/dash/admin">
|
||||
<button className={[
|
||||
"text-xl px-3 py-2 rounded-lg rounded-b-none focus:ring focus:ring-emerald-200 focus:ring-opacity-70",
|
||||
url == "/dash/admin" ? "bg-emerald-600 text-white" : "bg-emerald-200 text-black"
|
||||
].join(" ")}>
|
||||
Admin
|
||||
</button>
|
||||
</Link>
|
||||
<Link href="/dash/admin/roster">
|
||||
<button className={[
|
||||
"text-xl px-3 py-2 rounded-lg rounded-b-none focus:ring focus:ring-emerald-200 focus:ring-opacity-70",
|
||||
url == "/dash/admin/roster" ? "bg-emerald-600 text-white" : "bg-emerald-200 text-black"
|
||||
].join(" ")}>
|
||||
Print Roster
|
||||
</button>
|
||||
</Link>
|
||||
<Link href="/dash/admin/rfid">
|
||||
<button className={[
|
||||
"text-xl px-3 py-2 rounded-lg rounded-b-none focus:ring focus:ring-emerald-200 focus:ring-opacity-70",
|
||||
url == "/dash/admin/rfid" ? "bg-emerald-600 text-white" : "bg-emerald-200 text-black"
|
||||
].join(" ")}>
|
||||
RFID Log
|
||||
</button>
|
||||
</Link>
|
||||
</>
|
||||
)
|
||||
}
|
||||
</div>
|
||||
<button className="text-2xl ml-10 bg-indigo-600 px-3 py-2 rounded text-white focus:ring focus:ring-indigo-200 focus:ring-opacity-70 disabled:bg-indigo-400" disabled={logout.isLoading} onClick={() => logout.mutate()}>
|
||||
Logout
|
||||
</button>
|
||||
</div>
|
||||
<div className="flex items-center w-full gap-3">
|
||||
<Link href="/dash/time">
|
||||
<button className="text-xl bg-sky-600 px-3 py-2 rounded-lg rounded-b-none text-white focus:ring focus:ring-sky-200 focus:ring-opacity-70 disabled:bg-sky-400" disabled={logout.isLoading}>
|
||||
Time Selection
|
||||
</button>
|
||||
</Link>
|
||||
<Link href="/dash/chgPassword">
|
||||
<button className="text-xl bg-sky-600 px-3 py-2 rounded-lg rounded-b-none text-white focus:ring focus:ring-sky-200 focus:ring-opacity-70 disabled:bg-sky-400" disabled={logout.isLoading}>
|
||||
Change Password
|
||||
</button>
|
||||
</Link>
|
||||
{
|
||||
session?.data?.isAdmin && (
|
||||
<>
|
||||
<Link href="/dash/admin">
|
||||
<button className="text-xl bg-emerald-600 px-3 py-2 rounded-lg rounded-b-none text-white focus:ring focus:ring-emerald-200 focus:ring-opacity-70 disabled:bg-emerald-400" disabled={logout.isLoading}>
|
||||
Admin
|
||||
</button>
|
||||
</Link>
|
||||
<Link href="/dash/admin/roster">
|
||||
<button className="text-xl bg-emerald-600 px-3 py-2 rounded-lg rounded-b-none text-white focus:ring focus:ring-emerald-200 focus:ring-opacity-70 disabled:bg-emerald-400" disabled={logout.isLoading}>
|
||||
Print Roster
|
||||
</button>
|
||||
</Link>
|
||||
<Link href="/dash/admin/rfid">
|
||||
<button className="text-xl bg-emerald-600 px-3 py-2 rounded-lg rounded-b-none text-white focus:ring focus:ring-emerald-200 focus:ring-opacity-70 disabled:bg-emerald-400" disabled={logout.isLoading}>
|
||||
RFID Log
|
||||
</button>
|
||||
</Link>
|
||||
</>
|
||||
)
|
||||
}
|
||||
</div>
|
||||
<div className={[
|
||||
"w-full h-2",
|
||||
url.startsWith("/dash/admin") ? "bg-emerald-600" : "bg-sky-600"
|
||||
].join(" ")}></div>
|
||||
</div>)
|
||||
}
|
|
@ -24,7 +24,7 @@ export default function Dash() {
|
|||
<link rel="icon" href="/favicon.png" />
|
||||
</Head>
|
||||
<main className="">
|
||||
<DashboardHeader />
|
||||
<DashboardHeader url="/dash" />
|
||||
</main>
|
||||
</>)
|
||||
}
|
|
@ -17,16 +17,7 @@ export const adminRouter = createTRPCRouter({
|
|||
}).then((user) => {
|
||||
const result = compareSync(input.password, user?.password || "");
|
||||
if (result) {
|
||||
console.log(user)
|
||||
console.log(PublicUserType.parse({
|
||||
grade: user?.grade,
|
||||
class: user?.class,
|
||||
name: user?.name,
|
||||
username: user?.username,
|
||||
isAdmin: user?.isAdmin,
|
||||
}))
|
||||
const session = PublicUserType.parse(user)!;
|
||||
console.log(session)
|
||||
const token = jwt.sign(session, process.env.JWT_SECRET || "", { expiresIn: "1d" });
|
||||
ctx.res.setHeader("Set-Cookie", `token=${token}; Path=/; HttpOnly; SameSite=Strict; Max-Age=${60 * 60 * 24};`);
|
||||
return {
|
||||
|
|
Loading…
Reference in a new issue