Skip to content

Commit

Permalink
Merge pull request #95 from MinaFoundation/feature/ocv-consideration-…
Browse files Browse the repository at this point in the history
…votes-dashboard

Feature/ocv consideration votes dashboard
  • Loading branch information
iluxonchik authored Dec 19, 2024
2 parents 58fd131 + 583b08b commit a37e575
Show file tree
Hide file tree
Showing 11 changed files with 634 additions and 13 deletions.
29 changes: 27 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pgt-web-app",
"version": "0.1.25",
"version": "0.1.26",
"private": true,
"type": "module",
"scripts": {
Expand Down Expand Up @@ -33,6 +33,7 @@
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-label": "^2.1.0",
"@radix-ui/react-popover": "^1.1.2",
"@radix-ui/react-progress": "^1.1.1",
"@radix-ui/react-scroll-area": "^1.2.1",
"@radix-ui/react-select": "^2.1.2",
"@radix-ui/react-separator": "^1.1.0",
Expand Down
23 changes: 23 additions & 0 deletions src/app/admin/ocv-votes/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { OCVVotesTable } from "@/components/admin/ocv-votes/OCVVotesTable";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Metadata } from "next";

export const metadata: Metadata = {
title: "OCV Votes | MEF Admin",
description: "Monitor OCV consideration votes and project eligibility",
};

export default function OCVVotesPage() {
return (
<div className="container mx-auto p-6 max-w-7xl">
<Card>
<CardHeader>
<CardTitle className="text-2xl font-bold">OCV Consideration Votes</CardTitle>
</CardHeader>
<CardContent>
<OCVVotesTable />
</CardContent>
</Card>
</div>
);
}
42 changes: 42 additions & 0 deletions src/app/api/admin/ocv-votes/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { NextResponse } from "next/server";
import prisma from "@/lib/prisma";
import { getOrCreateUserFromRequest } from "@/lib/auth";
import { AdminService } from "@/services/AdminService";
import { OCVVotesService } from "@/services/OCVVotesService";
import { ApiResponse } from "@/lib/api-response";
import { AppError } from "@/lib/errors";
import { AuthErrors } from "@/constants/errors";

const adminService = new AdminService(prisma);
const ocvVotesService = new OCVVotesService(prisma);

export async function GET(request: Request) {
try {
const user = await getOrCreateUserFromRequest(request);
if (!user) {
throw AppError.unauthorized(AuthErrors.UNAUTHORIZED);
}

const isAdmin = await adminService.checkAdminStatus(user.id, user.linkId);
if (!isAdmin) {
throw AppError.forbidden(AuthErrors.FORBIDDEN);
}

const { searchParams } = new URL(request.url);
const page = Math.max(1, Number(searchParams.get('page')) || 1);
const pageSize = Math.max(1, Number(searchParams.get('pageSize')) || 25);
const sortField = searchParams.get('sortField') || 'updatedAt';
const sortOrder = (searchParams.get('sortOrder') || 'desc') as 'asc' | 'desc';

const votes = await ocvVotesService.getOCVVotes(
page,
pageSize,
sortField,
sortOrder
);

return ApiResponse.success(votes);
} catch (error) {
return ApiResponse.error(error);
}
}
2 changes: 0 additions & 2 deletions src/app/api/admin/worker-heartbeats/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ export async function GET(request: Request) {
},
});

logger.info(`Fetched ${heartbeats.length} worker heartbeats (page ${page}/${totalPages})`);

// Return paginated response
return ApiResponse.success({
data: heartbeats,
Expand Down
6 changes: 6 additions & 0 deletions src/components/AdminDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ export function AdminDashboardComponent() {
description: "Monitor background job statuses",
icon: <Activity className="h-5 w-5" />,
href: "/admin/worker-heartbeats"
},
{
title: "Consideration OCV Votes",
description: "Monitor OCV consideration votes",
icon: <Vote className="h-5 w-5" />,
href: "/admin/ocv-votes"
}
]

Expand Down
Loading

0 comments on commit a37e575

Please sign in to comment.