Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions nexus-frontend/src/utils/transitions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import type { TaskStatus } from '../types/task';

/**
* Defines the valid status transitions for tasks.
* State machine: TODO → IN_PROGRESS → IN_REVIEW → DONE
*/
const TRANSITION_MAP: Readonly<Record<TaskStatus, readonly TaskStatus[]>> = {
TODO: ['IN_PROGRESS'],
IN_PROGRESS: ['IN_REVIEW'],
IN_REVIEW: ['DONE'],
DONE: [],
};

/**
* Returns the list of valid next statuses for a given current status.
* Returns an empty array if no transitions are available (terminal state).
*/
export function getValidTransitions(currentStatus: TaskStatus): TaskStatus[] {
return [...(TRANSITION_MAP[currentStatus] ?? [])];
}

/**
* Checks whether transitioning from one status to another is valid.
*/
export function isValidTransition(
from: TaskStatus,
to: TaskStatus
): boolean {
return TRANSITION_MAP[from]?.includes(to) ?? false;
}

/**
* Human-readable labels for task statuses.
*/
export const STATUS_LABELS: Record<TaskStatus, string> = {
TODO: 'To Do',
IN_PROGRESS: 'In Progress',
IN_REVIEW: 'In Review',
DONE: 'Done',
};