Files
kandev/apps/web/hooks/use-update-task-priority.ts
Henry f441399441 feat(tasks): show and set task priority on the kanban board (#3333)
Co-authored-by: nova28 <17953305+nova28@users.noreply.github.com>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Co-authored-by: Carlos Florencio <carlosmflorencio@gmail.com>
2026-09-05 10:15:19 +00:00

34 lines
1.0 KiB
TypeScript

"use client";
import { useCallback } from "react";
import { useTranslation } from "react-i18next";
import { useToast } from "@/components/toast-provider";
import { updateTask } from "@/lib/api/domains/kanban-api";
import type { TaskPriority } from "@/lib/types/http";
/**
* Persists a priority change from a task menu. Not optimistic: each surface
* follows the stored value from the resulting `task.updated` event, so a
* failure here needs only a toast — the card keeps showing whatever it was
* already showing.
*/
export function useUpdateTaskPriority() {
const { toast } = useToast();
const { t } = useTranslation("task");
return useCallback(
async (taskId: string, priority: TaskPriority): Promise<void> => {
try {
await updateTask(taskId, { priority });
} catch (error) {
toast({
title: t("task:failedToUpdateTask"),
description: error instanceof Error ? error.message : String(error),
variant: "error",
});
}
},
[t, toast],
);
}