⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
fix(web): tighten project access pickers
Andrejd5b8b479f260
diff --git a/apps/web/src/components/shared/modals/create-task-modal.tsx b/apps/web/src/components/shared/modals/create-task-modal.tsxindex 79005bfb8..43aff8bdd 100644--- a/apps/web/src/components/shared/modals/create-task-modal.tsx+++ b/apps/web/src/components/shared/modals/create-task-modal.tsx@@ -282,8 +282,8 @@ function CreateTaskModalContent({});const assigneeOptions = useMemo(() =>- resolvedProjectId && projectMembers- ? projectMembers.map((member) => ({+ resolvedProjectId+ ? (projectMembers ?? []).map((member) => ({id: member.id,name: member.name,image: member.image,diff --git a/apps/web/src/components/task/subtask-assignee-popover.tsx b/apps/web/src/components/task/subtask-assignee-popover.tsxindex c1cedf9b8..925f7ccfc 100644--- a/apps/web/src/components/task/subtask-assignee-popover.tsx+++ b/apps/web/src/components/task/subtask-assignee-popover.tsx@@ -10,7 +10,7 @@ import {} from "@/components/ui/popover";import { ShortcutNumber } from "@/components/ui/shortcut-number";import { useUpdateTaskAssignee } from "@/hooks/mutations/task/use-update-task-assignee";-import useGetProjectMembers from "@/hooks/queries/workspace-users/use-get-project-members";+import useGetMembersOfProjects from "@/hooks/queries/workspace-users/use-get-members-of-projects";import { useNumberedShortcuts } from "@/hooks/use-numbered-shortcuts";import { useWorkspacePermission } from "@/hooks/use-workspace-permission";import { getInitials } from "@/lib/get-initials";@@ -37,9 +37,9 @@ export default function SubtaskAssigneePopover({INITIAL_VISIBLE_USERS,);const { mutateAsync: updateTaskAssignee } = useUpdateTaskAssignee();- const { data: projectMembers } = useGetProjectMembers({+ const { data: projectMembers } = useGetMembersOfProjects({workspaceId,- projectId: tasks[0]?.projectId ?? "",+ projectIds: tasks.map((task) => task.projectId),});const { canAssignTasks } = useWorkspacePermission();const canAssign = canAssignTasks();diff --git a/apps/web/src/components/team/invite-team-member-modal.tsx b/apps/web/src/components/team/invite-team-member-modal.tsxindex 7c2c81a8e..6bcb52978 100644--- a/apps/web/src/components/team/invite-team-member-modal.tsx+++ b/apps/web/src/components/team/invite-team-member-modal.tsx@@ -65,6 +65,8 @@ function InviteTeamMemberModal({ open, onClose }: Props) {const [showProjectAccessError, setShowProjectAccessError] = useState(false);const { data: projects, isLoading: isLoadingProjects } = useGetProjects({workspaceId: workspaceId ?? "",+ includeArchived: true,+ enabled: open,});const form = useForm<TeamMemberFormValues>({diff --git a/apps/web/src/hooks/queries/project/use-get-projects.ts b/apps/web/src/hooks/queries/project/use-get-projects.tsindex 06d19f534..de704047d 100644--- a/apps/web/src/hooks/queries/project/use-get-projects.ts+++ b/apps/web/src/hooks/queries/project/use-get-projects.ts@@ -5,7 +5,8 @@ function useGetProjects({workspaceId,includeArchived = false,- }: { workspaceId: string; includeArchived?: boolean },+ enabled = true,+ }: { workspaceId: string; includeArchived?: boolean; enabled?: boolean },refreshWhileVisible = false,) {return useQuery({@@ -18,7 +19,7 @@ function useGetProjects(queryKey: includeArchived? ["projects", workspaceId, "including-archived"]: ["projects", workspaceId],- enabled: !!workspaceId,+ enabled: enabled && !!workspaceId,// Home and the sidebar show statistics without a project socket....(refreshWhileVisible? {diff --git a/apps/web/src/hooks/queries/workspace-users/use-get-members-of-projects.ts b/apps/web/src/hooks/queries/workspace-users/use-get-members-of-projects.tsnew file mode 100644index 000000000..8cb364b37--- /dev/null+++ b/apps/web/src/hooks/queries/workspace-users/use-get-members-of-projects.ts@@ -0,0 +1,32 @@+import { useQueries } from "@tanstack/react-query";+import getProjectMembers from "@/fetchers/workspace-user/get-project-members";+import { intersectById } from "@/lib/intersect-by-id";++function useGetMembersOfProjects({+ workspaceId,+ projectIds,+}: {+ workspaceId: string;+ projectIds: readonly string[];+}) {+ const ids = [...new Set(projectIds.filter(Boolean))];+ return useQueries({+ queries: ids.map((projectId) => ({+ queryKey: ["workspace-users", workspaceId, "project", projectId],+ queryFn: () => getProjectMembers({ workspaceId, projectId }),+ enabled: !!workspaceId,+ })),+ combine: (results) => {+ const lists = results.map((result) => result.data);+ return {+ data:+ ids.length > 0 && lists.every((list) => list !== undefined)+ ? intersectById(lists as NonNullable<(typeof lists)[number]>[])+ : undefined,+ isLoading: results.some((result) => result.isLoading),+ };+ },+ });+}++export default useGetMembersOfProjects;diff --git a/apps/web/src/hooks/queries/workspace-users/use-get-workspace-project-access.ts b/apps/web/src/hooks/queries/workspace-users/use-get-workspace-project-access.tsindex 4835ecb27..c7b6c6a65 100644--- a/apps/web/src/hooks/queries/workspace-users/use-get-workspace-project-access.ts+++ b/apps/web/src/hooks/queries/workspace-users/use-get-workspace-project-access.ts@@ -6,6 +6,7 @@ function useGetWorkspaceProjectAccess(workspaceId: string, enabled = true) {queryKey: ["workspace-users", workspaceId, "project-access"],queryFn: () => getWorkspaceProjectAccess(workspaceId),enabled: enabled && !!workspaceId,+ refetchOnMount: "always",});}diff --git a/apps/web/src/lib/intersect-by-id.test.ts b/apps/web/src/lib/intersect-by-id.test.tsnew file mode 100644index 000000000..9cecc1544--- /dev/null+++ b/apps/web/src/lib/intersect-by-id.test.ts@@ -0,0 +1,19 @@+import { describe, expect, it } from "vite-plus/test";+import { intersectById } from "./intersect-by-id";++describe("intersectById", () => {+ it("keeps only items present in every list", () => {+ expect(+ intersectById([+ [{ id: "a" }, { id: "b" }, { id: "c" }],+ [{ id: "b" }, { id: "c" }],+ [{ id: "c" }, { id: "b" }, { id: "d" }],+ ]),+ ).toEqual([{ id: "b" }, { id: "c" }]);+ });++ it("returns the single list unchanged and nothing for no lists", () => {+ expect(intersectById([[{ id: "a" }]])).toEqual([{ id: "a" }]);+ expect(intersectById([])).toEqual([]);+ });+});diff --git a/apps/web/src/lib/intersect-by-id.ts b/apps/web/src/lib/intersect-by-id.tsnew file mode 100644index 000000000..8c3c0e18b--- /dev/null+++ b/apps/web/src/lib/intersect-by-id.ts@@ -0,0 +1,8 @@+export function intersectById<T extends { id: string }>(+ lists: readonly (readonly T[])[],+): T[] {+ const [first, ...rest] = lists;+ if (!first) return [];+ const others = rest.map((list) => new Set(list.map((item) => item.id)));+ return first.filter((item) => others.every((ids) => ids.has(item.id)));+}