Files
temetro/frontend/lib/tasks.ts
T
Khalid Abdi 25254dd4c1 feat: org-scoped tasks backend, wire tasks page
Add the tasks table, validation, service and routes (/api/tasks with a
PATCH for partial updates / the done toggle, RBAC-gated) and the frontend
data module. The tasks board now loads, creates and toggles real data
(optimistic toggle with rollback).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-07 19:41:10 +03:00

54 lines
1.3 KiB
TypeScript

import { apiFetch } from "@/lib/api-client";
// A care-team task. Mirrors the backend `src/types/task.ts`. Scoped to the active
// clinic (shared across the care team).
export type Priority = "high" | "medium" | "low";
export type Task = {
id: string;
title: string;
assignee: string;
due: string;
priority: Priority;
patient: string | null;
notes: string | null;
done: boolean;
createdAt: string;
updatedAt: string;
};
// Fields the "New task" dialog collects.
export type TaskInput = {
title: string;
assignee?: string;
due?: string;
priority?: Priority;
patient?: string | null;
notes?: string | null;
};
// Any subset of fields, plus `done` (used by the complete/reopen toggle).
export type TaskPatch = Partial<TaskInput> & { done?: boolean };
export function listTasks(): Promise<Task[]> {
return apiFetch<Task[]>("/api/tasks");
}
export function createTask(input: TaskInput): Promise<Task> {
return apiFetch<Task>("/api/tasks", {
method: "POST",
body: JSON.stringify(input),
});
}
export function updateTask(id: string, patch: TaskPatch): Promise<Task> {
return apiFetch<Task>(`/api/tasks/${id}`, {
method: "PATCH",
body: JSON.stringify(patch),
});
}
export function deleteTask(id: string): Promise<void> {
return apiFetch<void>(`/api/tasks/${id}`, { method: "DELETE" });
}