Skip to content

Commit

Permalink
Merge pull request #61 from emil-webkom/debugAndAeresemiler
Browse files Browse the repository at this point in the history
Debug and aeresemiler
  • Loading branch information
Mauritzskog authored Sep 3, 2024
2 parents e0d473f + fd546b5 commit a827ea7
Show file tree
Hide file tree
Showing 20 changed files with 571 additions and 310 deletions.
13 changes: 13 additions & 0 deletions frontend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,19 @@ model LavterskelArrangement {
@@index([userId])
}

model aeresEmiler {
id String @id @default(cuid())
type aeresEmilerType
navn String
aar Int
}

enum aeresEmilerType {
AERESEMILER
FORTJENESTEMEDALJE
}

enum BookedItem {
KONTOR
ONE_SOUNDBOX
Expand Down
Binary file added frontend/public/image/Komiteer/komiteer.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions frontend/src/app/api/aeresemiler/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { NextRequest, NextResponse } from "next/server";
import { db } from "@/lib/db";

export async function GET(request: NextRequest) {
try {
const aeresemilere = await db.aeresEmiler.findMany();
return NextResponse.json(aeresemilere, { status: 200 });
} catch (error) {
console.error("Error fetching aeresEmilere:", error);
return NextResponse.json(
{ error: "Failed to fetch aeresEmilere" },
{ status: 500 }
);
}
}

// Takes a json body-object on the format {id: String}
export async function DELETE(request: NextRequest) {
const body = await request.json();
const deleteId = body.id;

if (!deleteId) {
return NextResponse.json({ error: "ID is required" }, { status: 400 });
}

try {
const aeresemilere = await db.aeresEmiler.delete({
where: { id: deleteId }
});
return NextResponse.json(
{
message: "Deleted aeresEmilere",
aeresemilere: [aeresemilere]
},
{ status: 200 },
);
} catch (error) {
console.log("Error deleting aeresEmilere", error);
return NextResponse.json({ error: error }, { status: 500 });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,33 @@ export async function DELETE(request: NextRequest) {
);
}
}

export async function GET(request: NextRequest, { params }: { params: { id: string }}) {
const komiteId = params.id
if (!komiteId) {
return NextResponse.json(
{ error: "Komite ID is required" },
{ status: 400 }
);
}

try {
const komite = await db.komite.findUnique({
where: { id: komiteId },
});
if (!komite) {
return NextResponse.json(
{ error: "Komite not found" },
{ status: 404 }
);
}

return NextResponse.json(komite, { status: 200 });
} catch (error) {
console.error("Error fetching komite from database:", error);
return NextResponse.json(
{ message: "Internal server error" },
{ status: 500 }
);
}
}
20 changes: 20 additions & 0 deletions frontend/src/app/api/komite/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import fetchKomite from "@/utils/komite/fetchers";
import { NextRequest, NextResponse } from "next/server";


export async function GET(request: NextRequest){
try {
const data = await fetchKomite();

if (!data) {
return NextResponse.json({ message: "No data found" }, { status: 404 });
}
return NextResponse.json(data, { status: 200 });
} catch (error) {
console.error("Error fetching komite-data:", error);
return NextResponse.json(
{ message: "Internal server error" },
{ status: 500 },
);
}
}
176 changes: 162 additions & 14 deletions frontend/src/app/for_studenten/arkiv/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,43 @@ import MenuCard, {
MenuCardProps,
} from "@/components/ForStudenten/ui/menu-card";
import MenuCardView from "@/components/ForStudenten/ui/menu-card-view";
import SmallTransissionPCSPC from "@/components/hero/transissions/smallTransissionPCSPC";
import useFetch from "@/hooks/use-fetch";
import { AeresEmiler } from "@/schemas/aeresEmiler";
import { HandCoins, ScrollText, Archive, NotebookPen } from "lucide-react";
import { useState } from "react";

const ArkivPage = () => {
const { data, loading, error } = useFetch<AeresEmiler[] | null>(
"/api/aeresemiler",
);

// Define the page size (number of entries per page)
const PAGE_SIZE = 7;

// Pagination state
const [currentPage, setCurrentPage] = useState(0);

const sortedData = data ? [...data].sort((a, b) => b.aar - a.aar) : [];

// Calculate the start and end indices of the current page
const startIndex = currentPage * PAGE_SIZE;
const endIndex = startIndex + PAGE_SIZE;
const paginatedData = sortedData.slice(startIndex, endIndex);
const totalPages = Math.ceil(sortedData.length / PAGE_SIZE);

const handleNextPage = () => {
if (currentPage < totalPages - 1) {
setCurrentPage(currentPage + 1);
}
};

const handlePrevPage = () => {
if (currentPage > 0) {
setCurrentPage(currentPage - 1);
}
};

const cards: MenuCardProps[] = [
{
title: "Vedtekter",
Expand All @@ -28,7 +62,7 @@ const ArkivPage = () => {
title: "Rapporter",
logo: <Archive />,
description:
"Se arkivet for en oversikt over gamle rapporter f. eks. diplomundersøkelsen og trivselsrapporter. ",
"Se arkivet for en oversikt over gamle rapporter f. eks. diplomundersøkelsen og trivselsrapporter.",
buttonLabel: "Se rapporter",
href: "https://www.youtube.com/watch?v=xvFZjo5PgG0&ab_channel=Duran",
},
Expand All @@ -42,28 +76,142 @@ const ArkivPage = () => {
},
];

if (loading) {
return (
<div className="w-full flex items-center justify-center">
<div className="animate-ping h-4 w-4 bg-blue-400 rounded-full"></div>
</div>
);
}

if (error) {
return (
<div className="w-full flex items-center justify-center">
<p className="text-red-500">Failed to load data: {error}</p>
</div>
);
}

return (
<div className="flex flex-col items-center justify-center p-12 gap-y-6">
<div className="flex flex-col space-y-4">
<h1 className=" text-white text-center font-semibold text-4xl w-full">
<div className="flex flex-col items-center justify-center">
<div className="flex max-w-[512px] flex-col justify-center items-center space-y-4 pb-0 p-12">
<h1 className="text-white text-center font-semibold text-4xl w-full">
Viktige dokumenter
</h1>
<p className="text-white text-md text-center">
Her ligger alle viktige dokumenter som Emil publiserer hvert år. For å
se Diplomundersøkelsen må du trykke på “Se rapporter”.{" "}
se Diplomundersøkelsen må du trykke på “Se rapporter”.
</p>
</div>
<MenuCardView cards={cards}></MenuCardView>
<div className="p-8">
<MenuCardView cards={cards} />
</div>
<SmallTransissionPCSPC />
<div className="w-full flex flex-col items-center justify-center text-white bg-[#225654] px-2 lg:px-4 gap-y-4 pb-4 rounded-b-lg">
<div className="max-w-[512px] w-full px-4 lg:px-8">
<h1 className="text-white text-center font-semibold py-2 text-xl sm:text-2xl w-full">
Wall of fame
</h1>
<p className="text-white text-sm text-left">
Hvert år deler linjeforeningen ut ærespris og fortjenestemedajle til
medlemmene som har bemerket seg i linjeforeningen. Under finner du
emil's wall of fame
</p>
</div>
<div className="p-2 lg:px-4 rounded-md items-center justify-center w-full lg:w-2/3 bg-[#25504E]">
{paginatedData.length > 0 ? (
<div className="p-4">
<div className="overflow-x-auto w-full">
{/* Table for larger screens */}
<div className="hidden lg:block">
<table className="bg-[#25504E] text-white rounded-md w-full table-fixed">
<thead>
<tr className="bg-[#1F3A38]">
<th className="px-2 lg:px-6 py-3 text-left text-sm font-medium uppercase tracking-wider border-b border-primary rounded-l-md w-[15%]">
År
</th>
<th className="px-2 lg:px-6 py-3 text-left text-sm font-medium uppercase tracking-wider border-b border-primary w-[35%]">
Type
</th>
<th className="px-2 lg:px-6 py-3 text-left text-sm font-medium uppercase tracking-wider border-b border-primary rounded-r-md w-[50%]">
Navn
</th>
</tr>
</thead>
<tbody>
{paginatedData.map((aeresemiler) => (
<tr key={aeresemiler.id}>
<td className="px-2 lg:px-6 py-4 border-b border-[#003A42]">
{aeresemiler.aar}
</td>
<td className="px-2 lg:px-6 py-4 border-b border-[#003A42]">
{aeresemiler.type.charAt(0).toUpperCase() +
aeresemiler.type.slice(1).toLowerCase()}
</td>
<td className="px-2 lg:px-6 py-4 border-b border-[#003A42] whitespace-normal break-words">
{aeresemiler.navn}
</td>
</tr>
))}
</tbody>
</table>
</div>
{/* Card layout for smaller screens */}
<div className="lg:hidden">
{paginatedData.map((aeresemiler) => (
<div
key={aeresemiler.id}
className="bg-[#25504E] text-white mb-4 p-4 rounded-md shadow-md"
>
<div className="text-lg font-semibold">
År: {aeresemiler.aar}
</div>
<div className="text-md font-medium mt-2">
Type:{" "}
{aeresemiler.type.charAt(0).toUpperCase() +
aeresemiler.type.slice(1).toLowerCase()}
</div>
<div className="text-md mt-2">
Navn: {aeresemiler.navn}
</div>
</div>
))}
</div>
</div>

<div className="flex justify-between mt-4 w-full">
<button
onClick={handlePrevPage}
disabled={currentPage === 0}
className={`px-4 py-2 bg-[#1F3A38] text-white rounded-md ${
currentPage === 0 ? "opacity-50 cursor-not-allowed" : ""
}`}
>
Forrige
</button>
<span className="text-white flex items-center">
Side {currentPage + 1} av {totalPages}
</span>
<button
onClick={handleNextPage}
disabled={currentPage >= totalPages - 1}
className={`px-4 py-2 bg-[#1F3A38] text-white rounded-md ${
currentPage >= totalPages - 1
? "opacity-50 cursor-not-allowed"
: ""
}`}
>
Neste
</button>
</div>
</div>
) : (
<p className="text-white">No data available</p>
)}
</div>
</div>
</div>
);
};

export default ArkivPage;

// <MenuCard
// href="https://youtube.com"
// logo={<Speaker />}
// title="Soundbox"
// description="Emil har hele 2 soundboxer som studenter kan låne! Book en soundbox til en valgt dato eller tid. Ventetiden kan være lang så vær obs på å booke i god tid!"
// buttonLabel="Book Soundbox"
// ></MenuCard>
10 changes: 5 additions & 5 deletions frontend/src/app/for_studenten/arrangement/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ const ForStudentenPage = () => {

return (
<div className=" flex flex-col justify-center w-full text-white">
<div className="w-full pt-12 px-12">
<div className="w-full pt-12 px-4 lg:px-8">
<img
src="/image/Komiteer/HS/HSfelles.jpg"
alt="Hovedstyret fellesbilde"
className="rounded-md object-cover w-full h-[19rem]"
src="/image/arrangement/Arrangement.jpg"
alt="Arrangement forsidebilde"
className="rounded-md object-cover object-[0_15%] w-full h-[19rem]"
/>
</div>
<div className="flex flex-col justify-center items-center gap-y-3 py-3">
Expand Down Expand Up @@ -207,7 +207,7 @@ const ForStudentenPage = () => {
</g>
</svg>
</div>
<div className="flex flex-col max-w-[512px] space-y-3 text-sm lg:text-l px-12">
<div className="flex flex-col max-w-[512px] space-y-3 text-sm lg:text-l px-4">
<p>
Linjeforeningen arrangerer en rekke ulike arrangementer og disse kan
være for kun komiteene eller hele linjeforeningen. Ofte arrangerer
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/app/for_studenten/booking/soundbox/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,11 @@ const SoundboxPage = () => {
<div className="flex flex-col lg:flex-row justify-center items-center lg:gap-y-4 pb-4 w-full">
<div className="w-full px-2 pb-8">
<div className="text-xl sm:text-2xl font-bold flex h-auto lg:h-[650px] flex-col items-center gap-y-4">
<p className="w-full flex justify-center">Bookinger</p>
<p className="text-xs sm:text-sm font-light px-4 sm:px-16 text-center">
Hvis en dato ikke er markert i kalenderen er begge soundboxene
ledige.
</p>
<div className="flex flex-wrap justify-start font-normal px-4 sm:px-8">
<div className="flex max-w-[512px] flex-wrap justify-start font-normal px-4 sm:px-8">
<div className="flex gap-x-2 items-center">
<div className="w-2 h-2 bg-yellow-500 rounded-full"></div>
<span className="text-xs sm:text-sm">En booket soundbox</span>
Expand Down
Loading

0 comments on commit a827ea7

Please sign in to comment.