diff --git a/src/app/evaluations/[id]/page.tsx b/src/app/evaluations/[id]/page.tsx index 552f087..0494d9c 100644 --- a/src/app/evaluations/[id]/page.tsx +++ b/src/app/evaluations/[id]/page.tsx @@ -116,9 +116,25 @@ export default function EvaluationDetailPage() { if (!evaluation) return; setEvaluation((e) => { if (!e) return null; - const scores = e.dimensionScores.map((ds) => - ds.dimensionId === dimensionId ? { ...ds, ...data } : ds - ); + const existing = e.dimensionScores.find((ds) => ds.dimensionId === dimensionId); + const dim = e.template?.dimensions?.find((d) => d.id === dimensionId); + const scores = existing + ? e.dimensionScores.map((ds) => + ds.dimensionId === dimensionId ? { ...ds, ...data } : ds + ) + : [ + ...e.dimensionScores, + { + id: `temp-${dimensionId}`, + dimensionId, + score: (data as { score?: number }).score ?? null, + justification: (data as { justification?: string }).justification ?? null, + examplesObserved: (data as { examplesObserved?: string }).examplesObserved ?? null, + confidence: (data as { confidence?: string }).confidence ?? null, + candidateNotes: (data as { candidateNotes?: string }).candidateNotes ?? null, + dimension: dim ?? { id: dimensionId, slug: "", title: "", rubric: "" }, + }, + ]; const next = { ...e, dimensionScores: scores }; if (data.score !== undefined) { setTimeout(() => handleSave(next, { skipRefresh: true }), 0);