feat: add create-participant intent for inline participant creation
This commit is contained in:
parent
8723000cdd
commit
9d4931b8d9
1 changed files with 28 additions and 1 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import type { Route } from "./+types/admin.sports-seasons.$id.events.$eventId";
|
||||
import { logger } from "~/lib/logger";
|
||||
import { findSportsSeasonById } from "~/models/sports-season";
|
||||
import { findParticipantsBySportsSeasonId } from "~/models/participant";
|
||||
import { findParticipantsBySportsSeasonId, createParticipant } from "~/models/participant";
|
||||
import {
|
||||
getScoringEventById,
|
||||
completeScoringEvent,
|
||||
|
|
@ -366,5 +366,32 @@ export async function action({ request, params }: Route.ActionArgs) {
|
|||
}
|
||||
}
|
||||
|
||||
if (intent === "create-participant") {
|
||||
const name = formData.get("name");
|
||||
const sportsSeasonId = formData.get("sportsSeasonId");
|
||||
|
||||
if (typeof name !== "string" || !name.trim()) {
|
||||
return { error: "Participant name is required" };
|
||||
}
|
||||
|
||||
if (typeof sportsSeasonId !== "string" || !sportsSeasonId) {
|
||||
return { error: "Sports season ID is required" };
|
||||
}
|
||||
|
||||
try {
|
||||
const participant = await createParticipant({
|
||||
name: name.trim(),
|
||||
sportsSeasonId,
|
||||
});
|
||||
return {
|
||||
success: `Participant "${participant.name}" created.`,
|
||||
newParticipant: { id: participant.id, name: participant.name },
|
||||
};
|
||||
} catch (error) {
|
||||
logger.error("Error creating participant:", error);
|
||||
return { error: "Failed to create participant" };
|
||||
}
|
||||
}
|
||||
|
||||
return { error: "Invalid action" };
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue