Skip to content

Commit ed5dc93

Browse files
authored
Merge pull request #53 from IMTEL/editingFunc
Editing functionality and numerous input and UI improvements
2 parents b49f838 + 3ce08bf commit ed5dc93

23 files changed

Lines changed: 884 additions & 404 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- AlterTable
2+
ALTER TABLE "Borrower" ADD COLUMN "status" TEXT;
3+
4+
-- AlterTable
5+
ALTER TABLE "Equipment" ADD COLUMN "status" TEXT;
6+
7+
-- AlterTable
8+
ALTER TABLE "Item" ALTER COLUMN "status" DROP NOT NULL;
9+
10+
-- AlterTable
11+
ALTER TABLE "Loan" ALTER COLUMN "status" DROP NOT NULL;
12+
13+
-- AlterTable
14+
ALTER TABLE "User" ADD COLUMN "status" TEXT;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
Warnings:
3+
4+
- Made the column `status` on table `Borrower` required. This step will fail if there are existing NULL values in that column.
5+
- Made the column `status` on table `Equipment` required. This step will fail if there are existing NULL values in that column.
6+
- Made the column `status` on table `Item` required. This step will fail if there are existing NULL values in that column.
7+
- Made the column `status` on table `Loan` required. This step will fail if there are existing NULL values in that column.
8+
9+
*/
10+
UPDATE "Borrower" SET "status" = 'Active' WHERE "status" IS NULL;
11+
UPDATE "Equipment" SET "status" = 'Active' WHERE "status" IS NULL;
12+
13+
-- AlterTable
14+
ALTER TABLE "Borrower" ALTER COLUMN "status" SET NOT NULL;
15+
16+
-- AlterTable
17+
ALTER TABLE "Equipment" ALTER COLUMN "status" SET NOT NULL;
18+
19+
-- AlterTable
20+
ALTER TABLE "Item" ALTER COLUMN "status" SET NOT NULL;
21+
22+
-- AlterTable
23+
ALTER TABLE "Loan" ALTER COLUMN "status" SET NOT NULL;

labman/prisma/schema.prisma

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ model Equipment {
2727
name String @unique
2828
image String?
2929
createdAt DateTime @default(now())
30+
status String
3031
items Item[]
3132
category EquipmentCategory @relation(fields: [categoryId], references: [id])
3233
}
@@ -60,6 +61,7 @@ model User {
6061
username String @unique
6162
createdAt DateTime @default(now())
6263
latestActivity DateTime @default(now())
64+
status String?
6365
sessions Session[]
6466
loans Loan[]
6567
}
@@ -70,6 +72,7 @@ model Borrower {
7072
phone String? @unique
7173
email String? @unique
7274
note String?
75+
status String
7376
creationDate DateTime @default(now())
7477
loans Loan[]
7578
}

labman/src/app/(main)/globals.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ html {
8383
}
8484

8585
.item-view {
86-
@apply bg-brand-950 rounded-md p-3 h-180 overflow-y-auto
86+
@apply bg-brand-950 rounded-md p-3 h-149 overflow-y-auto
8787
}
8888

8989
.side-form-label {

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import NavBar from "@/components/core/NavBar";
55
//import {PopupProvider} from "./popupProvider"
66
import {getUser} from "@/lib/actions";
77
import SideBar from "@/components/core/SideBar";
8+
import {SideViewProvider} from "@/app/sideViewContext";
89

910
const spartan = League_Spartan({
1011
subsets: ["latin"],
@@ -27,20 +28,20 @@ export default async function RootLayout({
2728

2829
return (
2930
<html lang="en" className={spartan.variable}>
30-
3131
<body className="font-spartan h-screen">
32-
33-
<div className="flex h-screen">
34-
35-
<aside className="w-73 h-screen">
36-
< SideBar />
37-
</aside>
38-
39-
<main className="flex-1 overflow-auto">
40-
<NavBar username={user?.username ?? "Unknown"} />
41-
{children}
42-
</main>
43-
</div>
32+
<SideViewProvider initialType="">
33+
<div className="flex h-screen">
34+
35+
<aside className="w-73 h-screen">
36+
< SideBar />
37+
</aside>
38+
39+
<main className="flex-1 overflow-auto">
40+
<NavBar username={user?.username ?? "Unknown"} />
41+
{children}
42+
</main>
43+
</div>
44+
</SideViewProvider>
4445
</body>
4546
</html>
4647
);

labman/src/app/(main)/loans/page.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,23 @@ export default async function Loans() {
1515
}
1616
const loans = await prisma.loan.findMany({
1717
include: {
18+
borrower: true,
1819
item: {
1920
include: {
20-
equipment: true
21+
equipment: {
22+
include: {
23+
category: true,
24+
items: {
25+
include: {
26+
loans: true,
27+
activeLoan: true
28+
}
29+
}
30+
31+
}
32+
}
2133
}
22-
},
23-
borrower: true
34+
}
2435
}
2536
});
2637

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

Lines changed: 0 additions & 22 deletions
This file was deleted.

labman/src/app/api/equipment/route.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export async function POST(req: Request) {
3333
name,
3434
image,
3535
categoryId,
36+
status: "Active",
3637
items: {
3738
create: {
3839
status: "Available"

labman/src/app/sideViewContext.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"use client";
2+
3+
import React, { createContext, useContext, useState } from "react";
4+
5+
type SideViewCtx = {
6+
sideView: string;
7+
setSideView: React.Dispatch<React.SetStateAction<string>>;
8+
};
9+
10+
const SideViewContext = createContext<SideViewCtx | null>(null);
11+
12+
export function SideViewProvider({ children, initialType = "",}: { children: React.ReactNode; initialType?: string; }) {
13+
const [sideView, setSideView] = useState(initialType);
14+
15+
return (
16+
<SideViewContext.Provider value={{ sideView, setSideView }}>
17+
{children}
18+
</SideViewContext.Provider>
19+
);
20+
}
21+
22+
export function useSideView() {
23+
const ctx = useContext(SideViewContext);
24+
if (!ctx) throw new Error("useString must be used within <SideViewProvider>");
25+
return ctx;
26+
}

labman/src/components/core/Card.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import {LoanClass} from "@/types/Loan";
66
interface CardProps {
77
user?: UserClass
88
loan?: LoanClass;
9+
setSideView?: (view: string) => void;
10+
setSelectedLoanId?: (id: number | null) => void;
911
}
1012

1113
// TODO: Could have a button to reactivate a loan, not a priority right now
1214

13-
export default function Card({ loan, user }: CardProps) {
15+
export default function Card({ loan, user, setSelectedLoanId, setSideView }: CardProps) {
1416

1517
let {name, start, last} = {name: "", start: "", last: ""};
1618

@@ -31,9 +33,9 @@ export default function Card({ loan, user }: CardProps) {
3133
}
3234

3335
return(
34-
<div className="bg-brand-950 border-white border-[1px] rounded-[18px] w-fit">
36+
<div className="bg-brand-950 border-white border-[1px] rounded-[18px] ">
3537
<div className="border-b-white border-b-[1px] flex gap-2 ">
36-
<h1 className="text-3xl font-bold pl-3 pt-2.5">{name}</h1>
38+
<h1 className="text-3xl font-bold pl-3 pt-2.5 text-nowrap">{name}</h1>
3739
{loan && <span className={"mt-3 text-3xl"}>|</span>}
3840
{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>}
3941
{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" )}>
@@ -67,11 +69,15 @@ export default function Card({ loan, user }: CardProps) {
6769
</div>}
6870

6971
<div className="mb-3 ml-4 mt-5 flex gap-2">
70-
<button className="button bg-blue-600">Edit</button>
71-
<button onClick={() => loan ? loan.delete() : user ? user.delete() : alert("Error")} className="button bg-red-600">Delete</button>
72+
<button className="button bg-blue-600" onClick={() => {
73+
if (setSideView && setSelectedLoanId && loan) {
74+
setSideView("loanEdit");
75+
setSelectedLoanId(loan.id);
76+
}
77+
}}>Edit</button>
78+
<button onClick={() => loan ? loan.delete() : user ? user.delete() : alert("Error")} className="button bg-red-600">{user && user.status === "deleting" ? "Deleting..." : "Delete" }</button>
7279
{ loan && loan.status != "Returned" && <button onClick={() => loan.return()} className="button bg-green-500 ml-auto mr-3">Return</button>}
7380
</div>
74-
7581
</div>
7682
)
7783
}

0 commit comments

Comments
 (0)