From e32d329ecde946195ff4b4ba75adaf0a5eec15e9 Mon Sep 17 00:00:00 2001 From: Oliver Bryan Date: Thu, 5 Feb 2026 12:28:03 +0000 Subject: [PATCH] new sprint start date is now a day after the latest end date --- .../frontend/src/components/sprint-form.tsx | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/packages/frontend/src/components/sprint-form.tsx b/packages/frontend/src/components/sprint-form.tsx index 7e67606..f4646f3 100644 --- a/packages/frontend/src/components/sprint-form.tsx +++ b/packages/frontend/src/components/sprint-form.tsx @@ -42,11 +42,30 @@ const addDays = (date: Date, days: number) => { return next; }; -const getDefaultDates = () => { - const today = new Date(); +const getDefaultDates = (sprints: SprintRecord[]) => { + if (sprints.length === 0) { + const today = new Date(); + return { + start: getStartOfDay(today), + end: getEndOfDay(addDays(today, 6)), + }; + } + + const latest = sprints.reduce((current, sprint) => { + const currentEnd = new Date(current.endDate).getTime(); + const sprintEnd = new Date(sprint.endDate).getTime(); + if (sprintEnd !== currentEnd) { + return sprintEnd > currentEnd ? sprint : current; + } + const currentStart = new Date(current.startDate).getTime(); + const sprintStart = new Date(sprint.startDate).getTime(); + return sprintStart > currentStart ? sprint : current; + }, sprints[0]); + + const start = getStartOfDay(addDays(new Date(latest.endDate), 1)); return { - start: getStartOfDay(today), - end: getEndOfDay(addDays(today, 14)), + start, + end: getEndOfDay(addDays(start, 6)), }; }; @@ -78,11 +97,11 @@ export function SprintForm({ const open = isControlled ? controlledOpen : internalOpen; const setOpen = isControlled ? (controlledOnOpenChange ?? (() => {})) : setInternalOpen; - const { start, end } = getDefaultDates(); + const defaultDates = useMemo(() => getDefaultDates(sprints), [sprints]); const [name, setName] = useState(""); const [colour, setColour] = useState(DEFAULT_SPRINT_COLOUR); - const [startDate, setStartDate] = useState(start); - const [endDate, setEndDate] = useState(end); + const [startDate, setStartDate] = useState(defaultDates.start); + const [endDate, setEndDate] = useState(defaultDates.end); const [submitAttempted, setSubmitAttempted] = useState(false); const [submitting, setSubmitting] = useState(false); const [error, setError] = useState(null); @@ -107,7 +126,7 @@ export function SprintForm({ }, [endDate, startDate, submitAttempted]); const reset = () => { - const defaults = getDefaultDates(); + const defaults = getDefaultDates(sprints); setName(""); setColour(DEFAULT_SPRINT_COLOUR); setStartDate(defaults.start);