feat: add configurable initial and increment time settings for draft picks
This commit is contained in:
parent
469a85a0f8
commit
0bef91e530
2 changed files with 104 additions and 0 deletions
|
|
@ -212,6 +212,8 @@ export async function action(args: Route.ActionArgs) {
|
|||
const teamCount = formData.get("teamCount");
|
||||
const draftDateTime = formData.get("draftDateTime");
|
||||
const draftRounds = formData.get("draftRounds");
|
||||
const draftInitialTime = formData.get("draftInitialTime");
|
||||
const draftIncrementTime = formData.get("draftIncrementTime");
|
||||
|
||||
// Validation
|
||||
if (typeof name !== "string" || !name.trim()) {
|
||||
|
|
@ -250,6 +252,28 @@ export async function action(args: Route.ActionArgs) {
|
|||
seasonUpdates.draftDateTime = draftDateTime ? new Date(draftDateTime) : null;
|
||||
}
|
||||
|
||||
// Handle draft initial time
|
||||
if (typeof draftInitialTime === "string") {
|
||||
const initialTime = parseInt(draftInitialTime, 10);
|
||||
if (!isNaN(initialTime)) {
|
||||
if (initialTime < 30 || initialTime > 86400) {
|
||||
return { error: "Initial draft time must be between 30 seconds and 24 hours (86400 seconds)" };
|
||||
}
|
||||
seasonUpdates.draftInitialTime = initialTime;
|
||||
}
|
||||
}
|
||||
|
||||
// Handle draft increment time
|
||||
if (typeof draftIncrementTime === "string") {
|
||||
const incrementTime = parseInt(draftIncrementTime, 10);
|
||||
if (!isNaN(incrementTime)) {
|
||||
if (incrementTime < 0 || incrementTime > 3600) {
|
||||
return { error: "Draft increment time must be between 0 and 1 hour (3600 seconds)" };
|
||||
}
|
||||
seasonUpdates.draftIncrementTime = incrementTime;
|
||||
}
|
||||
}
|
||||
|
||||
// Update season if there are changes
|
||||
if (Object.keys(seasonUpdates).length > 0) {
|
||||
await updateSeason(season.id, seasonUpdates);
|
||||
|
|
@ -552,6 +576,40 @@ export default function LeagueSettings({ loaderData, actionData }: Route.Compone
|
|||
: "Draft date cannot be changed after draft has started"}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="draftInitialTime">Initial Draft Time (seconds)</Label>
|
||||
<Input
|
||||
id="draftInitialTime"
|
||||
name="draftInitialTime"
|
||||
type="number"
|
||||
min="30"
|
||||
max="86400"
|
||||
defaultValue={season?.draftInitialTime || 120}
|
||||
disabled={!canEditDraftRounds}
|
||||
required
|
||||
/>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Time each team starts with (30 seconds to 24 hours)
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="draftIncrementTime">Time Increment (seconds)</Label>
|
||||
<Input
|
||||
id="draftIncrementTime"
|
||||
name="draftIncrementTime"
|
||||
type="number"
|
||||
min="0"
|
||||
max="3600"
|
||||
defaultValue={season?.draftIncrementTime || 30}
|
||||
disabled={!canEditDraftRounds}
|
||||
required
|
||||
/>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Time added after each pick (0 to 1 hour)
|
||||
</p>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
|
|
|
|||
|
|
@ -76,6 +76,8 @@ export async function action(args: Route.ActionArgs) {
|
|||
const templateId = formData.get("templateId");
|
||||
const draftRounds = formData.get("draftRounds");
|
||||
const draftDateTime = formData.get("draftDateTime");
|
||||
const draftInitialTime = formData.get("draftInitialTime");
|
||||
const draftIncrementTime = formData.get("draftIncrementTime");
|
||||
|
||||
// Validation
|
||||
if (typeof name !== "string" || !name.trim()) {
|
||||
|
|
@ -96,6 +98,16 @@ export async function action(args: Route.ActionArgs) {
|
|||
return { error: "Draft rounds must be between 1 and 50" };
|
||||
}
|
||||
|
||||
const draftInitialTimeNum = typeof draftInitialTime === "string" ? parseInt(draftInitialTime, 10) : 120;
|
||||
if (isNaN(draftInitialTimeNum) || draftInitialTimeNum < 30 || draftInitialTimeNum > 86400) {
|
||||
return { error: "Initial draft time must be between 30 seconds and 24 hours" };
|
||||
}
|
||||
|
||||
const draftIncrementTimeNum = typeof draftIncrementTime === "string" ? parseInt(draftIncrementTime, 10) : 30;
|
||||
if (isNaN(draftIncrementTimeNum) || draftIncrementTimeNum < 0 || draftIncrementTimeNum > 3600) {
|
||||
return { error: "Draft increment time must be between 0 and 1 hour" };
|
||||
}
|
||||
|
||||
try {
|
||||
// Create league
|
||||
const league = await createLeague({
|
||||
|
|
@ -118,6 +130,8 @@ export async function action(args: Route.ActionArgs) {
|
|||
templateId: typeof templateId === "string" && templateId !== "" ? templateId : null,
|
||||
draftRounds: draftRoundsNum,
|
||||
draftDateTime: typeof draftDateTime === "string" && draftDateTime ? new Date(draftDateTime) : null,
|
||||
draftInitialTime: draftInitialTimeNum,
|
||||
draftIncrementTime: draftIncrementTimeNum,
|
||||
});
|
||||
|
||||
// Set this as the current season for the league
|
||||
|
|
@ -326,6 +340,38 @@ export default function NewLeague({ loaderData, actionData }: Route.ComponentPro
|
|||
</p>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="draftInitialTime">Initial Draft Time (seconds)</Label>
|
||||
<Input
|
||||
id="draftInitialTime"
|
||||
name="draftInitialTime"
|
||||
type="number"
|
||||
min="30"
|
||||
max="86400"
|
||||
defaultValue="120"
|
||||
required
|
||||
/>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Time each team starts with (30 seconds to 24 hours). Default: 120 seconds (2 minutes)
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="draftIncrementTime">Time Increment (seconds)</Label>
|
||||
<Input
|
||||
id="draftIncrementTime"
|
||||
name="draftIncrementTime"
|
||||
type="number"
|
||||
min="0"
|
||||
max="3600"
|
||||
defaultValue="30"
|
||||
required
|
||||
/>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Time added after each pick (0 to 1 hour). Default: 30 seconds
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="space-y-4">
|
||||
<Label>Sports Selection</Label>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue