diff --git a/components/proposals/components/UserProposalsTables/ProposalsTable.tsx b/components/proposals/components/UserProposalsTables/ProposalsTable.tsx index 27286dddfd..4fecb6c436 100644 --- a/components/proposals/components/UserProposalsTables/ProposalsTable.tsx +++ b/components/proposals/components/UserProposalsTables/ProposalsTable.tsx @@ -130,6 +130,11 @@ export function ProposalsTable({ {proposals.map((proposal) => { const result = proposal.currentEvaluation?.result; const statusLabel = result ? (result === 'pass' ? 'Passed' : 'Declined') : 'In progress'; + const rubricAnswers = proposal.currentEvaluation?.rubricAnswers || []; + const averageAnswer = rubricAnswers.length + ? rubricAnswers.reduce((acc, answer) => acc + answer.response.score, 0) / rubricAnswers.length + : 0; + return ( - {proposal.userReviewResult === 'pass' ? ( + {proposal.currentEvaluation?.type === 'rubric' && averageAnswer > 0 ? ( + {averageAnswer.toFixed(2)} + ) : proposal.userReviewResult === 'pass' ? ( ) : proposal.userReviewResult === 'fail' ? ( diff --git a/lib/proposals/getUserProposals.ts b/lib/proposals/getUserProposals.ts index 1aba616022..2a42aa46e7 100644 --- a/lib/proposals/getUserProposals.ts +++ b/lib/proposals/getUserProposals.ts @@ -10,12 +10,15 @@ import { getCurrentEvaluation, privateEvaluationSteps } from '@charmverse/core/p import { permissionsApiClient } from '../permissions/api/client'; +import type { ProposalRubricCriteriaAnswerWithTypedResponse, RubricRangeAnswer } from './rubric/interfaces'; + type CurrentEvaluation = { id: string; type: ProposalEvaluationType; dueDate: Date | null; title: string; result: ProposalEvaluationResult | null; + rubricAnswers: Pick[]; }; export type UserProposal = { @@ -296,7 +299,8 @@ export async function getUserProposals({ }, rubricAnswers: { select: { - userId: true + userId: true, + response: true } }, appealReviewers: { @@ -411,6 +415,9 @@ export async function getUserProposals({ evaluation.rubricAnswers.some((answer) => answer.userId === userId) || evaluation.appealReviews.some((review) => review.reviewerId === userId) ); + const hasReviewedRubricAnswers = proposal.evaluations.some((evaluation) => + evaluation.rubricAnswers.some((answer) => answer.userId === userId) + ); const userProposal = { id: proposal.id, @@ -423,7 +430,10 @@ export async function getUserProposals({ type: currentEvaluation.type, dueDate: currentEvaluation.dueDate || null, title: currentEvaluation.title, - result: currentEvaluation.result || null + result: currentEvaluation.result || null, + rubricAnswers: hasReviewedRubricAnswers + ? (currentEvaluation.rubricAnswers as { userId: string; response: RubricRangeAnswer }[]) + : [] } : undefined, updatedAt: proposal.page.updatedAt,