brackt/app/components/league/ScoringPresetPicker.tsx
Chris Parsons e201ecd28a
Extract reusable league wizard components; wire settings page (#350)
* Extract reusable league wizard components; wire settings page (#103)

Extracts 9 domain components from new.tsx and $leagueId.settings.tsx into
app/components/league/ (each with a Storybook story), consolidates wizard
form-building into wizard-state.ts, and updates the settings page to use
the shared components instead of hand-rolled duplicates. new.tsx shrinks
from ~2000 → ~1280 lines.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Fix sports-season test: add participants to mock data

findDraftableSportsSeasons now returns participantCount, which requires
participants in the mock db response.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Fix sports-season test: loosen makeMockDb type to Record<string, unknown>[]

typeof mockSeasons became too strict after adding participants to the mock
data, breaking inline arrays in other tests that don't include participants.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-28 22:24:13 -07:00

108 lines
3.9 KiB
TypeScript

import { cn } from "~/lib/utils";
import { DEFAULT_SCORING_RULES, type ScoringRules } from "~/lib/scoring-types";
export const OMNIFANTASY_SCORING: ScoringRules = {
pointsFor1st: 80,
pointsFor2nd: 50,
pointsFor3rd: 30,
pointsFor4th: 30,
pointsFor5th: 20,
pointsFor6th: 20,
pointsFor7th: 20,
pointsFor8th: 20,
};
export const PLACEMENT_LABELS = [
{ key: "pointsFor1st" as const, label: "1st", color: "text-yellow-500" },
{ key: "pointsFor2nd" as const, label: "2nd", color: "text-slate-400" },
{ key: "pointsFor3rd" as const, label: "3rd", color: "text-orange-400" },
{ key: "pointsFor4th" as const, label: "4th", color: "text-sky-400" },
{ key: "pointsFor5th" as const, label: "5th", color: "text-green-500" },
{ key: "pointsFor6th" as const, label: "6th", color: "text-green-500" },
{ key: "pointsFor7th" as const, label: "7th", color: "text-emerald-400" },
{ key: "pointsFor8th" as const, label: "8th", color: "text-emerald-400" },
];
export interface ScoringPresetPickerProps {
preset: "brackt" | "omnifantasy" | "custom";
onPresetChange: (v: "brackt" | "omnifantasy" | "custom") => void;
rules: ScoringRules;
onRulesChange: (r: ScoringRules) => void;
disabled?: boolean;
}
export function ScoringPresetPicker({
preset,
onPresetChange,
rules,
onRulesChange,
disabled,
}: ScoringPresetPickerProps) {
const maxPoints = Math.max(...Object.values(rules));
function applyPreset(p: "brackt" | "omnifantasy") {
onPresetChange(p);
onRulesChange(p === "brackt" ? { ...DEFAULT_SCORING_RULES } : { ...OMNIFANTASY_SCORING });
}
function handleFieldChange(key: keyof ScoringRules, raw: string) {
const val = parseInt(raw, 10);
if (!isNaN(val) && val >= 0 && val <= 1000) {
onPresetChange("custom");
onRulesChange({ ...rules, [key]: val });
}
}
return (
<div className="space-y-4">
{/* Preset tabs */}
<div className="flex rounded-lg border border-border overflow-hidden">
{(["brackt", "omnifantasy", "custom"] as const).map((p) => (
<button
key={p}
type="button"
disabled={disabled}
onClick={() => p !== "custom" ? applyPreset(p) : onPresetChange("custom")}
className={cn(
"flex-1 py-2 text-sm font-medium transition-colors",
preset === p
? "bg-primary text-primary-foreground"
: "text-muted-foreground hover:bg-accent",
disabled && "opacity-50 cursor-not-allowed"
)}
>
{p === "brackt" ? "Brackt Default" : p === "omnifantasy" ? "Omnifantasy Default" : "Custom"}
</button>
))}
</div>
{/* Placement fields */}
<div className="space-y-3">
{PLACEMENT_LABELS.map(({ key, label, color }) => {
const val = rules[key];
const barWidth = maxPoints > 0 ? (val / maxPoints) * 100 : 0;
return (
<div key={key} className="flex items-center gap-3">
<span className={cn("text-sm font-medium w-8 shrink-0", color)}>{label}</span>
<div className="flex-1 h-2 bg-muted rounded-full overflow-hidden">
<div
className="h-full bg-primary rounded-full transition-all duration-200"
style={{ width: `${barWidth}%` }}
/>
</div>
<input
type="number"
value={val}
disabled={disabled}
onChange={(e) => handleFieldChange(key, e.target.value)}
min={0}
max={1000}
className="w-14 h-8 text-center text-sm font-semibold border border-input rounded-md bg-background focus:outline-none focus:ring-2 focus:ring-ring [appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none disabled:opacity-50"
/>
</div>
);
})}
</div>
</div>
);
}