-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: coordinators, and bunch other stuff
- Loading branch information
1 parent
4eb8acf
commit 40242bb
Showing
32 changed files
with
1,128 additions
and
219 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
prisma/migrations/20240503202424_add_amount_to_the_database/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "payments" ADD COLUMN "amount" DOUBLE PRECISION NOT NULL DEFAULT 0; |
2 changes: 2 additions & 0 deletions
2
prisma/migrations/20240504063133_add_coordinator_role/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterEnum | ||
ALTER TYPE "UserRole" ADD VALUE 'COORDINATOR'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
Warnings: | ||
- You are about to drop the column `amount` on the `payments` table. All the data in the column will be lost. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "payments" DROP COLUMN "amount"; |
2 changes: 2 additions & 0 deletions
2
prisma/migrations/20240504154822_add_back_amount/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "payments" ADD COLUMN "amount" DOUBLE PRECISION NOT NULL DEFAULT 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"use client"; | ||
import React from "react"; | ||
import { DataTable } from "../../../coordinators/_components/datatable"; | ||
import { columns } from "../../../coordinators/_components/columns"; | ||
|
||
async function getData(event: string) { | ||
const response = await fetch(`/api/coordinators/${event}`); | ||
return response.json(); | ||
} | ||
|
||
function PerEventPage({ params }: { params: { event: string } }) { | ||
const [data, setData] = React.useState([]); | ||
React.useEffect(() => { | ||
getData(params.event).then(setData); | ||
}, [params.event]); | ||
return ( | ||
<> | ||
<h1>{decodeURIComponent(params.event)} Participants</h1> | ||
<DataTable columns={columns} data={data} /> | ||
</> | ||
); | ||
} | ||
|
||
export default PerEventPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
"use client"; | ||
|
||
import React from "react"; | ||
import Link from "next/link"; | ||
import { | ||
Table, | ||
TableBody, | ||
TableCaption, | ||
TableCell, | ||
TableHead, | ||
TableHeader, | ||
TableRow, | ||
} from "@/components/ui/table"; | ||
|
||
async function getData() { | ||
const response = await fetch("/api/coordinators"); | ||
return response.json(); | ||
} | ||
|
||
export default function AdminPage() { | ||
const [data, setData] = React.useState< | ||
{ name: string; registrations: string }[] | ||
>([]); | ||
React.useEffect(() => { | ||
getData().then(setData); | ||
}, []); | ||
return ( | ||
<> | ||
<Table> | ||
<TableCaption>List of Events</TableCaption> | ||
<TableHeader> | ||
<TableRow> | ||
<TableHead>Event Name</TableHead> | ||
<TableHead>Registrations</TableHead> | ||
</TableRow> | ||
</TableHeader> | ||
<TableBody> | ||
{data.map((event, i) => ( | ||
<Link | ||
key={i} | ||
href={`/admin/events/${event.name}`} | ||
legacyBehavior | ||
> | ||
<TableRow> | ||
<div style={{ display: "contents" }}> | ||
<TableCell>{event.name}</TableCell> | ||
<TableCell>{event.registrations}</TableCell> | ||
</div> | ||
</TableRow> | ||
</Link> | ||
))} | ||
</TableBody> | ||
</Table> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,20 @@ | ||
"use client"; | ||
|
||
import React from "react"; | ||
import { Payment, User, UserRole } from "@prisma/client"; | ||
import { Payment, User } from "@prisma/client"; | ||
import { DataTable } from "./_components/datatable"; | ||
import { columns } from "./_components/columnsUsers"; | ||
import { useSession } from "next-auth/react"; | ||
|
||
async function getData() { | ||
const response = await fetch("/api/admin"); | ||
return response.json(); | ||
} | ||
|
||
export default function AdminPage() { | ||
const { data: session } = useSession(); | ||
const [data, setData] = React.useState<(User & { payment: Payment })[]>([]); | ||
|
||
React.useEffect(() => { | ||
getData().then(setData); | ||
}, []); | ||
|
||
if (!session) { | ||
return <div>Unauthorized</div>; | ||
} | ||
|
||
if (session.user.role !== UserRole.ADMIN) { | ||
return <div>Forbidden</div>; | ||
} | ||
return <DataTable columns={columns} data={data} />; | ||
} |
Oops, something went wrong.