Fix code review issues in commissioner time bank adjustment
- Wrap fetch in try/finally so isAdjustingTimeBank is always reset, even on network errors that cause fetch to throw - Guard against totalSeconds rounding to 0 for tiny fractional inputs - Reject API requests when the draft is not in 'draft' status (409) - Set input min to 0.001 so the browser rejects zero in native validation https://claude.ai/code/session_013wxPKzLUCx3nC3LpxgjvQL
This commit is contained in:
parent
554a24eafb
commit
c6a26b17d3
2 changed files with 35 additions and 21 deletions
|
|
@ -33,6 +33,10 @@ export async function action(args: any) {
|
||||||
return Response.json({ error: "Season not found" }, { status: 404 });
|
return Response.json({ error: "Season not found" }, { status: 404 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (season.status !== "draft") {
|
||||||
|
return Response.json({ error: "Draft is not currently active" }, { status: 409 });
|
||||||
|
}
|
||||||
|
|
||||||
const isCommissioner = await db.query.commissioners.findFirst({
|
const isCommissioner = await db.query.commissioners.findFirst({
|
||||||
where: and(
|
where: and(
|
||||||
eq(schema.commissioners.leagueId, season.leagueId),
|
eq(schema.commissioners.leagueId, season.leagueId),
|
||||||
|
|
|
||||||
|
|
@ -837,9 +837,16 @@ export default function DraftRoom() {
|
||||||
|
|
||||||
const unitMultipliers = { seconds: 1, minutes: 60, hours: 3600 };
|
const unitMultipliers = { seconds: 1, minutes: 60, hours: 3600 };
|
||||||
const totalSeconds = Math.round(amount * unitMultipliers[timeBankUnit]);
|
const totalSeconds = Math.round(amount * unitMultipliers[timeBankUnit]);
|
||||||
|
|
||||||
|
if (totalSeconds === 0) {
|
||||||
|
toast.error("Adjustment rounds to 0 seconds — please enter a larger value");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const adjustment = timeBankDirection === "add" ? totalSeconds : -totalSeconds;
|
const adjustment = timeBankDirection === "add" ? totalSeconds : -totalSeconds;
|
||||||
|
|
||||||
setIsAdjustingTimeBank(true);
|
setIsAdjustingTimeBank(true);
|
||||||
|
try {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("seasonId", season.id);
|
formData.append("seasonId", season.id);
|
||||||
formData.append("teamId", timeBankTeamId);
|
formData.append("teamId", timeBankTeamId);
|
||||||
|
|
@ -850,8 +857,6 @@ export default function DraftRoom() {
|
||||||
body: formData,
|
body: formData,
|
||||||
});
|
});
|
||||||
|
|
||||||
setIsAdjustingTimeBank(false);
|
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
setTeamTimers((prev) => ({ ...prev, [timeBankTeamId]: data.timeRemaining }));
|
setTeamTimers((prev) => ({ ...prev, [timeBankTeamId]: data.timeRemaining }));
|
||||||
|
|
@ -863,6 +868,11 @@ export default function DraftRoom() {
|
||||||
const error = await response.json();
|
const error = await response.json();
|
||||||
toast.error(error.error || "Failed to adjust time bank");
|
toast.error(error.error || "Failed to adjust time bank");
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
toast.error("Network error — failed to adjust time bank");
|
||||||
|
} finally {
|
||||||
|
setIsAdjustingTimeBank(false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Calculate current round
|
// Calculate current round
|
||||||
|
|
@ -1541,7 +1551,7 @@ export default function DraftRoom() {
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
<input
|
<input
|
||||||
type="number"
|
type="number"
|
||||||
min="0"
|
min="0.001"
|
||||||
step="any"
|
step="any"
|
||||||
value={timeBankAmount}
|
value={timeBankAmount}
|
||||||
onChange={(e) => setTimeBankAmount(e.target.value)}
|
onChange={(e) => setTimeBankAmount(e.target.value)}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue