fix(profile): label downward leadership ratings as rate subordinate
Seniors viewing a junior's profile saw 'Rate leadership', but that rating is stored as a subordinate review. The section now passes the rank direction to the dialog, which labels the trigger, title, copy and toast accordingly.
This commit is contained in:
parent
2f81cc9ede
commit
502eef5228
3 changed files with 21 additions and 8 deletions
|
|
@ -610,6 +610,7 @@ export default async function ProfilePage({ params }: ProfilePageProps) {
|
||||||
latestMissionRows={latestMissionRows}
|
latestMissionRows={latestMissionRows}
|
||||||
canSubmitEvaluation={canSubmitEvaluation}
|
canSubmitEvaluation={canSubmitEvaluation}
|
||||||
canViewSubordinate={canViewSubordinate}
|
canViewSubordinate={canViewSubordinate}
|
||||||
|
ratingDirection={rankGap}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* ── Dossier ────────────────────────────────────────── */}
|
{/* ── Dossier ────────────────────────────────────────── */}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import {
|
||||||
isPerformanceLevelId,
|
isPerformanceLevelId,
|
||||||
type PerformanceLevelId,
|
type PerformanceLevelId,
|
||||||
} from "@/lib/evaluations/levels";
|
} from "@/lib/evaluations/levels";
|
||||||
|
import type { RankDirection } from "@/lib/evaluations/ranks";
|
||||||
import { submitEvaluation } from "@/app/(frontend)/profile/[username]/actions";
|
import { submitEvaluation } from "@/app/(frontend)/profile/[username]/actions";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Combobox } from "@/components/ui/combobox";
|
import { Combobox } from "@/components/ui/combobox";
|
||||||
|
|
@ -37,6 +38,7 @@ import type { EvaluationMissionOption } from "./evaluation-types";
|
||||||
interface LeadershipEvaluationDialogProps {
|
interface LeadershipEvaluationDialogProps {
|
||||||
readonly username: string;
|
readonly username: string;
|
||||||
readonly missions: readonly EvaluationMissionOption[];
|
readonly missions: readonly EvaluationMissionOption[];
|
||||||
|
readonly direction: RankDirection;
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatMissionDate(value: string): string {
|
function formatMissionDate(value: string): string {
|
||||||
|
|
@ -50,8 +52,11 @@ function formatMissionDate(value: string): string {
|
||||||
export function LeadershipEvaluationDialog({
|
export function LeadershipEvaluationDialog({
|
||||||
username,
|
username,
|
||||||
missions,
|
missions,
|
||||||
|
direction,
|
||||||
}: LeadershipEvaluationDialogProps) {
|
}: LeadershipEvaluationDialogProps) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const isUpward = direction === "upward";
|
||||||
|
const triggerLabel = isUpward ? "Rate leadership" : "Rate subordinate";
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const [missionId, setMissionId] = useState("");
|
const [missionId, setMissionId] = useState("");
|
||||||
const [level, setLevel] = useState<PerformanceLevelId | "">("");
|
const [level, setLevel] = useState<PerformanceLevelId | "">("");
|
||||||
|
|
@ -99,7 +104,7 @@ export function LeadershipEvaluationDialog({
|
||||||
|
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
reset();
|
reset();
|
||||||
toast.success("Leadership rating saved");
|
toast.success(isUpward ? "Leadership rating saved" : "Subordinate rating saved");
|
||||||
router.refresh();
|
router.refresh();
|
||||||
} catch (caught) {
|
} catch (caught) {
|
||||||
setError(caught instanceof Error ? caught.message : "Could not save the rating.");
|
setError(caught instanceof Error ? caught.message : "Could not save the rating.");
|
||||||
|
|
@ -120,16 +125,16 @@ export function LeadershipEvaluationDialog({
|
||||||
<DialogTrigger asChild>
|
<DialogTrigger asChild>
|
||||||
<Button type="button" size="sm" variant="outline">
|
<Button type="button" size="sm" variant="outline">
|
||||||
<PencilIcon data-icon="inline-start" />
|
<PencilIcon data-icon="inline-start" />
|
||||||
Rate leadership
|
{triggerLabel}
|
||||||
</Button>
|
</Button>
|
||||||
</DialogTrigger>
|
</DialogTrigger>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>Rate leadership</DialogTitle>
|
<DialogTitle>{triggerLabel}</DialogTitle>
|
||||||
<DialogDescription>
|
<DialogDescription>
|
||||||
Submit a new rating or update your existing rating for one completed mission. Ratings
|
{isUpward
|
||||||
follow rank: only operators strictly above or below your own rank can be rated here.
|
? "Rate this senior operator for one completed mission you both attended. Your rating is included anonymously in the leadership aggregate."
|
||||||
Your rating is included anonymously.
|
: "Rate this junior operator for one completed mission you both attended. Your rating is recorded as a command review and shown only to operators ranked above them."}
|
||||||
</DialogDescription>
|
</DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import {
|
||||||
} from "@/components/ui/item";
|
} from "@/components/ui/item";
|
||||||
import { Separator } from "@/components/ui/separator";
|
import { Separator } from "@/components/ui/separator";
|
||||||
import { getLeadershipDisplayLabel, PERFORMANCE_LEVELS } from "@/lib/evaluations/levels";
|
import { getLeadershipDisplayLabel, PERFORMANCE_LEVELS } from "@/lib/evaluations/levels";
|
||||||
|
import type { RankDirection } from "@/lib/evaluations/ranks";
|
||||||
import { LeadershipEvaluationDialog } from "./LeadershipEvaluationDialog";
|
import { LeadershipEvaluationDialog } from "./LeadershipEvaluationDialog";
|
||||||
import type {
|
import type {
|
||||||
EvaluationMissionOption,
|
EvaluationMissionOption,
|
||||||
|
|
@ -29,6 +30,7 @@ interface LeadershipEvaluationSectionProps {
|
||||||
readonly latestMissionRows: readonly LatestMissionRow[];
|
readonly latestMissionRows: readonly LatestMissionRow[];
|
||||||
readonly canSubmitEvaluation: boolean;
|
readonly canSubmitEvaluation: boolean;
|
||||||
readonly canViewSubordinate: boolean;
|
readonly canViewSubordinate: boolean;
|
||||||
|
readonly ratingDirection: RankDirection | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const PERFORMANCE_GRADIENT = `linear-gradient(to right, ${[...PERFORMANCE_LEVELS]
|
const PERFORMANCE_GRADIENT = `linear-gradient(to right, ${[...PERFORMANCE_LEVELS]
|
||||||
|
|
@ -56,6 +58,7 @@ export function LeadershipEvaluationSection({
|
||||||
latestMissionRows,
|
latestMissionRows,
|
||||||
canSubmitEvaluation,
|
canSubmitEvaluation,
|
||||||
canViewSubordinate,
|
canViewSubordinate,
|
||||||
|
ratingDirection,
|
||||||
}: LeadershipEvaluationSectionProps) {
|
}: LeadershipEvaluationSectionProps) {
|
||||||
return (
|
return (
|
||||||
<section className="flex flex-col gap-3" aria-labelledby="leadership-evaluation-heading">
|
<section className="flex flex-col gap-3" aria-labelledby="leadership-evaluation-heading">
|
||||||
|
|
@ -73,8 +76,12 @@ export function LeadershipEvaluationSection({
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle className="flex flex-wrap items-center justify-between gap-3 text-base">
|
<CardTitle className="flex flex-wrap items-center justify-between gap-3 text-base">
|
||||||
<span>Leadership performance</span>
|
<span>Leadership performance</span>
|
||||||
{canSubmitEvaluation && eligibleMissions.length > 0 && (
|
{canSubmitEvaluation && ratingDirection && eligibleMissions.length > 0 && (
|
||||||
<LeadershipEvaluationDialog username={username} missions={eligibleMissions} />
|
<LeadershipEvaluationDialog
|
||||||
|
username={username}
|
||||||
|
missions={eligibleMissions}
|
||||||
|
direction={ratingDirection}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
</CardTitle>
|
</CardTitle>
|
||||||
<CardDescription>
|
<CardDescription>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue