Files
kandev/apps/web/hooks/use-task-workflow-move.ts
T
José Almeida e2c076c71c feat(web): improve mobile task navigation (#1769)
* feat(web): improve mobile task and kanban navigation

* feat(web): refine mobile task navigation

* fix(web): address mobile navigation review feedback

* test(web): cover task title field modes

* fix(web): keep mobile board navigator open across workflows

* fix(web): address mobile workflow review feedback
2026-07-18 02:28:29 +01:00

62 lines
1.8 KiB
TypeScript

"use client";
import { useCallback } from "react";
import { bulkMoveSelectedTasks } from "@/lib/api";
import { useToast } from "@/components/toast-provider";
function errorMessage(error: unknown) {
return error instanceof Error ? error.message : "Failed to move task";
}
function movedTitle(movedCount: number, destination: "step" | "workflow") {
if (movedCount === 1) return `Moved task to ${destination}`;
return `Moved ${movedCount} tasks to ${destination}`;
}
function movedDescription(movedCount: number, destination: "step" | "workflow") {
if (destination === "step") {
return movedCount === 1
? "The task is now in the selected step."
: "The tasks are now in the selected step.";
}
return movedCount === 1
? "Switch to the destination workflow to see it."
: "Switch to the destination workflow to see them.";
}
export function useTaskWorkflowMove() {
const { toast } = useToast();
return useCallback(
async (
taskIds: string[],
targetWorkflowId: string,
targetStepId: string,
destination: "step" | "workflow" = "workflow",
) => {
const ids = [...new Set(taskIds.filter(Boolean))];
if (ids.length === 0) return;
try {
const result = await bulkMoveSelectedTasks({
task_ids: ids,
target_workflow_id: targetWorkflowId,
target_step_id: targetStepId,
});
toast({
title: movedTitle(result.moved_count, destination),
description: movedDescription(result.moved_count, destination),
variant: "success",
});
} catch (error) {
toast({
title: "Failed to move task",
description: errorMessage(error),
variant: "error",
});
throw error;
}
},
[toast],
);
}