Sprint Points: Decoupling Estimation Math from useReducer State in Next.js
How Sprint Points calculates base hours, checklist activities, and risk buffers into Story Points by keeping pure calculation functions separate from useReducer UI state.
During Sprint Planning, it is easy to estimate only coding hours and forget the surrounding work: unit tests, code review, QA feedback, and release checks.
I built Sprint Points (https://sprintpoints.miguelito.dev, source at https://github.com/rniguel/sprint-points) with Next.js, TypeScript, and shadcn/ui to make that hidden effort visible.
Keeping Calculation Logic Pure in lib/calculator.ts
Rather than burying math inside JSX components, the entire calculation lives in a pure, testable TypeScript function that sums enabled checklist activities, adds the risk buffer, and derives Story Points (Math.ceil(total / 6)):
import type { Task, CalculationResult } from "./types";
export function calculate(task: Task): CalculationResult {
const activeActivitiesHours = task.activities
.filter((activity) => activity.enabled)
.reduce((sum, activity) => sum + activity.hours, 0);
const subtotal = task.baseHours + activeActivitiesHours;
const riskAmount = subtotal * task.riskFactor;
const total = subtotal * (1 + task.riskFactor);
const storyPoints = Math.ceil(total / 6);
return {
subtotal,
riskAmount,
total,
storyPoints,
};
}Typed UI State via useReducer
On the client side, hooks/useSprintCalculator.ts orchestrates actions like TOGGLE_ACTIVITY, ADD_CUSTOM_ACTIVITY, and SET_RISK_FACTOR inside a single typed reducer, leaving app/page.tsx focused purely on composition across TaskHeader, ActivityChecklist, RiskSlider, and ResultCard.
Final Thoughts
Keeping business formulas in pure TypeScript modules and UI state inside useReducer keeps growing components easy to reason about and maintain.
Miguel Riquelme
Front-end Engineer. Software Engineering MBA student at USP/Esalq.