@carlonicora/nja-todos 0.0.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +675 -0
- package/README.md +791 -2
- package/dist/api/common/decorate.d.ts +21 -0
- package/dist/api/common/decorate.d.ts.map +1 -0
- package/dist/api/common/decorate.js +39 -0
- package/dist/api/common/decorate.js.map +1 -0
- package/dist/api/config/todos.config.d.ts +51 -0
- package/dist/api/config/todos.config.d.ts.map +1 -0
- package/dist/api/config/todos.config.js +7 -0
- package/dist/api/config/todos.config.js.map +1 -0
- package/dist/api/events/todos.event.payloads.d.ts +21 -0
- package/dist/api/events/todos.event.payloads.d.ts.map +1 -0
- package/dist/api/events/todos.event.payloads.js +3 -0
- package/dist/api/events/todos.event.payloads.js.map +1 -0
- package/dist/api/index.d.ts +22 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +49 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/notifications/todos.notification.processor.d.ts +48 -0
- package/dist/api/notifications/todos.notification.processor.d.ts.map +1 -0
- package/dist/api/notifications/todos.notification.processor.js +251 -0
- package/dist/api/notifications/todos.notification.processor.js.map +1 -0
- package/dist/api/notifications/todos.queue.d.ts +41 -0
- package/dist/api/notifications/todos.queue.d.ts.map +1 -0
- package/dist/api/notifications/todos.queue.js +35 -0
- package/dist/api/notifications/todos.queue.js.map +1 -0
- package/dist/api/task/controllers/task.controller.factory.d.ts +38 -0
- package/dist/api/task/controllers/task.controller.factory.d.ts.map +1 -0
- package/dist/api/task/controllers/task.controller.factory.js +314 -0
- package/dist/api/task/controllers/task.controller.factory.js.map +1 -0
- package/dist/api/task/dtos/task.dtos.d.ts +15 -0
- package/dist/api/task/dtos/task.dtos.d.ts.map +1 -0
- package/dist/api/task/dtos/task.dtos.js +260 -0
- package/dist/api/task/dtos/task.dtos.js.map +1 -0
- package/dist/api/task/entities/task.d.ts +21 -0
- package/dist/api/task/entities/task.d.ts.map +1 -0
- package/dist/api/task/entities/task.js +95 -0
- package/dist/api/task/entities/task.js.map +1 -0
- package/dist/api/task/entities/task.meta.d.ts +3 -0
- package/dist/api/task/entities/task.meta.d.ts.map +1 -0
- package/dist/api/task/entities/task.meta.js +11 -0
- package/dist/api/task/entities/task.meta.js.map +1 -0
- package/dist/api/task/repositories/task.repository.d.ts +104 -0
- package/dist/api/task/repositories/task.repository.d.ts.map +1 -0
- package/dist/api/task/repositories/task.repository.js +328 -0
- package/dist/api/task/repositories/task.repository.js.map +1 -0
- package/dist/api/task/services/task.service.d.ts +149 -0
- package/dist/api/task/services/task.service.d.ts.map +1 -0
- package/dist/api/task/services/task.service.js +378 -0
- package/dist/api/task/services/task.service.js.map +1 -0
- package/dist/api/taskcomment/controllers/taskcomment.controller.factory.d.ts +44 -0
- package/dist/api/taskcomment/controllers/taskcomment.controller.factory.d.ts.map +1 -0
- package/dist/api/taskcomment/controllers/taskcomment.controller.factory.js +136 -0
- package/dist/api/taskcomment/controllers/taskcomment.controller.factory.js.map +1 -0
- package/dist/api/taskcomment/dtos/taskcomment.post.dto.d.ts +23 -0
- package/dist/api/taskcomment/dtos/taskcomment.post.dto.d.ts.map +1 -0
- package/dist/api/taskcomment/dtos/taskcomment.post.dto.js +87 -0
- package/dist/api/taskcomment/dtos/taskcomment.post.dto.js.map +1 -0
- package/dist/api/taskcomment/dtos/taskcomment.put.dto.d.ts +21 -0
- package/dist/api/taskcomment/dtos/taskcomment.put.dto.d.ts.map +1 -0
- package/dist/api/taskcomment/dtos/taskcomment.put.dto.js +71 -0
- package/dist/api/taskcomment/dtos/taskcomment.put.dto.js.map +1 -0
- package/dist/api/taskcomment/entities/taskcomment.d.ts +11 -0
- package/dist/api/taskcomment/entities/taskcomment.d.ts.map +1 -0
- package/dist/api/taskcomment/entities/taskcomment.js +44 -0
- package/dist/api/taskcomment/entities/taskcomment.js.map +1 -0
- package/dist/api/taskcomment/entities/taskcomment.meta.d.ts +5 -0
- package/dist/api/taskcomment/entities/taskcomment.meta.d.ts.map +1 -0
- package/dist/api/taskcomment/entities/taskcomment.meta.js +13 -0
- package/dist/api/taskcomment/entities/taskcomment.meta.js.map +1 -0
- package/dist/api/taskcomment/repositories/taskcomment.repository.d.ts +25 -0
- package/dist/api/taskcomment/repositories/taskcomment.repository.d.ts.map +1 -0
- package/dist/api/taskcomment/repositories/taskcomment.repository.js +73 -0
- package/dist/api/taskcomment/repositories/taskcomment.repository.js.map +1 -0
- package/dist/api/taskcomment/services/taskcomment.service.d.ts +78 -0
- package/dist/api/taskcomment/services/taskcomment.service.d.ts.map +1 -0
- package/dist/api/taskcomment/services/taskcomment.service.js +190 -0
- package/dist/api/taskcomment/services/taskcomment.service.js.map +1 -0
- package/dist/api/todos.module.d.ts +20 -0
- package/dist/api/todos.module.d.ts.map +1 -0
- package/dist/api/todos.module.js +143 -0
- package/dist/api/todos.module.js.map +1 -0
- package/dist/chunk-CO56HIPE.mjs +283 -0
- package/dist/chunk-CO56HIPE.mjs.map +1 -0
- package/dist/chunk-K6KLDGC2.js +283 -0
- package/dist/chunk-K6KLDGC2.js.map +1 -0
- package/dist/seed/index.d.ts +4 -0
- package/dist/seed/index.d.ts.map +1 -0
- package/dist/seed/index.js +9 -0
- package/dist/seed/index.js.map +1 -0
- package/dist/seed/todos.module.seed.d.ts +12 -0
- package/dist/seed/todos.module.seed.d.ts.map +1 -0
- package/dist/seed/todos.module.seed.js +54 -0
- package/dist/seed/todos.module.seed.js.map +1 -0
- package/dist/shared/index.d.ts +7 -0
- package/dist/shared/index.d.ts.map +1 -0
- package/dist/shared/index.js +23 -0
- package/dist/shared/index.js.map +1 -0
- package/dist/shared/task.completed.filter.d.ts +2 -0
- package/dist/shared/task.completed.filter.d.ts.map +1 -0
- package/dist/shared/task.completed.filter.js +3 -0
- package/dist/shared/task.completed.filter.js.map +1 -0
- package/dist/shared/task.priority.d.ts +6 -0
- package/dist/shared/task.priority.d.ts.map +1 -0
- package/dist/shared/task.priority.js +10 -0
- package/dist/shared/task.priority.js.map +1 -0
- package/dist/shared/todos.endpoints.d.ts +7 -0
- package/dist/shared/todos.endpoints.d.ts.map +1 -0
- package/dist/shared/todos.endpoints.js +10 -0
- package/dist/shared/todos.endpoints.js.map +1 -0
- package/dist/shared/todos.events.d.ts +13 -0
- package/dist/shared/todos.events.d.ts.map +1 -0
- package/dist/shared/todos.events.js +16 -0
- package/dist/shared/todos.events.js.map +1 -0
- package/dist/shared/todos.module.ids.d.ts +5 -0
- package/dist/shared/todos.module.ids.d.ts.map +1 -0
- package/dist/shared/todos.module.ids.js +8 -0
- package/dist/shared/todos.module.ids.js.map +1 -0
- package/dist/shared/todos.notification.types.d.ts +6 -0
- package/dist/shared/todos.notification.types.d.ts.map +1 -0
- package/dist/shared/todos.notification.types.js +9 -0
- package/dist/shared/todos.notification.types.js.map +1 -0
- package/dist/web/config/todos.config.d.ts +25 -0
- package/dist/web/config/todos.config.d.ts.map +1 -0
- package/dist/web/config/todos.ui.config.d.ts +28 -0
- package/dist/web/config/todos.ui.config.d.ts.map +1 -0
- package/dist/web/core.d.ts +18 -0
- package/dist/web/core.d.ts.map +1 -0
- package/dist/web/core.js +208 -0
- package/dist/web/core.js.map +1 -0
- package/dist/web/core.mjs +208 -0
- package/dist/web/core.mjs.map +1 -0
- package/dist/web/index.d.ts +22 -0
- package/dist/web/index.d.ts.map +1 -0
- package/dist/web/index.js +1959 -0
- package/dist/web/index.js.map +1 -0
- package/dist/web/index.mjs +1958 -0
- package/dist/web/index.mjs.map +1 -0
- package/dist/web/task/TaskModule.d.ts +6 -0
- package/dist/web/task/TaskModule.d.ts.map +1 -0
- package/dist/web/task/components/EisenhowerIcon.d.ts +9 -0
- package/dist/web/task/components/EisenhowerIcon.d.ts.map +1 -0
- package/dist/web/task/components/EisenhowerMatrixBoard.d.ts +21 -0
- package/dist/web/task/components/EisenhowerMatrixBoard.d.ts.map +1 -0
- package/dist/web/task/components/TaskMatrixCard.d.ts +11 -0
- package/dist/web/task/components/TaskMatrixCard.d.ts.map +1 -0
- package/dist/web/task/components/containers/TaskListContainer.d.ts +12 -0
- package/dist/web/task/components/containers/TaskListContainer.d.ts.map +1 -0
- package/dist/web/task/components/editors/TaskEditor.d.ts +12 -0
- package/dist/web/task/components/editors/TaskEditor.d.ts.map +1 -0
- package/dist/web/task/components/filters/TaskListFilters.d.ts +9 -0
- package/dist/web/task/components/filters/TaskListFilters.d.ts.map +1 -0
- package/dist/web/task/components/filters/TaskViewSwitcher.d.ts +9 -0
- package/dist/web/task/components/filters/TaskViewSwitcher.d.ts.map +1 -0
- package/dist/web/task/components/forms/TaskCreateButton.d.ts +5 -0
- package/dist/web/task/components/forms/TaskCreateButton.d.ts.map +1 -0
- package/dist/web/task/components/forms/TaskDeleter.d.ts +8 -0
- package/dist/web/task/components/forms/TaskDeleter.d.ts.map +1 -0
- package/dist/web/task/components/lists/TasksList.d.ts +20 -0
- package/dist/web/task/components/lists/TasksList.d.ts.map +1 -0
- package/dist/web/task/components/screens/UserTasksScreen.d.ts +5 -0
- package/dist/web/task/components/screens/UserTasksScreen.d.ts.map +1 -0
- package/dist/web/task/contexts/TaskContext.d.ts +29 -0
- package/dist/web/task/contexts/TaskContext.d.ts.map +1 -0
- package/dist/web/task/data/Task.d.ts +25 -0
- package/dist/web/task/data/Task.d.ts.map +1 -0
- package/dist/web/task/data/TaskFields.d.ts +12 -0
- package/dist/web/task/data/TaskFields.d.ts.map +1 -0
- package/dist/web/task/data/TaskInterface.d.ts +29 -0
- package/dist/web/task/data/TaskInterface.d.ts.map +1 -0
- package/dist/web/task/data/TaskService.d.ts +51 -0
- package/dist/web/task/data/TaskService.d.ts.map +1 -0
- package/dist/web/task/hooks/useTaskDeepLink.d.ts +12 -0
- package/dist/web/task/hooks/useTaskDeepLink.d.ts.map +1 -0
- package/dist/web/task/hooks/useTaskOverdueParam.d.ts +19 -0
- package/dist/web/task/hooks/useTaskOverdueParam.d.ts.map +1 -0
- package/dist/web/task/hooks/useTaskTableStructure.d.ts +8 -0
- package/dist/web/task/hooks/useTaskTableStructure.d.ts.map +1 -0
- package/dist/web/task/lib/task.priority.options.d.ts +5 -0
- package/dist/web/task/lib/task.priority.options.d.ts.map +1 -0
- package/dist/web/task/utils/dueDate.d.ts +11 -0
- package/dist/web/task/utils/dueDate.d.ts.map +1 -0
- package/dist/web/task/utils/getEisenhowerQuadrant.d.ts +4 -0
- package/dist/web/task/utils/getEisenhowerQuadrant.d.ts.map +1 -0
- package/dist/web/task/utils/isTaskOverdue.d.ts +12 -0
- package/dist/web/task/utils/isTaskOverdue.d.ts.map +1 -0
- package/dist/web/taskcomment/TaskCommentModule.d.ts +5 -0
- package/dist/web/taskcomment/TaskCommentModule.d.ts.map +1 -0
- package/dist/web/taskcomment/components/forms/TaskCommentEditor.d.ts +2 -0
- package/dist/web/taskcomment/components/forms/TaskCommentEditor.d.ts.map +1 -0
- package/dist/web/taskcomment/components/lists/TaskCommentList.d.ts +2 -0
- package/dist/web/taskcomment/components/lists/TaskCommentList.d.ts.map +1 -0
- package/dist/web/taskcomment/contexts/TaskCommentContext.d.ts +22 -0
- package/dist/web/taskcomment/contexts/TaskCommentContext.d.ts.map +1 -0
- package/dist/web/taskcomment/data/TaskComment.d.ts +11 -0
- package/dist/web/taskcomment/data/TaskComment.d.ts.map +1 -0
- package/dist/web/taskcomment/data/TaskCommentInterface.d.ts +12 -0
- package/dist/web/taskcomment/data/TaskCommentInterface.d.ts.map +1 -0
- package/dist/web/taskcomment/data/TaskCommentService.d.ts +16 -0
- package/dist/web/taskcomment/data/TaskCommentService.d.ts.map +1 -0
- package/dist/web/todos.modules.d.ts +10 -0
- package/dist/web/todos.modules.d.ts.map +1 -0
- package/dist/web/utils/isNotFoundError.d.ts +11 -0
- package/dist/web/utils/isNotFoundError.d.ts.map +1 -0
- package/i18n/en/todos.json +13 -0
- package/i18n/it/todos.json +13 -0
- package/messages/en.json +132 -0
- package/messages/it.json +132 -0
- package/package.json +214 -5
- package/templates/email/en/taskAssigned.hbs +31 -0
- package/templates/email/en/taskCommented.hbs +31 -0
- package/templates/email/en/taskCompleted.hbs +31 -0
- package/templates/email/it/taskAssigned.hbs +31 -0
- package/templates/email/it/taskCommented.hbs +31 -0
- package/templates/email/it/taskCompleted.hbs +31 -0
|
@@ -0,0 +1,1958 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
TASK_ENDPOINT,
|
|
4
|
+
TaskCommentService,
|
|
5
|
+
TaskPriority,
|
|
6
|
+
TaskService,
|
|
7
|
+
TodosModules,
|
|
8
|
+
__name,
|
|
9
|
+
getTodosConfig
|
|
10
|
+
} from "../chunk-CO56HIPE.mjs";
|
|
11
|
+
|
|
12
|
+
// src/web/task/contexts/TaskContext.tsx
|
|
13
|
+
import { usePageUrlGenerator } from "@carlonicora/nextjs-jsonapi/client";
|
|
14
|
+
import { SharedProvider } from "@carlonicora/nextjs-jsonapi/contexts";
|
|
15
|
+
import { errorToast } from "@carlonicora/nextjs-jsonapi/components";
|
|
16
|
+
import { showError } from "@carlonicora/nextjs-jsonapi/core";
|
|
17
|
+
import { useTranslations } from "next-intl";
|
|
18
|
+
import { createContext, useContext, useEffect, useRef, useState } from "react";
|
|
19
|
+
|
|
20
|
+
// src/web/utils/isNotFoundError.ts
|
|
21
|
+
function statusOf(error) {
|
|
22
|
+
const status = error?.status;
|
|
23
|
+
return typeof status === "number" ? status : void 0;
|
|
24
|
+
}
|
|
25
|
+
__name(statusOf, "statusOf");
|
|
26
|
+
var NOT_FOUND_STATUSES = [400, 403, 404];
|
|
27
|
+
function isNotFoundError(error) {
|
|
28
|
+
const status = statusOf(error);
|
|
29
|
+
return status !== void 0 && NOT_FOUND_STATUSES.includes(status);
|
|
30
|
+
}
|
|
31
|
+
__name(isNotFoundError, "isNotFoundError");
|
|
32
|
+
function isTaskGoneError(error) {
|
|
33
|
+
return statusOf(error) === 404;
|
|
34
|
+
}
|
|
35
|
+
__name(isTaskGoneError, "isTaskGoneError");
|
|
36
|
+
|
|
37
|
+
// src/web/task/contexts/TaskContext.tsx
|
|
38
|
+
import { jsx } from "react/jsx-runtime";
|
|
39
|
+
var TaskContext = createContext(void 0);
|
|
40
|
+
function TaskProvider({ children, scope }) {
|
|
41
|
+
const generateUrl = usePageUrlGenerator();
|
|
42
|
+
const t = useTranslations();
|
|
43
|
+
const pageUrl = getTodosConfig().pageUrl;
|
|
44
|
+
const [task, setTask] = useState(void 0);
|
|
45
|
+
const [taskEditorShown, setTaskEditorShown] = useState(false);
|
|
46
|
+
const [version, setVersion] = useState(0);
|
|
47
|
+
const setTaskId = /* @__PURE__ */ __name(async (taskId) => {
|
|
48
|
+
try {
|
|
49
|
+
setTask(await TaskService.findOne({ id: taskId }));
|
|
50
|
+
setTaskEditorShown(true);
|
|
51
|
+
} catch (error) {
|
|
52
|
+
if (isNotFoundError(error))
|
|
53
|
+
showError(t("task.messages.not_found"), { description: t("task.messages.not_found_description") });
|
|
54
|
+
else errorToast({ title: t("task.errors.load"), error });
|
|
55
|
+
}
|
|
56
|
+
}, "setTaskId");
|
|
57
|
+
const showTask = /* @__PURE__ */ __name((currentTask) => {
|
|
58
|
+
setTask(currentTask);
|
|
59
|
+
setTaskEditorShown(true);
|
|
60
|
+
}, "showTask");
|
|
61
|
+
const setCurrentTask = /* @__PURE__ */ __name((currentTask) => {
|
|
62
|
+
setVersion((prev) => prev + 1);
|
|
63
|
+
setTask((prev) => prev?.id === currentTask.id ? currentTask : prev);
|
|
64
|
+
}, "setCurrentTask");
|
|
65
|
+
const setNewTask = /* @__PURE__ */ __name(() => {
|
|
66
|
+
setTask(void 0);
|
|
67
|
+
setTaskEditorShown(true);
|
|
68
|
+
}, "setNewTask");
|
|
69
|
+
const hideTaskEditor = /* @__PURE__ */ __name(() => {
|
|
70
|
+
setTask(void 0);
|
|
71
|
+
setTaskEditorShown(false);
|
|
72
|
+
}, "hideTaskEditor");
|
|
73
|
+
const content = /* @__PURE__ */ jsx(
|
|
74
|
+
TaskContext.Provider,
|
|
75
|
+
{
|
|
76
|
+
value: {
|
|
77
|
+
task,
|
|
78
|
+
scope,
|
|
79
|
+
setTaskId,
|
|
80
|
+
setNewTask,
|
|
81
|
+
showTask,
|
|
82
|
+
taskEditorShown,
|
|
83
|
+
setTaskEditorShown,
|
|
84
|
+
hideTaskEditor,
|
|
85
|
+
setCurrentTask,
|
|
86
|
+
version
|
|
87
|
+
},
|
|
88
|
+
children
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
if (!pageUrl || scope) return content;
|
|
92
|
+
const breadcrumb = /* @__PURE__ */ __name(() => [
|
|
93
|
+
{
|
|
94
|
+
name: t(`entities.tasks`, { count: 2 }),
|
|
95
|
+
href: generateUrl({ page: pageUrl })
|
|
96
|
+
}
|
|
97
|
+
], "breadcrumb");
|
|
98
|
+
const title = /* @__PURE__ */ __name(() => ({
|
|
99
|
+
type: t(`entities.tasks`, { count: task ? 1 : 2 })
|
|
100
|
+
}), "title");
|
|
101
|
+
return /* @__PURE__ */ jsx(SharedProvider, { value: { breadcrumbs: breadcrumb(), title: title() }, children: content });
|
|
102
|
+
}
|
|
103
|
+
__name(TaskProvider, "TaskProvider");
|
|
104
|
+
var defaultTaskContext = {
|
|
105
|
+
task: void 0,
|
|
106
|
+
scope: void 0,
|
|
107
|
+
setTaskId: /* @__PURE__ */ __name(async () => {
|
|
108
|
+
}, "setTaskId"),
|
|
109
|
+
setNewTask: /* @__PURE__ */ __name(() => {
|
|
110
|
+
}, "setNewTask"),
|
|
111
|
+
showTask: /* @__PURE__ */ __name(() => {
|
|
112
|
+
}, "showTask"),
|
|
113
|
+
taskEditorShown: false,
|
|
114
|
+
setTaskEditorShown: /* @__PURE__ */ __name(() => {
|
|
115
|
+
}, "setTaskEditorShown"),
|
|
116
|
+
hideTaskEditor: /* @__PURE__ */ __name(() => {
|
|
117
|
+
}, "hideTaskEditor"),
|
|
118
|
+
setCurrentTask: /* @__PURE__ */ __name(() => {
|
|
119
|
+
}, "setCurrentTask"),
|
|
120
|
+
version: 0
|
|
121
|
+
};
|
|
122
|
+
function useTaskContext() {
|
|
123
|
+
return useContext(TaskContext) ?? defaultTaskContext;
|
|
124
|
+
}
|
|
125
|
+
__name(useTaskContext, "useTaskContext");
|
|
126
|
+
var useRefreshOnTaskEditorClose = /* @__PURE__ */ __name((refresh) => {
|
|
127
|
+
const { taskEditorShown } = useTaskContext();
|
|
128
|
+
const prevEditorShown = useRef(taskEditorShown);
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
if (prevEditorShown.current && !taskEditorShown) refresh();
|
|
131
|
+
prevEditorShown.current = taskEditorShown;
|
|
132
|
+
}, [taskEditorShown]);
|
|
133
|
+
}, "useRefreshOnTaskEditorClose");
|
|
134
|
+
|
|
135
|
+
// src/web/task/hooks/useTaskDeepLink.ts
|
|
136
|
+
import { errorToast as errorToast2 } from "@carlonicora/nextjs-jsonapi/components";
|
|
137
|
+
import { showError as showError2 } from "@carlonicora/nextjs-jsonapi/core";
|
|
138
|
+
import { useTranslations as useTranslations2 } from "next-intl";
|
|
139
|
+
import { useEffect as useEffect2 } from "react";
|
|
140
|
+
var TASK_PARAM = "task";
|
|
141
|
+
function removeTaskParam() {
|
|
142
|
+
const search = new URLSearchParams(window.location.search);
|
|
143
|
+
if (!search.has(TASK_PARAM)) return;
|
|
144
|
+
search.delete(TASK_PARAM);
|
|
145
|
+
const next = search.toString();
|
|
146
|
+
window.history.replaceState(null, "", `${window.location.pathname}${next ? `?${next}` : ""}${window.location.hash}`);
|
|
147
|
+
}
|
|
148
|
+
__name(removeTaskParam, "removeTaskParam");
|
|
149
|
+
function useTaskDeepLink(params) {
|
|
150
|
+
const { showTask } = useTaskContext();
|
|
151
|
+
const t = useTranslations2();
|
|
152
|
+
useEffect2(() => {
|
|
153
|
+
const taskId = new URLSearchParams(window.location.search).get(TASK_PARAM);
|
|
154
|
+
if (!taskId) return;
|
|
155
|
+
const notFound = /* @__PURE__ */ __name(() => {
|
|
156
|
+
showError2(t("task.messages.not_found"), { description: t("task.messages.not_found_description") });
|
|
157
|
+
removeTaskParam();
|
|
158
|
+
}, "notFound");
|
|
159
|
+
TaskService.findOne({ id: taskId }).then((task) => {
|
|
160
|
+
if (!params?.scope || task.related(params.scope.key)?.id === params.scope.id) {
|
|
161
|
+
showTask(task);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
notFound();
|
|
165
|
+
}).catch((error) => {
|
|
166
|
+
if (isNotFoundError(error)) {
|
|
167
|
+
notFound();
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
errorToast2({ title: t("task.errors.load"), error });
|
|
171
|
+
removeTaskParam();
|
|
172
|
+
});
|
|
173
|
+
}, []);
|
|
174
|
+
useRefreshOnTaskEditorClose(() => removeTaskParam());
|
|
175
|
+
}
|
|
176
|
+
__name(useTaskDeepLink, "useTaskDeepLink");
|
|
177
|
+
|
|
178
|
+
// src/web/task/components/editors/TaskEditor.tsx
|
|
179
|
+
import { useDebounce } from "@carlonicora/nextjs-jsonapi/client";
|
|
180
|
+
import {
|
|
181
|
+
BlockNoteEditorContainer as BlockNoteEditorContainer3,
|
|
182
|
+
Button as Button3,
|
|
183
|
+
EditorSheet,
|
|
184
|
+
errorToast as errorToast6,
|
|
185
|
+
FormDate,
|
|
186
|
+
FormFieldWrapper,
|
|
187
|
+
FormInput,
|
|
188
|
+
FormSelect,
|
|
189
|
+
Tabs,
|
|
190
|
+
TabsContent,
|
|
191
|
+
TabsList,
|
|
192
|
+
TabsTrigger,
|
|
193
|
+
Tooltip as Tooltip2,
|
|
194
|
+
TooltipContent as TooltipContent2,
|
|
195
|
+
TooltipTrigger as TooltipTrigger2,
|
|
196
|
+
UserSelector
|
|
197
|
+
} from "@carlonicora/nextjs-jsonapi/components";
|
|
198
|
+
import { useCurrentUserContext as useCurrentUserContext3 } from "@carlonicora/nextjs-jsonapi/contexts";
|
|
199
|
+
import {
|
|
200
|
+
Action as Action3,
|
|
201
|
+
cn,
|
|
202
|
+
entityObjectSchema,
|
|
203
|
+
showToast,
|
|
204
|
+
userObjectSchema
|
|
205
|
+
} from "@carlonicora/nextjs-jsonapi/core";
|
|
206
|
+
import { zodResolver as zodResolver2 } from "@hookform/resolvers/zod";
|
|
207
|
+
import { CheckIcon, LinkIcon } from "lucide-react";
|
|
208
|
+
import { useTranslations as useTranslations8 } from "next-intl";
|
|
209
|
+
import { useEffect as useEffect5, useMemo, useRef as useRef3, useState as useState5 } from "react";
|
|
210
|
+
import { useForm as useForm2 } from "react-hook-form";
|
|
211
|
+
import { v4 as v42 } from "uuid";
|
|
212
|
+
import { z as z2 } from "zod";
|
|
213
|
+
|
|
214
|
+
// src/web/config/todos.ui.config.ts
|
|
215
|
+
var TODOS_UI_KEY = /* @__PURE__ */ Symbol.for("nja-todos.ui");
|
|
216
|
+
var EMPTY = Object.freeze({});
|
|
217
|
+
var noEditorProps = /* @__PURE__ */ __name(() => EMPTY, "noEditorProps");
|
|
218
|
+
function configureTodosUi(config) {
|
|
219
|
+
globalThis[TODOS_UI_KEY] = config;
|
|
220
|
+
}
|
|
221
|
+
__name(configureTodosUi, "configureTodosUi");
|
|
222
|
+
function getTodosUiConfig() {
|
|
223
|
+
return globalThis[TODOS_UI_KEY] ?? {};
|
|
224
|
+
}
|
|
225
|
+
__name(getTodosUiConfig, "getTodosUiConfig");
|
|
226
|
+
function useTodosEditorProps(context) {
|
|
227
|
+
const hook = getTodosUiConfig().useEditorProps ?? noEditorProps;
|
|
228
|
+
return hook(context);
|
|
229
|
+
}
|
|
230
|
+
__name(useTodosEditorProps, "useTodosEditorProps");
|
|
231
|
+
|
|
232
|
+
// src/web/taskcomment/components/forms/TaskCommentEditor.tsx
|
|
233
|
+
import { BlockNoteEditorContainer, Button, errorToast as errorToast4, Form, UserAvatar } from "@carlonicora/nextjs-jsonapi/components";
|
|
234
|
+
import { useCurrentUserContext } from "@carlonicora/nextjs-jsonapi/contexts";
|
|
235
|
+
import { Action } from "@carlonicora/nextjs-jsonapi/core";
|
|
236
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
237
|
+
import { useTranslations as useTranslations4 } from "next-intl";
|
|
238
|
+
import { useState as useState3 } from "react";
|
|
239
|
+
import { useForm } from "react-hook-form";
|
|
240
|
+
import { v4 } from "uuid";
|
|
241
|
+
import { z } from "zod";
|
|
242
|
+
|
|
243
|
+
// src/web/taskcomment/contexts/TaskCommentContext.tsx
|
|
244
|
+
import { errorToast as errorToast3 } from "@carlonicora/nextjs-jsonapi/components";
|
|
245
|
+
import { useTranslations as useTranslations3 } from "next-intl";
|
|
246
|
+
import { createContext as createContext2, useContext as useContext2, useEffect as useEffect3, useState as useState2 } from "react";
|
|
247
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
248
|
+
var TaskCommentContext = createContext2(void 0);
|
|
249
|
+
function TaskCommentProvider({ task, open = true, children }) {
|
|
250
|
+
const t = useTranslations3();
|
|
251
|
+
const [comments, setComments] = useState2([]);
|
|
252
|
+
useEffect3(() => {
|
|
253
|
+
if (!task || !open) return;
|
|
254
|
+
let cancelled = false;
|
|
255
|
+
TaskCommentService.findMany({ taskId: task.id, fetchAll: true }).then((loaded) => {
|
|
256
|
+
if (!cancelled) setComments(loaded);
|
|
257
|
+
}).catch((error) => {
|
|
258
|
+
if (!cancelled) errorToast3({ title: t("task.errors.load"), error });
|
|
259
|
+
});
|
|
260
|
+
return () => {
|
|
261
|
+
cancelled = true;
|
|
262
|
+
};
|
|
263
|
+
}, [task?.id, open]);
|
|
264
|
+
const addComment = /* @__PURE__ */ __name((comment) => {
|
|
265
|
+
setComments((prev) => [...prev, comment]);
|
|
266
|
+
}, "addComment");
|
|
267
|
+
const updateComment = /* @__PURE__ */ __name((comment) => {
|
|
268
|
+
setComments((prev) => prev.map((existing) => existing.id === comment.id ? comment : existing));
|
|
269
|
+
}, "updateComment");
|
|
270
|
+
const removeComment = /* @__PURE__ */ __name((id) => {
|
|
271
|
+
setComments((prev) => prev.filter((existing) => existing.id !== id));
|
|
272
|
+
}, "removeComment");
|
|
273
|
+
return /* @__PURE__ */ jsx2(
|
|
274
|
+
TaskCommentContext.Provider,
|
|
275
|
+
{
|
|
276
|
+
value: {
|
|
277
|
+
task,
|
|
278
|
+
comments,
|
|
279
|
+
setComments,
|
|
280
|
+
addComment,
|
|
281
|
+
updateComment,
|
|
282
|
+
removeComment
|
|
283
|
+
},
|
|
284
|
+
children
|
|
285
|
+
}
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
__name(TaskCommentProvider, "TaskCommentProvider");
|
|
289
|
+
function useTaskCommentContext() {
|
|
290
|
+
const context = useContext2(TaskCommentContext);
|
|
291
|
+
if (context === void 0) {
|
|
292
|
+
throw new Error("useTaskCommentContext must be used within a TaskCommentProvider");
|
|
293
|
+
}
|
|
294
|
+
return context;
|
|
295
|
+
}
|
|
296
|
+
__name(useTaskCommentContext, "useTaskCommentContext");
|
|
297
|
+
|
|
298
|
+
// src/web/taskcomment/components/forms/TaskCommentEditor.tsx
|
|
299
|
+
import { jsx as jsx3, jsxs } from "react/jsx-runtime";
|
|
300
|
+
function TaskCommentEditor() {
|
|
301
|
+
const { currentUser, hasPermissionToModule } = useCurrentUserContext();
|
|
302
|
+
const { task, addComment } = useTaskCommentContext();
|
|
303
|
+
const { scope } = useTaskContext();
|
|
304
|
+
const t = useTranslations4();
|
|
305
|
+
const editorProps = useTodosEditorProps({ task, scope });
|
|
306
|
+
const [editorKey, setEditorKey] = useState3(v4());
|
|
307
|
+
const [hasContent, setHasContent] = useState3(false);
|
|
308
|
+
const formSchema = z.object({
|
|
309
|
+
id: z.uuidv4(),
|
|
310
|
+
// The value is a blocks array (06-blocknote "Editing — inside a form"), so it is never string-validated.
|
|
311
|
+
content: z.any()
|
|
312
|
+
});
|
|
313
|
+
const form = useForm({
|
|
314
|
+
resolver: zodResolver(formSchema),
|
|
315
|
+
defaultValues: {
|
|
316
|
+
id: v4(),
|
|
317
|
+
content: []
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
if (!currentUser || !task || !hasPermissionToModule({ module: TodosModules.TaskComment, action: Action.Create }))
|
|
321
|
+
return null;
|
|
322
|
+
const resetForm = /* @__PURE__ */ __name(() => {
|
|
323
|
+
form.reset({
|
|
324
|
+
id: v4(),
|
|
325
|
+
content: []
|
|
326
|
+
});
|
|
327
|
+
setEditorKey(v4());
|
|
328
|
+
}, "resetForm");
|
|
329
|
+
const onChange = /* @__PURE__ */ __name(async (content, isEmpty) => {
|
|
330
|
+
form.setValue("content", content, { shouldDirty: !isEmpty });
|
|
331
|
+
setHasContent(!isEmpty);
|
|
332
|
+
}, "onChange");
|
|
333
|
+
const onSubmit = /* @__PURE__ */ __name(async (values) => {
|
|
334
|
+
if (!hasContent) return;
|
|
335
|
+
const payload = {
|
|
336
|
+
id: values.id,
|
|
337
|
+
taskId: task.id,
|
|
338
|
+
content: values.content
|
|
339
|
+
};
|
|
340
|
+
try {
|
|
341
|
+
const updatedTaskComment = await TaskCommentService.create(payload);
|
|
342
|
+
addComment(updatedTaskComment);
|
|
343
|
+
resetForm();
|
|
344
|
+
} catch (error) {
|
|
345
|
+
errorToast4({ title: t(`taskcomment.errors.save`), error });
|
|
346
|
+
}
|
|
347
|
+
setHasContent(false);
|
|
348
|
+
}, "onSubmit");
|
|
349
|
+
const handleSubmit = /* @__PURE__ */ __name(() => {
|
|
350
|
+
form.handleSubmit(onSubmit)();
|
|
351
|
+
}, "handleSubmit");
|
|
352
|
+
return /* @__PURE__ */ jsx3(Form, { ...form, children: /* @__PURE__ */ jsxs("div", { className: "flex w-full flex-row justify-between gap-x-2", children: [
|
|
353
|
+
/* @__PURE__ */ jsx3(UserAvatar, { user: currentUser, showLink: false }),
|
|
354
|
+
/* @__PURE__ */ jsx3("div", { "data-testid": "task-comment-input", className: "text-foreground flex w-full flex-col gap-y-2 rounded border", children: /* @__PURE__ */ jsxs("div", { className: "group relative flex flex-col", children: [
|
|
355
|
+
/* @__PURE__ */ jsx3(
|
|
356
|
+
BlockNoteEditorContainer,
|
|
357
|
+
{
|
|
358
|
+
id: form.getValues("id"),
|
|
359
|
+
type: "taskcomment",
|
|
360
|
+
placeholder: t("taskcomment.placeholder"),
|
|
361
|
+
onChange,
|
|
362
|
+
size: "sm",
|
|
363
|
+
className: "min-h-8 group-focus-within:min-h-32",
|
|
364
|
+
...editorProps
|
|
365
|
+
},
|
|
366
|
+
editorKey
|
|
367
|
+
),
|
|
368
|
+
/* @__PURE__ */ jsx3(
|
|
369
|
+
"div",
|
|
370
|
+
{
|
|
371
|
+
className: `pointer-events-none absolute end-2 bottom-2 opacity-0 transition-opacity duration-150 group-focus-within:pointer-events-auto group-focus-within:opacity-100 ${hasContent ? "pointer-events-auto opacity-100" : ""}`,
|
|
372
|
+
children: /* @__PURE__ */ jsx3(
|
|
373
|
+
Button,
|
|
374
|
+
{
|
|
375
|
+
"data-testid": "task-comment-submit",
|
|
376
|
+
disabled: !hasContent,
|
|
377
|
+
size: "sm",
|
|
378
|
+
onClick: (e) => {
|
|
379
|
+
e.preventDefault();
|
|
380
|
+
handleSubmit();
|
|
381
|
+
},
|
|
382
|
+
children: t(`taskcomment.buttons.comment`)
|
|
383
|
+
}
|
|
384
|
+
)
|
|
385
|
+
}
|
|
386
|
+
)
|
|
387
|
+
] }) })
|
|
388
|
+
] }) });
|
|
389
|
+
}
|
|
390
|
+
__name(TaskCommentEditor, "TaskCommentEditor");
|
|
391
|
+
|
|
392
|
+
// src/web/taskcomment/components/lists/TaskCommentList.tsx
|
|
393
|
+
import {
|
|
394
|
+
BlockNoteEditorContainer as BlockNoteEditorContainer2,
|
|
395
|
+
Button as Button2,
|
|
396
|
+
CommonDeleter,
|
|
397
|
+
errorToast as errorToast5,
|
|
398
|
+
SectionHeader,
|
|
399
|
+
UserAvatar as UserAvatar2
|
|
400
|
+
} from "@carlonicora/nextjs-jsonapi/components";
|
|
401
|
+
import { useCurrentUserContext as useCurrentUserContext2, useDateFormatter, useMountedNow } from "@carlonicora/nextjs-jsonapi/contexts";
|
|
402
|
+
import { Action as Action2 } from "@carlonicora/nextjs-jsonapi/core";
|
|
403
|
+
import { PencilIcon } from "lucide-react";
|
|
404
|
+
import { useTranslations as useTranslations5 } from "next-intl";
|
|
405
|
+
import { useEffect as useEffect4, useRef as useRef2, useState as useState4 } from "react";
|
|
406
|
+
import { Fragment, jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
407
|
+
function CommentAge({ date }) {
|
|
408
|
+
const { relative } = useDateFormatter();
|
|
409
|
+
const now = useMountedNow();
|
|
410
|
+
return /* @__PURE__ */ jsx4(Fragment, { children: now ? relative(date, { now }) : "" });
|
|
411
|
+
}
|
|
412
|
+
__name(CommentAge, "CommentAge");
|
|
413
|
+
function TaskCommentList() {
|
|
414
|
+
const { task, comments, updateComment, removeComment } = useTaskCommentContext();
|
|
415
|
+
const { scope } = useTaskContext();
|
|
416
|
+
const { currentUser, hasPermissionToModule } = useCurrentUserContext2();
|
|
417
|
+
const t = useTranslations5();
|
|
418
|
+
const editorProps = useTodosEditorProps({ task, scope });
|
|
419
|
+
const bottomRef = useRef2(null);
|
|
420
|
+
const firstLoad = useRef2(true);
|
|
421
|
+
const prevCommentCount = useRef2(comments.length);
|
|
422
|
+
const [editingId, setEditingId] = useState4(void 0);
|
|
423
|
+
const [draft, setDraft] = useState4(void 0);
|
|
424
|
+
const [draftEmpty, setDraftEmpty] = useState4(false);
|
|
425
|
+
useEffect4(() => {
|
|
426
|
+
if (comments.length === 0) return;
|
|
427
|
+
if (firstLoad.current) {
|
|
428
|
+
firstLoad.current = false;
|
|
429
|
+
prevCommentCount.current = comments.length;
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
if (comments.length > prevCommentCount.current) {
|
|
433
|
+
bottomRef.current?.scrollIntoView({ behavior: "smooth" });
|
|
434
|
+
}
|
|
435
|
+
prevCommentCount.current = comments.length;
|
|
436
|
+
}, [comments]);
|
|
437
|
+
if (!hasPermissionToModule({ module: TodosModules.TaskComment, action: Action2.Read })) return null;
|
|
438
|
+
const canUpdate = hasPermissionToModule({ module: TodosModules.TaskComment, action: Action2.Update });
|
|
439
|
+
const canDelete = hasPermissionToModule({ module: TodosModules.TaskComment, action: Action2.Delete });
|
|
440
|
+
const startEditing = /* @__PURE__ */ __name((comment) => {
|
|
441
|
+
setDraft(comment.content);
|
|
442
|
+
setDraftEmpty(false);
|
|
443
|
+
setEditingId(comment.id);
|
|
444
|
+
}, "startEditing");
|
|
445
|
+
const stopEditing = /* @__PURE__ */ __name(() => {
|
|
446
|
+
setEditingId(void 0);
|
|
447
|
+
setDraft(void 0);
|
|
448
|
+
}, "stopEditing");
|
|
449
|
+
const saveEdit = /* @__PURE__ */ __name(async (comment) => {
|
|
450
|
+
if (!task) return;
|
|
451
|
+
try {
|
|
452
|
+
const saved = await TaskCommentService.update({ id: comment.id, content: draft, taskId: task.id });
|
|
453
|
+
updateComment(saved);
|
|
454
|
+
stopEditing();
|
|
455
|
+
} catch (error) {
|
|
456
|
+
errorToast5({ title: t("taskcomment.errors.save"), error });
|
|
457
|
+
}
|
|
458
|
+
}, "saveEdit");
|
|
459
|
+
return /* @__PURE__ */ jsxs2("div", { className: "border-primary my-2 flex w-full flex-col gap-y-2 border-t pt-4", children: [
|
|
460
|
+
/* @__PURE__ */ jsx4("div", { className: "flex w-full items-center justify-between gap-x-2 ps-2", children: /* @__PURE__ */ jsx4(SectionHeader, { level: 3, children: t(`entities.taskcomments`, { count: comments.length }) }) }),
|
|
461
|
+
comments.map((comment) => {
|
|
462
|
+
const isAuthor = !!comment.owner && comment.owner.id === currentUser?.id;
|
|
463
|
+
const isEditing = editingId === comment.id;
|
|
464
|
+
return /* @__PURE__ */ jsxs2("div", { className: "flex w-full flex-col", "data-testid": `task-comment-${comment.id}`, children: [
|
|
465
|
+
/* @__PURE__ */ jsxs2("div", { className: "flex w-full items-center justify-between gap-x-2 ps-2", children: [
|
|
466
|
+
comment.owner && /* @__PURE__ */ jsx4(UserAvatar2, { user: comment.owner, showLink: false }),
|
|
467
|
+
/* @__PURE__ */ jsx4("span", { className: "flex w-full items-center text-sm font-semibold", children: comment.owner?.name ?? "" }),
|
|
468
|
+
/* @__PURE__ */ jsx4("span", { className: "text-muted-foreground text-xs pe-2 whitespace-nowrap", children: /* @__PURE__ */ jsx4(CommentAge, { date: comment.createdAt }) }),
|
|
469
|
+
isAuthor && canUpdate && !isEditing && /* @__PURE__ */ jsx4(
|
|
470
|
+
Button2,
|
|
471
|
+
{
|
|
472
|
+
type: "button",
|
|
473
|
+
variant: "ghost",
|
|
474
|
+
size: "icon-sm",
|
|
475
|
+
"data-testid": "task-comment-edit",
|
|
476
|
+
"aria-label": t("taskcomment.buttons.edit"),
|
|
477
|
+
onClick: () => startEditing(comment),
|
|
478
|
+
children: /* @__PURE__ */ jsx4(PencilIcon, {})
|
|
479
|
+
}
|
|
480
|
+
),
|
|
481
|
+
isAuthor && canDelete && /* @__PURE__ */ jsx4(
|
|
482
|
+
CommonDeleter,
|
|
483
|
+
{
|
|
484
|
+
testId: "task-comment-delete",
|
|
485
|
+
title: t("taskcomment.delete.title"),
|
|
486
|
+
subtitle: t("taskcomment.delete.subtitle"),
|
|
487
|
+
description: /* @__PURE__ */ jsx4("div", { className: "text-destructive p-4 text-sm", children: t("taskcomment.delete.description") }),
|
|
488
|
+
deleteFunction: () => TaskCommentService.delete({ id: comment.id }),
|
|
489
|
+
onSuccess: () => removeComment(comment.id)
|
|
490
|
+
}
|
|
491
|
+
)
|
|
492
|
+
] }),
|
|
493
|
+
/* @__PURE__ */ jsx4("div", { className: "flex w-full flex-col ps-10", children: isEditing ? /* @__PURE__ */ jsxs2("div", { className: "flex flex-col gap-y-2", children: [
|
|
494
|
+
/* @__PURE__ */ jsx4("div", { "data-testid": "task-comment-edit-input", children: /* @__PURE__ */ jsx4(
|
|
495
|
+
BlockNoteEditorContainer2,
|
|
496
|
+
{
|
|
497
|
+
id: comment.id,
|
|
498
|
+
type: "taskcomment",
|
|
499
|
+
initialContent: comment.content,
|
|
500
|
+
onChange: (content, isEmpty) => {
|
|
501
|
+
setDraft(content);
|
|
502
|
+
setDraftEmpty(isEmpty);
|
|
503
|
+
},
|
|
504
|
+
size: "sm",
|
|
505
|
+
...editorProps
|
|
506
|
+
},
|
|
507
|
+
`${comment.id}-edit`
|
|
508
|
+
) }),
|
|
509
|
+
/* @__PURE__ */ jsxs2("div", { className: "flex justify-end gap-x-2", children: [
|
|
510
|
+
/* @__PURE__ */ jsx4(
|
|
511
|
+
Button2,
|
|
512
|
+
{
|
|
513
|
+
type: "button",
|
|
514
|
+
size: "sm",
|
|
515
|
+
variant: "ghost",
|
|
516
|
+
"data-testid": "task-comment-cancel",
|
|
517
|
+
onClick: stopEditing,
|
|
518
|
+
children: t("taskcomment.buttons.cancel")
|
|
519
|
+
}
|
|
520
|
+
),
|
|
521
|
+
/* @__PURE__ */ jsx4(
|
|
522
|
+
Button2,
|
|
523
|
+
{
|
|
524
|
+
type: "button",
|
|
525
|
+
size: "sm",
|
|
526
|
+
"data-testid": "task-comment-edit-save",
|
|
527
|
+
disabled: draftEmpty,
|
|
528
|
+
onClick: () => saveEdit(comment),
|
|
529
|
+
children: t("taskcomment.buttons.save")
|
|
530
|
+
}
|
|
531
|
+
)
|
|
532
|
+
] })
|
|
533
|
+
] }) : /* @__PURE__ */ jsx4("div", { className: "group relative flex flex-col", children: /* @__PURE__ */ jsx4(
|
|
534
|
+
BlockNoteEditorContainer2,
|
|
535
|
+
{
|
|
536
|
+
id: comment.id,
|
|
537
|
+
type: "taskcomment",
|
|
538
|
+
initialContent: comment.content,
|
|
539
|
+
size: "sm",
|
|
540
|
+
...editorProps
|
|
541
|
+
}
|
|
542
|
+
) }) })
|
|
543
|
+
] }, comment.id);
|
|
544
|
+
}),
|
|
545
|
+
/* @__PURE__ */ jsx4("div", { ref: bottomRef })
|
|
546
|
+
] });
|
|
547
|
+
}
|
|
548
|
+
__name(TaskCommentList, "TaskCommentList");
|
|
549
|
+
|
|
550
|
+
// src/web/task/lib/task.priority.options.ts
|
|
551
|
+
var getTaskPrioritiesSelectOptions = /* @__PURE__ */ __name((t) => {
|
|
552
|
+
const priorities = Object.values(TaskPriority);
|
|
553
|
+
return priorities.map((priority) => ({
|
|
554
|
+
id: priority,
|
|
555
|
+
text: t(`task.priorities`, { priority })
|
|
556
|
+
}));
|
|
557
|
+
}, "getTaskPrioritiesSelectOptions");
|
|
558
|
+
|
|
559
|
+
// src/web/task/utils/dueDate.ts
|
|
560
|
+
function dueDateDay(dueDate) {
|
|
561
|
+
return dueDate.toISOString().slice(0, 10);
|
|
562
|
+
}
|
|
563
|
+
__name(dueDateDay, "dueDateDay");
|
|
564
|
+
function dueDateAsLocal(dueDate) {
|
|
565
|
+
return new Date(dueDate.getUTCFullYear(), dueDate.getUTCMonth(), dueDate.getUTCDate());
|
|
566
|
+
}
|
|
567
|
+
__name(dueDateAsLocal, "dueDateAsLocal");
|
|
568
|
+
|
|
569
|
+
// src/web/task/utils/getEisenhowerQuadrant.ts
|
|
570
|
+
function isWithinBusinessDays(dueDate, days, now) {
|
|
571
|
+
const today = new Date(now);
|
|
572
|
+
today.setHours(0, 0, 0, 0);
|
|
573
|
+
const due = dueDateAsLocal(dueDate);
|
|
574
|
+
if (due <= today) return true;
|
|
575
|
+
let count = 0;
|
|
576
|
+
const cursor = new Date(today);
|
|
577
|
+
while (count < days) {
|
|
578
|
+
cursor.setDate(cursor.getDate() + 1);
|
|
579
|
+
const dayOfWeek = cursor.getDay();
|
|
580
|
+
if (dayOfWeek !== 0 && dayOfWeek !== 6) {
|
|
581
|
+
count++;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
return due <= cursor;
|
|
585
|
+
}
|
|
586
|
+
__name(isWithinBusinessDays, "isWithinBusinessDays");
|
|
587
|
+
function getEisenhowerQuadrant(priority, dueDate, now) {
|
|
588
|
+
const isImportant = priority === "high";
|
|
589
|
+
const isUrgent = dueDate !== void 0 && isWithinBusinessDays(dueDate, 3, now);
|
|
590
|
+
if (isImportant && isUrgent) return "do";
|
|
591
|
+
if (isImportant && !isUrgent) return "defer";
|
|
592
|
+
if (!isImportant && isUrgent) return "delegate";
|
|
593
|
+
return "delete";
|
|
594
|
+
}
|
|
595
|
+
__name(getEisenhowerQuadrant, "getEisenhowerQuadrant");
|
|
596
|
+
|
|
597
|
+
// src/web/task/components/EisenhowerIcon.tsx
|
|
598
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from "@carlonicora/nextjs-jsonapi/components";
|
|
599
|
+
import { useTranslations as useTranslations6 } from "next-intl";
|
|
600
|
+
import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
601
|
+
var QUADRANT_CONFIG = {
|
|
602
|
+
do: { index: 0, fillClass: "fill-destructive" },
|
|
603
|
+
defer: { index: 1, fillClass: "fill-warning" },
|
|
604
|
+
delegate: { index: 2, fillClass: "fill-primary" },
|
|
605
|
+
delete: { index: 3, fillClass: "fill-muted-foreground" }
|
|
606
|
+
};
|
|
607
|
+
var QUADRANT_POSITIONS = [
|
|
608
|
+
{ x: 1, y: 1 },
|
|
609
|
+
// top-left: do
|
|
610
|
+
{ x: 13, y: 1 },
|
|
611
|
+
// top-right: defer
|
|
612
|
+
{ x: 1, y: 13 },
|
|
613
|
+
// bottom-left: delegate
|
|
614
|
+
{ x: 13, y: 13 }
|
|
615
|
+
// bottom-right: delete
|
|
616
|
+
];
|
|
617
|
+
function EisenhowerIcon({ quadrant, className }) {
|
|
618
|
+
const t = useTranslations6();
|
|
619
|
+
const config = QUADRANT_CONFIG[quadrant];
|
|
620
|
+
const label = t(`task.eisenhower.${quadrant}`);
|
|
621
|
+
return /* @__PURE__ */ jsxs3(Tooltip, { children: [
|
|
622
|
+
/* @__PURE__ */ jsx5(TooltipTrigger, { children: /* @__PURE__ */ jsx5(
|
|
623
|
+
"svg",
|
|
624
|
+
{
|
|
625
|
+
viewBox: "0 0 24 24",
|
|
626
|
+
fill: "none",
|
|
627
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
628
|
+
className,
|
|
629
|
+
role: "img",
|
|
630
|
+
"aria-label": label,
|
|
631
|
+
children: QUADRANT_POSITIONS.map((pos, i) => /* @__PURE__ */ jsx5(
|
|
632
|
+
"rect",
|
|
633
|
+
{
|
|
634
|
+
x: pos.x,
|
|
635
|
+
y: pos.y,
|
|
636
|
+
width: 10,
|
|
637
|
+
height: 10,
|
|
638
|
+
rx: 2,
|
|
639
|
+
className: i === config.index ? config.fillClass : "fill-transparent stroke-border",
|
|
640
|
+
strokeWidth: i === config.index ? 0 : 0.5
|
|
641
|
+
},
|
|
642
|
+
i
|
|
643
|
+
))
|
|
644
|
+
}
|
|
645
|
+
) }),
|
|
646
|
+
/* @__PURE__ */ jsx5(TooltipContent, { children: label })
|
|
647
|
+
] });
|
|
648
|
+
}
|
|
649
|
+
__name(EisenhowerIcon, "EisenhowerIcon");
|
|
650
|
+
|
|
651
|
+
// src/web/task/components/forms/TaskDeleter.tsx
|
|
652
|
+
import { useI18nRouter, usePageUrlGenerator as usePageUrlGenerator2 } from "@carlonicora/nextjs-jsonapi/client";
|
|
653
|
+
import { CommonDeleter as CommonDeleter2 } from "@carlonicora/nextjs-jsonapi/components";
|
|
654
|
+
import { useTranslations as useTranslations7 } from "next-intl";
|
|
655
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
656
|
+
function TaskDeleter({ task, onDeleted }) {
|
|
657
|
+
const t = useTranslations7();
|
|
658
|
+
const router = useI18nRouter();
|
|
659
|
+
const generateUrl = usePageUrlGenerator2();
|
|
660
|
+
const { scope } = useTaskContext();
|
|
661
|
+
const pageUrl = getTodosConfig().pageUrl;
|
|
662
|
+
const redirectTo = pageUrl && !scope ? generateUrl({ page: pageUrl }) : void 0;
|
|
663
|
+
return /* @__PURE__ */ jsx6(
|
|
664
|
+
CommonDeleter2,
|
|
665
|
+
{
|
|
666
|
+
testId: "task-editor-delete",
|
|
667
|
+
title: t("task.delete.title"),
|
|
668
|
+
subtitle: t("task.delete.subtitle", { name: task.name }),
|
|
669
|
+
description: /* @__PURE__ */ jsx6("div", { className: "text-destructive p-4 text-sm", children: t("task.delete.description") }),
|
|
670
|
+
deleteFunction: () => TaskService.delete({ id: task.id }),
|
|
671
|
+
onSuccess: () => {
|
|
672
|
+
onDeleted();
|
|
673
|
+
if (redirectTo) router.push(redirectTo);
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
);
|
|
677
|
+
}
|
|
678
|
+
__name(TaskDeleter, "TaskDeleter");
|
|
679
|
+
|
|
680
|
+
// src/web/task/components/editors/TaskEditor.tsx
|
|
681
|
+
import { Fragment as Fragment2, jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
682
|
+
function toRelatedIds(relationships, related) {
|
|
683
|
+
const response = {};
|
|
684
|
+
for (const relationship of relationships) {
|
|
685
|
+
const value = related?.[relationship.key];
|
|
686
|
+
if (relationship.cardinality === "many")
|
|
687
|
+
response[relationship.key] = (value ?? []).map((e) => e.id);
|
|
688
|
+
else response[relationship.key] = value?.id;
|
|
689
|
+
}
|
|
690
|
+
return response;
|
|
691
|
+
}
|
|
692
|
+
__name(toRelatedIds, "toRelatedIds");
|
|
693
|
+
function TaskEditor({ extraTabs }) {
|
|
694
|
+
const { task, scope, setCurrentTask, taskEditorShown, setTaskEditorShown, hideTaskEditor } = useTaskContext();
|
|
695
|
+
const { currentUser, hasPermissionToModule } = useCurrentUserContext3();
|
|
696
|
+
const t = useTranslations8();
|
|
697
|
+
const editorProps = useTodosEditorProps({ task, scope });
|
|
698
|
+
const config = getTodosConfig();
|
|
699
|
+
const relationships = config.relationships.filter((relationship) => !relationship.readOnly);
|
|
700
|
+
const selectors = getTodosUiConfig().selectors ?? {};
|
|
701
|
+
const canEdit = !task || hasPermissionToModule({ module: TodosModules.Task, action: Action3.Update, data: task });
|
|
702
|
+
const taskPriority = getTaskPrioritiesSelectOptions((key, values) => t(key, values));
|
|
703
|
+
const [isContentEmpty, setIsContentEmpty] = useState5(
|
|
704
|
+
!task?.content || Array.isArray(task.content) && task.content.length === 0
|
|
705
|
+
);
|
|
706
|
+
const defaultValues = useMemo(() => {
|
|
707
|
+
const related = {};
|
|
708
|
+
for (const relationship of relationships) {
|
|
709
|
+
const key = relationship.key;
|
|
710
|
+
if (task) {
|
|
711
|
+
related[key] = relationship.cardinality === "many" ? task.relatedMany(key).map((entity) => ({ id: entity.id, name: entity.name ?? "" })) : (() => {
|
|
712
|
+
const entity = task.related(key);
|
|
713
|
+
return entity ? { id: entity.id, name: entity.name ?? "" } : void 0;
|
|
714
|
+
})();
|
|
715
|
+
} else if (scope?.key === key) {
|
|
716
|
+
const value = { id: scope.id, name: "" };
|
|
717
|
+
related[key] = relationship.cardinality === "many" ? [value] : value;
|
|
718
|
+
} else {
|
|
719
|
+
related[key] = relationship.cardinality === "many" ? [] : void 0;
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
const toUser = /* @__PURE__ */ __name((user) => ({ id: user.id, name: user.name, avatar: user.avatar }), "toUser");
|
|
723
|
+
return {
|
|
724
|
+
id: task?.id ?? v42(),
|
|
725
|
+
name: task?.name || "",
|
|
726
|
+
completed: task?.completed || false,
|
|
727
|
+
// The picker works in local time: hand it the due date's own calendar day at local midnight.
|
|
728
|
+
dueDate: task?.dueDate ? dueDateAsLocal(task.dueDate) : void 0,
|
|
729
|
+
priority: task?.priority ?? void 0,
|
|
730
|
+
content: task?.content ?? [],
|
|
731
|
+
assignee: task ? task.assignee ? toUser(task.assignee) : void 0 : currentUser ? toUser(currentUser) : void 0,
|
|
732
|
+
related
|
|
733
|
+
};
|
|
734
|
+
}, [task, currentUser, scope]);
|
|
735
|
+
const relatedSchema = {};
|
|
736
|
+
for (const relationship of relationships) {
|
|
737
|
+
if (relationship.cardinality === "many") relatedSchema[relationship.key] = z2.array(entityObjectSchema);
|
|
738
|
+
else if (relationship.required)
|
|
739
|
+
relatedSchema[relationship.key] = entityObjectSchema.optional().refine((value) => value !== void 0, {
|
|
740
|
+
message: t("task.fields.related.required")
|
|
741
|
+
});
|
|
742
|
+
else relatedSchema[relationship.key] = entityObjectSchema.optional();
|
|
743
|
+
}
|
|
744
|
+
const formSchema = z2.object({
|
|
745
|
+
id: z2.uuidv4(),
|
|
746
|
+
name: z2.string().min(1, { message: t(`task.fields.name.error`) }),
|
|
747
|
+
assignee: userObjectSchema.optional(),
|
|
748
|
+
dueDate: z2.date().optional(),
|
|
749
|
+
priority: z2.string().optional(),
|
|
750
|
+
completed: z2.boolean(),
|
|
751
|
+
content: z2.any().optional(),
|
|
752
|
+
related: z2.object(relatedSchema)
|
|
753
|
+
});
|
|
754
|
+
const form = useForm2({
|
|
755
|
+
resolver: zodResolver2(formSchema),
|
|
756
|
+
defaultValues
|
|
757
|
+
});
|
|
758
|
+
useEffect5(() => {
|
|
759
|
+
form.reset(defaultValues);
|
|
760
|
+
setIsContentEmpty(!task?.content || Array.isArray(task.content) && task.content.length === 0);
|
|
761
|
+
}, [task?.id, taskEditorShown]);
|
|
762
|
+
const pending = useRef3({});
|
|
763
|
+
const handleSaveError = /* @__PURE__ */ __name((error) => {
|
|
764
|
+
errorToast6({ title: t("task.errors.save"), error });
|
|
765
|
+
if (isTaskGoneError(error)) {
|
|
766
|
+
save.cancel();
|
|
767
|
+
pending.current = {};
|
|
768
|
+
hideTaskEditor();
|
|
769
|
+
}
|
|
770
|
+
}, "handleSaveError");
|
|
771
|
+
const flush = /* @__PURE__ */ __name(async () => {
|
|
772
|
+
const changes = pending.current;
|
|
773
|
+
pending.current = {};
|
|
774
|
+
if (!task || changes.name === void 0 && changes.content === void 0) return;
|
|
775
|
+
try {
|
|
776
|
+
const updated = await TaskService.patch({ id: task.id, ...changes });
|
|
777
|
+
if (changes.name !== void 0 && updated) setCurrentTask(updated);
|
|
778
|
+
} catch (error) {
|
|
779
|
+
handleSaveError(error);
|
|
780
|
+
}
|
|
781
|
+
}, "flush");
|
|
782
|
+
const save = useDebounce(flush, 500);
|
|
783
|
+
const onNameChange = /* @__PURE__ */ __name(async (value) => {
|
|
784
|
+
if (!task || !canEdit) return;
|
|
785
|
+
const name = String(value);
|
|
786
|
+
if (name.trim() !== "") pending.current.name = name;
|
|
787
|
+
else delete pending.current.name;
|
|
788
|
+
save();
|
|
789
|
+
}, "onNameChange");
|
|
790
|
+
const onContentChange = canEdit ? (content, isEmpty) => {
|
|
791
|
+
if (!task) {
|
|
792
|
+
form.setValue("content", content, { shouldDirty: !isEmpty });
|
|
793
|
+
setIsContentEmpty(isEmpty);
|
|
794
|
+
return;
|
|
795
|
+
}
|
|
796
|
+
pending.current.content = content;
|
|
797
|
+
save();
|
|
798
|
+
} : void 0;
|
|
799
|
+
const updateDueDate = /* @__PURE__ */ __name(async (date) => {
|
|
800
|
+
if (!task || !canEdit) return;
|
|
801
|
+
try {
|
|
802
|
+
setCurrentTask(await TaskService.patch({ id: task.id, dueDate: date ?? null }));
|
|
803
|
+
} catch (error) {
|
|
804
|
+
handleSaveError(error);
|
|
805
|
+
}
|
|
806
|
+
}, "updateDueDate");
|
|
807
|
+
const updatePriority = /* @__PURE__ */ __name(async (value) => {
|
|
808
|
+
if (!task || !canEdit) return;
|
|
809
|
+
try {
|
|
810
|
+
setCurrentTask(await TaskService.patch({ id: task.id, priority: value || null }));
|
|
811
|
+
} catch (error) {
|
|
812
|
+
handleSaveError(error);
|
|
813
|
+
}
|
|
814
|
+
}, "updatePriority");
|
|
815
|
+
const updateAssignee = /* @__PURE__ */ __name(async (user) => {
|
|
816
|
+
if (!task || !canEdit) return;
|
|
817
|
+
try {
|
|
818
|
+
setCurrentTask(
|
|
819
|
+
user ? await TaskService.changeAssignee({ taskId: task.id, assigneeId: user.id }) : await TaskService.clearAssignee({ taskId: task.id }).then(() => TaskService.findOne({ id: task.id }))
|
|
820
|
+
);
|
|
821
|
+
} catch (error) {
|
|
822
|
+
handleSaveError(error);
|
|
823
|
+
}
|
|
824
|
+
}, "updateAssignee");
|
|
825
|
+
const toggleCompleted = /* @__PURE__ */ __name(async () => {
|
|
826
|
+
if (!task || !canEdit) return;
|
|
827
|
+
try {
|
|
828
|
+
setCurrentTask(await TaskService.toggleComplete({ taskId: task.id, completed: !task.completed }));
|
|
829
|
+
} catch (error) {
|
|
830
|
+
handleSaveError(error);
|
|
831
|
+
}
|
|
832
|
+
}, "toggleCompleted");
|
|
833
|
+
const onRelatedChange = /* @__PURE__ */ __name(async () => {
|
|
834
|
+
if (!task || !canEdit) return;
|
|
835
|
+
try {
|
|
836
|
+
setCurrentTask(
|
|
837
|
+
await TaskService.patchRelationships({
|
|
838
|
+
id: task.id,
|
|
839
|
+
related: toRelatedIds(relationships, form.getValues("related"))
|
|
840
|
+
})
|
|
841
|
+
);
|
|
842
|
+
} catch (error) {
|
|
843
|
+
handleSaveError(error);
|
|
844
|
+
}
|
|
845
|
+
}, "onRelatedChange");
|
|
846
|
+
const taskLink = task ? config.taskPath?.(task) : void 0;
|
|
847
|
+
const copyLink = /* @__PURE__ */ __name(() => {
|
|
848
|
+
if (!taskLink) return;
|
|
849
|
+
if (!navigator.clipboard) {
|
|
850
|
+
errorToast6({ title: t("task.errors.copy_link"), error: new Error("Clipboard API unavailable") });
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
navigator.clipboard.writeText(`${window.location.origin}${taskLink}`).catch((error) => {
|
|
854
|
+
errorToast6({ title: t("task.errors.copy_link"), error });
|
|
855
|
+
});
|
|
856
|
+
}, "copyLink");
|
|
857
|
+
const onSubmit = /* @__PURE__ */ __name(async (values) => {
|
|
858
|
+
if (task) return;
|
|
859
|
+
const created = await TaskService.create({
|
|
860
|
+
id: values.id,
|
|
861
|
+
name: values.name,
|
|
862
|
+
content: isContentEmpty ? void 0 : values.content,
|
|
863
|
+
priority: values.priority || void 0,
|
|
864
|
+
dueDate: values.dueDate,
|
|
865
|
+
assigneeId: values.assignee?.id,
|
|
866
|
+
related: toRelatedIds(relationships, values.related)
|
|
867
|
+
});
|
|
868
|
+
showToast(t("task.messages.saved_title"), {
|
|
869
|
+
description: t("task.messages.saved_description", { name: created.name })
|
|
870
|
+
});
|
|
871
|
+
}, "onSubmit");
|
|
872
|
+
const onDialogOpenChange = /* @__PURE__ */ __name(async (open) => {
|
|
873
|
+
if (open === taskEditorShown) return;
|
|
874
|
+
if (!open) {
|
|
875
|
+
save.cancel();
|
|
876
|
+
await flush();
|
|
877
|
+
}
|
|
878
|
+
setTaskEditorShown(open);
|
|
879
|
+
}, "onDialogOpenChange");
|
|
880
|
+
const visibleSelectors = relationships.filter(
|
|
881
|
+
(relationship) => selectors[relationship.key] && relationship.key !== scope?.key
|
|
882
|
+
);
|
|
883
|
+
const watchedRelated = form.watch("related");
|
|
884
|
+
const missingRequired = !task && visibleSelectors.some(
|
|
885
|
+
(relationship) => relationship.required && relationship.cardinality === "one" && !watchedRelated?.[relationship.key]
|
|
886
|
+
);
|
|
887
|
+
const headerActions = task ? /* @__PURE__ */ jsxs4(Fragment2, { children: [
|
|
888
|
+
!task.completed && /* @__PURE__ */ jsx7(
|
|
889
|
+
EisenhowerIcon,
|
|
890
|
+
{
|
|
891
|
+
quadrant: getEisenhowerQuadrant(form.watch("priority") || void 0, task.dueDate, /* @__PURE__ */ new Date()),
|
|
892
|
+
className: "h-6 w-6"
|
|
893
|
+
}
|
|
894
|
+
),
|
|
895
|
+
taskLink && /* @__PURE__ */ jsxs4(Tooltip2, { children: [
|
|
896
|
+
/* @__PURE__ */ jsx7(
|
|
897
|
+
TooltipTrigger2,
|
|
898
|
+
{
|
|
899
|
+
render: /* @__PURE__ */ jsx7(
|
|
900
|
+
Button3,
|
|
901
|
+
{
|
|
902
|
+
type: "button",
|
|
903
|
+
variant: "ghost",
|
|
904
|
+
size: "icon-sm",
|
|
905
|
+
"data-testid": "task-editor-copy-link",
|
|
906
|
+
"aria-label": t("task.actions.copy_link"),
|
|
907
|
+
onClick: copyLink
|
|
908
|
+
}
|
|
909
|
+
),
|
|
910
|
+
children: /* @__PURE__ */ jsx7(LinkIcon, { className: "h-4 w-4" })
|
|
911
|
+
}
|
|
912
|
+
),
|
|
913
|
+
/* @__PURE__ */ jsx7(TooltipContent2, { children: t("task.actions.copy_link") })
|
|
914
|
+
] }),
|
|
915
|
+
canEdit && /* @__PURE__ */ jsxs4(
|
|
916
|
+
Button3,
|
|
917
|
+
{
|
|
918
|
+
type: "button",
|
|
919
|
+
size: "sm",
|
|
920
|
+
variant: task.completed ? "secondary" : "outline",
|
|
921
|
+
className: "text-xs",
|
|
922
|
+
"data-testid": "task-editor-complete",
|
|
923
|
+
onClick: toggleCompleted,
|
|
924
|
+
children: [
|
|
925
|
+
/* @__PURE__ */ jsx7(CheckIcon, { className: "h-4 w-4" }),
|
|
926
|
+
t(task.completed ? "task.buttons.completed" : "task.buttons.mark_complete")
|
|
927
|
+
]
|
|
928
|
+
}
|
|
929
|
+
),
|
|
930
|
+
canEdit && /* @__PURE__ */ jsx7(
|
|
931
|
+
TaskDeleter,
|
|
932
|
+
{
|
|
933
|
+
task,
|
|
934
|
+
onDeleted: () => {
|
|
935
|
+
save.cancel();
|
|
936
|
+
pending.current = {};
|
|
937
|
+
hideTaskEditor();
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
)
|
|
941
|
+
] }) : void 0;
|
|
942
|
+
return /* @__PURE__ */ jsx7(TaskCommentProvider, { task, open: taskEditorShown, children: /* @__PURE__ */ jsx7(
|
|
943
|
+
EditorSheet,
|
|
944
|
+
{
|
|
945
|
+
form,
|
|
946
|
+
onSubmit,
|
|
947
|
+
onReset: () => {
|
|
948
|
+
setIsContentEmpty(!task?.content || Array.isArray(task.content) && task.content.length === 0);
|
|
949
|
+
return defaultValues;
|
|
950
|
+
},
|
|
951
|
+
isFormDirty: () => false,
|
|
952
|
+
entityType: t(`entities.tasks`, { count: 1 }),
|
|
953
|
+
entityName: task?.name,
|
|
954
|
+
title: task ? t(`task.edit`) : t(`task.create`),
|
|
955
|
+
isEdit: !!task,
|
|
956
|
+
module: TodosModules.Task,
|
|
957
|
+
dialogOpen: taskEditorShown,
|
|
958
|
+
onDialogOpenChange,
|
|
959
|
+
size: "lg",
|
|
960
|
+
disabled: !form.watch("name")?.trim() || missingRequired,
|
|
961
|
+
actions: headerActions,
|
|
962
|
+
renderFooter: task ? () => /* @__PURE__ */ jsx7(TaskCommentEditor, {}) : void 0,
|
|
963
|
+
children: /* @__PURE__ */ jsxs4("div", { "data-testid": "task-editor", className: "flex w-full flex-col gap-y-2", children: [
|
|
964
|
+
task && !canEdit && /* @__PURE__ */ jsx7("p", { className: "text-muted-foreground text-xs/relaxed", children: t("task.read_only") }),
|
|
965
|
+
/* @__PURE__ */ jsxs4(
|
|
966
|
+
"fieldset",
|
|
967
|
+
{
|
|
968
|
+
"data-testid": "task-editor-fields",
|
|
969
|
+
disabled: !canEdit,
|
|
970
|
+
className: cn("contents", !canEdit && "pointer-events-none"),
|
|
971
|
+
children: [
|
|
972
|
+
/* @__PURE__ */ jsx7(
|
|
973
|
+
FormInput,
|
|
974
|
+
{
|
|
975
|
+
autoFocus: true,
|
|
976
|
+
form,
|
|
977
|
+
id: "name",
|
|
978
|
+
name: t("task.fields.name.label"),
|
|
979
|
+
placeholder: t("task.fields.name.placeholder"),
|
|
980
|
+
onChange: onNameChange,
|
|
981
|
+
testId: "task-editor-name"
|
|
982
|
+
}
|
|
983
|
+
),
|
|
984
|
+
/* @__PURE__ */ jsxs4("div", { className: "grid grid-cols-3 gap-x-4", children: [
|
|
985
|
+
/* @__PURE__ */ jsx7("div", { "data-testid": "task-editor-assignee", children: /* @__PURE__ */ jsx7(
|
|
986
|
+
UserSelector,
|
|
987
|
+
{
|
|
988
|
+
form,
|
|
989
|
+
id: "assignee",
|
|
990
|
+
label: t("task.fields.assignee.label"),
|
|
991
|
+
placeholder: t("task.fields.assignee.placeholder"),
|
|
992
|
+
onChange: updateAssignee
|
|
993
|
+
}
|
|
994
|
+
) }),
|
|
995
|
+
/* @__PURE__ */ jsx7("div", { "data-testid": "task-editor-due-date", children: /* @__PURE__ */ jsx7(
|
|
996
|
+
FormDate,
|
|
997
|
+
{
|
|
998
|
+
form,
|
|
999
|
+
id: "dueDate",
|
|
1000
|
+
name: t("task.fields.due_date.label"),
|
|
1001
|
+
placeholder: t("task.fields.due_date.placeholder"),
|
|
1002
|
+
onChange: updateDueDate
|
|
1003
|
+
}
|
|
1004
|
+
) }),
|
|
1005
|
+
/* @__PURE__ */ jsx7(
|
|
1006
|
+
FormSelect,
|
|
1007
|
+
{
|
|
1008
|
+
form,
|
|
1009
|
+
id: "priority",
|
|
1010
|
+
name: t("task.fields.priority.label"),
|
|
1011
|
+
placeholder: t("task.fields.priority.none"),
|
|
1012
|
+
values: taskPriority,
|
|
1013
|
+
allowEmpty: true,
|
|
1014
|
+
testId: "task-editor-priority",
|
|
1015
|
+
onChange: updatePriority
|
|
1016
|
+
}
|
|
1017
|
+
)
|
|
1018
|
+
] }),
|
|
1019
|
+
/* @__PURE__ */ jsx7(FormFieldWrapper, { form, name: "content", label: t("task.fields.description.label"), className: "pt-2", children: () => /* @__PURE__ */ jsx7("div", { "data-testid": "task-editor-notes", className: "flex w-full flex-col rounded border py-2", children: /* @__PURE__ */ jsx7(
|
|
1020
|
+
BlockNoteEditorContainer3,
|
|
1021
|
+
{
|
|
1022
|
+
id: form.getValues("id"),
|
|
1023
|
+
type: "task",
|
|
1024
|
+
initialContent: task?.content,
|
|
1025
|
+
onChange: onContentChange,
|
|
1026
|
+
size: "sm",
|
|
1027
|
+
className: "min-h-40",
|
|
1028
|
+
...editorProps
|
|
1029
|
+
}
|
|
1030
|
+
) }) }),
|
|
1031
|
+
visibleSelectors.length > 0 && /* @__PURE__ */ jsx7("div", { className: "mt-2 grid grid-cols-2 gap-x-4 border-t pt-2", children: visibleSelectors.map((relationship) => {
|
|
1032
|
+
const Selector = selectors[relationship.key];
|
|
1033
|
+
return /* @__PURE__ */ jsx7(
|
|
1034
|
+
FormFieldWrapper,
|
|
1035
|
+
{
|
|
1036
|
+
form,
|
|
1037
|
+
name: `related.${relationship.key}`,
|
|
1038
|
+
label: t(`entities.${relationship.module().name}`, {
|
|
1039
|
+
count: relationship.cardinality === "many" ? 2 : 1
|
|
1040
|
+
}),
|
|
1041
|
+
testId: `task-editor-related-${relationship.key}`,
|
|
1042
|
+
children: () => /* @__PURE__ */ jsx7(
|
|
1043
|
+
Selector,
|
|
1044
|
+
{
|
|
1045
|
+
form,
|
|
1046
|
+
id: `related.${relationship.key}`,
|
|
1047
|
+
relationship,
|
|
1048
|
+
disabled: !canEdit || !!task && relationship.immutable,
|
|
1049
|
+
onChange: () => onRelatedChange()
|
|
1050
|
+
}
|
|
1051
|
+
)
|
|
1052
|
+
},
|
|
1053
|
+
relationship.key
|
|
1054
|
+
);
|
|
1055
|
+
}) })
|
|
1056
|
+
]
|
|
1057
|
+
}
|
|
1058
|
+
),
|
|
1059
|
+
task && taskEditorShown && /* @__PURE__ */ jsxs4(Tabs, { defaultValue: "comments", className: "mt-4", children: [
|
|
1060
|
+
/* @__PURE__ */ jsxs4(TabsList, { children: [
|
|
1061
|
+
/* @__PURE__ */ jsx7(TabsTrigger, { value: "comments", children: t("task.tabs.comments") }),
|
|
1062
|
+
extraTabs?.map((entry) => /* @__PURE__ */ jsx7(TabsTrigger, { value: entry.key, children: entry.label }, entry.key))
|
|
1063
|
+
] }),
|
|
1064
|
+
/* @__PURE__ */ jsx7(TabsContent, { value: "comments", children: /* @__PURE__ */ jsx7(TaskCommentList, {}) }),
|
|
1065
|
+
extraTabs?.map((entry) => /* @__PURE__ */ jsx7(TabsContent, { value: entry.key, children: entry.content(task) }, entry.key))
|
|
1066
|
+
] })
|
|
1067
|
+
] })
|
|
1068
|
+
}
|
|
1069
|
+
) });
|
|
1070
|
+
}
|
|
1071
|
+
__name(TaskEditor, "TaskEditor");
|
|
1072
|
+
|
|
1073
|
+
// src/web/task/components/lists/TasksList.tsx
|
|
1074
|
+
import { useDataListRetriever } from "@carlonicora/nextjs-jsonapi/client";
|
|
1075
|
+
import { ContentListTable } from "@carlonicora/nextjs-jsonapi/components";
|
|
1076
|
+
import { useTranslations as useTranslations12 } from "next-intl";
|
|
1077
|
+
import { useEffect as useEffect7, useRef as useRef4 } from "react";
|
|
1078
|
+
|
|
1079
|
+
// src/web/task/hooks/useTaskOverdueParam.ts
|
|
1080
|
+
import { useCallback, useEffect as useEffect6, useState as useState6 } from "react";
|
|
1081
|
+
var OVERDUE_PARAM = "overdue";
|
|
1082
|
+
function useTaskOverdueParam() {
|
|
1083
|
+
const [overdue, setOverdueState] = useState6(false);
|
|
1084
|
+
const [ready, setReady] = useState6(false);
|
|
1085
|
+
useEffect6(() => {
|
|
1086
|
+
setOverdueState(new URLSearchParams(window.location.search).get(OVERDUE_PARAM) === "true");
|
|
1087
|
+
setReady(true);
|
|
1088
|
+
}, []);
|
|
1089
|
+
const setOverdue = useCallback((value) => {
|
|
1090
|
+
const search = new URLSearchParams(window.location.search);
|
|
1091
|
+
if (value) search.set(OVERDUE_PARAM, "true");
|
|
1092
|
+
else search.delete(OVERDUE_PARAM);
|
|
1093
|
+
const next = search.toString();
|
|
1094
|
+
window.history.replaceState(
|
|
1095
|
+
null,
|
|
1096
|
+
"",
|
|
1097
|
+
`${window.location.pathname}${next ? `?${next}` : ""}${window.location.hash}`
|
|
1098
|
+
);
|
|
1099
|
+
setOverdueState(value);
|
|
1100
|
+
}, []);
|
|
1101
|
+
return { overdue, ready, setOverdue };
|
|
1102
|
+
}
|
|
1103
|
+
__name(useTaskOverdueParam, "useTaskOverdueParam");
|
|
1104
|
+
|
|
1105
|
+
// src/web/task/hooks/useTaskTableStructure.tsx
|
|
1106
|
+
import {
|
|
1107
|
+
registerTableGenerator,
|
|
1108
|
+
usePageUrlGenerator as usePageUrlGenerator3
|
|
1109
|
+
} from "@carlonicora/nextjs-jsonapi/client";
|
|
1110
|
+
import {
|
|
1111
|
+
Badge,
|
|
1112
|
+
cellDate,
|
|
1113
|
+
cellId,
|
|
1114
|
+
DatePickerPopover,
|
|
1115
|
+
DropdownMenu,
|
|
1116
|
+
DropdownMenuContent,
|
|
1117
|
+
DropdownMenuItem,
|
|
1118
|
+
DropdownMenuTrigger,
|
|
1119
|
+
errorToast as errorToast7,
|
|
1120
|
+
Link,
|
|
1121
|
+
Tooltip as Tooltip3,
|
|
1122
|
+
TooltipContent as TooltipContent3,
|
|
1123
|
+
TooltipTrigger as TooltipTrigger3,
|
|
1124
|
+
UserAvatar as UserAvatar3,
|
|
1125
|
+
UserSearchPopover
|
|
1126
|
+
} from "@carlonicora/nextjs-jsonapi/components";
|
|
1127
|
+
import { useCurrentUserContext as useCurrentUserContext4, useDateFormatter as useDateFormatter2, useMountedNow as useMountedNow2 } from "@carlonicora/nextjs-jsonapi/contexts";
|
|
1128
|
+
import { Action as Action4, cn as cn2 } from "@carlonicora/nextjs-jsonapi/core";
|
|
1129
|
+
import { ChevronDown, CircleCheckIcon, CircleX } from "lucide-react";
|
|
1130
|
+
import { useTranslations as useTranslations9 } from "next-intl";
|
|
1131
|
+
import { useMemo as useMemo2, useState as useState7 } from "react";
|
|
1132
|
+
|
|
1133
|
+
// src/web/task/utils/isTaskOverdue.ts
|
|
1134
|
+
import { formatLocalDate } from "@carlonicora/nextjs-jsonapi/core";
|
|
1135
|
+
function isTaskOverdue(task, now) {
|
|
1136
|
+
if (!task.dueDate || !now || task.completed) return false;
|
|
1137
|
+
return dueDateDay(task.dueDate) < formatLocalDate(now);
|
|
1138
|
+
}
|
|
1139
|
+
__name(isTaskOverdue, "isTaskOverdue");
|
|
1140
|
+
|
|
1141
|
+
// src/web/task/hooks/useTaskTableStructure.tsx
|
|
1142
|
+
import { Fragment as Fragment3, jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
1143
|
+
function DueDateText({ date, overdue }) {
|
|
1144
|
+
const { format } = useDateFormatter2();
|
|
1145
|
+
return /* @__PURE__ */ jsx8("span", { className: cn2("text-xs", overdue ? "text-destructive" : "text-muted-foreground"), children: format(dueDateAsLocal(date), "dateMedium") });
|
|
1146
|
+
}
|
|
1147
|
+
__name(DueDateText, "DueDateText");
|
|
1148
|
+
var getBadgeVariant = /* @__PURE__ */ __name((priority) => priority === "high" ? "destructive" : priority === "medium" ? "default" : "secondary", "getBadgeVariant");
|
|
1149
|
+
function AssigneeCell({
|
|
1150
|
+
task,
|
|
1151
|
+
onChange,
|
|
1152
|
+
onClear
|
|
1153
|
+
}) {
|
|
1154
|
+
const t = useTranslations9();
|
|
1155
|
+
const [isHovered, setIsHovered] = useState7(false);
|
|
1156
|
+
return /* @__PURE__ */ jsxs5("div", { className: "group inline-flex items-center gap-1", children: [
|
|
1157
|
+
/* @__PURE__ */ jsx8(UserSearchPopover, { onSelect: onChange, align: "start", children: /* @__PURE__ */ jsxs5(
|
|
1158
|
+
"div",
|
|
1159
|
+
{
|
|
1160
|
+
"data-testid": `task-row-assignee-${task.id}`,
|
|
1161
|
+
className: "inline-flex cursor-pointer items-center gap-1",
|
|
1162
|
+
onMouseEnter: () => setIsHovered(true),
|
|
1163
|
+
onMouseLeave: () => setIsHovered(false),
|
|
1164
|
+
onClick: (e) => e.stopPropagation(),
|
|
1165
|
+
children: [
|
|
1166
|
+
task.assignee ? /* @__PURE__ */ jsx8("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ jsx8(UserAvatar3, { user: task.assignee, showTooltip: false, showLink: false }) }) : /* @__PURE__ */ jsx8("span", { className: "text-muted-foreground text-xs", children: t(`task.fields.assignee.placeholder`) }),
|
|
1167
|
+
/* @__PURE__ */ jsx8(
|
|
1168
|
+
ChevronDown,
|
|
1169
|
+
{
|
|
1170
|
+
"data-testid": `task-row-assignee-chevron-${task.id}`,
|
|
1171
|
+
className: cn2("h-3 w-3 transition-opacity", isHovered ? "opacity-100" : "opacity-0")
|
|
1172
|
+
}
|
|
1173
|
+
)
|
|
1174
|
+
]
|
|
1175
|
+
}
|
|
1176
|
+
) }),
|
|
1177
|
+
task.assignee && /* @__PURE__ */ jsx8(
|
|
1178
|
+
"button",
|
|
1179
|
+
{
|
|
1180
|
+
type: "button",
|
|
1181
|
+
"data-testid": "task-row-assignee-clear",
|
|
1182
|
+
"aria-label": t("task.fields.assignee.clear"),
|
|
1183
|
+
className: "text-muted-foreground hover:text-destructive opacity-0 group-hover:opacity-100",
|
|
1184
|
+
onClick: (e) => {
|
|
1185
|
+
e.stopPropagation();
|
|
1186
|
+
onClear();
|
|
1187
|
+
},
|
|
1188
|
+
children: /* @__PURE__ */ jsx8(CircleX, { className: "h-3 w-3" })
|
|
1189
|
+
}
|
|
1190
|
+
)
|
|
1191
|
+
] });
|
|
1192
|
+
}
|
|
1193
|
+
__name(AssigneeCell, "AssigneeCell");
|
|
1194
|
+
function PriorityCell({ task, onChange }) {
|
|
1195
|
+
const t = useTranslations9();
|
|
1196
|
+
const [isHovered, setIsHovered] = useState7(false);
|
|
1197
|
+
const priorityOptions = getTaskPrioritiesSelectOptions((key, values) => t(key, values));
|
|
1198
|
+
return /* @__PURE__ */ jsxs5(DropdownMenu, { children: [
|
|
1199
|
+
/* @__PURE__ */ jsxs5(
|
|
1200
|
+
DropdownMenuTrigger,
|
|
1201
|
+
{
|
|
1202
|
+
"data-testid": `task-row-priority-${task.id}`,
|
|
1203
|
+
className: "inline-flex cursor-pointer items-center gap-1 px-1",
|
|
1204
|
+
onMouseEnter: () => setIsHovered(true),
|
|
1205
|
+
onMouseLeave: () => setIsHovered(false),
|
|
1206
|
+
onClick: (e) => e.stopPropagation(),
|
|
1207
|
+
children: [
|
|
1208
|
+
task.priority ? /* @__PURE__ */ jsx8(Badge, { variant: getBadgeVariant(task.priority), children: t(`task.priorities`, { priority: task.priority }) }) : /* @__PURE__ */ jsx8(Fragment3, {}),
|
|
1209
|
+
/* @__PURE__ */ jsx8(ChevronDown, { className: cn2("h-3 w-3 transition-opacity", isHovered ? "opacity-100" : "opacity-0") })
|
|
1210
|
+
]
|
|
1211
|
+
}
|
|
1212
|
+
),
|
|
1213
|
+
/* @__PURE__ */ jsxs5(DropdownMenuContent, { align: "start", onClick: (e) => e.stopPropagation(), children: [
|
|
1214
|
+
task.priority && /* @__PURE__ */ jsx8(
|
|
1215
|
+
DropdownMenuItem,
|
|
1216
|
+
{
|
|
1217
|
+
onClick: (e) => {
|
|
1218
|
+
e.stopPropagation();
|
|
1219
|
+
onChange("");
|
|
1220
|
+
},
|
|
1221
|
+
children: /* @__PURE__ */ jsx8("span", { className: "text-muted-foreground text-xs", children: t(`task.fields.priority.none`) })
|
|
1222
|
+
}
|
|
1223
|
+
),
|
|
1224
|
+
priorityOptions.map((option) => /* @__PURE__ */ jsx8(
|
|
1225
|
+
DropdownMenuItem,
|
|
1226
|
+
{
|
|
1227
|
+
onClick: (e) => {
|
|
1228
|
+
e.stopPropagation();
|
|
1229
|
+
onChange(option.id);
|
|
1230
|
+
},
|
|
1231
|
+
children: /* @__PURE__ */ jsx8(Badge, { variant: getBadgeVariant(option.id), className: "cursor-pointer", children: option.text })
|
|
1232
|
+
},
|
|
1233
|
+
option.id
|
|
1234
|
+
))
|
|
1235
|
+
] })
|
|
1236
|
+
] });
|
|
1237
|
+
}
|
|
1238
|
+
__name(PriorityCell, "PriorityCell");
|
|
1239
|
+
function DueDateCell({
|
|
1240
|
+
task,
|
|
1241
|
+
canEdit,
|
|
1242
|
+
onSelect
|
|
1243
|
+
}) {
|
|
1244
|
+
const t = useTranslations9();
|
|
1245
|
+
const [isHovered, setIsHovered] = useState7(false);
|
|
1246
|
+
const now = useMountedNow2();
|
|
1247
|
+
const isOverdue = isTaskOverdue(task, now);
|
|
1248
|
+
const text = task.dueDate ? /* @__PURE__ */ jsx8(DueDateText, { date: task.dueDate, overdue: isOverdue }) : /* @__PURE__ */ jsx8("span", { className: "text-muted-foreground text-xs", children: t(`task.fields.due_date.placeholder`) });
|
|
1249
|
+
if (!canEdit) return text;
|
|
1250
|
+
return /* @__PURE__ */ jsx8(
|
|
1251
|
+
DatePickerPopover,
|
|
1252
|
+
{
|
|
1253
|
+
value: task.dueDate ? dueDateAsLocal(task.dueDate) : void 0,
|
|
1254
|
+
onSelect,
|
|
1255
|
+
align: "start",
|
|
1256
|
+
nativeButton: false,
|
|
1257
|
+
children: /* @__PURE__ */ jsxs5(
|
|
1258
|
+
"div",
|
|
1259
|
+
{
|
|
1260
|
+
"data-testid": `task-row-due-date-${task.id}`,
|
|
1261
|
+
className: "inline-flex cursor-pointer items-center gap-1",
|
|
1262
|
+
onMouseEnter: () => setIsHovered(true),
|
|
1263
|
+
onMouseLeave: () => setIsHovered(false),
|
|
1264
|
+
onClick: (e) => e.stopPropagation(),
|
|
1265
|
+
children: [
|
|
1266
|
+
text,
|
|
1267
|
+
/* @__PURE__ */ jsx8(ChevronDown, { className: cn2("h-3 w-3 transition-opacity", isHovered ? "opacity-100" : "opacity-0") })
|
|
1268
|
+
]
|
|
1269
|
+
}
|
|
1270
|
+
)
|
|
1271
|
+
}
|
|
1272
|
+
);
|
|
1273
|
+
}
|
|
1274
|
+
__name(DueDateCell, "DueDateCell");
|
|
1275
|
+
var useTaskTableStructure = /* @__PURE__ */ __name((params) => {
|
|
1276
|
+
const t = useTranslations9();
|
|
1277
|
+
const generateUrl = usePageUrlGenerator3();
|
|
1278
|
+
const { setTaskId } = useTaskContext();
|
|
1279
|
+
const { hasPermissionToModule } = useCurrentUserContext4();
|
|
1280
|
+
const canEdit = /* @__PURE__ */ __name((task) => hasPermissionToModule({ module: TodosModules.Task, action: Action4.Update, data: task }), "canEdit");
|
|
1281
|
+
const now = /* @__PURE__ */ new Date();
|
|
1282
|
+
const scope = params.context?.scope;
|
|
1283
|
+
const nameBadges = params.context?.nameBadges;
|
|
1284
|
+
const saveRow = /* @__PURE__ */ __name(async (call) => {
|
|
1285
|
+
try {
|
|
1286
|
+
const updated = await call();
|
|
1287
|
+
if (updated) params.dataRetriever?.setRefreshedElement(updated);
|
|
1288
|
+
} catch (error) {
|
|
1289
|
+
errorToast7({ title: t("task.errors.save"), error });
|
|
1290
|
+
if (isTaskGoneError(error)) await params.dataRetriever?.refresh();
|
|
1291
|
+
}
|
|
1292
|
+
}, "saveRow");
|
|
1293
|
+
const toggleCompleted = /* @__PURE__ */ __name(async (task) => {
|
|
1294
|
+
try {
|
|
1295
|
+
await TaskService.toggleComplete({ taskId: task.id, completed: !task.completed });
|
|
1296
|
+
} catch (error) {
|
|
1297
|
+
errorToast7({ title: t("task.errors.save"), error });
|
|
1298
|
+
if (!isTaskGoneError(error)) return;
|
|
1299
|
+
}
|
|
1300
|
+
await params.dataRetriever?.refresh();
|
|
1301
|
+
}, "toggleCompleted");
|
|
1302
|
+
const updatePriority = /* @__PURE__ */ __name((task, newPriority) => saveRow(
|
|
1303
|
+
() => TaskService.patch({ id: task.id, priority: newPriority === "" ? null : newPriority })
|
|
1304
|
+
), "updatePriority");
|
|
1305
|
+
const changeAssignee = /* @__PURE__ */ __name((task, newAssigneeId) => saveRow(() => TaskService.changeAssignee({ taskId: task.id, assigneeId: newAssigneeId })), "changeAssignee");
|
|
1306
|
+
const clearAssignee = /* @__PURE__ */ __name((task) => saveRow(async () => {
|
|
1307
|
+
await TaskService.clearAssignee({ taskId: task.id });
|
|
1308
|
+
return TaskService.findOne({ id: task.id });
|
|
1309
|
+
}), "clearAssignee");
|
|
1310
|
+
const updateDueDate = /* @__PURE__ */ __name((task, newDueDate) => saveRow(() => TaskService.patch({ id: task.id, dueDate: newDueDate ?? null })), "updateDueDate");
|
|
1311
|
+
const linkRelationships = getTodosConfig().relationships.filter((r) => r.key !== scope?.key);
|
|
1312
|
+
const tableData = useMemo2(() => {
|
|
1313
|
+
return params.data.map((task) => {
|
|
1314
|
+
const entry = {
|
|
1315
|
+
jsonApiData: task
|
|
1316
|
+
};
|
|
1317
|
+
entry["taskId" /* taskId */] = task.id;
|
|
1318
|
+
params.fields.forEach((field) => {
|
|
1319
|
+
entry[field] = task[field];
|
|
1320
|
+
});
|
|
1321
|
+
return entry;
|
|
1322
|
+
});
|
|
1323
|
+
}, [params.data, params.fields]);
|
|
1324
|
+
const fieldColumnMap = {
|
|
1325
|
+
["taskId" /* taskId */]: () => cellId({
|
|
1326
|
+
name: "taskId",
|
|
1327
|
+
checkedIds: params.checkedIds,
|
|
1328
|
+
toggleId: params.toggleId
|
|
1329
|
+
}),
|
|
1330
|
+
["name" /* name */]: () => ({
|
|
1331
|
+
id: "name",
|
|
1332
|
+
accessorKey: "name",
|
|
1333
|
+
header: t(`task.fields.name.label`),
|
|
1334
|
+
meta: { className: "w-96" },
|
|
1335
|
+
cell: /* @__PURE__ */ __name(({ row }) => {
|
|
1336
|
+
const task = row.original.jsonApiData;
|
|
1337
|
+
return /* @__PURE__ */ jsxs5(
|
|
1338
|
+
"div",
|
|
1339
|
+
{
|
|
1340
|
+
"data-testid": `task-row-${task.id}`,
|
|
1341
|
+
className: `flex cursor-pointer items-center gap-x-2 ${task.completed ? `text-muted-foreground` : `text-primary`}`,
|
|
1342
|
+
onClick: () => setTaskId(task.id),
|
|
1343
|
+
children: [
|
|
1344
|
+
canEdit(task) && /* @__PURE__ */ jsx8(
|
|
1345
|
+
CircleCheckIcon,
|
|
1346
|
+
{
|
|
1347
|
+
"data-testid": "task-toggle-complete",
|
|
1348
|
+
className: `h-5 w-5 min-w-5 ${task.completed ? `text-muted fill-success` : `text-muted-foreground hover:text-success`}`,
|
|
1349
|
+
onClick: (e) => {
|
|
1350
|
+
e.stopPropagation();
|
|
1351
|
+
toggleCompleted(task);
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
),
|
|
1355
|
+
!task.completed && /* @__PURE__ */ jsx8(
|
|
1356
|
+
EisenhowerIcon,
|
|
1357
|
+
{
|
|
1358
|
+
quadrant: getEisenhowerQuadrant(task.priority || void 0, task.dueDate, now),
|
|
1359
|
+
className: "h-4 w-4 min-w-4"
|
|
1360
|
+
}
|
|
1361
|
+
),
|
|
1362
|
+
/* @__PURE__ */ jsx8("span", { className: "w-0 flex-1 truncate", children: task.name }),
|
|
1363
|
+
nameBadges?.(task)
|
|
1364
|
+
]
|
|
1365
|
+
}
|
|
1366
|
+
);
|
|
1367
|
+
}, "cell"),
|
|
1368
|
+
enableSorting: true,
|
|
1369
|
+
enableHiding: false
|
|
1370
|
+
}),
|
|
1371
|
+
["assignee" /* assignee */]: () => ({
|
|
1372
|
+
id: "assignee",
|
|
1373
|
+
accessorKey: "assignee",
|
|
1374
|
+
header: t(`task.fields.assignee.label`),
|
|
1375
|
+
cell: /* @__PURE__ */ __name(({ row }) => {
|
|
1376
|
+
const task = row.original.jsonApiData;
|
|
1377
|
+
if (!canEdit(task)) return task.assignee ? /* @__PURE__ */ jsx8(UserAvatar3, { user: task.assignee, showLink: false }) : null;
|
|
1378
|
+
return /* @__PURE__ */ jsx8(
|
|
1379
|
+
AssigneeCell,
|
|
1380
|
+
{
|
|
1381
|
+
task,
|
|
1382
|
+
onChange: (userId) => changeAssignee(task, userId),
|
|
1383
|
+
onClear: () => clearAssignee(task)
|
|
1384
|
+
}
|
|
1385
|
+
);
|
|
1386
|
+
}, "cell"),
|
|
1387
|
+
enableSorting: false,
|
|
1388
|
+
enableHiding: false
|
|
1389
|
+
}),
|
|
1390
|
+
["owner" /* owner */]: () => ({
|
|
1391
|
+
id: "owner",
|
|
1392
|
+
accessorKey: "owner",
|
|
1393
|
+
header: /* @__PURE__ */ __name(() => /* @__PURE__ */ jsx8("span", { className: "sr-only", children: t("task.fields.owner.label") }), "header"),
|
|
1394
|
+
cell: /* @__PURE__ */ __name(({ row }) => {
|
|
1395
|
+
const task = row.original.jsonApiData;
|
|
1396
|
+
return task.creator ? /* @__PURE__ */ jsx8(UserAvatar3, { user: task.creator, showLink: false }) : null;
|
|
1397
|
+
}, "cell"),
|
|
1398
|
+
enableSorting: false,
|
|
1399
|
+
enableHiding: false
|
|
1400
|
+
}),
|
|
1401
|
+
["priority" /* priority */]: () => ({
|
|
1402
|
+
id: "priority",
|
|
1403
|
+
accessorKey: "priority",
|
|
1404
|
+
header: t(`task.fields.priority.label`),
|
|
1405
|
+
cell: /* @__PURE__ */ __name(({ row }) => {
|
|
1406
|
+
const task = row.original.jsonApiData;
|
|
1407
|
+
if (!canEdit(task))
|
|
1408
|
+
return task.priority ? /* @__PURE__ */ jsx8(Badge, { variant: getBadgeVariant(task.priority), children: t(`task.priorities`, { priority: task.priority }) }) : null;
|
|
1409
|
+
return /* @__PURE__ */ jsx8(PriorityCell, { task, onChange: (priority) => updatePriority(task, priority) });
|
|
1410
|
+
}, "cell"),
|
|
1411
|
+
enableSorting: true,
|
|
1412
|
+
enableHiding: false
|
|
1413
|
+
}),
|
|
1414
|
+
["relationships" /* relationships */]: () => linkRelationships.length === 0 ? void 0 : {
|
|
1415
|
+
id: "relationships",
|
|
1416
|
+
accessorKey: "relationships",
|
|
1417
|
+
header: t(`task.fields.relationships.label`),
|
|
1418
|
+
cell: /* @__PURE__ */ __name(({ row }) => {
|
|
1419
|
+
const task = row.original.jsonApiData;
|
|
1420
|
+
const items = linkRelationships.flatMap(
|
|
1421
|
+
(r) => task.relatedMany(r.key).map((entity) => ({ entity, module: r.module() }))
|
|
1422
|
+
);
|
|
1423
|
+
if (items.length === 0) return /* @__PURE__ */ jsx8(Fragment3, {});
|
|
1424
|
+
return /* @__PURE__ */ jsx8("div", { className: "flex flex-wrap items-center gap-1", children: items.map(({ entity, module }) => {
|
|
1425
|
+
const Icon = module.icon;
|
|
1426
|
+
return /* @__PURE__ */ jsxs5(Tooltip3, { children: [
|
|
1427
|
+
/* @__PURE__ */ jsx8(
|
|
1428
|
+
TooltipTrigger3,
|
|
1429
|
+
{
|
|
1430
|
+
render: module.pageUrl ? /* @__PURE__ */ jsx8(
|
|
1431
|
+
Link,
|
|
1432
|
+
{
|
|
1433
|
+
href: generateUrl({ page: module, id: entity.id }),
|
|
1434
|
+
onClick: (e) => e.stopPropagation()
|
|
1435
|
+
}
|
|
1436
|
+
) : /* @__PURE__ */ jsx8("span", {}),
|
|
1437
|
+
children: /* @__PURE__ */ jsxs5(Badge, { variant: "secondary", className: "inline-flex items-center gap-1 font-normal", children: [
|
|
1438
|
+
Icon && /* @__PURE__ */ jsx8(Icon, { className: "h-4 w-4" }),
|
|
1439
|
+
/* @__PURE__ */ jsx8("span", { className: "max-w-[140px] truncate", children: entity.name })
|
|
1440
|
+
] })
|
|
1441
|
+
}
|
|
1442
|
+
),
|
|
1443
|
+
/* @__PURE__ */ jsx8(TooltipContent3, { children: t(`entities.${module.name}`, { count: 1 }) })
|
|
1444
|
+
] }, `${module.name}-${entity.id}`);
|
|
1445
|
+
}) });
|
|
1446
|
+
}, "cell"),
|
|
1447
|
+
enableSorting: false,
|
|
1448
|
+
enableHiding: false
|
|
1449
|
+
},
|
|
1450
|
+
["createdAt" /* createdAt */]: () => cellDate({
|
|
1451
|
+
name: "createdAt",
|
|
1452
|
+
title: t(`task.fields.created_at.label`)
|
|
1453
|
+
}),
|
|
1454
|
+
["dueDate" /* dueDate */]: () => ({
|
|
1455
|
+
id: "dueDate",
|
|
1456
|
+
accessorKey: "dueDate",
|
|
1457
|
+
header: t(`task.fields.due_date.label`),
|
|
1458
|
+
cell: /* @__PURE__ */ __name(({ row }) => {
|
|
1459
|
+
const task = row.original.jsonApiData;
|
|
1460
|
+
return /* @__PURE__ */ jsx8(DueDateCell, { task, canEdit: canEdit(task), onSelect: (date) => updateDueDate(task, date) });
|
|
1461
|
+
}, "cell"),
|
|
1462
|
+
enableSorting: true,
|
|
1463
|
+
enableHiding: false
|
|
1464
|
+
}),
|
|
1465
|
+
["updatedAt" /* updatedAt */]: () => cellDate({
|
|
1466
|
+
name: "updatedAt",
|
|
1467
|
+
title: t(`task.fields.updated_at.label`)
|
|
1468
|
+
})
|
|
1469
|
+
};
|
|
1470
|
+
const columns = useMemo2(() => {
|
|
1471
|
+
return params.fields.map((field) => fieldColumnMap[field]?.()).filter((col) => col !== void 0);
|
|
1472
|
+
}, [params.fields, fieldColumnMap, t, generateUrl]);
|
|
1473
|
+
return useMemo2(() => ({ data: tableData, columns }), [tableData, columns]);
|
|
1474
|
+
}, "useTaskTableStructure");
|
|
1475
|
+
registerTableGenerator(TASK_ENDPOINT, useTaskTableStructure);
|
|
1476
|
+
|
|
1477
|
+
// src/web/task/components/filters/TaskListFilters.tsx
|
|
1478
|
+
import {
|
|
1479
|
+
Badge as Badge2,
|
|
1480
|
+
Button as Button4,
|
|
1481
|
+
Checkbox,
|
|
1482
|
+
Popover,
|
|
1483
|
+
PopoverContent,
|
|
1484
|
+
PopoverTrigger,
|
|
1485
|
+
Switch
|
|
1486
|
+
} from "@carlonicora/nextjs-jsonapi/components";
|
|
1487
|
+
import { ListFilterIcon, XIcon } from "lucide-react";
|
|
1488
|
+
import { useTranslations as useTranslations10 } from "next-intl";
|
|
1489
|
+
import { useCallback as useCallback2, useState as useState8 } from "react";
|
|
1490
|
+
import { jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
1491
|
+
function TaskListFilters({ data, overdue, onOverdueChange }) {
|
|
1492
|
+
const t = useTranslations10();
|
|
1493
|
+
const [showCompleted, setShowCompleted] = useState8(false);
|
|
1494
|
+
const [selectedPriorities, setSelectedPriorities] = useState8([]);
|
|
1495
|
+
const handleCompletedToggle = useCallback2(
|
|
1496
|
+
(checked) => {
|
|
1497
|
+
setShowCompleted(checked);
|
|
1498
|
+
if (checked) {
|
|
1499
|
+
if (overdue) onOverdueChange(false);
|
|
1500
|
+
data.addAdditionalParameter("completedFilter", "completed");
|
|
1501
|
+
} else {
|
|
1502
|
+
data.removeAdditionalParameter("completedFilter");
|
|
1503
|
+
}
|
|
1504
|
+
},
|
|
1505
|
+
[data, overdue, onOverdueChange]
|
|
1506
|
+
);
|
|
1507
|
+
const handleOverdueToggle = useCallback2(
|
|
1508
|
+
(checked) => {
|
|
1509
|
+
if (checked) {
|
|
1510
|
+
setShowCompleted(false);
|
|
1511
|
+
onOverdueChange(true);
|
|
1512
|
+
data.addAdditionalParameter("completedFilter", "overdue");
|
|
1513
|
+
} else {
|
|
1514
|
+
onOverdueChange(false);
|
|
1515
|
+
data.removeAdditionalParameter("completedFilter");
|
|
1516
|
+
}
|
|
1517
|
+
},
|
|
1518
|
+
[data, onOverdueChange]
|
|
1519
|
+
);
|
|
1520
|
+
const handlePriorityToggle = useCallback2(
|
|
1521
|
+
(priority) => {
|
|
1522
|
+
const next = selectedPriorities.includes(priority) ? selectedPriorities.filter((p) => p !== priority) : [...selectedPriorities, priority];
|
|
1523
|
+
setSelectedPriorities(next);
|
|
1524
|
+
if (next.length > 0) {
|
|
1525
|
+
data.addAdditionalParameter("filterPriority", next.join(","));
|
|
1526
|
+
} else {
|
|
1527
|
+
data.removeAdditionalParameter("filterPriority");
|
|
1528
|
+
}
|
|
1529
|
+
},
|
|
1530
|
+
[data, selectedPriorities]
|
|
1531
|
+
);
|
|
1532
|
+
const handleClearPriorities = useCallback2(() => {
|
|
1533
|
+
setSelectedPriorities([]);
|
|
1534
|
+
data.removeAdditionalParameter("filterPriority");
|
|
1535
|
+
}, [data]);
|
|
1536
|
+
return /* @__PURE__ */ jsxs6("div", { className: "flex items-center gap-x-2", children: [
|
|
1537
|
+
/* @__PURE__ */ jsxs6("div", { className: "flex items-center gap-x-1.5", children: [
|
|
1538
|
+
/* @__PURE__ */ jsx9(
|
|
1539
|
+
Switch,
|
|
1540
|
+
{
|
|
1541
|
+
id: "completed-filter",
|
|
1542
|
+
"data-testid": "task-filter-completed",
|
|
1543
|
+
checked: showCompleted,
|
|
1544
|
+
onCheckedChange: handleCompletedToggle,
|
|
1545
|
+
className: "scale-75"
|
|
1546
|
+
}
|
|
1547
|
+
),
|
|
1548
|
+
/* @__PURE__ */ jsx9("label", { htmlFor: "completed-filter", className: "text-muted-foreground cursor-pointer text-xs", children: t("task.filter.completed") })
|
|
1549
|
+
] }),
|
|
1550
|
+
/* @__PURE__ */ jsxs6("div", { className: "flex items-center gap-x-1.5", children: [
|
|
1551
|
+
/* @__PURE__ */ jsx9(
|
|
1552
|
+
Switch,
|
|
1553
|
+
{
|
|
1554
|
+
id: "overdue-filter",
|
|
1555
|
+
"data-testid": "task-filter-overdue",
|
|
1556
|
+
checked: overdue,
|
|
1557
|
+
onCheckedChange: handleOverdueToggle,
|
|
1558
|
+
className: "scale-75"
|
|
1559
|
+
}
|
|
1560
|
+
),
|
|
1561
|
+
/* @__PURE__ */ jsx9("label", { htmlFor: "overdue-filter", className: "text-muted-foreground cursor-pointer text-xs", children: t("task.filter.overdue") })
|
|
1562
|
+
] }),
|
|
1563
|
+
/* @__PURE__ */ jsxs6(Popover, { children: [
|
|
1564
|
+
/* @__PURE__ */ jsxs6(
|
|
1565
|
+
PopoverTrigger,
|
|
1566
|
+
{
|
|
1567
|
+
"data-testid": "task-filter-priority",
|
|
1568
|
+
render: /* @__PURE__ */ jsx9(Button4, { size: "sm", variant: "ghost", className: "text-muted-foreground gap-x-1" }),
|
|
1569
|
+
children: [
|
|
1570
|
+
/* @__PURE__ */ jsx9(ListFilterIcon, { className: "h-3.5 w-3.5" }),
|
|
1571
|
+
t("task.filter.priority"),
|
|
1572
|
+
selectedPriorities.length > 0 && /* @__PURE__ */ jsx9(Badge2, { "data-testid": "task-filter-priority-count", className: "ms-0.5 tabular-nums", children: selectedPriorities.length })
|
|
1573
|
+
]
|
|
1574
|
+
}
|
|
1575
|
+
),
|
|
1576
|
+
/* @__PURE__ */ jsxs6(PopoverContent, { align: "start", className: "w-48 p-0", children: [
|
|
1577
|
+
/* @__PURE__ */ jsx9("div", { className: "p-2", children: Object.values(TaskPriority).map((priority) => /* @__PURE__ */ jsxs6(
|
|
1578
|
+
"label",
|
|
1579
|
+
{
|
|
1580
|
+
className: "hover:bg-muted flex cursor-pointer items-center gap-x-2 rounded-md px-2 py-1.5",
|
|
1581
|
+
children: [
|
|
1582
|
+
/* @__PURE__ */ jsx9(
|
|
1583
|
+
Checkbox,
|
|
1584
|
+
{
|
|
1585
|
+
checked: selectedPriorities.includes(priority),
|
|
1586
|
+
onCheckedChange: () => handlePriorityToggle(priority)
|
|
1587
|
+
}
|
|
1588
|
+
),
|
|
1589
|
+
/* @__PURE__ */ jsx9("span", { className: "text-xs", children: t("task.priorities", { priority }) })
|
|
1590
|
+
]
|
|
1591
|
+
},
|
|
1592
|
+
priority
|
|
1593
|
+
)) }),
|
|
1594
|
+
selectedPriorities.length > 0 && /* @__PURE__ */ jsx9("div", { className: "border-t px-2 py-1.5", children: /* @__PURE__ */ jsxs6(Button4, { size: "sm", variant: "ghost", className: "h-7 w-full text-xs", onClick: handleClearPriorities, children: [
|
|
1595
|
+
/* @__PURE__ */ jsx9(XIcon, { className: "me-1 h-3 w-3" }),
|
|
1596
|
+
t("task.filter.clear")
|
|
1597
|
+
] }) })
|
|
1598
|
+
] })
|
|
1599
|
+
] })
|
|
1600
|
+
] });
|
|
1601
|
+
}
|
|
1602
|
+
__name(TaskListFilters, "TaskListFilters");
|
|
1603
|
+
|
|
1604
|
+
// src/web/task/components/forms/TaskCreateButton.tsx
|
|
1605
|
+
import { Button as Button5 } from "@carlonicora/nextjs-jsonapi/components";
|
|
1606
|
+
import { useCurrentUserContext as useCurrentUserContext5 } from "@carlonicora/nextjs-jsonapi/contexts";
|
|
1607
|
+
import { Action as Action5 } from "@carlonicora/nextjs-jsonapi/core";
|
|
1608
|
+
import { useTranslations as useTranslations11 } from "next-intl";
|
|
1609
|
+
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
1610
|
+
function TaskCreateButton() {
|
|
1611
|
+
const t = useTranslations11();
|
|
1612
|
+
const { setNewTask, scope } = useTaskContext();
|
|
1613
|
+
const { hasPermissionToModule } = useCurrentUserContext5();
|
|
1614
|
+
if (!hasPermissionToModule({ module: TodosModules.Task, action: Action5.Create })) return null;
|
|
1615
|
+
const selectors = getTodosUiConfig().selectors ?? {};
|
|
1616
|
+
const unpickable = getTodosConfig().relationships.some(
|
|
1617
|
+
(relationship) => relationship.required && relationship.cardinality === "one" && !relationship.readOnly && relationship.key !== scope?.key && !selectors[relationship.key]
|
|
1618
|
+
);
|
|
1619
|
+
if (unpickable) return null;
|
|
1620
|
+
return /* @__PURE__ */ jsx10(Button5, { "data-testid": "task-create", size: "sm", onClick: () => setNewTask(), variant: `outline`, children: t(`task.create`) });
|
|
1621
|
+
}
|
|
1622
|
+
__name(TaskCreateButton, "TaskCreateButton");
|
|
1623
|
+
|
|
1624
|
+
// src/web/task/components/lists/TasksList.tsx
|
|
1625
|
+
import { jsx as jsx11, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
1626
|
+
function TasksList({ scope, user, type, headerControl, fullWidth, limit, nameBadges } = {}) {
|
|
1627
|
+
const t = useTranslations12();
|
|
1628
|
+
const creatorFlag = type === "created" ? true : void 0;
|
|
1629
|
+
const overdueParam = useTaskOverdueParam();
|
|
1630
|
+
const data = useDataListRetriever({
|
|
1631
|
+
// Held until the address has been read, so `overdue=true` costs one filtered request.
|
|
1632
|
+
ready: false,
|
|
1633
|
+
module: TodosModules.Task,
|
|
1634
|
+
retriever: /* @__PURE__ */ __name((params) => scope ? TaskService.findManyByRelated({ ...params, key: scope.key, id: scope.id }) : user ? TaskService.findManyByUser({ ...params, userId: user.id, creator: creatorFlag }) : TaskService.findMany(params), "retriever"),
|
|
1635
|
+
retrieverParams: scope ? { key: scope.key, id: scope.id, ...limit ? { pageSize: limit } : {} } : user ? { userId: user.id, creator: creatorFlag, ...limit ? { pageSize: limit } : {} } : {}
|
|
1636
|
+
});
|
|
1637
|
+
useRefreshOnTaskEditorClose(data.refresh);
|
|
1638
|
+
const releasedRef = useRef4(false);
|
|
1639
|
+
useEffect7(() => {
|
|
1640
|
+
if (!overdueParam.ready || releasedRef.current) return;
|
|
1641
|
+
releasedRef.current = true;
|
|
1642
|
+
if (overdueParam.overdue) data.addAdditionalParameter("completedFilter", "overdue");
|
|
1643
|
+
else data.setReady(true);
|
|
1644
|
+
}, [overdueParam.ready, overdueParam.overdue, data]);
|
|
1645
|
+
const showLinks = getTodosConfig().relationships.filter((r) => r.key !== scope?.key).length > 0;
|
|
1646
|
+
const fields = [
|
|
1647
|
+
"name" /* name */,
|
|
1648
|
+
"assignee" /* assignee */,
|
|
1649
|
+
"priority" /* priority */,
|
|
1650
|
+
"dueDate" /* dueDate */,
|
|
1651
|
+
...showLinks ? ["relationships" /* relationships */] : [],
|
|
1652
|
+
"owner" /* owner */
|
|
1653
|
+
];
|
|
1654
|
+
const functions = user ? [] : [/* @__PURE__ */ jsx11(TaskCreateButton, {}, "new-task")];
|
|
1655
|
+
const title = user ? type === "created" ? t(`task.my_created_tasks`) : t(`task.my_tasks`) : t(`entities.tasks`, { count: 2 });
|
|
1656
|
+
const filters = user ? /* @__PURE__ */ jsxs7("div", { className: "flex items-center gap-x-2", children: [
|
|
1657
|
+
/* @__PURE__ */ jsx11(TaskListFilters, { data, overdue: overdueParam.overdue, onOverdueChange: overdueParam.setOverdue }),
|
|
1658
|
+
headerControl,
|
|
1659
|
+
/* @__PURE__ */ jsx11(TaskCreateButton, {})
|
|
1660
|
+
] }) : /* @__PURE__ */ jsxs7("div", { className: "flex items-center gap-x-2", children: [
|
|
1661
|
+
headerControl,
|
|
1662
|
+
/* @__PURE__ */ jsx11(TaskListFilters, { data, overdue: overdueParam.overdue, onOverdueChange: overdueParam.setOverdue })
|
|
1663
|
+
] });
|
|
1664
|
+
return /* @__PURE__ */ jsx11(
|
|
1665
|
+
ContentListTable,
|
|
1666
|
+
{
|
|
1667
|
+
data,
|
|
1668
|
+
fields,
|
|
1669
|
+
tableGeneratorType: TodosModules.Task,
|
|
1670
|
+
context: { scope, nameBadges },
|
|
1671
|
+
title,
|
|
1672
|
+
functions,
|
|
1673
|
+
filters,
|
|
1674
|
+
allowSearch: limit ? false : void 0,
|
|
1675
|
+
fullWidth,
|
|
1676
|
+
hidePagination: !!limit
|
|
1677
|
+
}
|
|
1678
|
+
);
|
|
1679
|
+
}
|
|
1680
|
+
__name(TasksList, "TasksList");
|
|
1681
|
+
|
|
1682
|
+
// src/web/task/components/containers/TaskListContainer.tsx
|
|
1683
|
+
import { RoundPageContainer } from "@carlonicora/nextjs-jsonapi/components";
|
|
1684
|
+
import { useCurrentUserContext as useCurrentUserContext7 } from "@carlonicora/nextjs-jsonapi/contexts";
|
|
1685
|
+
import { Action as Action7 } from "@carlonicora/nextjs-jsonapi/core";
|
|
1686
|
+
import { useEffect as useEffect8, useState as useState9 } from "react";
|
|
1687
|
+
|
|
1688
|
+
// src/web/task/components/EisenhowerMatrixBoard.tsx
|
|
1689
|
+
import { useDataListRetriever as useDataListRetriever2 } from "@carlonicora/nextjs-jsonapi/client";
|
|
1690
|
+
import { ContentTableSearch, SectionHeader as SectionHeader2 } from "@carlonicora/nextjs-jsonapi/components";
|
|
1691
|
+
import { cn as cn4 } from "@carlonicora/nextjs-jsonapi/core";
|
|
1692
|
+
import { useTranslations as useTranslations14 } from "next-intl";
|
|
1693
|
+
import { useMemo as useMemo3 } from "react";
|
|
1694
|
+
|
|
1695
|
+
// src/web/task/components/TaskMatrixCard.tsx
|
|
1696
|
+
import { usePageUrlGenerator as usePageUrlGenerator4 } from "@carlonicora/nextjs-jsonapi/client";
|
|
1697
|
+
import { Badge as Badge3, errorToast as errorToast8, Link as Link2 } from "@carlonicora/nextjs-jsonapi/components";
|
|
1698
|
+
import { useCurrentUserContext as useCurrentUserContext6, useDateFormatter as useDateFormatter3, useMountedNow as useMountedNow3 } from "@carlonicora/nextjs-jsonapi/contexts";
|
|
1699
|
+
import { Action as Action6, cn as cn3 } from "@carlonicora/nextjs-jsonapi/core";
|
|
1700
|
+
import { CalendarIcon, CircleCheckIcon as CircleCheckIcon2 } from "lucide-react";
|
|
1701
|
+
import { useTranslations as useTranslations13 } from "next-intl";
|
|
1702
|
+
import { jsx as jsx12, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
1703
|
+
function DueDate({ date, completed }) {
|
|
1704
|
+
const { format } = useDateFormatter3();
|
|
1705
|
+
const now = useMountedNow3();
|
|
1706
|
+
const isOverdue = isTaskOverdue({ dueDate: date, completed }, now);
|
|
1707
|
+
return /* @__PURE__ */ jsxs8(
|
|
1708
|
+
"div",
|
|
1709
|
+
{
|
|
1710
|
+
className: cn3(
|
|
1711
|
+
"flex items-center gap-1 whitespace-nowrap text-xs",
|
|
1712
|
+
isOverdue ? "text-destructive" : "text-muted-foreground"
|
|
1713
|
+
),
|
|
1714
|
+
children: [
|
|
1715
|
+
/* @__PURE__ */ jsx12(CalendarIcon, { className: "h-3 w-3" }),
|
|
1716
|
+
format(dueDateAsLocal(date), "dateMedium")
|
|
1717
|
+
]
|
|
1718
|
+
}
|
|
1719
|
+
);
|
|
1720
|
+
}
|
|
1721
|
+
__name(DueDate, "DueDate");
|
|
1722
|
+
function TaskMatrixCard({ task, dataRetriever, scope }) {
|
|
1723
|
+
const t = useTranslations13();
|
|
1724
|
+
const { setTaskId } = useTaskContext();
|
|
1725
|
+
const { hasPermissionToModule } = useCurrentUserContext6();
|
|
1726
|
+
const generateUrl = usePageUrlGenerator4();
|
|
1727
|
+
const canEdit = hasPermissionToModule({ module: TodosModules.Task, action: Action6.Update, data: task });
|
|
1728
|
+
const toggleCompleted = /* @__PURE__ */ __name(async () => {
|
|
1729
|
+
try {
|
|
1730
|
+
const updatedTask = await TaskService.toggleComplete({ taskId: task.id, completed: !task.completed });
|
|
1731
|
+
dataRetriever?.setRefreshedElement(updatedTask);
|
|
1732
|
+
} catch (error) {
|
|
1733
|
+
errorToast8({ title: t("task.errors.save"), error });
|
|
1734
|
+
if (isTaskGoneError(error)) await dataRetriever?.refresh();
|
|
1735
|
+
}
|
|
1736
|
+
}, "toggleCompleted");
|
|
1737
|
+
const badgeVariant = task.priority === "high" ? "destructive" : task.priority === "medium" ? "default" : "secondary";
|
|
1738
|
+
const links = getTodosConfig().relationships.filter((r) => r.key !== scope?.key).flatMap((r) => task.relatedMany(r.key).map((entity) => ({ entity, module: r.module() })));
|
|
1739
|
+
return /* @__PURE__ */ jsxs8(
|
|
1740
|
+
"div",
|
|
1741
|
+
{
|
|
1742
|
+
"data-testid": `task-matrix-card-${task.id}`,
|
|
1743
|
+
className: "flex cursor-pointer flex-col gap-1 rounded bg-card px-3 py-2 transition-colors hover:bg-accent",
|
|
1744
|
+
onClick: () => setTaskId(task.id),
|
|
1745
|
+
children: [
|
|
1746
|
+
/* @__PURE__ */ jsxs8("div", { className: "flex items-center gap-2", children: [
|
|
1747
|
+
canEdit && /* @__PURE__ */ jsx12(
|
|
1748
|
+
CircleCheckIcon2,
|
|
1749
|
+
{
|
|
1750
|
+
"data-testid": "task-matrix-toggle-complete",
|
|
1751
|
+
className: "h-4 w-4 min-w-4 text-muted-foreground hover:text-success",
|
|
1752
|
+
onClick: (e) => {
|
|
1753
|
+
e.stopPropagation();
|
|
1754
|
+
toggleCompleted();
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
),
|
|
1758
|
+
/* @__PURE__ */ jsx12("div", { className: "min-w-0 flex-1", children: /* @__PURE__ */ jsx12("div", { className: "truncate text-sm", children: task.name }) }),
|
|
1759
|
+
task.priority && /* @__PURE__ */ jsx12(Badge3, { variant: badgeVariant, className: "text-xs", children: t(`task.priorities`, { priority: task.priority }) }),
|
|
1760
|
+
task.dueDate && /* @__PURE__ */ jsx12(DueDate, { date: task.dueDate, completed: task.completed })
|
|
1761
|
+
] }),
|
|
1762
|
+
links.length > 0 && /* @__PURE__ */ jsx12("div", { className: "ms-6 flex flex-wrap items-center gap-1", children: links.map(({ entity, module }) => {
|
|
1763
|
+
const badge = /* @__PURE__ */ jsx12(Badge3, { variant: "secondary", className: "max-w-[140px] truncate", children: entity.name });
|
|
1764
|
+
return module.pageUrl ? /* @__PURE__ */ jsx12(
|
|
1765
|
+
Link2,
|
|
1766
|
+
{
|
|
1767
|
+
href: generateUrl({ page: module, id: entity.id }),
|
|
1768
|
+
onClick: (e) => e.stopPropagation(),
|
|
1769
|
+
children: badge
|
|
1770
|
+
},
|
|
1771
|
+
`${module.name}-${entity.id}`
|
|
1772
|
+
) : /* @__PURE__ */ jsx12("span", { children: badge }, `${module.name}-${entity.id}`);
|
|
1773
|
+
}) })
|
|
1774
|
+
]
|
|
1775
|
+
}
|
|
1776
|
+
);
|
|
1777
|
+
}
|
|
1778
|
+
__name(TaskMatrixCard, "TaskMatrixCard");
|
|
1779
|
+
|
|
1780
|
+
// src/web/task/components/EisenhowerMatrixBoard.tsx
|
|
1781
|
+
import { jsx as jsx13, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
1782
|
+
var QUADRANTS = [
|
|
1783
|
+
{ key: "do", textClass: "text-destructive" },
|
|
1784
|
+
{ key: "defer", textClass: "text-warning" },
|
|
1785
|
+
{ key: "delegate", textClass: "text-primary" },
|
|
1786
|
+
{ key: "delete", textClass: "text-muted-foreground" }
|
|
1787
|
+
];
|
|
1788
|
+
function EisenhowerMatrixBoard({ tasks, dataRetriever, headerControl, scope }) {
|
|
1789
|
+
const t = useTranslations14();
|
|
1790
|
+
const grouped = useMemo3(() => {
|
|
1791
|
+
const groups = {
|
|
1792
|
+
do: [],
|
|
1793
|
+
defer: [],
|
|
1794
|
+
delegate: [],
|
|
1795
|
+
delete: []
|
|
1796
|
+
};
|
|
1797
|
+
const now = /* @__PURE__ */ new Date();
|
|
1798
|
+
for (const task of tasks) {
|
|
1799
|
+
if (task.completed) continue;
|
|
1800
|
+
const quadrant = getEisenhowerQuadrant(task.priority, task.dueDate, now);
|
|
1801
|
+
groups[quadrant].push(task);
|
|
1802
|
+
}
|
|
1803
|
+
return groups;
|
|
1804
|
+
}, [tasks]);
|
|
1805
|
+
const Icon = TodosModules.Task.icon;
|
|
1806
|
+
return /* @__PURE__ */ jsxs9("div", { className: cn4("flex flex-col", headerControl ? "" : "gap-4"), children: [
|
|
1807
|
+
headerControl ? /* @__PURE__ */ jsxs9("div", { className: "bg-card text-primary flex w-full items-center justify-between gap-x-2 rounded-t-lg border-b p-4 font-bold", children: [
|
|
1808
|
+
/* @__PURE__ */ jsxs9("h2", { className: "text-muted-foreground flex items-center gap-x-2 text-xl font-light whitespace-nowrap", children: [
|
|
1809
|
+
Icon && /* @__PURE__ */ jsx13(Icon, { className: "text-primary h-6 w-6" }),
|
|
1810
|
+
t(`task.eisenhower_matrix`)
|
|
1811
|
+
] }),
|
|
1812
|
+
/* @__PURE__ */ jsxs9("div", { className: "flex items-center gap-x-2", children: [
|
|
1813
|
+
headerControl,
|
|
1814
|
+
/* @__PURE__ */ jsx13(TaskCreateButton, {}),
|
|
1815
|
+
dataRetriever && /* @__PURE__ */ jsx13(ContentTableSearch, { data: dataRetriever })
|
|
1816
|
+
] })
|
|
1817
|
+
] }) : /* @__PURE__ */ jsx13("div", { className: "flex justify-end", children: /* @__PURE__ */ jsx13(TaskCreateButton, {}) }),
|
|
1818
|
+
/* @__PURE__ */ jsx13("div", { className: cn4("grid grid-cols-2 items-start gap-4", headerControl && "p-4"), children: QUADRANTS.map((q) => /* @__PURE__ */ jsxs9(
|
|
1819
|
+
"div",
|
|
1820
|
+
{
|
|
1821
|
+
"data-testid": `task-matrix-quadrant-${q.key}`,
|
|
1822
|
+
className: "flex max-h-96 min-h-48 flex-col rounded-lg border p-4",
|
|
1823
|
+
children: [
|
|
1824
|
+
/* @__PURE__ */ jsxs9("div", { className: "mb-3 flex items-center gap-2", children: [
|
|
1825
|
+
/* @__PURE__ */ jsx13(EisenhowerIcon, { quadrant: q.key, className: "h-5 w-5" }),
|
|
1826
|
+
/* @__PURE__ */ jsx13(SectionHeader2, { level: 3, className: q.textClass, children: t(`task.eisenhower.${q.key}`) })
|
|
1827
|
+
] }),
|
|
1828
|
+
/* @__PURE__ */ jsx13("div", { className: "flex min-h-0 flex-1 flex-col gap-1.5 overflow-y-auto", children: grouped[q.key].length === 0 ? /* @__PURE__ */ jsx13("p", { className: "text-muted-foreground py-4 text-center text-xs italic", children: "\u2014" }) : grouped[q.key].map((task) => /* @__PURE__ */ jsx13(TaskMatrixCard, { task, dataRetriever, scope }, task.id)) })
|
|
1829
|
+
]
|
|
1830
|
+
},
|
|
1831
|
+
q.key
|
|
1832
|
+
)) })
|
|
1833
|
+
] });
|
|
1834
|
+
}
|
|
1835
|
+
__name(EisenhowerMatrixBoard, "EisenhowerMatrixBoard");
|
|
1836
|
+
function EisenhowerMatrixBoardTab({ scope, user, headerControl }) {
|
|
1837
|
+
const data = useDataListRetriever2({
|
|
1838
|
+
module: TodosModules.Task,
|
|
1839
|
+
retriever: /* @__PURE__ */ __name((params) => scope ? TaskService.findManyByRelated({ ...params, key: scope.key, id: scope.id }) : user ? TaskService.findManyByUser({ ...params, userId: user.id, creator: void 0 }) : TaskService.findMany(params), "retriever"),
|
|
1840
|
+
retrieverParams: scope ? { key: scope.key, id: scope.id, fetchAll: true } : user ? { userId: user.id, fetchAll: true } : { fetchAll: true }
|
|
1841
|
+
});
|
|
1842
|
+
useRefreshOnTaskEditorClose(data.refresh);
|
|
1843
|
+
if (!data.data) return null;
|
|
1844
|
+
return /* @__PURE__ */ jsx13(EisenhowerMatrixBoard, { tasks: data.data, dataRetriever: data, headerControl, scope });
|
|
1845
|
+
}
|
|
1846
|
+
__name(EisenhowerMatrixBoardTab, "EisenhowerMatrixBoardTab");
|
|
1847
|
+
|
|
1848
|
+
// src/web/task/components/filters/TaskViewSwitcher.tsx
|
|
1849
|
+
import { cn as cn5 } from "@carlonicora/nextjs-jsonapi/core";
|
|
1850
|
+
import { useTranslations as useTranslations15 } from "next-intl";
|
|
1851
|
+
import { jsx as jsx14 } from "react/jsx-runtime";
|
|
1852
|
+
var MODE_LABELS = {
|
|
1853
|
+
list: "task.views.list",
|
|
1854
|
+
matrix: "task.views.matrix",
|
|
1855
|
+
assigned: "task.my_tasks",
|
|
1856
|
+
created: "task.my_created_tasks"
|
|
1857
|
+
};
|
|
1858
|
+
function TaskViewSwitcher({ value, modes, onChange }) {
|
|
1859
|
+
const t = useTranslations15();
|
|
1860
|
+
return /* @__PURE__ */ jsx14("div", { className: "bg-muted inline-flex items-center rounded-md p-0.5", children: modes.map((mode) => /* @__PURE__ */ jsx14(
|
|
1861
|
+
"button",
|
|
1862
|
+
{
|
|
1863
|
+
type: "button",
|
|
1864
|
+
"data-testid": `task-view-${mode}`,
|
|
1865
|
+
onClick: () => onChange(mode),
|
|
1866
|
+
className: cn5(
|
|
1867
|
+
"rounded-sm px-3 py-1 text-xs font-medium whitespace-nowrap transition-colors",
|
|
1868
|
+
value === mode ? "bg-background text-foreground shadow-sm" : "text-muted-foreground hover:text-foreground"
|
|
1869
|
+
),
|
|
1870
|
+
children: t(MODE_LABELS[mode])
|
|
1871
|
+
},
|
|
1872
|
+
mode
|
|
1873
|
+
)) });
|
|
1874
|
+
}
|
|
1875
|
+
__name(TaskViewSwitcher, "TaskViewSwitcher");
|
|
1876
|
+
|
|
1877
|
+
// src/web/task/components/containers/TaskListContainer.tsx
|
|
1878
|
+
import { jsx as jsx15 } from "react/jsx-runtime";
|
|
1879
|
+
function TaskListContainer({ scope, user, nameBadges }) {
|
|
1880
|
+
const { hasPermissionToModule } = useCurrentUserContext7();
|
|
1881
|
+
const modes = user ? ["assigned", "created", "matrix"] : ["list", "matrix"];
|
|
1882
|
+
const [mode, setMode] = useState9(void 0);
|
|
1883
|
+
useEffect8(() => {
|
|
1884
|
+
const tabParam = new URLSearchParams(window.location.search).get("tab");
|
|
1885
|
+
setMode(tabParam && modes.includes(tabParam) ? tabParam : modes[0]);
|
|
1886
|
+
}, []);
|
|
1887
|
+
if (!hasPermissionToModule({ module: TodosModules.Task, action: Action7.Read })) return null;
|
|
1888
|
+
const handleModeChange = /* @__PURE__ */ __name((next) => {
|
|
1889
|
+
setMode(next);
|
|
1890
|
+
const url = new URL(window.location.href);
|
|
1891
|
+
url.searchParams.set("tab", next);
|
|
1892
|
+
window.history.replaceState(null, "", url.toString());
|
|
1893
|
+
}, "handleModeChange");
|
|
1894
|
+
if (!mode) return /* @__PURE__ */ jsx15(RoundPageContainer, { module: TodosModules.Task, fullWidth: true, testId: "page-task-list" });
|
|
1895
|
+
const switcher = /* @__PURE__ */ jsx15(TaskViewSwitcher, { value: mode, modes, onChange: handleModeChange });
|
|
1896
|
+
return /* @__PURE__ */ jsx15(RoundPageContainer, { module: TodosModules.Task, fullWidth: true, testId: "page-task-list", children: mode === "matrix" ? /* @__PURE__ */ jsx15(EisenhowerMatrixBoardTab, { scope, user, headerControl: switcher }) : /* @__PURE__ */ jsx15(
|
|
1897
|
+
TasksList,
|
|
1898
|
+
{
|
|
1899
|
+
scope,
|
|
1900
|
+
user,
|
|
1901
|
+
type: user ? mode : void 0,
|
|
1902
|
+
fullWidth: true,
|
|
1903
|
+
headerControl: switcher,
|
|
1904
|
+
nameBadges
|
|
1905
|
+
},
|
|
1906
|
+
mode
|
|
1907
|
+
) });
|
|
1908
|
+
}
|
|
1909
|
+
__name(TaskListContainer, "TaskListContainer");
|
|
1910
|
+
|
|
1911
|
+
// src/web/task/components/screens/UserTasksScreen.tsx
|
|
1912
|
+
import { useCurrentUserContext as useCurrentUserContext8 } from "@carlonicora/nextjs-jsonapi/contexts";
|
|
1913
|
+
import { jsx as jsx16, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
1914
|
+
function UserTaskDeepLink() {
|
|
1915
|
+
useTaskDeepLink();
|
|
1916
|
+
return null;
|
|
1917
|
+
}
|
|
1918
|
+
__name(UserTaskDeepLink, "UserTaskDeepLink");
|
|
1919
|
+
function UserTasksScreen() {
|
|
1920
|
+
const { currentUser } = useCurrentUserContext8();
|
|
1921
|
+
if (!currentUser) return null;
|
|
1922
|
+
return /* @__PURE__ */ jsxs10(TaskProvider, { children: [
|
|
1923
|
+
/* @__PURE__ */ jsx16(UserTaskDeepLink, {}),
|
|
1924
|
+
/* @__PURE__ */ jsx16(TaskListContainer, { user: currentUser }),
|
|
1925
|
+
/* @__PURE__ */ jsx16(TaskEditor, {})
|
|
1926
|
+
] });
|
|
1927
|
+
}
|
|
1928
|
+
__name(UserTasksScreen, "UserTasksScreen");
|
|
1929
|
+
export {
|
|
1930
|
+
EisenhowerIcon,
|
|
1931
|
+
EisenhowerMatrixBoard,
|
|
1932
|
+
EisenhowerMatrixBoardTab,
|
|
1933
|
+
TaskCommentEditor,
|
|
1934
|
+
TaskCommentList,
|
|
1935
|
+
TaskCommentProvider,
|
|
1936
|
+
TaskCreateButton,
|
|
1937
|
+
TaskDeleter,
|
|
1938
|
+
TaskEditor,
|
|
1939
|
+
TaskListContainer,
|
|
1940
|
+
TaskListFilters,
|
|
1941
|
+
TaskMatrixCard,
|
|
1942
|
+
TaskProvider,
|
|
1943
|
+
TaskViewSwitcher,
|
|
1944
|
+
TasksList,
|
|
1945
|
+
UserTasksScreen,
|
|
1946
|
+
configureTodosUi,
|
|
1947
|
+
getEisenhowerQuadrant,
|
|
1948
|
+
getTaskPrioritiesSelectOptions,
|
|
1949
|
+
getTodosUiConfig,
|
|
1950
|
+
useRefreshOnTaskEditorClose,
|
|
1951
|
+
useTaskCommentContext,
|
|
1952
|
+
useTaskContext,
|
|
1953
|
+
useTaskDeepLink,
|
|
1954
|
+
useTaskOverdueParam,
|
|
1955
|
+
useTaskTableStructure,
|
|
1956
|
+
useTodosEditorProps
|
|
1957
|
+
};
|
|
1958
|
+
//# sourceMappingURL=index.mjs.map
|