Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix: scope workspace inbox and refresh personal work reliably

Tin536c5a6660c8
diff --git a/apps/api/src/activity/comment-excerpt.test.ts b/apps/api/src/activity/comment-excerpt.test.ts
index e1c1f031d..02953ea13 100644
--- a/apps/api/src/activity/comment-excerpt.test.ts
+++ b/apps/api/src/activity/comment-excerpt.test.ts
@@ -24,7 +24,7 @@ describe("commentExcerpt", () => {
it("truncates long comments", () => {
const excerpt = commentExcerpt("a".repeat(500));
- expect(excerpt).toHaveLength(241);
+ expect(excerpt).toHaveLength(240);
expect(excerpt?.endsWith("…")).toBe(true);
});
diff --git a/apps/api/src/activity/comment-excerpt.ts b/apps/api/src/activity/comment-excerpt.ts
index 28bf286c4..c8161058d 100644
--- a/apps/api/src/activity/comment-excerpt.ts
+++ b/apps/api/src/activity/comment-excerpt.ts
@@ -14,5 +14,5 @@ export function commentExcerpt(content: string | null): string | null {
if (!text) return null;
if (text.length <= EXCERPT_LENGTH) return text;
- return `${text.slice(0, EXCERPT_LENGTH).trimEnd()}…`;
+ return `${text.slice(0, EXCERPT_LENGTH - 1).trimEnd()}…`;
}
diff --git a/apps/api/src/notification/controllers/clear-notifications.ts b/apps/api/src/notification/controllers/clear-notifications.ts
index 5dee21faa..3ddb4c1cb 100644
--- a/apps/api/src/notification/controllers/clear-notifications.ts
+++ b/apps/api/src/notification/controllers/clear-notifications.ts
@@ -1,11 +1,26 @@
-import { eq } from "drizzle-orm";
+import { and, eq } from "drizzle-orm";
import db from "../../database";
import { notificationTable } from "../../database/schema";
-async function clearNotifications(userId: string) {
+import { notificationResourceAccess } from "../resource-access";
+import { notificationWorkspaceFilter } from "../workspace-filter";
+
+async function clearNotifications(userId: string, workspaceId?: string) {
await db
.delete(notificationTable)
- .where(eq(notificationTable.userId, userId));
+ .where(
+ and(
+ eq(notificationTable.userId, userId),
+ notificationWorkspaceFilter(workspaceId),
+ workspaceId
+ ? notificationResourceAccess(
+ userId,
+ notificationTable.resourceId,
+ notificationTable.resourceType,
+ )
+ : undefined,
+ ),
+ );
return { success: true };
}
diff --git a/apps/api/src/notification/controllers/get-notifications.ts b/apps/api/src/notification/controllers/get-notifications.ts
index 98567317f..734089890 100644
--- a/apps/api/src/notification/controllers/get-notifications.ts
+++ b/apps/api/src/notification/controllers/get-notifications.ts
@@ -8,8 +8,9 @@ import {
} from "../../database/schema";
import { notificationResourceAccess } from "../resource-access";
+import { notificationWorkspaceFilter } from "../workspace-filter";
-async function getNotifications(userId: string) {
+async function getNotifications(userId: string, workspaceId?: string) {
const rows = await db
.select({
notification: notificationTable,
@@ -29,6 +30,7 @@ async function getNotifications(userId: string) {
.where(
and(
eq(notificationTable.userId, userId),
+ notificationWorkspaceFilter(workspaceId),
notificationResourceAccess(
userId,
notificationTable.resourceId,
diff --git a/apps/api/src/notification/controllers/mark-all-notifications-as-read.ts b/apps/api/src/notification/controllers/mark-all-notifications-as-read.ts
index 6bcfb4c17..1f24f9aa1 100644
--- a/apps/api/src/notification/controllers/mark-all-notifications-as-read.ts
+++ b/apps/api/src/notification/controllers/mark-all-notifications-as-read.ts
@@ -1,12 +1,30 @@
-import { eq } from "drizzle-orm";
+import { and, eq } from "drizzle-orm";
import db from "../../database";
import { notificationTable } from "../../database/schema";
-async function markAllNotificationsAsRead(userId: string) {
+import { notificationResourceAccess } from "../resource-access";
+import { notificationWorkspaceFilter } from "../workspace-filter";
+
+async function markAllNotificationsAsRead(
+ userId: string,
+ workspaceId?: string,
+) {
await db
.update(notificationTable)
.set({ isRead: true })
- .where(eq(notificationTable.userId, userId));
+ .where(
+ and(
+ eq(notificationTable.userId, userId),
+ notificationWorkspaceFilter(workspaceId),
+ workspaceId
+ ? notificationResourceAccess(
+ userId,
+ notificationTable.resourceId,
+ notificationTable.resourceType,
+ )
+ : undefined,
+ ),
+ );
return { success: true };
}
diff --git a/apps/api/src/notification/index.ts b/apps/api/src/notification/index.ts
index fad0333bb..443c9557e 100644
--- a/apps/api/src/notification/index.ts
+++ b/apps/api/src/notification/index.ts
@@ -18,7 +18,11 @@ import {
notificationListSchema,
notificationSchema,
} from "./response";
-import { createNotificationBody, notificationParam } from "./schema";
+import {
+ createNotificationBody,
+ notificationParam,
+ notificationWorkspaceQuery,
+} from "./schema";
const listNotificationsRoute = createRoute({
method: "get",
@@ -26,7 +30,9 @@ const listNotificationsRoute = createRoute({
path: "/",
tags: ["Notifications"],
summary: "List notifications",
- description: "Get every notification for the current user, read and unread.",
+ request: { query: notificationWorkspaceQuery },
+ description:
+ "Get up to 50 notifications for the current user, read and unread. Optionally limit them to one workspace before applying the limit.",
responses: {
200: jsonResponse("List of notifications", notificationListSchema),
},
@@ -76,7 +82,9 @@ const markAllAsReadRoute = createRoute({
path: "/read-all",
tags: ["Notifications"],
summary: "Mark all read",
- description: "Mark every notification for the current user as read.",
+ request: { query: notificationWorkspaceQuery },
+ description:
+ "Mark notifications for the current user as read, optionally limited to one workspace.",
responses: {
200: jsonResponse("All notifications marked as read", bulkResultSchema),
},
@@ -88,8 +96,9 @@ const clearAllRoute = createRoute({
path: "/clear-all",
tags: ["Notifications"],
summary: "Clear all",
+ request: { query: notificationWorkspaceQuery },
description:
- "Permanently delete every notification for the current user. This cannot be undone.",
+ "Permanently delete notifications for the current user, optionally limited to one workspace. This cannot be undone.",
responses: {
200: jsonResponse("All notifications cleared", bulkResultSchema),
},
@@ -97,7 +106,10 @@ const clearAllRoute = createRoute({
const notification = apiRouter()
.openapi(listNotificationsRoute, async (c) =>
- c.json(await getNotifications(c.get("userId")), 200),
+ c.json(
+ await getNotifications(c.get("userId"), c.req.valid("query").workspaceId),
+ 200,
+ ),
)
.openapi(createNotificationRoute, async (c) => {
const {
@@ -125,10 +137,22 @@ const notification = apiRouter()
c.json(await markAsRead(c.req.valid("param").id, c.get("userId")), 200),
)
.openapi(markAllAsReadRoute, async (c) =>
- c.json(await markAllNotificationsAsRead(c.get("userId")), 200),
+ c.json(
+ await markAllNotificationsAsRead(
+ c.get("userId"),
+ c.req.valid("query").workspaceId,
+ ),
+ 200,
+ ),
)
.openapi(clearAllRoute, async (c) =>
- c.json(await clearNotifications(c.get("userId")), 200),
+ c.json(
+ await clearNotifications(
+ c.get("userId"),
+ c.req.valid("query").workspaceId,
+ ),
+ 200,
+ ),
);
subscribeToEvent<{
diff --git a/apps/api/src/notification/schema.ts b/apps/api/src/notification/schema.ts
index 381178c11..91b4c9cce 100644
--- a/apps/api/src/notification/schema.ts
+++ b/apps/api/src/notification/schema.ts
@@ -1,5 +1,12 @@
import { z } from "../openapi";
+export const notificationWorkspaceQuery = z.object({
+ workspaceId: z.string().min(1).optional().openapi({
+ description:
+ "Limit notifications to resources currently in this workspace. Omit to include all workspaces.",
+ }),
+});
+
export const notificationParam = z.object({ id: z.string() });
export const createNotificationBody = z.object({
diff --git a/apps/api/src/notification/workspace-filter.ts b/apps/api/src/notification/workspace-filter.ts
new file mode 100644
index 000000000..414efc355
--- /dev/null
+++ b/apps/api/src/notification/workspace-filter.ts
@@ -0,0 +1,17 @@
+import { sql } from "drizzle-orm";
+import { notificationTable } from "../database/schema";
+
+// Resolve the resource's current workspace, rather than trusting eventData,
+// which integrations can supply and older notifications may omit.
+export function notificationWorkspaceFilter(workspaceId?: string) {
+ if (!workspaceId) return undefined;
+ return sql<boolean>`(
+ (${notificationTable.resourceType} = 'workspace' AND ${notificationTable.resourceId} = ${workspaceId})
+ OR (${notificationTable.resourceType} = 'task' AND EXISTS (
+ SELECT 1 FROM task AS inbox_task
+ JOIN project AS inbox_project ON inbox_project.id = inbox_task.project_id
+ WHERE inbox_task.id = ${notificationTable.resourceId}
+ AND inbox_project.workspace_id = ${workspaceId}
+ ))
+ )`;
+}
diff --git a/apps/docs/openapi.json b/apps/docs/openapi.json
index 4162debfe..926d30945 100644
--- a/apps/docs/openapi.json
+++ b/apps/docs/openapi.json
@@ -12713,7 +12713,20 @@
"Notifications"
],
"summary": "List notifications",
- "description": "Get every notification for the current user, read and unread.",
+ "description": "Get up to 50 notifications for the current user, read and unread. Optionally limit them to one workspace before applying the limit.",
+ "parameters": [
+ {
+ "schema": {
+ "type": "string",
+ "minLength": 1,
+ "description": "Limit notifications to resources currently in this workspace. Omit to include all workspaces."
+ },
+ "required": false,
+ "description": "Limit notifications to resources currently in this workspace. Omit to include all workspaces.",
+ "name": "workspaceId",
+ "in": "query"
+ }
+ ],
"responses": {
"200": {
"description": "List of notifications",
@@ -12875,7 +12888,20 @@
"Notifications"
],
"summary": "Mark all read",
- "description": "Mark every notification for the current user as read.",
+ "description": "Mark notifications for the current user as read, optionally limited to one workspace.",
+ "parameters": [
+ {
+ "schema": {
+ "type": "string",
+ "minLength": 1,
+ "description": "Limit notifications to resources currently in this workspace. Omit to include all workspaces."
+ },
+ "required": false,
+ "description": "Limit notifications to resources currently in this workspace. Omit to include all workspaces.",
+ "name": "workspaceId",
+ "in": "query"
+ }
+ ],
"responses": {
"200": {
"description": "All notifications marked as read",
@@ -12900,7 +12926,20 @@
"Notifications"
],
"summary": "Clear all",
- "description": "Permanently delete every notification for the current user. This cannot be undone.",
+ "description": "Permanently delete notifications for the current user, optionally limited to one workspace. This cannot be undone.",
+ "parameters": [
+ {
+ "schema": {
+ "type": "string",
+ "minLength": 1,
+ "description": "Limit notifications to resources currently in this workspace. Omit to include all workspaces."
+ },
+ "required": false,
+ "description": "Limit notifications to resources currently in this workspace. Omit to include all workspaces.",
+ "name": "workspaceId",
+ "in": "query"
+ }
+ ],
"responses": {
"200": {
"description": "All notifications cleared",
diff --git a/apps/web/src/components/home/home-projects.tsx b/apps/web/src/components/home/home-projects.tsx
index 53d94a3ea..ba1a9b614 100644
--- a/apps/web/src/components/home/home-projects.tsx
+++ b/apps/web/src/components/home/home-projects.tsx
@@ -1,5 +1,6 @@
import { Link } from "@tanstack/react-router";
import { useTranslation } from "react-i18next";
+import { Skeleton } from "@/components/ui/skeleton";
import icons from "@/constants/project-icons";
import useGetProjects from "@/hooks/queries/project/use-get-projects";
import { SectionHeader } from "./section-header";
@@ -12,9 +13,11 @@ const VISIBLE_PROJECTS = 3;
export function HomeProjects({ workspaceId }: HomeProjectsProps) {
const { t } = useTranslation();
- const { data: projects } = useGetProjects({ workspaceId });
-
- if (!projects?.length) return null;
+ const {
+ data: projects,
+ isPending,
+ isError,
+ } = useGetProjects({ workspaceId });
return (
<section className="flex flex-col gap-3">
@@ -30,44 +33,59 @@ export function HomeProjects({ workspaceId }: HomeProjectsProps) {
</Link>
}
/>
- <div className="grid gap-3 sm:grid-cols-3">
- {projects.slice(0, VISIBLE_PROJECTS).map((project) => {
- const ProjectIcon =
- icons[project.icon as keyof typeof icons] || icons.Layout;
- const { completionPercentage, totalTasks } = project.statistics;
+ {isPending ? (
+ <Skeleton
+ aria-label={t("common:empty.loading")}
+ className="h-28 w-full"
+ />
+ ) : isError ? (
+ <p role="alert" className="text-muted-foreground text-sm">
+ {t("workspace:home.projects.loadError")}
+ </p>
+ ) : !projects?.length ? (
+ <p className="text-muted-foreground text-sm">
+ {t("workspace:projects.emptyTitle")}
+ </p>
+ ) : (
+ <div className="grid gap-3 sm:grid-cols-3">
+ {projects.slice(0, VISIBLE_PROJECTS).map((project) => {
+ const ProjectIcon =
+ icons[project.icon as keyof typeof icons] || icons.Layout;
+ const { completionPercentage, totalTasks } = project.statistics;
- return (
- <Link
- key={project.id}
- to="/dashboard/workspace/$workspaceId/project/$projectId/board"
- params={{ workspaceId, projectId: project.id }}
- className="flex flex-col gap-3.5 rounded-lg border border-border p-3.5 outline-none transition-colors hover:bg-accent/40 focus-visible:ring-2 focus-visible:ring-ring"
- >
- <div className="flex items-center gap-2">
- <ProjectIcon
- aria-hidden="true"
- className="size-4 shrink-0 text-muted-foreground"
- />
- <span className="min-w-0 flex-1 truncate font-medium text-foreground text-sm">
- {project.name}
- </span>
- <span className="text-muted-foreground text-xs tabular-nums">
- {completionPercentage}%
+ return (
+ <Link
+ key={project.id}
+ to="/dashboard/workspace/$workspaceId/project/$projectId/board"
+ params={{ workspaceId, projectId: project.id }}
+ className="flex flex-col gap-3.5 rounded-lg border border-border p-3.5 outline-none transition-colors hover:bg-accent/40 focus-visible:ring-2 focus-visible:ring-ring"
+ >
+ <div className="flex items-center gap-2">
+ <ProjectIcon
+ aria-hidden="true"
+ className="size-4 shrink-0 text-muted-foreground"
+ />
+ <span className="min-w-0 flex-1 truncate font-medium text-foreground text-sm">
+ {project.name}
+ </span>
+ <span className="text-muted-foreground text-xs tabular-nums">
+ {completionPercentage}%
+ </span>
+ </div>
+ <div className="h-1 overflow-hidden rounded-full bg-muted">
+ <div
+ className="h-full rounded-full bg-foreground/80"
+ style={{ width: `${completionPercentage}%` }}
+ />
+ </div>
+ <span className="text-muted-foreground text-xs">
+ {t("workspace:home.projects.tasks", { count: totalTasks })}
</span>
- </div>
- <div className="h-1 overflow-hidden rounded-full bg-muted">
- <div
- className="h-full rounded-full bg-foreground/80"
- style={{ width: `${completionPercentage}%` }}
- />
- </div>
- <span className="text-muted-foreground text-xs">
- {t("workspace:home.projects.tasks", { count: totalTasks })}
- </span>
- </Link>
- );
- })}
- </div>
+ </Link>
+ );
+ })}
+ </div>
+ )}
</section>
);
}
diff --git a/apps/web/src/components/home/week-strip.tsx b/apps/web/src/components/home/week-strip.tsx
index a625a5770..b0093e13e 100644
--- a/apps/web/src/components/home/week-strip.tsx
+++ b/apps/web/src/components/home/week-strip.tsx
@@ -2,6 +2,7 @@ import { Link } from "@tanstack/react-router";
import { useMemo } from "react";
import { useTranslation } from "react-i18next";
import type { AssignedTask } from "@/fetchers/task/get-assigned-tasks";
+import { useLocalDay } from "@/hooks/use-local-day";
import { cn } from "@/lib/cn";
import { formatDate } from "@/lib/format";
import { buildWeek } from "./build-week";
@@ -15,7 +16,8 @@ const VISIBLE_TASKS_PER_DAY = 2;
export function WeekStrip({ tasks, workspaceId }: WeekStripProps) {
const { t } = useTranslation();
- const week = useMemo(() => buildWeek(tasks), [tasks]);
+ const day = useLocalDay();
+ const week = useMemo(() => buildWeek(tasks, new Date(day)), [tasks, day]);
return (
<div className="overflow-x-auto rounded-xl border border-border bg-card">
diff --git a/apps/web/src/components/inbox/inbox-list.tsx b/apps/web/src/components/inbox/inbox-list.tsx
index 294be3126..65506f26b 100644
--- a/apps/web/src/components/inbox/inbox-list.tsx
+++ b/apps/web/src/components/inbox/inbox-list.tsx
@@ -23,12 +23,14 @@ import {
import { InboxListItem } from "./inbox-list-item";
type InboxListProps = {
+ workspaceId: string;
notifications: Notification[];
selectedId: string | undefined;
onSelect: (notification: Notification) => void;
};
export function InboxList({
+ workspaceId,
notifications,
selectedId,
onSelect,
@@ -36,8 +38,8 @@ export function InboxList({
const { t } = useTranslation();
const [filter, setFilter] = useState<InboxFilter>("all");
const [showClearDialog, setShowClearDialog] = useState(false);
- const { mutate: markAllAsRead } = useMarkAllNotificationsAsRead();
- const { mutate: clearAll } = useClearNotifications();
+ const { mutate: markAllAsRead } = useMarkAllNotificationsAsRead(workspaceId);
+ const { mutate: clearAll } = useClearNotifications(workspaceId);
const unreadCount = notifications.filter(
(notification) => !notification.isRead,
diff --git a/apps/web/src/components/inbox/inbox-task.tsx b/apps/web/src/components/inbox/inbox-task.tsx
index f1083c7b8..4e3226738 100644
--- a/apps/web/src/components/inbox/inbox-task.tsx
+++ b/apps/web/src/components/inbox/inbox-task.tsx
@@ -23,7 +23,11 @@ const VISIBLE_ACTIVITIES = 6;
export function InboxTask({ taskId }: InboxTaskProps) {
const { t } = useTranslation();
const { data: task, isLoading, isError } = useGetTask(taskId);
- const { data: activities = [] } = useGetActivitiesByTaskId(taskId);
+ const {
+ data: activities = [],
+ isPending: activityPending,
+ isError: activityError,
+ } = useGetActivitiesByTaskId(taskId);
const { canUpdateTasks } = useWorkspacePermission();
if (isLoading) {
@@ -88,24 +92,35 @@ export function InboxTask({ taskId }: InboxTaskProps) {
<h3 className="font-medium text-muted-foreground text-xs">
{t("notifications:inbox.recentActivity")}
</h3>
- {recent.length > 0 && (
- <Timeline>
- {recent.map((activity, index) => {
- const next = recent[index + 1];
- return (
- <Activity
- key={activity.id}
- activity={activity}
- step={recent.length - index}
- showConnector={
- !isCommentActivity(activity) &&
- Boolean(next) &&
- !isCommentActivity(next)
- }
- />
- );
- })}
- </Timeline>
+ {activityPending ? (
+ <Skeleton
+ aria-label={t("common:empty.loading")}
+ className="h-24 w-full"
+ />
+ ) : activityError ? (
+ <p role="alert" className="text-muted-foreground text-sm">
+ {t("workspace:home.activity.loadError")}
+ </p>
+ ) : (
+ recent.length > 0 && (
+ <Timeline>
+ {recent.map((activity, index) => {
+ const next = recent[index + 1];
+ return (
+ <Activity
+ key={activity.id}
+ activity={activity}
+ step={recent.length - index}
+ showConnector={
+ !isCommentActivity(activity) &&
+ Boolean(next) &&
+ !isCommentActivity(next)
+ }
+ />
+ );
+ })}
+ </Timeline>
+ )
)}
{canUpdateTasks() && <CommentInput taskId={taskId} />}
</div>
diff --git a/apps/web/src/components/kanban-board/index.tsx b/apps/web/src/components/kanban-board/index.tsx
index 542bf04ee..434c86239 100644
--- a/apps/web/src/components/kanban-board/index.tsx
+++ b/apps/web/src/components/kanban-board/index.tsx
@@ -1,3 +1,4 @@
+import { invalidateMyWork } from "@/lib/invalidate-my-work";
import { markBoardCacheChanged } from "@/lib/board-cache-version";
import { selectReorderBoard } from "./select-reorder-board";
import {
@@ -67,6 +68,7 @@ function KanbanBoard({
reorderTasks(request),
onMutate: (variables) => ({ previousBoard: variables.previousBoard }),
onSuccess: (_result, variables) => {
+ invalidateMyWork(queryClient);
void queryClient.invalidateQueries({
queryKey: ["tasks", variables.projectId],
});
diff --git a/apps/web/src/components/my-tasks/my-tasks-list.tsx b/apps/web/src/components/my-tasks/my-tasks-list.tsx
index 10969f34f..f250bec57 100644
--- a/apps/web/src/components/my-tasks/my-tasks-list.tsx
+++ b/apps/web/src/components/my-tasks/my-tasks-list.tsx
@@ -7,6 +7,7 @@ import {
groupAssignedTasksByProject,
} from "@/components/my-work/group-assigned-tasks";
import type { AssignedTask } from "@/fetchers/task/get-assigned-tasks";
+import { useLocalDay } from "@/hooks/use-local-day";
import { cn } from "@/lib/cn";
import type { MyTasksGroupBy } from "./my-tasks-group-by";
@@ -24,12 +25,13 @@ export function MyTasksList({
workspaceId,
}: MyTasksListProps) {
const { t } = useTranslation();
+ const day = useLocalDay();
const groups = useMemo(
() =>
groupBy === "project"
? groupAssignedTasksByProject(tasks)
- : groupAssignedTasksByDueDate(tasks),
- [tasks, groupBy],
+ : groupAssignedTasksByDueDate(tasks, new Date(day)),
+ [tasks, groupBy, day],
);
const bucketTitles: Record<DueBucket, string> = {
diff --git a/apps/web/src/components/nav-main.tsx b/apps/web/src/components/nav-main.tsx
index 534fca7c4..8325f89f9 100644
--- a/apps/web/src/components/nav-main.tsx
+++ b/apps/web/src/components/nav-main.tsx
@@ -39,7 +39,7 @@ export function NavMain() {
select: (location) => location.pathname.replace(/\/+$/, ""),
});
const { data: invitations = [] } = usePendingInvitations();
- const { data: notifications = [] } = useGetNotifications();
+ const { data: notifications = [] } = useGetNotifications(workspace?.id);
const { data: assignedTasks } = useGetAssignedTasks(workspace?.id);
const inboxUrl = workspace
diff --git a/apps/web/src/fetchers/notification/clear-notifications.ts b/apps/web/src/fetchers/notification/clear-notifications.ts
index a252bcccc..fcb48e539 100644
--- a/apps/web/src/fetchers/notification/clear-notifications.ts
+++ b/apps/web/src/fetchers/notification/clear-notifications.ts
@@ -2,8 +2,10 @@ import { client } from "@kaneo/libs";
import { HttpError } from "@/lib/http-error";
-async function clearNotifications() {
- const response = await client.notification["clear-all"].$delete();
+async function clearNotifications(workspaceId?: string) {
+ const response = await client.notification["clear-all"].$delete({
+ query: { workspaceId },
+ });
if (!response.ok) {
throw new HttpError(response.status, await response.text());
diff --git a/apps/web/src/fetchers/notification/get-notifications.ts b/apps/web/src/fetchers/notification/get-notifications.ts
index abe68365e..fbf91c346 100644
--- a/apps/web/src/fetchers/notification/get-notifications.ts
+++ b/apps/web/src/fetchers/notification/get-notifications.ts
@@ -2,8 +2,8 @@ import { client } from "@kaneo/libs";
import { HttpError } from "@/lib/http-error";
-async function getNotifications() {
- const response = await client.notification.$get();
+async function getNotifications(workspaceId?: string) {
+ const response = await client.notification.$get({ query: { workspaceId } });
if (!response.ok) {
throw new HttpError(response.status, await response.text());
diff --git a/apps/web/src/fetchers/notification/mark-all-notifications-as-read.ts b/apps/web/src/fetchers/notification/mark-all-notifications-as-read.ts
index d67d0db94..1ac0e0236 100644
--- a/apps/web/src/fetchers/notification/mark-all-notifications-as-read.ts
+++ b/apps/web/src/fetchers/notification/mark-all-notifications-as-read.ts
@@ -2,8 +2,10 @@ import { client } from "@kaneo/libs";
import { HttpError } from "@/lib/http-error";
-async function markAllNotificationsAsRead() {
- const response = await client.notification["read-all"].$patch();
+async function markAllNotificationsAsRead(workspaceId?: string) {
+ const response = await client.notification["read-all"].$patch({
+ query: { workspaceId },
+ });
if (!response.ok) {
throw new HttpError(response.status, await response.text());
diff --git a/apps/web/src/hooks/mutations/notification/use-clear-notifications.ts b/apps/web/src/hooks/mutations/notification/use-clear-notifications.ts
index 5a3213666..75452290f 100644
--- a/apps/web/src/hooks/mutations/notification/use-clear-notifications.ts
+++ b/apps/web/src/hooks/mutations/notification/use-clear-notifications.ts
@@ -1,11 +1,11 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import clearNotifications from "@/fetchers/notification/clear-notifications";
-function useClearNotifications() {
+function useClearNotifications(workspaceId: string) {
const queryClient = useQueryClient();
return useMutation({
- mutationFn: clearNotifications,
+ mutationFn: () => clearNotifications(workspaceId),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["notifications"] });
},
diff --git a/apps/web/src/hooks/mutations/notification/use-mark-all-notifications-as-read.ts b/apps/web/src/hooks/mutations/notification/use-mark-all-notifications-as-read.ts
index 887a9c68c..0d9cb23c0 100644
--- a/apps/web/src/hooks/mutations/notification/use-mark-all-notifications-as-read.ts
+++ b/apps/web/src/hooks/mutations/notification/use-mark-all-notifications-as-read.ts
@@ -1,11 +1,11 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import markAllNotificationsAsRead from "@/fetchers/notification/mark-all-notifications-as-read";
-function useMarkAllNotificationsAsRead() {
+function useMarkAllNotificationsAsRead(workspaceId: string) {
const queryClient = useQueryClient();
return useMutation({
- mutationFn: markAllNotificationsAsRead,
+ mutationFn: () => markAllNotificationsAsRead(workspaceId),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["notifications"] });
},
diff --git a/apps/web/src/hooks/mutations/task/use-import-tasks.ts b/apps/web/src/hooks/mutations/task/use-import-tasks.ts
index 09c3fc099..b746da871 100644
--- a/apps/web/src/hooks/mutations/task/use-import-tasks.ts
+++ b/apps/web/src/hooks/mutations/task/use-import-tasks.ts
@@ -1,7 +1,10 @@
-import { useMutation } from "@tanstack/react-query";
+import { useMutation, useQueryClient } from "@tanstack/react-query";
import importTasks, { type TaskToImport } from "@/fetchers/task/import-tasks";
+import { invalidateMyWork } from "@/lib/invalidate-my-work";
+
const useImportTasks = () => {
+ const queryClient = useQueryClient();
return useMutation({
mutationFn: ({
projectId,
@@ -10,6 +13,7 @@ const useImportTasks = () => {
projectId: string;
tasks: TaskToImport[];
}) => importTasks(projectId, tasks),
+ onSuccess: () => invalidateMyWork(queryClient),
});
};
diff --git a/apps/web/src/hooks/queries/activity/use-get-workspace-activities.ts b/apps/web/src/hooks/queries/activity/use-get-workspace-activities.ts
index 1ade928de..20b70e221 100644
--- a/apps/web/src/hooks/queries/activity/use-get-workspace-activities.ts
+++ b/apps/web/src/hooks/queries/activity/use-get-workspace-activities.ts
@@ -9,6 +9,10 @@ function useGetWorkspaceActivities(workspaceId: string | undefined) {
// The app default skips refetching on mount; these lists go stale while
// the user works elsewhere.
refetchOnMount: "always",
+ // Workspace pages have no project socket; refresh remote edits and activity
+ // even when they do not produce a notification. Poll only while visible.
+ refetchInterval: 30_000,
+ refetchOnWindowFocus: "always",
});
}
diff --git a/apps/web/src/hooks/queries/notification/use-get-notifications.ts b/apps/web/src/hooks/queries/notification/use-get-notifications.ts
index 5f86f3153..95325df03 100644
--- a/apps/web/src/hooks/queries/notification/use-get-notifications.ts
+++ b/apps/web/src/hooks/queries/notification/use-get-notifications.ts
@@ -1,10 +1,11 @@
import { useQuery } from "@tanstack/react-query";
import getNotifications from "@/fetchers/notification/get-notifications";
-function useGetNotifications() {
+function useGetNotifications(workspaceId?: string) {
return useQuery({
- queryKey: ["notifications"],
- queryFn: getNotifications,
+ queryKey: ["notifications", workspaceId],
+ queryFn: () => getNotifications(workspaceId),
+ enabled: Boolean(workspaceId),
});
}
diff --git a/apps/web/src/hooks/queries/personal-work-refresh.test.tsx b/apps/web/src/hooks/queries/personal-work-refresh.test.tsx
new file mode 100644
index 000000000..051ea25b0
--- /dev/null
+++ b/apps/web/src/hooks/queries/personal-work-refresh.test.tsx
@@ -0,0 +1,84 @@
+import {
+ QueryClient,
+ QueryClientProvider,
+ focusManager,
+} from "@tanstack/react-query";
+import { act, cleanup, renderHook } from "@testing-library/react";
+import type { PropsWithChildren } from "react";
+import { afterEach, describe, expect, it, vi } from "vite-plus/test";
+import useGetWorkspaceActivities from "./activity/use-get-workspace-activities";
+import useGetAssignedTasks from "./task/use-get-assigned-tasks";
+
+const mocks = vi.hoisted(() => ({
+ assigned: vi.fn(),
+ activities: vi.fn(),
+}));
+vi.mock("@/fetchers/task/get-assigned-tasks", () => ({
+ default: mocks.assigned,
+}));
+vi.mock("@/fetchers/activity/get-workspace-activities", () => ({
+ default: mocks.activities,
+}));
+
+afterEach(() => {
+ cleanup();
+ focusManager.setFocused(undefined);
+ vi.useRealTimers();
+ vi.clearAllMocks();
+});
+
+describe("personal work refresh", () => {
+ it("refreshes remote edits and comments without a project socket or notification", async () => {
+ vi.useFakeTimers();
+ focusManager.setFocused(true);
+ const client = new QueryClient({
+ defaultOptions: { queries: { retry: false } },
+ });
+ const wrapper = ({ children }: PropsWithChildren) => (
+ <QueryClientProvider client={client}>{children}</QueryClientProvider>
+ );
+ mocks.assigned.mockResolvedValue({
+ tasks: [{ id: "task", title: "Before" }],
+ total: 1,
+ });
+ mocks.activities.mockResolvedValue([]);
+ const { result } = renderHook(
+ () => {
+ const tasks = useGetAssignedTasks("workspace");
+ const activity = useGetWorkspaceActivities("workspace");
+ return {
+ tasks: tasks.data,
+ activity: activity.data,
+ ready: tasks.isSuccess && activity.isSuccess,
+ };
+ },
+ { wrapper },
+ );
+ await act(async () => {
+ await vi.advanceTimersByTimeAsync(10);
+ });
+ expect(result.current.ready).toBe(true);
+ mocks.assigned.mockResolvedValue({
+ tasks: [{ id: "task", title: "After" }],
+ total: 1,
+ });
+ mocks.activities.mockResolvedValue([{ id: "comment" }]);
+ await act(async () => {
+ await vi.advanceTimersByTimeAsync(30_010);
+ });
+ expect(mocks.assigned).toHaveBeenCalledTimes(2);
+ await act(async () => {
+ await vi.advanceTimersByTimeAsync(10);
+ });
+ expect(result.current.tasks?.tasks[0].title).toBe("After");
+ expect(result.current.activity).toEqual([{ id: "comment" }]);
+
+ focusManager.setFocused(false);
+ const calls = mocks.assigned.mock.calls.length;
+ await act(async () => {
+ await vi.advanceTimersByTimeAsync(60_000);
+ });
+ expect(mocks.assigned).toHaveBeenCalledTimes(calls);
+ client.clear();
+ });
+});
diff --git a/apps/web/src/hooks/queries/task/use-get-assigned-tasks.ts b/apps/web/src/hooks/queries/task/use-get-assigned-tasks.ts
index ffedc81e5..a75ee9b99 100644
--- a/apps/web/src/hooks/queries/task/use-get-assigned-tasks.ts
+++ b/apps/web/src/hooks/queries/task/use-get-assigned-tasks.ts
@@ -9,6 +9,10 @@ function useGetAssignedTasks(workspaceId: string | undefined) {
// The app default skips refetching on mount; these lists go stale while
// the user works elsewhere.
refetchOnMount: "always",
+ // Workspace pages have no project socket; refresh remote edits and activity
+ // even when they do not produce a notification. Poll only while visible.
+ refetchInterval: 30_000,
+ refetchOnWindowFocus: "always",
});
}
diff --git a/apps/web/src/hooks/use-local-day.test.tsx b/apps/web/src/hooks/use-local-day.test.tsx
new file mode 100644
index 000000000..30f288331
--- /dev/null
+++ b/apps/web/src/hooks/use-local-day.test.tsx
@@ -0,0 +1,32 @@
+import { act, cleanup, renderHook } from "@testing-library/react";
+import { afterEach, describe, expect, it, vi } from "vite-plus/test";
+import { useLocalDay } from "./use-local-day";
+
+afterEach(() => {
+ cleanup();
+ vi.useRealTimers();
+});
+
+describe("useLocalDay", () => {
+ it("advances at local midnight without task data changing", () => {
+ vi.useFakeTimers();
+ vi.setSystemTime(new Date(2030, 0, 1, 23, 59, 59));
+ const { result } = renderHook(useLocalDay);
+ expect(result.current).toBe(new Date(2030, 0, 1).getTime());
+ act(() => vi.advanceTimersByTime(1000));
+ expect(result.current).toBe(new Date(2030, 0, 2).getTime());
+ act(() => vi.advanceTimersByTime(24 * 60 * 60 * 1000));
+ expect(result.current).toBe(new Date(2030, 0, 3).getTime());
+ });
+
+ it("catches up when a suspended tab regains focus and clears its timer", () => {
+ vi.useFakeTimers();
+ vi.setSystemTime(new Date(2030, 0, 1, 12));
+ const { result, unmount } = renderHook(useLocalDay);
+ vi.setSystemTime(new Date(2030, 0, 4, 12));
+ act(() => window.dispatchEvent(new Event("focus")));
+ expect(result.current).toBe(new Date(2030, 0, 4).getTime());
+ unmount();
+ expect(vi.getTimerCount()).toBe(0);
+ });
+});
diff --git a/apps/web/src/hooks/use-local-day.ts b/apps/web/src/hooks/use-local-day.ts
new file mode 100644
index 000000000..24f8c41e2
--- /dev/null
+++ b/apps/web/src/hooks/use-local-day.ts
@@ -0,0 +1,28 @@
+import { startOfDay } from "date-fns";
+import { useEffect, useState } from "react";
+
+export function useLocalDay() {
+ const [day, setDay] = useState(() => startOfDay(new Date()).getTime());
+
+ useEffect(() => {
+ let timer: ReturnType<typeof setTimeout>;
+ const update = () => {
+ clearTimeout(timer);
+ const now = new Date();
+ setDay(startOfDay(now).getTime());
+ const midnight = new Date(now);
+ midnight.setHours(24, 0, 0, 0);
+ timer = setTimeout(update, midnight.getTime() - now.getTime());
+ };
+ update();
+ window.addEventListener("focus", update);
+ document.addEventListener("visibilitychange", update);
+ return () => {
+ clearTimeout(timer);
+ window.removeEventListener("focus", update);
+ document.removeEventListener("visibilitychange", update);
+ };
+ }, []);
+
+ return day;
+}
diff --git a/apps/web/src/hooks/use-user-websocket.ts b/apps/web/src/hooks/use-user-websocket.ts
index a0a518691..da4d0ad32 100644
--- a/apps/web/src/hooks/use-user-websocket.ts
+++ b/apps/web/src/hooks/use-user-websocket.ts
@@ -134,10 +134,6 @@ export function useUserWebSocket() {
}
if (message.type === "NOTIFICATION_CREATED") {
queryClient.invalidateQueries({ queryKey: ["notifications"] });
- // Home and My tasks sit outside any project socket; a notification
- // is their signal that the caller's work changed.
- queryClient.invalidateQueries({ queryKey: ["assigned-tasks"] });
- queryClient.invalidateQueries({ queryKey: ["workspace-activity"] });
}
} catch {
// Ignore malformed messages
diff --git a/apps/web/src/routes/_layout/_authenticated/dashboard/workspace/$workspaceId/inbox.tsx b/apps/web/src/routes/_layout/_authenticated/dashboard/workspace/$workspaceId/inbox.tsx
index 1e5785f50..569aab1e0 100644
--- a/apps/web/src/routes/_layout/_authenticated/dashboard/workspace/$workspaceId/inbox.tsx
+++ b/apps/web/src/routes/_layout/_authenticated/dashboard/workspace/$workspaceId/inbox.tsx
@@ -5,6 +5,7 @@ import { useTranslation } from "react-i18next";
import WorkspaceLayout from "@/components/common/workspace-layout";
import { InboxDetail } from "@/components/inbox/inbox-detail";
import { InboxList } from "@/components/inbox/inbox-list";
+import { Button } from "@/components/ui/button";
import PageTitle from "@/components/page-title";
import useMarkNotificationAsRead from "@/hooks/mutations/notification/use-mark-notification-as-read";
import useGetNotifications from "@/hooks/queries/notification/use-get-notifications";
@@ -19,7 +20,13 @@ export const Route = createFileRoute(
function RouteComponent() {
const { t } = useTranslation();
- const { data: notifications = [] } = useGetNotifications();
+ const { workspaceId } = Route.useParams();
+ const {
+ data: notifications = [],
+ isPending,
+ isError,
+ refetch,
+ } = useGetNotifications(workspaceId);
const { mutate: markAsRead } = useMarkNotificationAsRead();
const [selectedId, setSelectedId] = useState<string>();
@@ -44,11 +51,27 @@ function RouteComponent() {
selected && "hidden",
)}
>
- <InboxList
- notifications={notifications}
- selectedId={selected?.id}
- onSelect={handleSelect}
- />
+ {isPending ? (
+ <p role="status" className="p-5 text-muted-foreground text-sm">
+ {t("common:empty.loading")}
+ </p>
+ ) : isError ? (
+ <div className="flex flex-col items-start gap-3 p-5">
+ <p role="alert" className="text-muted-foreground text-sm">
+ {t("notifications:inbox.loadError")}
+ </p>
+ <Button variant="outline" onClick={() => void refetch()}>
+ {t("common:error.tryAgain")}
+ </Button>
+ </div>
+ ) : (
+ <InboxList
+ workspaceId={workspaceId}
+ notifications={notifications}
+ selectedId={selected?.id}
+ onSelect={handleSelect}
+ />
+ )}
</div>
<div className={cn("min-w-0 flex-1", !selected && "hidden lg:block")}>
{selected ? (
diff --git a/i18n/az-AZ.json b/i18n/az-AZ.json
index a87d1377f..56f2200a3 100644
--- a/i18n/az-AZ.json
+++ b/i18n/az-AZ.json
@@ -2052,7 +2052,8 @@
"selectPrompt": "Select a notification to read it",
"taskUnavailable": "This task is no longer available.",
"today": "Today",
- "unread": "Unread"
+ "unread": "Unread",
+ "loadError": "Notifications couldn't be loaded."
}
},
"activity": {
@@ -2740,7 +2741,8 @@
"all": "All projects",
"tasks_one": "{{count}} task",
"tasks_other": "{{count}} tasks",
- "title": "Your projects"
+ "title": "Your projects",
+ "loadError": "Projects couldn't be loaded."
},
"upNext": {
"assigned_one": "{{count}} assigned to you",
diff --git a/i18n/de-DE.json b/i18n/de-DE.json
index 43cf8adad..34727b882 100644
--- a/i18n/de-DE.json
+++ b/i18n/de-DE.json
@@ -2052,7 +2052,8 @@
"selectPrompt": "Select a notification to read it",
"taskUnavailable": "This task is no longer available.",
"today": "Today",
- "unread": "Unread"
+ "unread": "Unread",
+ "loadError": "Notifications couldn't be loaded."
}
},
"activity": {
@@ -2740,7 +2741,8 @@
"all": "All projects",
"tasks_one": "{{count}} task",
"tasks_other": "{{count}} tasks",
- "title": "Your projects"
+ "title": "Your projects",
+ "loadError": "Projects couldn't be loaded."
},
"upNext": {
"assigned_one": "{{count}} assigned to you",
diff --git a/i18n/el-GR.json b/i18n/el-GR.json
index b43ecafc4..e2ecc3f67 100644
--- a/i18n/el-GR.json
+++ b/i18n/el-GR.json
@@ -2052,7 +2052,8 @@
"selectPrompt": "Select a notification to read it",
"taskUnavailable": "This task is no longer available.",
"today": "Today",
- "unread": "Unread"
+ "unread": "Unread",
+ "loadError": "Notifications couldn't be loaded."
}
},
"activity": {
@@ -2740,7 +2741,8 @@
"all": "All projects",
"tasks_one": "{{count}} task",
"tasks_other": "{{count}} tasks",
- "title": "Your projects"
+ "title": "Your projects",
+ "loadError": "Projects couldn't be loaded."
},
"upNext": {
"assigned_one": "{{count}} assigned to you",
diff --git a/i18n/en-US.json b/i18n/en-US.json
index 683cfdfcf..a8c6905c1 100644
--- a/i18n/en-US.json
+++ b/i18n/en-US.json
@@ -2048,6 +2048,7 @@
"mentions": "Mentions"
},
"emptyFilter": "Nothing here",
+ "loadError": "Notifications couldn't be loaded.",
"selectPrompt": "Select a notification to read it",
"back": "Inbox",
"openTask": "Open task",
@@ -2742,6 +2743,7 @@
"projects": {
"title": "Your projects",
"all": "All projects",
+ "loadError": "Projects couldn't be loaded.",
"tasks_one": "{{count}} task",
"tasks_other": "{{count}} tasks"
},
diff --git a/i18n/es-ES.json b/i18n/es-ES.json
index d318a0a62..1b0e4384f 100644
--- a/i18n/es-ES.json
+++ b/i18n/es-ES.json
@@ -2063,7 +2063,8 @@
"selectPrompt": "Select a notification to read it",
"taskUnavailable": "This task is no longer available.",
"today": "Today",
- "unread": "Unread"
+ "unread": "Unread",
+ "loadError": "Notifications couldn't be loaded."
}
},
"activity": {
@@ -2754,7 +2755,8 @@
"tasks_many": "{{count}} tasks",
"tasks_one": "{{count}} task",
"tasks_other": "{{count}} tasks",
- "title": "Your projects"
+ "title": "Your projects",
+ "loadError": "Projects couldn't be loaded."
},
"upNext": {
"assigned_many": "{{count}} assigned to you",
diff --git a/i18n/fr-FR.json b/i18n/fr-FR.json
index 932d27944..be6092126 100644
--- a/i18n/fr-FR.json
+++ b/i18n/fr-FR.json
@@ -2063,7 +2063,8 @@
"selectPrompt": "Select a notification to read it",
"taskUnavailable": "This task is no longer available.",
"today": "Today",
- "unread": "Unread"
+ "unread": "Unread",
+ "loadError": "Notifications couldn't be loaded."
}
},
"activity": {
@@ -2754,7 +2755,8 @@
"tasks_many": "{{count}} tasks",
"tasks_one": "{{count}} task",
"tasks_other": "{{count}} tasks",
- "title": "Your projects"
+ "title": "Your projects",
+ "loadError": "Projects couldn't be loaded."
},
"upNext": {
"assigned_many": "{{count}} assigned to you",
diff --git a/i18n/hi-IN.json b/i18n/hi-IN.json
index 3d5290cb8..2624fd59f 100644
--- a/i18n/hi-IN.json
+++ b/i18n/hi-IN.json
@@ -2052,7 +2052,8 @@
"selectPrompt": "Select a notification to read it",
"taskUnavailable": "This task is no longer available.",
"today": "Today",
- "unread": "Unread"
+ "unread": "Unread",
+ "loadError": "Notifications couldn't be loaded."
}
},
"activity": {
@@ -2740,7 +2741,8 @@
"all": "All projects",
"tasks_one": "{{count}} task",
"tasks_other": "{{count}} tasks",
- "title": "Your projects"
+ "title": "Your projects",
+ "loadError": "Projects couldn't be loaded."
},
"upNext": {
"assigned_one": "{{count}} assigned to you",
diff --git a/i18n/id-ID.json b/i18n/id-ID.json
index 35bb97b9a..7ff0244f9 100644
--- a/i18n/id-ID.json
+++ b/i18n/id-ID.json
@@ -2041,7 +2041,8 @@
"selectPrompt": "Select a notification to read it",
"taskUnavailable": "This task is no longer available.",
"today": "Today",
- "unread": "Unread"
+ "unread": "Unread",
+ "loadError": "Notifications couldn't be loaded."
}
},
"activity": {
@@ -2726,7 +2727,8 @@
"projects": {
"all": "All projects",
"tasks_other": "{{count}} tasks",
- "title": "Your projects"
+ "title": "Your projects",
+ "loadError": "Projects couldn't be loaded."
},
"upNext": {
"assigned_other": "{{count}} assigned to you",
diff --git a/i18n/it-IT.json b/i18n/it-IT.json
index 799c54813..2721e4ae2 100644
--- a/i18n/it-IT.json
+++ b/i18n/it-IT.json
@@ -2063,7 +2063,8 @@
"selectPrompt": "Select a notification to read it",
"taskUnavailable": "This task is no longer available.",
"today": "Today",
- "unread": "Unread"
+ "unread": "Unread",
+ "loadError": "Notifications couldn't be loaded."
}
},
"activity": {
@@ -2754,7 +2755,8 @@
"tasks_many": "{{count}} tasks",
"tasks_one": "{{count}} task",
"tasks_other": "{{count}} tasks",
- "title": "Your projects"
+ "title": "Your projects",
+ "loadError": "Projects couldn't be loaded."
},
"upNext": {
"assigned_many": "{{count}} assigned to you",
diff --git a/i18n/ja-JP.json b/i18n/ja-JP.json
index 163920b13..7e1ab96d5 100644
--- a/i18n/ja-JP.json
+++ b/i18n/ja-JP.json
@@ -2041,7 +2041,8 @@
"selectPrompt": "Select a notification to read it",
"taskUnavailable": "This task is no longer available.",
"today": "Today",
- "unread": "Unread"
+ "unread": "Unread",
+ "loadError": "Notifications couldn't be loaded."
}
},
"activity": {
@@ -2726,7 +2727,8 @@
"projects": {
"all": "All projects",
"tasks_other": "{{count}} tasks",
- "title": "Your projects"
+ "title": "Your projects",
+ "loadError": "Projects couldn't be loaded."
},
"upNext": {
"assigned_other": "{{count}} assigned to you",
diff --git a/i18n/ko-KR.json b/i18n/ko-KR.json
index aa7c8d085..459f498af 100644
--- a/i18n/ko-KR.json
+++ b/i18n/ko-KR.json
@@ -2041,7 +2041,8 @@
"selectPrompt": "Select a notification to read it",
"taskUnavailable": "This task is no longer available.",
"today": "Today",
- "unread": "Unread"
+ "unread": "Unread",
+ "loadError": "Notifications couldn't be loaded."
}
},
"activity": {
@@ -2726,7 +2727,8 @@
"projects": {
"all": "All projects",
"tasks_other": "{{count}} tasks",
- "title": "Your projects"
+ "title": "Your projects",
+ "loadError": "Projects couldn't be loaded."
},
"upNext": {
"assigned_other": "{{count}} assigned to you",
diff --git a/i18n/mk-MK.json b/i18n/mk-MK.json
index c1d16cbca..a76f4a984 100644
--- a/i18n/mk-MK.json
+++ b/i18n/mk-MK.json
@@ -2052,7 +2052,8 @@
"selectPrompt": "Select a notification to read it",
"taskUnavailable": "This task is no longer available.",
"today": "Today",
- "unread": "Unread"
+ "unread": "Unread",
+ "loadError": "Notifications couldn't be loaded."
}
},
"activity": {
@@ -2740,7 +2741,8 @@
"all": "All projects",
"tasks_one": "{{count}} task",
"tasks_other": "{{count}} tasks",
- "title": "Your projects"
+ "title": "Your projects",
+ "loadError": "Projects couldn't be loaded."
},
"upNext": {
"assigned_one": "{{count}} assigned to you",
diff --git a/i18n/nl-NL.json b/i18n/nl-NL.json
index deb77e5e8..1b312a558 100644
--- a/i18n/nl-NL.json
+++ b/i18n/nl-NL.json
@@ -2052,7 +2052,8 @@
"selectPrompt": "Select a notification to read it",
"taskUnavailable": "This task is no longer available.",
"today": "Today",
- "unread": "Unread"
+ "unread": "Unread",
+ "loadError": "Notifications couldn't be loaded."
}
},
"activity": {
@@ -2740,7 +2741,8 @@
"all": "All projects",
"tasks_one": "{{count}} task",
"tasks_other": "{{count}} tasks",
- "title": "Your projects"
+ "title": "Your projects",
+ "loadError": "Projects couldn't be loaded."
},
"upNext": {
"assigned_one": "{{count}} assigned to you",
diff --git a/i18n/pl-PL.json b/i18n/pl-PL.json
index 5ed4265da..5638e0e60 100644
--- a/i18n/pl-PL.json
+++ b/i18n/pl-PL.json
@@ -617,7 +617,8 @@
"selectPrompt": "Select a notification to read it",
"taskUnavailable": "This task is no longer available.",
"today": "Today",
- "unread": "Unread"
+ "unread": "Unread",
+ "loadError": "Notifications couldn't be loaded."
}
},
"workspace": {
@@ -697,7 +698,8 @@
"tasks_many": "{{count}} tasks",
"tasks_one": "{{count}} task",
"tasks_other": "{{count}} tasks",
- "title": "Your projects"
+ "title": "Your projects",
+ "loadError": "Projects couldn't be loaded."
},
"upNext": {
"assigned_few": "{{count}} assigned to you",
diff --git a/i18n/pt-BR.json b/i18n/pt-BR.json
index 0301ca244..dc015ba4d 100644
--- a/i18n/pt-BR.json
+++ b/i18n/pt-BR.json
@@ -2063,7 +2063,8 @@
"selectPrompt": "Select a notification to read it",
"taskUnavailable": "This task is no longer available.",
"today": "Today",
- "unread": "Unread"
+ "unread": "Unread",
+ "loadError": "Notifications couldn't be loaded."
}
},
"activity": {
@@ -2754,7 +2755,8 @@
"tasks_many": "{{count}} tasks",
"tasks_one": "{{count}} task",
"tasks_other": "{{count}} tasks",
- "title": "Your projects"
+ "title": "Your projects",
+ "loadError": "Projects couldn't be loaded."
},
"upNext": {
"assigned_many": "{{count}} assigned to you",
diff --git a/i18n/ru-RU.json b/i18n/ru-RU.json
index a8d649f63..209b03fcb 100644
--- a/i18n/ru-RU.json
+++ b/i18n/ru-RU.json
@@ -2082,7 +2082,8 @@
"selectPrompt": "Select a notification to read it",
"taskUnavailable": "This task is no longer available.",
"today": "Today",
- "unread": "Unread"
+ "unread": "Unread",
+ "loadError": "Notifications couldn't be loaded."
}
},
"activity": {
@@ -2824,7 +2825,8 @@
"tasks_many": "{{count}} tasks",
"tasks_one": "{{count}} task",
"tasks_other": "{{count}} tasks",
- "title": "Your projects"
+ "title": "Your projects",
+ "loadError": "Projects couldn't be loaded."
},
"upNext": {
"assigned_few": "{{count}} assigned to you",
diff --git a/i18n/schema.json b/i18n/schema.json
index 372be9d9c..f5ad831c8 100644
--- a/i18n/schema.json
+++ b/i18n/schema.json
@@ -8277,6 +8277,9 @@
"emptyFilter": {
"type": "string"
},
+ "loadError": {
+ "type": "string"
+ },
"selectPrompt": {
"type": "string"
},
@@ -8300,6 +8303,7 @@
"earlier",
"filters",
"emptyFilter",
+ "loadError",
"selectPrompt",
"back",
"openTask",
@@ -11296,6 +11300,9 @@
"all": {
"type": "string"
},
+ "loadError": {
+ "type": "string"
+ },
"tasks_one": {
"type": "string"
},
@@ -11315,7 +11322,7 @@
"type": "string"
}
},
- "required": ["title", "all"]
+ "required": ["title", "all", "loadError"]
},
"activity": {
"type": "object",
diff --git a/i18n/tr-TR.json b/i18n/tr-TR.json
index 3f138b9af..0680121c8 100644
--- a/i18n/tr-TR.json
+++ b/i18n/tr-TR.json
@@ -2052,7 +2052,8 @@
"selectPrompt": "Select a notification to read it",
"taskUnavailable": "This task is no longer available.",
"today": "Today",
- "unread": "Unread"
+ "unread": "Unread",
+ "loadError": "Notifications couldn't be loaded."
}
},
"activity": {
@@ -2740,7 +2741,8 @@
"all": "All projects",
"tasks_one": "{{count}} task",
"tasks_other": "{{count}} tasks",
- "title": "Your projects"
+ "title": "Your projects",
+ "loadError": "Projects couldn't be loaded."
},
"upNext": {
"assigned_one": "{{count}} assigned to you",
diff --git a/i18n/uk-UA.json b/i18n/uk-UA.json
index e78ac5d78..d214dc4fc 100644
--- a/i18n/uk-UA.json
+++ b/i18n/uk-UA.json
@@ -2074,7 +2074,8 @@
"selectPrompt": "Select a notification to read it",
"taskUnavailable": "This task is no longer available.",
"today": "Today",
- "unread": "Unread"
+ "unread": "Unread",
+ "loadError": "Notifications couldn't be loaded."
}
},
"activity": {
@@ -2768,7 +2769,8 @@
"tasks_many": "{{count}} tasks",
"tasks_one": "{{count}} task",
"tasks_other": "{{count}} tasks",
- "title": "Your projects"
+ "title": "Your projects",
+ "loadError": "Projects couldn't be loaded."
},
"upNext": {
"assigned_few": "{{count}} assigned to you",
diff --git a/i18n/vi-VN.json b/i18n/vi-VN.json
index 629d3b8a5..eddc5de62 100644
--- a/i18n/vi-VN.json
+++ b/i18n/vi-VN.json
@@ -2041,7 +2041,8 @@
"selectPrompt": "Select a notification to read it",
"taskUnavailable": "This task is no longer available.",
"today": "Today",
- "unread": "Unread"
+ "unread": "Unread",
+ "loadError": "Notifications couldn't be loaded."
}
},
"activity": {
@@ -2726,7 +2727,8 @@
"projects": {
"all": "All projects",
"tasks_other": "{{count}} tasks",
- "title": "Your projects"
+ "title": "Your projects",
+ "loadError": "Projects couldn't be loaded."
},
"upNext": {
"assigned_other": "{{count}} assigned to you",
diff --git a/i18n/zh-CN.json b/i18n/zh-CN.json
index 474074a70..99d9a46cd 100644
--- a/i18n/zh-CN.json
+++ b/i18n/zh-CN.json
@@ -2041,7 +2041,8 @@
"selectPrompt": "Select a notification to read it",
"taskUnavailable": "This task is no longer available.",
"today": "Today",
- "unread": "Unread"
+ "unread": "Unread",
+ "loadError": "Notifications couldn't be loaded."
}
},
"activity": {
@@ -2726,7 +2727,8 @@
"projects": {
"all": "All projects",
"tasks_other": "{{count}} tasks",
- "title": "Your projects"
+ "title": "Your projects",
+ "loadError": "Projects couldn't be loaded."
},
"upNext": {
"assigned_other": "{{count}} assigned to you",
diff --git a/tests/api-integration/notification-workspace.test.ts b/tests/api-integration/notification-workspace.test.ts
new file mode 100644
index 000000000..4f7a086a5
--- /dev/null
+++ b/tests/api-integration/notification-workspace.test.ts
@@ -0,0 +1,136 @@
+import { beforeEach, describe, expect, it } from "vite-plus/test";
+import db, { schema } from "../../apps/api/src/database";
+import { createApp } from "../../apps/api/src/index";
+import { mockAuthenticatedSession } from "./helpers/auth";
+import { resetTestDatabase } from "./helpers/database";
+import {
+ createProjectFixture,
+ createWorkspaceMember,
+} from "./helpers/fixtures";
+
+async function fixture() {
+ const member = await createWorkspaceMember();
+ const other = await createWorkspaceMember();
+ await db.insert(schema.workspaceUserTable).values({
+ workspaceId: other.workspace.id,
+ userId: member.user.id,
+ role: "member",
+ joinedAt: new Date(),
+ });
+ const { project, columns } = await createProjectFixture({
+ workspaceId: member.workspace.id,
+ });
+ const [task] = await db
+ .insert(schema.taskTable)
+ .values({
+ projectId: project.id,
+ columnId: columns.todo.id,
+ title: "Local task",
+ })
+ .returning();
+ const [local, workspace, foreign, anotherUser] = await db
+ .insert(schema.notificationTable)
+ .values([
+ {
+ userId: member.user.id,
+ resourceType: "task",
+ resourceId: task.id,
+ eventData: { workspaceId: other.workspace.id },
+ createdAt: new Date(0),
+ },
+ {
+ userId: member.user.id,
+ resourceType: "workspace",
+ resourceId: member.workspace.id,
+ },
+ {
+ userId: member.user.id,
+ resourceType: "workspace",
+ resourceId: other.workspace.id,
+ },
+ {
+ userId: other.user.id,
+ resourceType: "workspace",
+ resourceId: member.workspace.id,
+ },
+ ])
+ .returning();
+ mockAuthenticatedSession(member.user);
+ return {
+ member,
+ other,
+ local,
+ workspace,
+ foreign,
+ anotherUser,
+ app: createApp().app,
+ };
+}
+
+describe("workspace inbox", () => {
+ beforeEach(resetTestDatabase);
+
+ it("filters by current resources before the limit and ignores forged event data", async () => {
+ const { member, other, local, workspace, app } = await fixture();
+ await db.insert(schema.notificationTable).values(
+ Array.from({ length: 60 }, () => ({
+ userId: member.user.id,
+ resourceType: "workspace",
+ resourceId: other.workspace.id,
+ })),
+ );
+ const response = await app.request(
+ `/api/notification?workspaceId=${member.workspace.id}`,
+ );
+ expect(response.status).toBe(200);
+ expect(
+ ((await response.json()) as Array<{ id: string }>).map((n) => n.id),
+ ).toEqual([workspace.id, local.id]);
+ });
+
+ it("marks and clears only this user's notifications in the selected workspace", async () => {
+ const { member, local, workspace, foreign, anotherUser, app } =
+ await fixture();
+ const query = `?workspaceId=${member.workspace.id}`;
+ const marked = await app.request(`/api/notification/read-all${query}`, {
+ method: "PATCH",
+ });
+ expect(marked.status).toBe(200);
+ const rows = await db.select().from(schema.notificationTable);
+ expect(
+ rows
+ .filter((n) => n.isRead)
+ .map((n) => n.id)
+ .sort(),
+ ).toEqual([local.id, workspace.id].sort());
+ const cleared = await app.request(`/api/notification/clear-all${query}`, {
+ method: "DELETE",
+ });
+ expect(cleared.status).toBe(200);
+ expect(
+ (await db.select().from(schema.notificationTable))
+ .map((n) => n.id)
+ .sort(),
+ ).toEqual([foreign.id, anotherUser.id].sort());
+ });
+
+ it("keeps the unscoped API compatible and rejects empty workspace filters", async () => {
+ const { local, workspace, foreign, app } = await fixture();
+ const response = await app.request("/api/notification");
+ expect(
+ ((await response.json()) as Array<{ id: string }>)
+ .map((n) => n.id)
+ .sort(),
+ ).toEqual([local.id, workspace.id, foreign.id].sort());
+ for (const [path, method] of [
+ ["", "GET"],
+ ["/read-all", "PATCH"],
+ ["/clear-all", "DELETE"],
+ ]) {
+ expect(
+ (await app.request(`/api/notification${path}?workspaceId=`, { method }))
+ .status,
+ ).toBe(400);
+ }
+ });
+});
diff --git a/tests/e2e/tasks.spec.ts b/tests/e2e/tasks.spec.ts
index 5fc5c55af..9b492f585 100644
--- a/tests/e2e/tasks.spec.ts
+++ b/tests/e2e/tasks.spec.ts
@@ -44,6 +44,8 @@ async function createWorkspace(page: Page) {
}
async function createProject(page: Page) {
+ await page.getByRole("link", { name: "All projects", exact: true }).click();
+ await expect(page).toHaveURL(/\/projects$/);
await page
.getByRole("button", { name: "Create project", exact: true })
.first()