Skip to documentation
Design system / Sources & standards
Current repository source
editionReviewForm.tsx
src/components/reviews/editionReviewForm.tsx
This view contains the escaped source read during the deployment build. Code and policy text are unchanged. Markdown is shown as source, not rendered as a document. A new deployment refreshes the content.
"use client";
import type { EditionRubricCriterion, EditionReviewScoreRecord } from "@/lib/domains/console/reviews/contracts";
import { useEditionReviewForm } from "./useEditionReviewForm";
import { ReviewDrawer } from "./reviewDrawer";
import { SCORE_VALUES } from "@/lib/domains/console/evaluation-criteria/contracts";
import { genericScoreGuidance } from "@/lib/domains/console/evaluation-criteria/validation";
type EditionReviewFormProps = {
endpoint: string;
submissionId: string;
criteria: EditionRubricCriterion[];
existingScore: EditionReviewScoreRecord | null;
allowPromotion: boolean;
commentsEnabled?: boolean;
recommendedEnabled?: boolean;
canEdit?: boolean;
presentation?: "inline" | "drawer";
};
/** Review-owned organism; its server route supplies authorized values and mutation capability. */
export function EditionReviewForm({ endpoint, submissionId, criteria, existingScore, allowPromotion, commentsEnabled = true, recommendedEnabled = false, canEdit = true, presentation = "inline" }: EditionReviewFormProps) {
const behavior = useEditionReviewForm({ endpoint, submissionId, criteria, existingScore, allowPromotion: allowPromotion && recommendedEnabled, commentsEnabled, canEdit });
const form = <form onSubmit={behavior.submit} className="min-w-0 space-y-6">
{!canEdit ? <p role="status" className="rounded-md border bg-muted/20 p-3 text-sm">This review round is inactive. Your review is read-only.</p> : existingScore ? <p className="text-sm text-muted-foreground">Your review has been submitted. You can edit it while this round is active.</p> : null}
{behavior.error ? <p role="alert" className="rounded-md bg-destructive/10 p-3 text-sm text-destructive">{behavior.error}</p> : null}
<fieldset disabled={!canEdit || behavior.submitting} className="min-w-0 space-y-6">
<legend className="sr-only">Review fields</legend>
{criteria.map((criterion) => {
const guidance = criterion.scoreGuidance ?? genericScoreGuidance(criterion.label);
const instructions = criterion.judgeInstructions && criterion.judgeInstructions !== criterion.description ? criterion.judgeInstructions : null;
const guidePreview = instructions?.trim().split(/\r?\n/)[0] || `1: ${guidance["1"]}`;
return <fieldset key={criterion.id} className="min-w-0 space-y-2">
<legend className="font-medium">{criterion.label} <span className="text-sm font-normal text-muted-foreground">({criterion.weight}%)</span></legend>
{criterion.description ? <p className="text-sm text-muted-foreground">{criterion.description}</p> : null}
<details className="group/scoring-guide min-w-0 rounded-md border bg-muted/20 p-3 text-sm [overflow-wrap:anywhere]">
<summary className="cursor-pointer font-medium">Scoring guide{" "}
<span data-slot="scoring-guide-preview" className="mt-1 block truncate font-normal text-muted-foreground group-open/scoring-guide:hidden">{guidePreview}</span>
</summary>
{instructions ? <p className="mt-3 text-muted-foreground">{instructions}</p> : null}
{criterion.imageUrl ? <img src={criterion.imageUrl} alt="" className="mt-3 max-h-72 rounded-md object-contain" /> : null}
<ol className="mt-3 grid gap-2 sm:grid-cols-2">{SCORE_VALUES.map((score) => <li key={score} className={behavior.values[criterion.id] === String(score) ? "rounded bg-primary/10 p-2" : "p-2"}><strong>{score}:</strong> {guidance[String(score) as keyof typeof guidance]}</li>)}</ol>
</details>
<div className="flex flex-wrap gap-2" aria-label={`${criterion.label} score`}>
{SCORE_VALUES.map((value) => <label key={value} title={guidance[String(value) as keyof typeof guidance]} className="cursor-pointer rounded-md border px-3 py-2 has-[:checked]:border-primary has-[:checked]:bg-primary has-[:checked]:text-primary-foreground"><input className="sr-only" type="radio" name={criterion.id} value={value} checked={behavior.values[criterion.id] === String(value)} onChange={() => behavior.setCriterionValue(criterion.id, String(value))} />{value}</label>)}
</div>
</fieldset>; })}
{allowPromotion && recommendedEnabled ? <label className="flex items-center gap-2 text-sm"><input type="checkbox" checked={behavior.promoteToNextPhase} onChange={(event) => behavior.setPromoteToNextPhase(event.target.checked)} /> Promote to next round</label> : null}
{commentsEnabled ? <label className="block space-y-2 text-sm font-medium">Comments <span className="font-normal text-muted-foreground">(optional)</span><textarea className="block min-h-24 w-full rounded-md border bg-background p-3 font-normal" maxLength={2000} value={behavior.comments} onChange={(event) => behavior.setComments(event.target.value)} /></label> : null}
</fieldset>
{canEdit ? <button className="rounded-md bg-primary px-4 py-2 font-medium text-primary-foreground disabled:opacity-50" type="submit" disabled={behavior.submitting || behavior.isIncomplete}>{behavior.submitting ? "Saving..." : existingScore ? "Save changes" : "Submit review"}</button> : null}
</form>;
// Keep behavior above Sheet's mount boundary so closing never discards the draft.
return presentation === "drawer" ? <ReviewDrawer hasReview={existingScore !== null} canEdit={canEdit} busy={behavior.submitting}>{form}</ReviewDrawer> : form;
}
All sources and standards