refactor(FN-1289): extract AppInner logic into hooks and modal component
- Extract view state, project actions, and task handler concerns from AppInner into dedicated hooks - Add AppModals component to centralize modal rendering and related props wiring - Inline thin aliases and complete AppInner cleanup after moving responsibilities out - Add unit tests for useViewState, useProjectActions, and useTaskHandlers hooks
This commit is contained in:
70
packages/dashboard/app/hooks/useTaskHandlers.ts
Normal file
70
packages/dashboard/app/hooks/useTaskHandlers.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
import { useCallback } from "react";
|
||||
import type { Task, TaskCreateInput } from "@fusion/core";
|
||||
import type { ToastType } from "./useToast";
|
||||
|
||||
interface UseTaskHandlersOptions {
|
||||
createTask: (input: TaskCreateInput) => Promise<Task>;
|
||||
onPlanningTaskCreated: (task: Task, addToast: (msg: string, type?: ToastType) => void) => void;
|
||||
onPlanningTasksCreated: (tasks: Task[], addToast: (msg: string, type?: ToastType) => void) => void;
|
||||
onSubtaskTasksCreated: (tasks: Task[], addToast: (msg: string, type?: ToastType) => void) => void;
|
||||
addToast: (message: string, type?: ToastType) => void;
|
||||
}
|
||||
|
||||
export interface UseTaskHandlersResult {
|
||||
handleBoardQuickCreate: (input: TaskCreateInput) => Promise<void>;
|
||||
handleModalCreate: (input: TaskCreateInput) => Promise<Task>;
|
||||
handlePlanningTaskCreated: (task: Task) => void;
|
||||
handlePlanningTasksCreated: (tasks: Task[]) => void;
|
||||
handleSubtaskTasksCreated: (tasks: Task[]) => void;
|
||||
handleGitHubImport: (task: Task) => void;
|
||||
}
|
||||
|
||||
export function useTaskHandlers(options: UseTaskHandlersOptions): UseTaskHandlersResult {
|
||||
const {
|
||||
createTask,
|
||||
onPlanningTaskCreated,
|
||||
onPlanningTasksCreated,
|
||||
onSubtaskTasksCreated,
|
||||
addToast,
|
||||
} = options;
|
||||
|
||||
const handleBoardQuickCreate = useCallback(
|
||||
async (input: TaskCreateInput): Promise<void> => {
|
||||
await createTask({ ...input, column: "triage" });
|
||||
},
|
||||
[createTask],
|
||||
);
|
||||
|
||||
const handleModalCreate = useCallback(
|
||||
async (input: TaskCreateInput): Promise<Task> => {
|
||||
const task = await createTask({ ...input, column: "triage" });
|
||||
return task;
|
||||
},
|
||||
[createTask],
|
||||
);
|
||||
|
||||
const handlePlanningTaskCreated = useCallback((task: Task) => {
|
||||
onPlanningTaskCreated(task, addToast);
|
||||
}, [onPlanningTaskCreated, addToast]);
|
||||
|
||||
const handlePlanningTasksCreated = useCallback((tasks: Task[]) => {
|
||||
onPlanningTasksCreated(tasks, addToast);
|
||||
}, [onPlanningTasksCreated, addToast]);
|
||||
|
||||
const handleSubtaskTasksCreated = useCallback((tasks: Task[]) => {
|
||||
onSubtaskTasksCreated(tasks, addToast);
|
||||
}, [onSubtaskTasksCreated, addToast]);
|
||||
|
||||
const handleGitHubImport = useCallback((task: Task) => {
|
||||
addToast(`Imported ${task.id} from GitHub`, "success");
|
||||
}, [addToast]);
|
||||
|
||||
return {
|
||||
handleBoardQuickCreate,
|
||||
handleModalCreate,
|
||||
handlePlanningTaskCreated,
|
||||
handlePlanningTasksCreated,
|
||||
handleSubtaskTasksCreated,
|
||||
handleGitHubImport,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user