Refresh HiveGrid Cloud reference snapshot

This commit is contained in:
david committed 2026-08-03 15:31:14 +02:00
1 parent 5e99e14772
commit 7f88026f79
5955 files changed
+1177325 -188362

No files matched your search

@@ -6,7 +6,7 @@
// server-driven (<form method="post"> + intent). Final Subframe optics land as a
// tracked design-nachzug once David's D-P4 delta ships.
import { type ActionFunctionArgs, type LoaderFunctionArgs, redirect, useLoaderData } from "react-router";
import { type ActionFunctionArgs, type LoaderFunctionArgs, redirect, useActionData, useLoaderData } from "react-router";
import { buildTaskDetailVM, taskEntityLabelKey, type TaskDetailVM, type TaskWatcherView } from "@hivegrid/view-models";
import { badRequestResponse, loadTasksContext, notFoundResponse, requireTasksPermission } from "~/utils/integrations/taskAccess.server";
import {
@@ -27,12 +27,23 @@ import {
type TaskStatus,
} from "~/utils/integrations/taskService.server";
import { auditTaskEvent, logTaskActivity } from "~/utils/integrations/taskAudit.server";
import { tasksDetailPath, tasksListPath } from "~/utils/integrations/taskRoutePaths";
import { TaskDetailPage } from "~/components/screens/tasks/TaskDetailPage";
import { tasksListPath } from "~/utils/integrations/taskRoutePaths";
import { NO_WATCHER, TaskDetailPage } from "~/components/screens/tasks/TaskDetailPage";
import ServerError from "~/components/ui/errors/ServerError";
import { useSaveToast } from "~/hooks/use-save-toast";
type LoaderData = { title: string; vm: TaskDetailVM };
type ActionData = { intent: string; ok?: true; messageKey?: string; error?: string };
const TASK_SUCCESS_KEYS: Readonly<Record<string, string>> = {
update: "tasks.toast.saved",
complete: "tasks.toast.completed",
removeWatcher: "tasks.toast.watcherRemoved",
archive: "tasks.toast.archived",
reactivate: "tasks.toast.reactivated",
};
const TASK_STATUSES: TaskStatus[] = ["open", "in_progress", "blocked", "done", "cancelled"];
const TASK_PRIORITIES: TaskPriority[] = ["low", "normal", "high", "urgent"];
const TERMINAL: ReadonlySet<TaskStatus> = new Set<TaskStatus>(["done", "cancelled"]);
@@ -119,13 +130,17 @@ export const action = async ({ request, params }: ActionFunctionArgs) => {
try {
if (intent === "delete") {
requireTasksPermission(ctx, "tasks.delete");
await hardDeleteTask({ tenantId: ctx.tenantId, taskId });
await hardDeleteTask({ tenantId: ctx.tenantId, taskId, ctx });
await auditTaskEvent({ ctx, action: "task.deleted", taskId });
return redirect(tasksListPath(tenantSlug));
return redirect(`${tasksListPath(tenantSlug)}?toast=${encodeURIComponent("tasks.toast.deleted")}`);
}
requireTasksPermission(ctx, "tasks.write");
// One save for the whole detail form: master data, assignment and an
// optionally added watcher. The screen has a single save button, so
// reassignment and watcher-add are folded into this intent instead of
// sitting behind their own submits.
if (intent === "update") {
const title = String(formData.get("title") ?? "").trim();
const description = String(formData.get("description") ?? "");
@@ -138,6 +153,7 @@ export const action = async ({ request, params }: ActionFunctionArgs) => {
await updateTask({
tenantId: ctx.tenantId,
taskId,
ctx,
title,
description: description || null,
status: statusRaw ? (statusRaw as TaskStatus) : undefined,
@@ -145,65 +161,62 @@ export const action = async ({ request, params }: ActionFunctionArgs) => {
deadline: deadlineRaw ? new Date(deadlineRaw) : null,
});
await auditTaskEvent({ ctx, action: "task.updated", taskId });
return redirect(tasksDetailPath(tenantSlug, taskId));
const assigneeType = String(formData.get("assigneeType") ?? "user");
const assigneeId = String(formData.get("assigneeId") ?? "").trim();
if (assigneeId) {
await reassignTask({
tenantId: ctx.tenantId,
tenantSlug: params.tenant,
taskId,
ctx,
assignedToUserId: assigneeType === "user" ? assigneeId : null,
assignedToGroupId: assigneeType === "group" ? assigneeId : null,
});
await auditTaskEvent({ ctx, action: "task.reassigned", taskId, metadata: { assigneeType } });
}
// The picker's sentinel means "no watcher picked" and must not be stored.
const watcherUserId = String(formData.get("watcherUserId") ?? "").trim();
if (watcherUserId && watcherUserId !== NO_WATCHER) {
await addWatcher({ tenantId: ctx.tenantId, taskId, userId: watcherUserId, ctx });
await auditTaskEvent({ ctx, action: "task.watcher_added", taskId, metadata: { userId: watcherUserId } });
}
return Response.json({ intent, ok: true, messageKey: TASK_SUCCESS_KEYS[intent] } satisfies ActionData);
}
if (intent === "complete") {
await completeTask({ tenantId: ctx.tenantId, taskId });
await completeTask({ tenantId: ctx.tenantId, taskId, ctx });
await auditTaskEvent({ ctx, action: "task.completed", taskId });
const linked = await getVisibleTaskWithWatchers(ctx.tenantId, taskId, ctx).catch(() => null);
await logTaskActivity({
ctx,
taskId,
activityType: "task_completed",
summaryText: "Aufgabe erledigt",
summaryText: "crm.activity.task_completed",
linkedEntityType: linked?.task.linkedEntityType ?? null,
linkedEntityId: linked?.task.linkedEntityId ?? null,
});
return redirect(tasksDetailPath(tenantSlug, taskId));
}
if (intent === "reassign") {
const assigneeType = String(formData.get("assigneeType") ?? "user");
const assigneeId = String(formData.get("assigneeId") ?? "").trim();
if (!assigneeId) {
throw badRequestResponse();
}
await reassignTask({
tenantId: ctx.tenantId,
taskId,
assignedToUserId: assigneeType === "user" ? assigneeId : null,
assignedToGroupId: assigneeType === "group" ? assigneeId : null,
});
await auditTaskEvent({ ctx, action: "task.reassigned", taskId, metadata: { assigneeType } });
return redirect(tasksDetailPath(tenantSlug, taskId));
}
if (intent === "addWatcher") {
const userId = String(formData.get("userId") ?? "").trim();
if (!userId) {
throw badRequestResponse();
}
await addWatcher({ tenantId: ctx.tenantId, taskId, userId });
await auditTaskEvent({ ctx, action: "task.watcher_added", taskId, metadata: { userId } });
return redirect(tasksDetailPath(tenantSlug, taskId));
return Response.json({ intent, ok: true, messageKey: TASK_SUCCESS_KEYS[intent] } satisfies ActionData);
}
if (intent === "removeWatcher") {
const userId = String(formData.get("userId") ?? "").trim();
await removeWatcher({ tenantId: ctx.tenantId, taskId, userId });
await removeWatcher({ tenantId: ctx.tenantId, taskId, userId, ctx });
await auditTaskEvent({ ctx, action: "task.watcher_removed", taskId, metadata: { userId } });
return redirect(tasksDetailPath(tenantSlug, taskId));
return Response.json({ intent, ok: true, messageKey: TASK_SUCCESS_KEYS[intent] } satisfies ActionData);
}
if (intent === "archive") {
await archiveTask({ tenantId: ctx.tenantId, taskId });
await archiveTask({ tenantId: ctx.tenantId, taskId, ctx });
await auditTaskEvent({ ctx, action: "task.archived", taskId });
} else if (intent === "reactivate") {
await reactivateTask({ tenantId: ctx.tenantId, taskId });
await reactivateTask({ tenantId: ctx.tenantId, taskId, ctx });
await auditTaskEvent({ ctx, action: "task.reactivated", taskId });
}
return redirect(tasksDetailPath(tenantSlug, taskId));
const messageKey = TASK_SUCCESS_KEYS[intent];
if (!messageKey) return Response.json({ intent, error: "tasks.error.invalidAction" } satisfies ActionData, { status: 400 });
return Response.json({ intent, ok: true, messageKey } satisfies ActionData);
} catch (error) {
if (error instanceof Response) throw error;
throw notFoundResponse();
@@ -212,6 +225,10 @@ export const action = async ({ request, params }: ActionFunctionArgs) => {
export default function TaskDetailRoute() {
const { vm } = useLoaderData<LoaderData>();
const actionData = useActionData<ActionData>();
useSaveToast(actionData);
if (vm.status !== "ready" || !vm.data) {
return <div className="flex w-full max-w-[960px] flex-col gap-6 p-6" data-ui-id="ui.tasks.detail" />;
}