diff --git a/src/app/(jury)/jury/competitions/[roundId]/projects/[projectId]/evaluate/page.tsx b/src/app/(jury)/jury/competitions/[roundId]/projects/[projectId]/evaluate/page.tsx index ccdd869..19aa2bc 100644 --- a/src/app/(jury)/jury/competitions/[roundId]/projects/[projectId]/evaluate/page.tsx +++ b/src/app/(jury)/jury/competitions/[roundId]/projects/[projectId]/evaluate/page.tsx @@ -173,6 +173,24 @@ export default function JuryEvaluatePage({ params: paramsPromise }: PageProps) { } }) + // Initialize numeric criteria with midpoint values so slider visual matches stored value. + const criteriaInitializedRef = useRef(false) + useEffect(() => { + if (criteriaInitializedRef.current || criteria.length === 0) return + if (existingEvaluation?.criterionScoresJson) return + criteriaInitializedRef.current = true + + const defaults: Record = {} + for (const c of criteria) { + if (c.type === 'numeric') { + defaults[c.id] = Math.ceil((c.minScore + c.maxScore) / 2) + } + } + if (Object.keys(defaults).length > 0) { + setCriteriaValues((prev) => ({ ...defaults, ...prev })) + } + }, [criteria, existingEvaluation?.criterionScoresJson]) + // Build current form data for autosave const buildSavePayload = useCallback(() => { return { @@ -370,13 +388,17 @@ export default function JuryEvaluatePage({ params: paramsPromise }: PageProps) { } } - submitMutation.mutate({ - id: evaluationId, - criterionScoresJson: scoringMode === 'criteria' ? criteriaValues : {}, - globalScore: scoringMode === 'global' ? parseInt(globalScore, 10) : computedGlobalScore, - binaryDecision: scoringMode === 'binary' ? binaryDecision === 'accept' : true, - feedbackText: feedbackText || 'No feedback provided', - }) + try { + await submitMutation.mutateAsync({ + id: evaluationId, + criterionScoresJson: scoringMode === 'criteria' ? criteriaValues : {}, + globalScore: scoringMode === 'global' ? parseInt(globalScore, 10) : computedGlobalScore, + binaryDecision: scoringMode === 'binary' ? binaryDecision === 'accept' : true, + feedbackText: feedbackText || 'No feedback provided', + }) + } catch { + // Error toast already handled by onError callback + } } if (!round || !project) { @@ -840,7 +862,7 @@ export default function JuryEvaluatePage({ params: paramsPromise }: PageProps) { + ) : isVotingOpen && isDraft ? ( + ) : isVotingOpen ? ( ) : ( diff --git a/src/components/forms/evaluation-form.tsx b/src/components/forms/evaluation-form.tsx index c94f85e..d789c68 100644 --- a/src/components/forms/evaluation-form.tsx +++ b/src/components/forms/evaluation-form.tsx @@ -303,7 +303,10 @@ export function EvaluationForm({ // Submit handler const onSubmit = async (data: EvaluationFormData) => { - if (!currentEvaluationId) return + if (!currentEvaluationId) { + toast.error('Evaluation is still being created. Please wait a moment and try again.') + return + } try { await submit.mutateAsync({ @@ -325,6 +328,7 @@ export function EvaluationForm({ }) } catch (error) { console.error('Submit failed:', error) + toast.error(error instanceof Error ? error.message : 'Failed to submit evaluation. Please try again.') } } @@ -359,7 +363,7 @@ export function EvaluationForm({