feat: add CRM task type API hooks

This commit is contained in:
Matthew Meszaros
2026-06-07 06:18:06 +02:00
parent f4c738de06
commit 49ac868956
9 changed files with 98 additions and 0 deletions
@@ -0,0 +1,11 @@
import type TaskType from "@/lib/api/models/app/crm/TaskType";
import Request from "../../../Request";
export default async function createTaskType(data: { name: string; color?: string }): Promise<TaskType> {
return await Request<TaskType>({
method: "POST",
url: "/crm/task-types",
data,
authorization: true,
});
}
@@ -0,0 +1,9 @@
import Request from "../../../Request";
export default async function deleteTaskType(id: string): Promise<void> {
await Request<void>({
method: "DELETE",
url: `/crm/task-types/${id}`,
authorization: true,
});
}
@@ -0,0 +1,12 @@
import type TaskType from "@/lib/api/models/app/crm/TaskType";
import Request from "../../../Request";
export default async function listTaskTypes(): Promise<TaskType[]> {
const res = await Request<{ data: TaskType[] } | TaskType[]>({
method: "GET",
url: "/crm/task-types",
authorization: true,
});
if (Array.isArray(res)) return res;
return res?.data ?? [];
}
@@ -0,0 +1,14 @@
import type TaskType from "@/lib/api/models/app/crm/TaskType";
import Request from "../../../Request";
export default async function updateTaskType(
id: string,
data: { name?: string; color?: string; position?: number },
): Promise<TaskType> {
return await Request<TaskType>({
method: "PATCH",
url: `/crm/task-types/${id}`,
data,
authorization: true,
});
}
@@ -0,0 +1,10 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import createTaskType from "@/lib/api/client/app/crm/taskTypes/createTaskType";
export default function useCreateTaskType() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: (data: { name: string; color?: string }) => createTaskType(data),
onSuccess: () => queryClient.invalidateQueries({ queryKey: ["crm", "task-types"] }),
});
}
@@ -0,0 +1,10 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import deleteTaskType from "@/lib/api/client/app/crm/taskTypes/deleteTaskType";
export default function useDeleteTaskType() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: (id: string) => deleteTaskType(id),
onSuccess: () => queryClient.invalidateQueries({ queryKey: ["crm", "task-types"] }),
});
}
@@ -0,0 +1,10 @@
import { useQuery } from "@tanstack/react-query";
import listTaskTypes from "@/lib/api/client/app/crm/taskTypes/listTaskTypes";
export default function useTaskTypes() {
return useQuery({
queryKey: ["crm", "task-types"],
queryFn: () => listTaskTypes(),
staleTime: 5 * 60 * 1000,
});
}
@@ -0,0 +1,11 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import updateTaskType from "@/lib/api/client/app/crm/taskTypes/updateTaskType";
export default function useUpdateTaskType() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: ({ id, data }: { id: string; data: { name?: string; color?: string; position?: number } }) =>
updateTaskType(id, data),
onSuccess: () => queryClient.invalidateQueries({ queryKey: ["crm", "task-types"] }),
});
}
@@ -0,0 +1,11 @@
// A user-managed CRM task type (Call, Email, Meeting, or anything the user
// creates). Org-scoped. Tasks reference a type by its name string.
export default interface TaskType {
id: string;
organization_id: string;
name: string;
color: string;
position: number;
created_at: string;
updated_at: string;
}