mirror of
https://github.com/aaronleetw/savage-tracking.git
synced 2024-11-14 19:11: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,7 +15,8 @@ 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="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>
|
||||
|
@ -27,13 +28,19 @@ export default function DashboardHeader() {
|
|||
</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}>
|
||||
<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 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}>
|
||||
<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>
|
||||
|
@ -41,17 +48,26 @@ export default function DashboardHeader() {
|
|||
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}>
|
||||
<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 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}>
|
||||
<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 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}>
|
||||
<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>
|
||||
|
@ -59,5 +75,10 @@ export default function DashboardHeader() {
|
|||
)
|
||||
}
|
||||
</div>
|
||||
</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