Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/proposal see more #120

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 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.40",
"version": "0.1.41",
"private": true,
"type": "module",
"scripts": {
Expand Down
32 changes: 29 additions & 3 deletions src/app/api/funding-rounds/[id]/consideration-proposals/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import logger from "@/logging";
import { OCVVotesService } from "@/services/OCVVotesService";
import { ProposalStatusMoveService } from "@/services/ProposalStatusMoveService";
import type { OCVVoteData, OCVVote } from '@/types/consideration';
import { UserService } from "@/services";

// Add this helper function to safely parse OCV vote data
function parseOCVVoteData(data: JsonValue | null | undefined): OCVVoteData {
Expand Down Expand Up @@ -49,6 +50,7 @@ export async function GET(
}

const fundingRoundId = (await params).id;
const userService = new UserService(prisma);

// Get the funding round with topic and reviewer groups
const fundingRound = await prisma.fundingRound.findUnique({
Expand Down Expand Up @@ -92,6 +94,7 @@ export async function GET(
include: {
user: {
select: {
id: true,
metadata: true
}
},
Expand Down Expand Up @@ -158,15 +161,29 @@ export async function GET(
);

// Transform the data to match the expected format
const formattedProposals = proposals.map(p => {
const formattedProposals = await Promise.all(proposals.map(async p => {
const voteCounts = proposalVoteCounts.find(vc => vc.proposalId === p.id)?.voteStats;
const linkedAccounts = await userService.getLinkedAccounts(p.user.id);
const linkedAccountsMetadata = linkedAccounts.map(account => ({
id: account.id,
authSource: (account.metadata as UserMetadata)?.authSource || {
type: '',
id: '',
username: ''
}
}));

return {
id: p.id,
proposalName: p.proposalName,
submitter: ((p.user.metadata as unknown) as UserMetadata).username,
abstract: p.abstract,
status: p.considerationVotes[0]?.decision?.toLowerCase() || 'pending',
motivation: p.motivation,
rationale: p.rationale,
deliveryRequirements: p.deliveryRequirements,
securityAndPerformance: p.securityAndPerformance,
budgetRequest: p.budgetRequest,
userVote: p.considerationVotes[0] ? {
decision: p.considerationVotes[0].decision,
feedback: p.considerationVotes[0].feedback
Expand All @@ -185,9 +202,18 @@ export async function GET(
},
reviewerEligible: false
},
currentPhase: p.status
currentPhase: p.status,
email: p.email || '',
submitterMetadata: {
authSource: {
type: ((p.user.metadata as unknown) as UserMetadata)?.authSource?.type || '',
id: ((p.user.metadata as unknown) as UserMetadata)?.authSource?.id || '',
username: ((p.user.metadata as unknown) as UserMetadata)?.authSource?.username || ''
},
linkedAccounts: linkedAccountsMetadata
}
};
});
}));

// Sort proposals:
// 1. Consideration phase pending first
Expand Down
73 changes: 64 additions & 9 deletions src/app/api/funding-rounds/[id]/submitted-proposals/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,37 @@ import prisma from "@/lib/prisma";
import { getOrCreateUserFromRequest } from "@/lib/auth";
import { ProposalStatus, Prisma } from "@prisma/client";
import logger from "@/logging";
import { UserMetadata } from "@/services/UserService";
import { UserService } from "@/services";

interface FormattedProposal {
export interface SumbmittedProposalsJSON {
id: number;
proposalName: string;
abstract: string;
budgetRequest: number;
createdAt: Date;
status: ProposalStatus;
submitter: string;
motivation: string;
rationale: string;
deliveryRequirements: string;
securityAndPerformance: string;
email: string;
submitterMetadata: {
authSource: {
type: string;
id: string;
username: string;
};
linkedAccounts?: Array<{
id: string;
authSource: {
type: string;
id: string;
username: string;
};
}>;
};
}

// Type for the raw proposal from database
Expand All @@ -22,7 +44,13 @@ interface RawProposal {
budgetRequest: Prisma.Decimal;
createdAt: Date;
status: ProposalStatus;
motivation: string;
rationale: string;
deliveryRequirements: string;
securityAndPerformance: string;
email: string;
user: {
id: string;
metadata: Prisma.JsonValue;
};
}
Expand Down Expand Up @@ -56,6 +84,7 @@ export async function GET(
}

const fundingRoundId = (await params).id;
const userService = new UserService(prisma);

// Get all proposals for this funding round
const proposals = await prisma.proposal.findMany({
Expand All @@ -66,6 +95,7 @@ export async function GET(
include: {
user: {
select: {
id: true,
metadata: true
}
}
Expand All @@ -76,14 +106,39 @@ export async function GET(
});

// Transform the proposals to include user information
const formattedProposals = proposals.map((proposal: RawProposal): FormattedProposal => ({
id: proposal.id,
proposalName: proposal.proposalName,
abstract: proposal.abstract,
budgetRequest: proposal.budgetRequest.toNumber(),
createdAt: proposal.createdAt,
status: proposal.status,
submitter: getUsernameFromMetadata(proposal.user.metadata)
const formattedProposals = await Promise.all(proposals.map(async (proposal: RawProposal): Promise<SumbmittedProposalsJSON> => {
const linkedAccounts = await userService.getLinkedAccounts(proposal.user.id);
const linkedAccountsMetadata = linkedAccounts.map(account => ({
id: account.id,
authSource: (account.metadata as UserMetadata)?.authSource || {
type: '',
id: '',
username: ''
}
}));

return {
id: proposal.id,
proposalName: proposal.proposalName,
abstract: proposal.abstract,
budgetRequest: proposal.budgetRequest.toNumber(),
createdAt: proposal.createdAt,
status: proposal.status,
submitter: hasUsername(proposal.user.metadata) ? proposal.user.metadata.username : 'Unknown',
motivation: proposal.motivation,
rationale: proposal.rationale,
deliveryRequirements: proposal.deliveryRequirements,
securityAndPerformance: proposal.securityAndPerformance,
email: proposal.email || '',
submitterMetadata: {
authSource: {
type: (proposal.user.metadata as UserMetadata)?.authSource?.type || '',
id: (proposal.user.metadata as UserMetadata)?.authSource?.id || '',
username: (proposal.user.metadata as UserMetadata)?.authSource?.username || ''
},
linkedAccounts: linkedAccountsMetadata
}
};
}));

return NextResponse.json(formattedProposals);
Expand Down
114 changes: 102 additions & 12 deletions src/components/ConsiderationProposalList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -618,12 +618,57 @@ export function ConsiderationProposalList({ fundingRoundId, fundingRoundMEFId, f
{expanded[proposal.id] ? (
<>
<p className="text-muted-foreground mb-4">{proposal.abstract}</p>
<Link
href={`/proposals/${proposal.id}`}
className="text-primary hover:underline"
>
View full proposal details ↗
</Link>
<div className="space-y-4">
<div>
<h3 className="text-xl font-semibold mb-2">Motivation</h3>
<p className="text-muted-foreground">{proposal.motivation}</p>
</div>
<div>
<h3 className="text-xl font-semibold mb-2">Rationale</h3>
<p className="text-muted-foreground">{proposal.rationale}</p>
</div>
<div>
<h3 className="text-xl font-semibold mb-2">Delivery Requirements</h3>
<p className="text-muted-foreground">{proposal.deliveryRequirements}</p>
</div>
<div>
<h3 className="text-xl font-semibold mb-2">Security & Performance</h3>
<p className="text-muted-foreground">{proposal.securityAndPerformance}</p>
</div>
<div>
<h3 className="text-xl font-semibold mb-2">Budget Request</h3>
<p className="text-muted-foreground">
{proposal.budgetRequest.toLocaleString()} MINA
</p>
</div>
<div>
<h3 className="text-xl font-semibold mb-2">Contact Information</h3>
<div className="space-y-2">
{/* Show Discord info if author is a Discord user */}
{proposal.submitterMetadata?.authSource?.type === 'discord' ? (
<p className="text-muted-foreground">
Discord: {proposal.submitterMetadata.authSource.username}
</p>
) : (
/* Check for linked Discord account */
proposal.submitterMetadata?.linkedAccounts?.some(account =>
account.authSource.type === 'discord'
) ? (
<p className="text-muted-foreground">
Discord: {proposal.submitterMetadata.linkedAccounts.find(account =>
account.authSource.type === 'discord'
)?.authSource.username} (linked account)
</p>
) : (
<p className="text-muted-foreground text-sm italic">
No Discord account linked
</p>
)
)}
<p className="text-muted-foreground">Email: {proposal.email}</p>
</div>
</div>
</div>
</>
) : (
<p className="text-muted-foreground line-clamp-3">{proposal.abstract}</p>
Expand Down Expand Up @@ -837,12 +882,57 @@ export function ConsiderationProposalList({ fundingRoundId, fundingRoundMEFId, f
{expanded[proposal.id] ? (
<>
<p className="text-muted-foreground mb-4">{proposal.abstract}</p>
<Link
href={`/proposals/${proposal.id}`}
className="text-primary hover:underline"
>
View full proposal details ↗
</Link>
<div className="space-y-4">
<div>
<h3 className="text-xl font-semibold mb-2">Motivation</h3>
<p className="text-muted-foreground">{proposal.motivation}</p>
</div>
<div>
<h3 className="text-xl font-semibold mb-2">Rationale</h3>
<p className="text-muted-foreground">{proposal.rationale}</p>
</div>
<div>
<h3 className="text-xl font-semibold mb-2">Delivery Requirements</h3>
<p className="text-muted-foreground">{proposal.deliveryRequirements}</p>
</div>
<div>
<h3 className="text-xl font-semibold mb-2">Security & Performance</h3>
<p className="text-muted-foreground">{proposal.securityAndPerformance}</p>
</div>
<div>
<h3 className="text-xl font-semibold mb-2">Budget Request</h3>
<p className="text-muted-foreground">
{proposal.budgetRequest.toLocaleString()} MINA
</p>
</div>
<div>
<h3 className="text-xl font-semibold mb-2">Contact Information</h3>
<div className="space-y-2">
{/* Show Discord info if author is a Discord user */}
{proposal.submitterMetadata?.authSource?.type === 'discord' ? (
<p className="text-muted-foreground">
Discord: {proposal.submitterMetadata.authSource.username}
</p>
) : (
/* Check for linked Discord account */
proposal.submitterMetadata?.linkedAccounts?.some(account =>
account.authSource.type === 'discord'
) ? (
<p className="text-muted-foreground">
Discord: {proposal.submitterMetadata.linkedAccounts.find(account =>
account.authSource.type === 'discord'
)?.authSource.username} (linked account)
</p>
) : (
<p className="text-muted-foreground text-sm italic">
No Discord account linked
</p>
)
)}
<p className="text-muted-foreground">Email: {proposal.email}</p>
</div>
</div>
</div>
</>
) : (
<p className="text-muted-foreground line-clamp-3">{proposal.abstract}</p>
Expand Down
6 changes: 3 additions & 3 deletions src/components/ProposalDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -269,17 +269,17 @@ const fetchProposal = useCallback(async () => {
</div>

<div>
<h3 className="text-xl font-semibold mb-2">Delivery requirements</h3>
<h3 className="text-xl font-semibold mb-2">Delivery Requirements</h3>
<p className="text-muted-foreground">{proposal.deliveryRequirements}</p>
</div>

<div>
<h3 className="text-xl font-semibold mb-2">Security and Performance considerations</h3>
<h3 className="text-xl font-semibold mb-2">Security and Performance Considerations</h3>
<p className="text-muted-foreground">{proposal.securityAndPerformance}</p>
</div>

<div>
<h3 className="text-xl font-semibold mb-2">Budget request</h3>
<h3 className="text-xl font-semibold mb-2">Budget Request</h3>
<p className="text-muted-foreground">{proposal.budgetRequest.toString()} MINA</p>
</div>

Expand Down
Loading