2026-04-01 17:56:42 -07:00
|
|
|
import { useState, useEffect } from "react";
|
2025-10-12 21:54:49 -07:00
|
|
|
import { Form, Link } from "react-router";
|
|
|
|
|
import type { Route } from "./+types/admin.sports-seasons.$id.participants";
|
2026-03-10 12:10:52 -07:00
|
|
|
|
2026-03-21 13:41:39 -07:00
|
|
|
import { logger } from "~/lib/logger";
|
2026-05-02 10:29:28 -07:00
|
|
|
import { findSportsSeasonById, findSportsSeasonsBySportId } from "~/models/sports-season";
|
2026-03-27 01:09:04 -07:00
|
|
|
import {
|
|
|
|
|
findParticipantsBySportsSeasonId,
|
|
|
|
|
findParticipantByName,
|
2025-10-12 21:54:49 -07:00
|
|
|
createParticipant,
|
2026-03-27 01:09:04 -07:00
|
|
|
deleteParticipant,
|
2026-04-01 17:56:42 -07:00
|
|
|
updateParticipant,
|
2026-05-02 10:29:28 -07:00
|
|
|
copyParticipantsFromSeason,
|
Canonical tournament layer: schema + backfill (1/2) (#365)
* refactor(schema): rename per-window tables to season_* prefix
Renames participants, participant_expected_values, participant_qualifying_totals,
participant_results, participant_surface_elos to season_* prefixed names.
Renames event_results.participant_id to season_participant_id.
Phase 1a of canonical tournament layer migration.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* refactor: rename participant.ts model file to season-participant.ts
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* refactor(models): update model layer to use renamed schema exports
Updated all model files to use the renamed schema exports from Task 1:
- participants → seasonParticipants
- participantExpectedValues → seasonParticipantExpectedValues
- participantQualifyingTotals → seasonParticipantQualifyingTotals
- participantResults → seasonParticipantResults
- participantSurfaceElos → seasonParticipantSurfaceElos
- eventResults.participantId → eventResults.seasonParticipantId
- db.query relation accessors updated
- Relation field .participant → .seasonParticipant where applicable
- Import paths updated: ./participant → ./season-participant
Files updated (14 model files + 3 test files):
- draft-pick.ts
- draft-utils.ts
- event-result.ts
- group-stage-match.ts
- participant-result.ts
- qualifying-points.ts
- scoring-calculator.ts
- scoring-event.ts
- sports-season.ts
- surface-elo.ts
- team-score-events.ts
- cs2-major-stage.ts
- golf-skills.ts
- participant-expected-value.ts
- __tests__/sports-season.clone.test.ts
- __tests__/auto-pick.test.ts
- __tests__/executeAutoPick.timer.test.ts
Typecheck errors decreased: 779 → 499 (280 fewer)
All model file errors related to renamed schemas resolved.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* refactor(routes): update route layer to use renamed schema exports
- Update model import from ~/models/participant to ~/models/season-participant
- Rename schema.participants to schema.seasonParticipants
- Rename schema.participantResults to schema.seasonParticipantResults
- Rename db.query.participants to db.query.seasonParticipants
- Update 9 route files and 1 test file
Affected files:
- admin.sports-seasons.$id.events.$eventId.bracket.server.ts
- admin.sports-seasons.$id.participants.tsx
- api/draft.force-manual-pick.ts
- api/draft.make-pick.ts
- api/draft.replace-pick.ts
- api/seasons.$seasonId.draft.ts
- leagues/$leagueId.draft-board.$seasonId.tsx
- leagues/$leagueId.sports-seasons.$sportsSeasonId.server.ts
- admin/__tests__/sports-seasons-participants.test.ts
Error count reduced from 499 to 453 (46 errors fixed).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* refactor(routes): update route files for schema rename
Update route imports from ~/models/participant to ~/models/season-participant
and fix references to .participant/.participantId on event results to use
.seasonParticipant/.seasonParticipantId after schema rename.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* refactor(services): update simulators and services for renamed schema
Update all simulators, services, and server files to use renamed schema tables:
- participants → seasonParticipants
- participantExpectedValues → seasonParticipantExpectedValues
- participantResults → seasonParticipantResults
- eventResults.participantId → eventResults.seasonParticipantId
Files updated:
- 20 sport simulators (NBA, NHL, NFL, MLB, etc.)
- probability-updater.ts
- standings-sync/index.ts
- sports-data-sync.server.ts
- server/socket.ts
Typecheck errors reduced from 365 to 0.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* migration: rename per-window tables to season_* prefix
* fix(tests): update mock query keys after participants table rename
Change mock db.query.participants to db.query.seasonParticipants in test
files to match the schema rename from commit 66145a9. This fixes
"Cannot read properties of undefined (reading 'findFirst'/'findMany')"
errors that occurred when production code queries db.query.seasonParticipants
but test mocks only defined the old participants key.
Files updated:
- app/services/simulations/__tests__/world-cup-simulator.test.ts
- app/routes/api/__tests__/draft.force-manual-pick.test.ts
- app/routes/api/__tests__/draft.force-manual-pick.timer-mode.test.ts
- app/routes/api/__tests__/draft.make-pick.timer-mode.test.ts
- server/__tests__/timer-autodraft.test.ts
- app/models/__tests__/team-score-events.test.ts
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* fix(tests): update remaining mock paths and keys after schema rename
* fix(tests): final two mock stragglers after schema rename
- draft-pick.test.ts: assertion on db.query.participantQualifyingTotals
- process-match-result.test.ts: mock key participants → seasonParticipants
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* chore: add post-phase1a baseline capture (temp, for diff verification)
* chore: capture pre-migration baselines
* chore: remove post-phase1a capture helper after verification
* schema: add canonical tournament & participant tables
Adds tournaments, participants (canonical), tournament_results, and
participant_surface_elos (canonical). Adds nullable tournament_id to
scoring_events and nullable participant_id to season_participants.
Phase 1b of canonical tournament layer migration.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* feat(models): add canonical tournament, participant, result, surface-elo models
Adds CRUD modules for the canonical tables created in commit 775b905.
Each module mirrors existing app/models conventions (database() from
~/database/context, schema from ~/database/schema, mock-based tests).
Key implementation notes:
- participant.ts exports use "Canonical" prefix (CanonicalParticipant,
createCanonicalParticipant, etc.) to avoid collision with existing
season-participant.ts exports
- All four models include comprehensive unit tests following the
audit-log.test.ts pattern
- Tests use mocked db responses (no real database access)
- Upsert functions use onConflictDoUpdate for appropriate unique constraints
Part of Phase 1b of canonical tournament layer migration.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* migration: create canonical tables, add nullable FKs
* scripts: add extractTournamentIdentity helper for backfill
Pure function that derives canonical (name, year) identity from a
scoring_events row, stripping trailing 4-digit years from the name or
falling back to eventDate. Used by the Phase 2 backfill to group
per-window events into canonical tournaments.
* scripts: add backfill orchestrator for canonical layer
Populates canonical tournaments, participants, tournament_results, and
participant_surface_elos from per-window data for qualifying-points
sports. Skips already-linked rows, is idempotent, and supports dry-run
mode.
Critical invariants enforced by the implementation:
- qualifying_points_awarded is never copied to tournament_results
- season_participant_qualifying_totals is never touched
- conflicting surface-Elo values between windows raise a loud error
(recorded in report.errors) rather than overwriting
* scripts: add backfill CLI with dry-run default
Wires backfill-canonical-layer.ts to a CLI entry point exposed as
`npm run backfill:canonical`. Defaults to --dry-run; requires --apply
to actually write. Supports --sport=<uuid> to limit to a single sport.
Exits 2 if the backfill reports errors (e.g., surface-Elo conflicts).
* fix(backfill-cli): wrap runBackfill in DatabaseContext.run
The orchestrator uses database() from ~/database/context, which requires
AsyncLocalStorage to be populated. Wrap the CLI invocation with
DatabaseContext.run(db, ...) using server/db's cached connection pool.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* fix(backfill-cli): exit 0 on success so pg pool doesn't block
The cached postgres connection pool keeps the Node event loop open after
main() returns. Explicit process.exit(0) on success mirrors the pattern
in scripts/capture-baseline.ts.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
---------
Co-authored-by: Chris Parsons <chrisp@extrahop.com>
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-01 20:13:18 -07:00
|
|
|
} from "~/models/season-participant";
|
2025-10-12 21:54:49 -07:00
|
|
|
import { Button } from "~/components/ui/button";
|
|
|
|
|
import { Input } from "~/components/ui/input";
|
|
|
|
|
import { Label } from "~/components/ui/label";
|
2025-10-15 21:21:33 -07:00
|
|
|
import { Textarea } from "~/components/ui/textarea";
|
2025-10-12 21:54:49 -07:00
|
|
|
import {
|
|
|
|
|
Card,
|
|
|
|
|
CardContent,
|
|
|
|
|
CardDescription,
|
|
|
|
|
CardHeader,
|
|
|
|
|
CardTitle,
|
|
|
|
|
} from "~/components/ui/card";
|
|
|
|
|
import {
|
|
|
|
|
Table,
|
|
|
|
|
TableBody,
|
|
|
|
|
TableCell,
|
|
|
|
|
TableHead,
|
|
|
|
|
TableHeader,
|
|
|
|
|
TableRow,
|
|
|
|
|
} from "~/components/ui/table";
|
2026-05-02 10:29:28 -07:00
|
|
|
import { Plus, Trash2, ArrowLeft, Pencil, Check, X, Copy } from "lucide-react";
|
|
|
|
|
import {
|
|
|
|
|
Select,
|
|
|
|
|
SelectContent,
|
|
|
|
|
SelectItem,
|
|
|
|
|
SelectTrigger,
|
|
|
|
|
SelectValue,
|
|
|
|
|
} from "~/components/ui/select";
|
2025-10-12 21:54:49 -07:00
|
|
|
|
2026-03-10 12:10:52 -07:00
|
|
|
export function meta({ data }: Route.MetaArgs): Route.MetaDescriptors {
|
|
|
|
|
return [{ title: `Participants — ${data?.sportsSeason?.name ?? "Sports Season"} - Brackt Admin` }];
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-12 21:54:49 -07:00
|
|
|
export async function loader({ params }: Route.LoaderArgs) {
|
|
|
|
|
const sportsSeason = await findSportsSeasonById(params.id);
|
|
|
|
|
|
|
|
|
|
if (!sportsSeason) {
|
|
|
|
|
throw new Response("Sports season not found", { status: 404 });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const participants = await findParticipantsBySportsSeasonId(params.id);
|
|
|
|
|
|
2026-05-02 10:29:28 -07:00
|
|
|
const sameSportSeasons = (await findSportsSeasonsBySportId(sportsSeason.sportId))
|
|
|
|
|
.filter((s) => s.id !== params.id)
|
|
|
|
|
.toSorted((a, b) => b.year - a.year);
|
|
|
|
|
|
2025-10-12 21:54:49 -07:00
|
|
|
// Type assertion since we know the sport relation is included
|
|
|
|
|
return {
|
|
|
|
|
sportsSeason: sportsSeason as typeof sportsSeason & { sport: { id: string; name: string; type: string; slug: string } },
|
2026-05-02 10:29:28 -07:00
|
|
|
participants,
|
|
|
|
|
sameSportSeasons,
|
2025-10-12 21:54:49 -07:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function action({ request, params }: Route.ActionArgs) {
|
|
|
|
|
const formData = await request.formData();
|
|
|
|
|
const intent = formData.get("intent");
|
|
|
|
|
|
|
|
|
|
if (intent === "delete") {
|
|
|
|
|
const participantId = formData.get("participantId");
|
|
|
|
|
if (typeof participantId === "string") {
|
|
|
|
|
await deleteParticipant(participantId);
|
|
|
|
|
}
|
|
|
|
|
return { success: true };
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-09 09:51:16 -04:00
|
|
|
if (intent === "update-participant") {
|
|
|
|
|
const participantId = formData.get("participantId");
|
|
|
|
|
const newName = formData.get("newName");
|
|
|
|
|
const newExternalId = formData.get("newExternalId");
|
|
|
|
|
|
|
|
|
|
if (typeof participantId !== "string") {
|
|
|
|
|
return { error: "Invalid participant", intent: "update-participant" };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (typeof newName !== "string" || !newName.trim()) {
|
|
|
|
|
return { error: "Name is required", intent: "update-participant" };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const trimmedName = newName.trim();
|
|
|
|
|
const existing = await findParticipantByName(params.id, trimmedName);
|
|
|
|
|
if (existing && existing.id !== participantId) {
|
|
|
|
|
return { error: `"${trimmedName}" already exists in this season.`, intent: "update-participant" };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const externalIdValue =
|
|
|
|
|
typeof newExternalId === "string" && newExternalId.trim()
|
|
|
|
|
? newExternalId.trim()
|
|
|
|
|
: null;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await updateParticipant(participantId, { name: trimmedName, externalId: externalIdValue });
|
|
|
|
|
return { success: true, intent: "update-participant" };
|
|
|
|
|
} catch (error) {
|
|
|
|
|
logger.error("Error updating participant:", error);
|
|
|
|
|
return { error: "Failed to update participant. Please try again.", intent: "update-participant" };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-01 17:56:42 -07:00
|
|
|
if (intent === "update-name") {
|
|
|
|
|
const participantId = formData.get("participantId");
|
|
|
|
|
const newName = formData.get("newName");
|
|
|
|
|
|
|
|
|
|
if (typeof participantId !== "string") {
|
|
|
|
|
return { error: "Invalid participant", intent: "update-name" };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (typeof newName !== "string" || !newName.trim()) {
|
|
|
|
|
return { error: "Name is required", intent: "update-name" };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const trimmedName = newName.trim();
|
|
|
|
|
const existing = await findParticipantByName(params.id, trimmedName);
|
|
|
|
|
if (existing && existing.id !== participantId) {
|
|
|
|
|
return { error: `"${trimmedName}" already exists in this season.`, intent: "update-name" };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
await updateParticipant(participantId, { name: trimmedName });
|
|
|
|
|
return { success: true, intent: "update-name" };
|
|
|
|
|
} catch (error) {
|
|
|
|
|
logger.error("Error updating participant:", error);
|
|
|
|
|
return { error: "Failed to update participant. Please try again.", intent: "update-name" };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-15 21:21:33 -07:00
|
|
|
// Bulk add participants
|
|
|
|
|
if (intent === "bulk") {
|
|
|
|
|
const bulkNames = formData.get("bulkNames");
|
2026-03-27 01:09:04 -07:00
|
|
|
|
2025-10-15 21:21:33 -07:00
|
|
|
if (typeof bulkNames !== "string" || !bulkNames.trim()) {
|
|
|
|
|
return { error: "Please enter at least one participant name" };
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-27 01:09:04 -07:00
|
|
|
// Dedup case-insensitively, preserving first occurrence's casing
|
|
|
|
|
const seenKeys = new Map<string, string>();
|
|
|
|
|
for (const raw of bulkNames.split("\n").map(n => n.trim()).filter(n => n.length > 0)) {
|
|
|
|
|
const key = raw.toLowerCase();
|
|
|
|
|
if (!seenKeys.has(key)) seenKeys.set(key, raw);
|
|
|
|
|
}
|
|
|
|
|
const names = [...seenKeys.values()];
|
2025-10-15 21:21:33 -07:00
|
|
|
|
|
|
|
|
if (names.length === 0) {
|
|
|
|
|
return { error: "Please enter at least one participant name" };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
2026-03-27 01:09:04 -07:00
|
|
|
const existingParticipants = await findParticipantsBySportsSeasonId(params.id);
|
|
|
|
|
const existingNames = new Set(existingParticipants.map(p => p.name.toLowerCase()));
|
|
|
|
|
|
|
|
|
|
const skipped: string[] = [];
|
|
|
|
|
let added = 0;
|
|
|
|
|
|
2025-10-15 21:21:33 -07:00
|
|
|
for (const name of names) {
|
2026-03-27 01:09:04 -07:00
|
|
|
if (existingNames.has(name.toLowerCase())) {
|
|
|
|
|
skipped.push(name);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2025-10-15 21:21:33 -07:00
|
|
|
await createParticipant({
|
|
|
|
|
sportsSeasonId: params.id,
|
|
|
|
|
name,
|
|
|
|
|
shortName: null,
|
|
|
|
|
externalId: null,
|
2026-02-19 11:26:40 -08:00
|
|
|
expectedValue: "0",
|
2025-10-15 21:21:33 -07:00
|
|
|
});
|
2026-03-27 01:09:04 -07:00
|
|
|
added++;
|
2025-10-15 21:21:33 -07:00
|
|
|
}
|
|
|
|
|
|
2026-03-27 01:09:04 -07:00
|
|
|
return { success: true, count: added, skipped };
|
2025-10-15 21:21:33 -07:00
|
|
|
} catch (error) {
|
2026-03-21 13:41:39 -07:00
|
|
|
logger.error("Error creating participants:", error);
|
2025-10-15 21:21:33 -07:00
|
|
|
return { error: "Failed to add participants. Please try again." };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-02 10:29:28 -07:00
|
|
|
if (intent === "copy-from-season") {
|
|
|
|
|
const sourceSeasonId = formData.get("sourceSeasonId");
|
|
|
|
|
if (typeof sourceSeasonId !== "string" || !sourceSeasonId) {
|
|
|
|
|
return { error: "Please select a source season.", intent: "copy-from-season" };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const targetSeason = await findSportsSeasonById(params.id);
|
|
|
|
|
if (!targetSeason) {
|
|
|
|
|
return { error: "Target season not found.", intent: "copy-from-season" };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const sourceSeason = await findSportsSeasonById(sourceSeasonId);
|
|
|
|
|
if (!sourceSeason) {
|
|
|
|
|
return { error: "Source season not found.", intent: "copy-from-season" };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sourceSeason.sportId !== targetSeason.sportId) {
|
|
|
|
|
return { error: "Source season must be the same sport.", intent: "copy-from-season" };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const result = await copyParticipantsFromSeason(sourceSeasonId, params.id);
|
|
|
|
|
return { success: true, intent: "copy-from-season", copyResult: result };
|
|
|
|
|
} catch (error) {
|
|
|
|
|
logger.error("Error copying participants:", error);
|
|
|
|
|
return { error: "Failed to copy participants. Please try again.", intent: "copy-from-season" };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-15 21:21:33 -07:00
|
|
|
// Add single participant
|
2025-10-12 21:54:49 -07:00
|
|
|
const name = formData.get("name");
|
|
|
|
|
|
|
|
|
|
if (typeof name !== "string" || !name.trim()) {
|
|
|
|
|
return { error: "Participant name is required" };
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-27 01:09:04 -07:00
|
|
|
const trimmedName = name.trim();
|
|
|
|
|
const existing = await findParticipantByName(params.id, trimmedName);
|
|
|
|
|
if (existing) {
|
|
|
|
|
return { error: `"${trimmedName}" already exists in this season.` };
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-12 21:54:49 -07:00
|
|
|
try {
|
|
|
|
|
await createParticipant({
|
|
|
|
|
sportsSeasonId: params.id,
|
2026-03-27 01:09:04 -07:00
|
|
|
name: trimmedName,
|
2025-10-15 21:21:33 -07:00
|
|
|
shortName: null,
|
2025-10-12 21:54:49 -07:00
|
|
|
externalId: null,
|
2026-02-19 11:26:40 -08:00
|
|
|
expectedValue: "0",
|
2025-10-12 21:54:49 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return { success: true };
|
|
|
|
|
} catch (error) {
|
2026-03-21 13:41:39 -07:00
|
|
|
logger.error("Error creating participant:", error);
|
2025-10-12 21:54:49 -07:00
|
|
|
return { error: "Failed to add participant. Please try again." };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function ManageParticipants({ loaderData, actionData }: Route.ComponentProps) {
|
2026-05-02 10:29:28 -07:00
|
|
|
const { sportsSeason, participants, sameSportSeasons } = loaderData;
|
2026-04-09 09:51:16 -04:00
|
|
|
const [editing, setEditing] = useState<{ id: string; name: string; externalId: string } | null>(null);
|
2026-05-02 10:29:28 -07:00
|
|
|
const [sourceSeasonId, setSourceSeasonId] = useState("");
|
2026-04-01 17:56:42 -07:00
|
|
|
|
|
|
|
|
const cancelEdit = () => setEditing(null);
|
|
|
|
|
|
2025-10-15 21:21:33 -07:00
|
|
|
// Use success state to reset forms by changing the key
|
|
|
|
|
const formKey = actionData?.success ? Date.now() : 'static';
|
2025-10-12 21:54:49 -07:00
|
|
|
|
2026-04-01 17:56:42 -07:00
|
|
|
useEffect(() => {
|
2026-04-09 09:51:16 -04:00
|
|
|
if (actionData?.success && (actionData?.intent === "update-name" || actionData?.intent === "update-participant")) {
|
2026-04-01 17:56:42 -07:00
|
|
|
cancelEdit();
|
|
|
|
|
}
|
|
|
|
|
}, [actionData]);
|
|
|
|
|
|
2025-10-12 21:54:49 -07:00
|
|
|
return (
|
|
|
|
|
<div className="p-8">
|
|
|
|
|
<div className="max-w-4xl">
|
|
|
|
|
<div className="mb-6">
|
|
|
|
|
<Button variant="ghost" size="sm" asChild className="mb-2">
|
|
|
|
|
<Link to={`/admin/sports-seasons/${sportsSeason.id}`}>
|
|
|
|
|
<ArrowLeft className="mr-2 h-4 w-4" />
|
|
|
|
|
Back to Sports Season
|
|
|
|
|
</Link>
|
|
|
|
|
</Button>
|
|
|
|
|
<h1 className="text-3xl font-bold">Manage Participants</h1>
|
|
|
|
|
<p className="text-muted-foreground mt-1">
|
|
|
|
|
{sportsSeason.sport.name} - {sportsSeason.name}
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
|
2025-10-15 21:21:33 -07:00
|
|
|
<div className="grid gap-6 md:grid-cols-2 mb-6">
|
2025-10-12 21:54:49 -07:00
|
|
|
<Card>
|
|
|
|
|
<CardHeader>
|
|
|
|
|
<CardTitle>Add Participant</CardTitle>
|
|
|
|
|
<CardDescription>
|
|
|
|
|
Add a {sportsSeason.sport.type === "team" ? "team" : "player"} to this season
|
|
|
|
|
</CardDescription>
|
|
|
|
|
</CardHeader>
|
|
|
|
|
<CardContent>
|
2025-10-15 21:21:33 -07:00
|
|
|
<Form method="post" className="space-y-4" key={`single-${formKey}`}>
|
2025-10-12 21:54:49 -07:00
|
|
|
<div className="space-y-2">
|
2025-10-15 21:21:33 -07:00
|
|
|
<Label htmlFor="name">Participant Name</Label>
|
2025-10-12 21:54:49 -07:00
|
|
|
<Input
|
|
|
|
|
id="name"
|
|
|
|
|
name="name"
|
|
|
|
|
type="text"
|
|
|
|
|
placeholder={sportsSeason.sport.type === "team" ? "e.g., Kansas City Chiefs" : "e.g., Tiger Woods"}
|
|
|
|
|
required
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-04-09 09:51:16 -04:00
|
|
|
{actionData?.error && !actionData?.count && actionData?.intent !== "update-name" && actionData?.intent !== "update-participant" && (
|
2025-10-15 21:21:33 -07:00
|
|
|
<div className="bg-destructive/15 text-destructive px-4 py-3 rounded-md text-sm">
|
|
|
|
|
{actionData.error}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
2026-04-09 09:51:16 -04:00
|
|
|
{actionData?.success && !actionData?.count && actionData?.intent !== "update-participant" && (
|
2026-02-20 19:26:11 -08:00
|
|
|
<div className="bg-emerald-500/15 text-emerald-400 px-4 py-3 rounded-md text-sm">
|
2025-10-15 21:21:33 -07:00
|
|
|
Participant added successfully!
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<Button type="submit" className="w-full">
|
|
|
|
|
<Plus className="mr-2 h-4 w-4" />
|
|
|
|
|
Add Participant
|
|
|
|
|
</Button>
|
|
|
|
|
</Form>
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
|
|
|
|
|
<Card>
|
|
|
|
|
<CardHeader>
|
|
|
|
|
<CardTitle>Bulk Add Participants</CardTitle>
|
|
|
|
|
<CardDescription>
|
|
|
|
|
Add multiple participants at once (one per line)
|
|
|
|
|
</CardDescription>
|
|
|
|
|
</CardHeader>
|
|
|
|
|
<CardContent>
|
|
|
|
|
<Form method="post" className="space-y-4" key={`bulk-${formKey}`}>
|
|
|
|
|
<input type="hidden" name="intent" value="bulk" />
|
2025-10-12 21:54:49 -07:00
|
|
|
<div className="space-y-2">
|
2025-10-15 21:21:33 -07:00
|
|
|
<Label htmlFor="bulkNames">Participant Names</Label>
|
|
|
|
|
<Textarea
|
|
|
|
|
id="bulkNames"
|
|
|
|
|
name="bulkNames"
|
|
|
|
|
placeholder={sportsSeason.sport.type === "team"
|
|
|
|
|
? "Kansas City Chiefs\nBuffalo Bills\nSan Francisco 49ers"
|
|
|
|
|
: "Tiger Woods\nRory McIlroy\nJon Rahm"}
|
|
|
|
|
rows={8}
|
|
|
|
|
className="font-mono text-sm"
|
2025-10-12 21:54:49 -07:00
|
|
|
/>
|
2025-10-15 21:21:33 -07:00
|
|
|
<p className="text-xs text-muted-foreground">
|
|
|
|
|
Enter one participant name per line
|
|
|
|
|
</p>
|
2025-10-12 21:54:49 -07:00
|
|
|
</div>
|
|
|
|
|
|
2026-04-09 09:51:16 -04:00
|
|
|
{actionData?.error && actionData?.count === undefined && actionData?.intent !== "update-name" && actionData?.intent !== "update-participant" && (
|
2025-10-12 21:54:49 -07:00
|
|
|
<div className="bg-destructive/15 text-destructive px-4 py-3 rounded-md text-sm">
|
|
|
|
|
{actionData.error}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
2026-03-27 01:09:04 -07:00
|
|
|
{actionData?.success && actionData?.count !== undefined && (
|
2026-02-20 19:26:11 -08:00
|
|
|
<div className="bg-emerald-500/15 text-emerald-400 px-4 py-3 rounded-md text-sm">
|
2026-03-27 01:09:04 -07:00
|
|
|
{actionData.count} participant{actionData.count !== 1 ? 's' : ''} added.
|
|
|
|
|
{actionData.skipped && actionData.skipped.length > 0 && (
|
|
|
|
|
<span className="block mt-1 text-yellow-400">
|
|
|
|
|
{actionData.skipped.length} skipped (already exist): {actionData.skipped.join(", ")}
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
2025-10-12 21:54:49 -07:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<Button type="submit" className="w-full">
|
|
|
|
|
<Plus className="mr-2 h-4 w-4" />
|
2025-10-15 21:21:33 -07:00
|
|
|
Add All Participants
|
2025-10-12 21:54:49 -07:00
|
|
|
</Button>
|
|
|
|
|
</Form>
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
2025-10-15 21:21:33 -07:00
|
|
|
</div>
|
2025-10-12 21:54:49 -07:00
|
|
|
|
2026-05-02 10:29:28 -07:00
|
|
|
{sameSportSeasons.length > 0 && (
|
|
|
|
|
<Card className="mb-6">
|
|
|
|
|
<CardHeader>
|
|
|
|
|
<CardTitle>Copy from Another Season</CardTitle>
|
|
|
|
|
<CardDescription>
|
|
|
|
|
Copy participants and their EV data (odds, Elo, rankings) from an
|
|
|
|
|
existing {sportsSeason.sport.name} season. Duplicates are skipped by name.
|
|
|
|
|
Golf skills and tennis surface Elos are shared automatically via canonical
|
|
|
|
|
player records.
|
|
|
|
|
</CardDescription>
|
|
|
|
|
</CardHeader>
|
|
|
|
|
<CardContent>
|
|
|
|
|
<Form method="post" className="space-y-4" key={`copy-${formKey}`}>
|
|
|
|
|
<input type="hidden" name="intent" value="copy-from-season" />
|
|
|
|
|
<div className="flex gap-4 items-end">
|
|
|
|
|
<div className="flex-1 space-y-2">
|
|
|
|
|
<Label htmlFor="sourceSeasonId">Source Season</Label>
|
|
|
|
|
<Select name="sourceSeasonId" value={sourceSeasonId} onValueChange={setSourceSeasonId}>
|
|
|
|
|
<SelectTrigger>
|
|
|
|
|
<SelectValue placeholder="Select a season to copy from" />
|
|
|
|
|
</SelectTrigger>
|
|
|
|
|
<SelectContent>
|
|
|
|
|
{sameSportSeasons.map((s) => (
|
|
|
|
|
<SelectItem key={s.id} value={s.id}>
|
|
|
|
|
{s.name} ({s.year}) — {s.status}
|
|
|
|
|
</SelectItem>
|
|
|
|
|
))}
|
|
|
|
|
</SelectContent>
|
|
|
|
|
</Select>
|
|
|
|
|
</div>
|
|
|
|
|
<Button type="submit" disabled={!sourceSeasonId}>
|
|
|
|
|
<Copy className="mr-2 h-4 w-4" />
|
|
|
|
|
Copy Participants
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{actionData?.error && actionData?.intent === "copy-from-season" && (
|
|
|
|
|
<div className="bg-destructive/15 text-destructive px-4 py-3 rounded-md text-sm">
|
|
|
|
|
{actionData.error}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{actionData?.success && actionData?.intent === "copy-from-season" && actionData.copyResult && (
|
|
|
|
|
<div className="bg-emerald-500/15 text-emerald-400 px-4 py-3 rounded-md text-sm">
|
|
|
|
|
{actionData.copyResult.copied} participant{actionData.copyResult.copied !== 1 ? "s" : ""} copied
|
|
|
|
|
{actionData.copyResult.skipped > 0 && `, ${actionData.copyResult.skipped} skipped (already exist)`}
|
|
|
|
|
{actionData.copyResult.evStubsCopied > 0 && ` — ${actionData.copyResult.evStubsCopied} EV stubs (odds/Elo) copied`}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</Form>
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
)}
|
|
|
|
|
|
2025-10-15 21:21:33 -07:00
|
|
|
<Card>
|
2025-10-12 21:54:49 -07:00
|
|
|
<CardHeader>
|
|
|
|
|
<CardTitle>All Participants</CardTitle>
|
|
|
|
|
<CardDescription>
|
|
|
|
|
{participants.length} {participants.length === 1 ? "participant" : "participants"} total
|
|
|
|
|
</CardDescription>
|
|
|
|
|
</CardHeader>
|
|
|
|
|
<CardContent>
|
|
|
|
|
{participants.length === 0 ? (
|
|
|
|
|
<p className="text-sm text-muted-foreground text-center py-8">
|
|
|
|
|
No participants yet. Add your first {sportsSeason.sport.type === "team" ? "team" : "player"}.
|
|
|
|
|
</p>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="max-h-[500px] overflow-y-auto">
|
|
|
|
|
<Table>
|
|
|
|
|
<TableHeader>
|
|
|
|
|
<TableRow>
|
|
|
|
|
<TableHead>Name</TableHead>
|
2026-04-09 09:51:16 -04:00
|
|
|
<TableHead className="w-[120px]">Group</TableHead>
|
2026-04-01 17:56:42 -07:00
|
|
|
<TableHead className="w-[100px]" />
|
2025-10-12 21:54:49 -07:00
|
|
|
</TableRow>
|
|
|
|
|
</TableHeader>
|
|
|
|
|
<TableBody>
|
|
|
|
|
{participants.map((participant) => (
|
|
|
|
|
<TableRow key={participant.id}>
|
2026-04-01 17:56:42 -07:00
|
|
|
<TableCell className="font-medium">
|
|
|
|
|
{editing?.id === participant.id ? (
|
|
|
|
|
<div className="space-y-1">
|
|
|
|
|
<Input
|
|
|
|
|
value={editing.name}
|
2026-04-09 09:51:16 -04:00
|
|
|
onChange={(e) => setEditing({ ...editing, name: e.target.value })}
|
2026-04-01 17:56:42 -07:00
|
|
|
className="h-8"
|
|
|
|
|
autoFocus
|
|
|
|
|
onKeyDown={(e) => { if (e.key === "Escape") cancelEdit(); }}
|
|
|
|
|
/>
|
2026-04-09 09:51:16 -04:00
|
|
|
{actionData?.error && (actionData?.intent === "update-name" || actionData?.intent === "update-participant") && (
|
2026-04-01 17:56:42 -07:00
|
|
|
<p className="text-xs text-destructive">{actionData.error}</p>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
participant.name
|
|
|
|
|
)}
|
|
|
|
|
</TableCell>
|
2026-04-09 09:51:16 -04:00
|
|
|
<TableCell>
|
|
|
|
|
{editing?.id === participant.id ? (
|
|
|
|
|
<Input
|
|
|
|
|
value={editing.externalId}
|
|
|
|
|
onChange={(e) => setEditing({ ...editing, externalId: e.target.value })}
|
|
|
|
|
className="h-8 font-mono text-xs"
|
|
|
|
|
placeholder="US, Intl, US:A…"
|
|
|
|
|
onKeyDown={(e) => { if (e.key === "Escape") cancelEdit(); }}
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<span className="text-xs font-mono text-muted-foreground">
|
|
|
|
|
{participant.externalId ?? "—"}
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</TableCell>
|
2025-10-12 21:54:49 -07:00
|
|
|
<TableCell>
|
2026-04-01 17:56:42 -07:00
|
|
|
{editing?.id === participant.id ? (
|
|
|
|
|
<div className="flex gap-1">
|
|
|
|
|
<Form method="post">
|
2026-04-09 09:51:16 -04:00
|
|
|
<input type="hidden" name="intent" value="update-participant" />
|
2026-04-01 17:56:42 -07:00
|
|
|
<input type="hidden" name="participantId" value={participant.id} />
|
|
|
|
|
<input type="hidden" name="newName" value={editing.name} />
|
2026-04-09 09:51:16 -04:00
|
|
|
<input type="hidden" name="newExternalId" value={editing.externalId} />
|
2026-04-01 17:56:42 -07:00
|
|
|
<Button
|
|
|
|
|
type="submit"
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="sm"
|
|
|
|
|
className="h-8 w-8 p-0 text-emerald-500 hover:text-emerald-400"
|
|
|
|
|
>
|
|
|
|
|
<Check className="h-4 w-4" />
|
|
|
|
|
</Button>
|
|
|
|
|
</Form>
|
|
|
|
|
<Button
|
|
|
|
|
type="button"
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="sm"
|
|
|
|
|
className="h-8 w-8 p-0"
|
|
|
|
|
onClick={cancelEdit}
|
|
|
|
|
>
|
|
|
|
|
<X className="h-4 w-4" />
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="flex gap-1">
|
|
|
|
|
<Button
|
|
|
|
|
type="button"
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="sm"
|
|
|
|
|
className="h-8 w-8 p-0"
|
2026-04-09 09:51:16 -04:00
|
|
|
onClick={() => setEditing({ id: participant.id, name: participant.name, externalId: participant.externalId ?? "" })}
|
2026-04-01 17:56:42 -07:00
|
|
|
>
|
|
|
|
|
<Pencil className="h-4 w-4" />
|
|
|
|
|
</Button>
|
|
|
|
|
<Form method="post">
|
|
|
|
|
<input type="hidden" name="intent" value="delete" />
|
|
|
|
|
<input type="hidden" name="participantId" value={participant.id} />
|
|
|
|
|
<Button
|
|
|
|
|
type="submit"
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="sm"
|
|
|
|
|
className="h-8 w-8 p-0 text-destructive hover:text-destructive"
|
|
|
|
|
>
|
|
|
|
|
<Trash2 className="h-4 w-4" />
|
|
|
|
|
</Button>
|
|
|
|
|
</Form>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2025-10-12 21:54:49 -07:00
|
|
|
</TableCell>
|
|
|
|
|
</TableRow>
|
|
|
|
|
))}
|
|
|
|
|
</TableBody>
|
|
|
|
|
</Table>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|