Skip to content

Commit ae4116e

Browse files
committed
feat: add a provider for popup context and small fixes
add a context provider for popus which can be used in a future implementation and some small other fixes Refs: #41
1 parent 374fab3 commit ae4116e

4 files changed

Lines changed: 29 additions & 11 deletions

File tree

labman/src/app/(main)/layout.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ import type { Metadata } from "next";
22
import "./globals.css";
33
import { League_Spartan } from "next/font/google";
44
import NavBar from "@/components/core/NavBar";
5-
import prisma from "@/lib/prisma";
6-
import { cookies } from "next/headers";
7-
import {validateSessionToken} from "@/auth/session";
8-
import {getSession, getUser} from "@/lib/actions";
5+
import {PopupProvider} from "./popupProvider"
6+
import {getUser} from "@/lib/actions";
97
import SideBar from "@/components/core/SideBar";
108

119
const spartan = League_Spartan({
@@ -40,7 +38,9 @@ export default async function RootLayout({
4038

4139
<main className="flex-1 overflow-auto">
4240
<NavBar username={user?.username ?? "Unknown"} />
43-
{children}
41+
<PopupProvider>
42+
{children}
43+
</PopupProvider>
4444
</main>
4545
</div>
4646
</body>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"use client"
2+
import {createContext, useState} from "react";
3+
4+
export const popupContext = createContext(null);
5+
6+
export const PopupProvider = ({children}) => {
7+
const [isOpen, setIsOpen] = useState(false);
8+
const [message, setMessage] = useState("");
9+
10+
return (
11+
<popupContext.Provider value={{isOpen, setIsOpen, message, setMessage}}>
12+
<>
13+
{children}
14+
<div className={`${isOpen ? "block" : "hidden"}`}>
15+
<div className="bg-white rounded-md p-4 mx-auto mt-20 w-[300px]">
16+
<h1 className="text-2xl text-black font-bold">{message}</h1>
17+
</div>
18+
</div>
19+
</>
20+
</popupContext.Provider>
21+
)
22+
}

labman/src/components/core/Card.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ export default function Card({ loan, user }: CardProps) {
2424
last = loan.endDate.toLocaleDateString("no");
2525
}
2626

27-
/* const name = loan?.item.equipment.name || user?.username;
28-
const start = loan?.startDate.toLocaleDateString("no") || new Date(user.createdAt).toLocaleDateString("no");
29-
const last = loan?.endDate.toLocaleDateString("no") || new Date(user.latestActivity).toLocaleDateString("no"); */
30-
3127
if (loan) {
3228
if (new Date(loan.endDate) < new Date() && loan.status === "Active") {
3329
loan.status = "Due";
@@ -39,7 +35,7 @@ export default function Card({ loan, user }: CardProps) {
3935
<div className="border-b-white border-b-[1px] flex gap-2 ">
4036
<h1 className="text-3xl font-bold pl-3 pt-2.5">{name}</h1>
4137
{loan && <span className={"mt-3 text-3xl"}>|</span>}
42-
{loan && <p title={loan.item.equipment.name} className="mt-4 text-2xl w-40 whitespace-nowrap overflow-hidden text-ellipsis">{loan.item?.equipment.name}</p>}
38+
{loan && <p title={loan.item.equipment.name} className="mt-4 text-2xl w-40 whitespace-nowrap overflow-hidden text-ellipsis">Unit {loan.item?.id}</p>}
4339
{loan && <div className={"mt-4 mr-3 ml-auto rounded-md flex justify-center px-1 w-fit h-5 left-3" + (loan.status === "Returned" ? " bg-green-400" : loan.status === "Active" ? " bg-yellow-400" : " bg-red-600" )}>
4440
<p className={"font-bold text text-black text-nowrap"}>{loan.status === "Returned" ? "Returned" : loan.status === "Active" ? "Active" : "Due" }</p>
4541
</div>}

labman/src/middleware.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ export async function middleware(req: NextRequest) {
2222
return NextResponse.next();
2323
}
2424

25-
export const config = {matcher: ["/", "/users"]};
25+
export const config = {matcher: ["/", "/users", "/loans"]};

0 commit comments

Comments
 (0)