@burdenoff/microfe-workspaces 2026.601.2 → 2026.601.4
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/dist/hooks/useMemberMutations.js +36 -24
- package/dist/hooks/useMemberMutations.js.map +1 -1
- package/dist/hooks/useProjectMutations.js +19 -15
- package/dist/hooks/useProjectMutations.js.map +1 -1
- package/dist/hooks/useWorkspaceMembers.js +4 -3
- package/dist/hooks/useWorkspaceMembers.js.map +1 -1
- package/dist/hooks/useWorkspaceMutations.js +19 -11
- package/dist/hooks/useWorkspaceMutations.js.map +1 -1
- package/dist/pages/WorkspaceInvitePage.js +296 -268
- package/dist/pages/WorkspaceInvitePage.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWorkspaceMembers.js","names":[],"sources":["../../src/hooks/useWorkspaceMembers.ts"],"sourcesContent":["import { useInfiniteQuery, useQuery } from '@tanstack/react-query';\nimport { print } from 'graphql';\nimport { graphqlFetch } from '@burdenoff/fe-libs/shared/graphql';\nimport { useWorkspacesContext } from '../providers/WorkspacesProvider';\nimport {\n GetWorkspaceMembersDocument,\n GetWorkspaceMemberDocument,\n GetUserWorkspacesDocument,\n GetWorkspaceInvitationsDocument,\n GetInvitationDocument,\n} from '../generated/wspace-operations';\nimport type {\n MemberList,\n WorkspaceMember,\n WorkspaceInvitation,\n InvitationList,\n PaginationInput,\n InvitationStatus,\n} from '../types';\n\n/**\n * Hook to fetch all members of the current workspace\n */\nexport const useWorkspaceMembers = (workspaceId: string, pagination?: PaginationInput) => {\n const { authToken } = useWorkspacesContext();\n\n return useQuery({\n queryKey: ['workspaceMembers', workspaceId, pagination],\n queryFn: async (): Promise<MemberList> => {\n const result = await graphqlFetch<{ workspaceMembers: MemberList }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(GetWorkspaceMembersDocument),\n variables: { workspaceId, pagination },\n workspaceId,\n workspaceToken: true, // Auto-read from profile context for x-workspace-id header (required by gateway RBAC)\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n if (!result.data?.workspaceMembers) {\n throw new Error('Workspace members query returned no data');\n }\n\n return result.data.workspaceMembers;\n },\n enabled: !!workspaceId,\n staleTime: 5 * 60 * 1000,\n });\n};\n\nexport const useInfiniteWorkspaceMembers = (\n workspaceId: string,\n pageSize = 100,\n enabled = true\n) => {\n const { authToken } = useWorkspacesContext();\n\n return useInfiniteQuery({\n queryKey: ['workspaceMembersInfinite', workspaceId, pageSize],\n initialPageParam: 0,\n queryFn: async ({ pageParam }): Promise<MemberList> => {\n const result = await graphqlFetch<{ workspaceMembers: MemberList }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(GetWorkspaceMembersDocument),\n variables: {\n workspaceId,\n pagination: {\n limit: pageSize,\n offset: pageParam,\n },\n },\n workspaceId,\n workspaceToken: true,\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n if (!result.data?.workspaceMembers) {\n throw new Error('Workspace members query returned no data');\n }\n\n return result.data.workspaceMembers;\n },\n getNextPageParam: (lastPage, _pages, lastPageParam) =>\n lastPage.hasMore ? Number(lastPageParam) + pageSize : undefined,\n enabled: enabled && !!workspaceId,\n staleTime: 5 * 60 * 1000,\n });\n};\n\n/**\n * Hook to fetch a single workspace member by ID\n */\nexport const useWorkspaceMember = (id: string) => {\n const { authToken, workspaceId } = useWorkspacesContext();\n\n return useQuery({\n queryKey: ['workspaceMember', workspaceId, id],\n queryFn: async (): Promise<WorkspaceMember> => {\n const result = await graphqlFetch<{ workspaceMember: WorkspaceMember }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(GetWorkspaceMemberDocument),\n variables: { id },\n workspaceId: workspaceId || undefined,\n workspaceToken: true, // Required by gateway RBAC for wspace-scoped operations\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n if (!result.data?.workspaceMember) {\n throw new Error('Workspace member query returned no data');\n }\n\n return result.data.workspaceMember;\n },\n enabled: !!id,\n staleTime: 5 * 60 * 1000,\n });\n};\n\n/**\n * Hook to fetch all workspaces a user is a member of\n */\nexport const useUserWorkspaces = (userId: string, pagination?: PaginationInput) => {\n const { authToken, workspaceId } = useWorkspacesContext();\n\n return useQuery({\n queryKey: ['userWorkspaces', userId, pagination],\n queryFn: async (): Promise<MemberList> => {\n const result = await graphqlFetch<{ userWorkspaces: MemberList }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(GetUserWorkspacesDocument),\n variables: { userId, pagination },\n workspaceId: workspaceId || undefined,\n workspaceToken: true, // Required by gateway RBAC for wspace-scoped operations\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n if (!result.data?.userWorkspaces) {\n throw new Error('User workspaces query returned no data');\n }\n\n return result.data.userWorkspaces;\n },\n enabled: !!userId,\n staleTime: 5 * 60 * 1000,\n });\n};\n\n/**\n * Hook to fetch workspace invitations\n * Requires x-workspace-id header for workspace context\n */\nexport const useWorkspaceInvitations = (\n workspaceId: string,\n status?: InvitationStatus,\n pagination?: PaginationInput\n) => {\n const { authToken } = useWorkspacesContext();\n\n return useQuery({\n queryKey: ['workspaceInvitations', workspaceId, status, pagination],\n queryFn: async (): Promise<InvitationList> => {\n const result = await graphqlFetch<{ workspaceInvitations: InvitationList }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(GetWorkspaceInvitationsDocument),\n variables: { status, pagination },\n workspaceId,\n workspaceToken: true, // Auto-read from profile context for x-workspace-id header\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n if (!result.data?.workspaceInvitations) {\n throw new Error('Workspace invitations query returned no data');\n }\n\n return result.data.workspaceInvitations;\n },\n enabled: !!workspaceId,\n staleTime: 5 * 60 * 1000,\n });\n};\n\n/**\n * Hook to get a single invitation by ID (for acceptance page)\n */\nexport const useInvitation = (id: string, enabled = true) => {\n const { authToken } = useWorkspacesContext();\n\n return useQuery({\n queryKey: ['invitation', id],\n queryFn: async (): Promise<WorkspaceInvitation> => {\n const result = await graphqlFetch<{ invitation: WorkspaceInvitation }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(GetInvitationDocument),\n variables: { id },\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'Failed to fetch invitation');\n }\n\n if (!result.data?.invitation) {\n throw new Error('Invitation not found');\n }\n\n return result.data.invitation;\n },\n enabled: !!id && enabled,\n retry: 1,\n staleTime: 5 * 60 * 1000,\n });\n};\n"],"mappings":";;;;;;AAuBA,IAAa,KAAuB,GAAqB,MAAiC;CACxF,IAAM,EAAE,iBAAc,GAAsB;AAE5C,QAAO,EAAS;EACd,UAAU;GAAC;GAAoB;GAAa;GAAW;EACvD,SAAS,YAAiC;GACxC,IAAM,IAAS,MAAM,EAA+C;IAClE,SAAS;IACT,WAAW,KAAa,KAAA;IACxB,OAAO,EAAM,EAA4B;IACzC,WAAW;KAAE;KAAa;KAAY;IACtC;IACA,gBAAgB;IACjB,CAAC;AAEF,OAAI,EAAO,QAAQ,OACjB,OAAU,MAAM,EAAO,OAAO,IAAI,WAAW,gBAAgB;AAG/D,OAAI,CAAC,EAAO,MAAM,iBAChB,OAAU,MAAM,2CAA2C;AAG7D,UAAO,EAAO,KAAK;;EAErB,SAAS,CAAC,CAAC;EACX,WAAW,MAAS;EACrB,CAAC;GAGS,KACX,GACA,IAAW,KACX,IAAU,OACP;CACH,IAAM,EAAE,iBAAc,GAAsB;AAE5C,QAAO,EAAiB;EACtB,UAAU;GAAC;GAA4B;GAAa;GAAS;EAC7D,kBAAkB;EAClB,SAAS,OAAO,EAAE,mBAAqC;GACrD,IAAM,IAAS,MAAM,EAA+C;IAClE,SAAS;IACT,WAAW,KAAa,KAAA;IACxB,OAAO,EAAM,EAA4B;IACzC,WAAW;KACT;KACA,YAAY;MACV,OA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/useWorkspaceMembers.ts"],"sourcesContent":["import { useInfiniteQuery, useQuery } from '@tanstack/react-query';\nimport { print } from 'graphql';\nimport { graphqlFetch } from '@burdenoff/fe-libs/shared/graphql';\nimport { useWorkspacesContext } from '../providers/WorkspacesProvider';\nimport {\n GetWorkspaceMembersDocument,\n GetWorkspaceMemberDocument,\n GetUserWorkspacesDocument,\n GetWorkspaceInvitationsDocument,\n GetInvitationDocument,\n} from '../generated/wspace-operations';\nimport type {\n MemberList,\n WorkspaceMember,\n WorkspaceInvitation,\n InvitationList,\n PaginationInput,\n InvitationStatus,\n} from '../types';\n\n/**\n * Hook to fetch all members of the current workspace\n */\nexport const useWorkspaceMembers = (workspaceId: string, pagination?: PaginationInput) => {\n const { authToken } = useWorkspacesContext();\n\n return useQuery({\n queryKey: ['workspaceMembers', workspaceId, pagination],\n queryFn: async (): Promise<MemberList> => {\n const result = await graphqlFetch<{ workspaceMembers: MemberList }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(GetWorkspaceMembersDocument),\n variables: { workspaceId, pagination },\n workspaceId,\n workspaceToken: true, // Auto-read from profile context for x-workspace-id header (required by gateway RBAC)\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n if (!result.data?.workspaceMembers) {\n throw new Error('Workspace members query returned no data');\n }\n\n return result.data.workspaceMembers;\n },\n enabled: !!workspaceId,\n staleTime: 5 * 60 * 1000,\n });\n};\n\nexport const useInfiniteWorkspaceMembers = (\n workspaceId: string,\n pageSize = 100,\n enabled = true\n) => {\n const { authToken } = useWorkspacesContext();\n\n return useInfiniteQuery({\n queryKey: ['workspaceMembersInfinite', workspaceId, pageSize],\n initialPageParam: 0,\n queryFn: async ({ pageParam }): Promise<MemberList> => {\n const result = await graphqlFetch<{ workspaceMembers: MemberList }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(GetWorkspaceMembersDocument),\n variables: {\n workspaceId,\n pagination: {\n limit: pageSize,\n offset: pageParam,\n },\n },\n workspaceId,\n workspaceToken: true,\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n if (!result.data?.workspaceMembers) {\n throw new Error('Workspace members query returned no data');\n }\n\n return result.data.workspaceMembers;\n },\n getNextPageParam: (lastPage, _pages, lastPageParam) =>\n lastPage.hasMore ? Number(lastPageParam) + pageSize : undefined,\n enabled: enabled && !!workspaceId,\n staleTime: 5 * 60 * 1000,\n });\n};\n\n/**\n * Hook to fetch a single workspace member by ID\n */\nexport const useWorkspaceMember = (id: string) => {\n const { authToken, workspaceId } = useWorkspacesContext();\n\n return useQuery({\n queryKey: ['workspaceMember', workspaceId, id],\n queryFn: async (): Promise<WorkspaceMember> => {\n const result = await graphqlFetch<{ workspaceMember: WorkspaceMember }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(GetWorkspaceMemberDocument),\n variables: { id },\n workspaceId: workspaceId || undefined,\n workspaceToken: true, // Required by gateway RBAC for wspace-scoped operations\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n if (!result.data?.workspaceMember) {\n throw new Error('Workspace member query returned no data');\n }\n\n return result.data.workspaceMember;\n },\n enabled: !!id,\n staleTime: 5 * 60 * 1000,\n });\n};\n\n/**\n * Hook to fetch all workspaces a user is a member of\n */\nexport const useUserWorkspaces = (userId: string, pagination?: PaginationInput) => {\n const { authToken, workspaceId } = useWorkspacesContext();\n\n return useQuery({\n queryKey: ['userWorkspaces', userId, pagination],\n queryFn: async (): Promise<MemberList> => {\n const result = await graphqlFetch<{ userWorkspaces: MemberList }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(GetUserWorkspacesDocument),\n variables: { userId, pagination },\n workspaceId: workspaceId || undefined,\n workspaceToken: true, // Required by gateway RBAC for wspace-scoped operations\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n if (!result.data?.userWorkspaces) {\n throw new Error('User workspaces query returned no data');\n }\n\n return result.data.userWorkspaces;\n },\n enabled: !!userId,\n staleTime: 5 * 60 * 1000,\n });\n};\n\n/**\n * Hook to fetch workspace invitations\n * Requires x-workspace-id header for workspace context\n */\nexport const useWorkspaceInvitations = (\n workspaceId: string,\n status?: InvitationStatus,\n pagination?: PaginationInput,\n options?: {\n retry?: boolean | number;\n }\n) => {\n const { authToken } = useWorkspacesContext();\n\n return useQuery({\n queryKey: ['workspaceInvitations', workspaceId, status, pagination],\n queryFn: async (): Promise<InvitationList> => {\n const result = await graphqlFetch<{ workspaceInvitations: InvitationList }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(GetWorkspaceInvitationsDocument),\n variables: { status, pagination },\n workspaceId,\n workspaceToken: true, // Auto-read from profile context for x-workspace-id header\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n if (!result.data?.workspaceInvitations) {\n throw new Error('Workspace invitations query returned no data');\n }\n\n return result.data.workspaceInvitations;\n },\n enabled: !!workspaceId,\n retry: options?.retry,\n staleTime: 5 * 60 * 1000,\n });\n};\n\n/**\n * Hook to get a single invitation by ID (for acceptance page)\n */\nexport const useInvitation = (id: string, enabled = true) => {\n const { authToken } = useWorkspacesContext();\n\n return useQuery({\n queryKey: ['invitation', id],\n queryFn: async (): Promise<WorkspaceInvitation> => {\n const result = await graphqlFetch<{ invitation: WorkspaceInvitation }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(GetInvitationDocument),\n variables: { id },\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'Failed to fetch invitation');\n }\n\n if (!result.data?.invitation) {\n throw new Error('Invitation not found');\n }\n\n return result.data.invitation;\n },\n enabled: !!id && enabled,\n retry: 1,\n staleTime: 5 * 60 * 1000,\n });\n};\n"],"mappings":";;;;;;AAuBA,IAAa,KAAuB,GAAqB,MAAiC;CACxF,IAAM,EAAE,iBAAc,GAAsB;AAE5C,QAAO,EAAS;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AAM,EAAO,OAAO,IAAI,WAAW,gBAAgB;AAG/D,OAAI,CAAC,EAAO,MAAM,qBAChB,OAAU,MAAM,+CAA+C;AAGjE,UAAO,EAAO,KAAK;;EAErB,SAAS,CAAC,CAAC;EACX,OAAO,GAAS;EAChB,WAAW,MAAS;EACrB,CAAC;GAMS,KAAiB,GAAY,IAAU,OAAS;CAC3D,IAAM,EAAE,iBAAc,GAAsB;AAE5C,QAAO,EAAS;EACd,UAAU,CAAC,cAAc,EAAG;EAC5B,SAAS,YAA0C;GACjD,IAAM,IAAS,MAAM,EAAkD;IACrE,SAAS;IACT,WAAW,KAAa,KAAA;IACxB,OAAO,EAAM,EAAsB;IACnC,WAAW,EAAE,OAAI;IAClB,CAAC;AAEF,OAAI,EAAO,QAAQ,OACjB,OAAU,MAAM,EAAO,OAAO,IAAI,WAAW,6BAA6B;AAG5E,OAAI,CAAC,EAAO,MAAM,WAChB,OAAU,MAAM,uBAAuB;AAGzC,UAAO,EAAO,KAAK;;EAErB,SAAS,CAAC,CAAC,KAAM;EACjB,OAAO;EACP,WAAW,MAAS;EACrB,CAAC"}
|
|
@@ -6,7 +6,15 @@ import { useMutation as s, useQueryClient as c } from "@tanstack/react-query";
|
|
|
6
6
|
import { print as l } from "graphql";
|
|
7
7
|
import { graphqlFetch as u } from "@burdenoff/fe-libs/shared/graphql";
|
|
8
8
|
//#region src/hooks/useWorkspaceMutations.ts
|
|
9
|
-
var d = "\n mutation CreateGlobalWorkspace($input: CreateWorkspaceInput!) {\n createWorkspace(input: $input) {\n id\n name\n slug\n type\n status\n tenantId\n organizationId\n createdAt\n }\n }\n"
|
|
9
|
+
var d = "\n mutation CreateGlobalWorkspace($input: CreateWorkspaceInput!) {\n createWorkspace(input: $input) {\n id\n name\n slug\n type\n status\n tenantId\n organizationId\n createdAt\n }\n }\n";
|
|
10
|
+
function f(e, t) {
|
|
11
|
+
e.invalidateQueries({ queryKey: ["workspaces"] }), t && (e.invalidateQueries({ queryKey: ["workspace", t] }), e.invalidateQueries({ queryKey: [
|
|
12
|
+
"dashboard",
|
|
13
|
+
"workspace",
|
|
14
|
+
t
|
|
15
|
+
] })), e.invalidateQueries({ queryKey: ["myWorkspaces"] }), e.invalidateQueries({ queryKey: ["myTenants"] }), e.invalidateQueries({ queryKey: ["myOrganizations"] }), e.invalidateQueries({ queryKey: ["dashboard", "global"] });
|
|
16
|
+
}
|
|
17
|
+
var p = () => {
|
|
10
18
|
let { authToken: t, onWorkspaceCreate: n } = e(), r = c(), { emit: i } = a();
|
|
11
19
|
return s({
|
|
12
20
|
mutationFn: async (e) => {
|
|
@@ -20,7 +28,7 @@ var d = "\n mutation CreateGlobalWorkspace($input: CreateWorkspaceInput!) {\n
|
|
|
20
28
|
return n.data.createWorkspace;
|
|
21
29
|
},
|
|
22
30
|
onSuccess: (e) => {
|
|
23
|
-
|
|
31
|
+
f(r, e.id), i("workspace.created", {
|
|
24
32
|
workspaceId: e.id,
|
|
25
33
|
source: "microfe-workspaces"
|
|
26
34
|
}), n && n(e);
|
|
@@ -32,7 +40,7 @@ var d = "\n mutation CreateGlobalWorkspace($input: CreateWorkspaceInput!) {\n
|
|
|
32
40
|
});
|
|
33
41
|
}
|
|
34
42
|
});
|
|
35
|
-
},
|
|
43
|
+
}, m = () => {
|
|
36
44
|
let { authToken: t } = e(), n = c(), { emit: r } = a();
|
|
37
45
|
return s({
|
|
38
46
|
mutationFn: async ({ id: e, input: n }) => {
|
|
@@ -50,7 +58,7 @@ var d = "\n mutation CreateGlobalWorkspace($input: CreateWorkspaceInput!) {\n
|
|
|
50
58
|
return r.data.updateWorkspace;
|
|
51
59
|
},
|
|
52
60
|
onSuccess: (e) => {
|
|
53
|
-
|
|
61
|
+
f(n, e.id), r("workspace.updated", {
|
|
54
62
|
workspaceId: e.id,
|
|
55
63
|
source: "microfe-workspaces"
|
|
56
64
|
});
|
|
@@ -63,7 +71,7 @@ var d = "\n mutation CreateGlobalWorkspace($input: CreateWorkspaceInput!) {\n
|
|
|
63
71
|
});
|
|
64
72
|
}
|
|
65
73
|
});
|
|
66
|
-
},
|
|
74
|
+
}, h = () => {
|
|
67
75
|
let { authToken: t } = e(), r = c(), { emit: i } = a();
|
|
68
76
|
return s({
|
|
69
77
|
mutationFn: async (e) => {
|
|
@@ -78,7 +86,7 @@ var d = "\n mutation CreateGlobalWorkspace($input: CreateWorkspaceInput!) {\n
|
|
|
78
86
|
return r.data.deleteWorkspace;
|
|
79
87
|
},
|
|
80
88
|
onSuccess: (e, t) => {
|
|
81
|
-
|
|
89
|
+
f(r, t), i("workspace.deleted", {
|
|
82
90
|
workspaceId: t,
|
|
83
91
|
source: "microfe-workspaces"
|
|
84
92
|
});
|
|
@@ -91,7 +99,7 @@ var d = "\n mutation CreateGlobalWorkspace($input: CreateWorkspaceInput!) {\n
|
|
|
91
99
|
});
|
|
92
100
|
}
|
|
93
101
|
});
|
|
94
|
-
},
|
|
102
|
+
}, g = () => {
|
|
95
103
|
let { authToken: n } = e(), r = c(), { emit: i } = a();
|
|
96
104
|
return s({
|
|
97
105
|
mutationFn: async (e) => {
|
|
@@ -106,7 +114,7 @@ var d = "\n mutation CreateGlobalWorkspace($input: CreateWorkspaceInput!) {\n
|
|
|
106
114
|
return r.data.updateWorkspace;
|
|
107
115
|
},
|
|
108
116
|
onSuccess: (e) => {
|
|
109
|
-
|
|
117
|
+
f(r, e.id), i("workspace.archived", {
|
|
110
118
|
workspaceId: e.id,
|
|
111
119
|
source: "microfe-workspaces"
|
|
112
120
|
});
|
|
@@ -119,7 +127,7 @@ var d = "\n mutation CreateGlobalWorkspace($input: CreateWorkspaceInput!) {\n
|
|
|
119
127
|
});
|
|
120
128
|
}
|
|
121
129
|
});
|
|
122
|
-
},
|
|
130
|
+
}, _ = () => {
|
|
123
131
|
let { authToken: t } = e(), n = c(), { emit: i } = a();
|
|
124
132
|
return s({
|
|
125
133
|
mutationFn: async (e) => {
|
|
@@ -134,7 +142,7 @@ var d = "\n mutation CreateGlobalWorkspace($input: CreateWorkspaceInput!) {\n
|
|
|
134
142
|
return n.data.updateWorkspace;
|
|
135
143
|
},
|
|
136
144
|
onSuccess: (e) => {
|
|
137
|
-
|
|
145
|
+
f(n, e.id), i("workspace.reactivated", {
|
|
138
146
|
workspaceId: e.id,
|
|
139
147
|
source: "microfe-workspaces"
|
|
140
148
|
});
|
|
@@ -149,6 +157,6 @@ var d = "\n mutation CreateGlobalWorkspace($input: CreateWorkspaceInput!) {\n
|
|
|
149
157
|
});
|
|
150
158
|
};
|
|
151
159
|
//#endregion
|
|
152
|
-
export {
|
|
160
|
+
export { g as useArchiveWorkspace, p as useCreateWorkspace, h as useDeleteWorkspace, _ as useReactivateWorkspace, m as useUpdateWorkspace };
|
|
153
161
|
|
|
154
162
|
//# sourceMappingURL=useWorkspaceMutations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWorkspaceMutations.js","names":[],"sources":["../../src/hooks/useWorkspaceMutations.ts"],"sourcesContent":["import { useMutation, useQueryClient } from '@tanstack/react-query';\nimport { print } from 'graphql';\nimport { graphqlFetch } from '@burdenoff/fe-libs/shared/graphql';\nimport { useWorkspacesContext } from '../providers/WorkspacesProvider';\nimport { useWorkspacesEventEmitter } from './useWorkspacesEventEmitter';\nimport {\n UpdateWorkspaceDocument,\n DeleteWorkspaceDocument,\n ArchiveWorkspaceDocument,\n ReactivateWorkspaceDocument,\n} from '../generated/wspace-operations';\nimport type { CreateWorkspaceInput, UpdateWorkspaceInput, Workspace } from '../types';\nimport { safeTelemetryError } from '../utils/telemetryError';\n\n/**\n * GraphQL mutation to create workspace via global-tenant-svc\n * This creates workspace in global layer, which then syncs to wspace layer\n */\nconst CREATE_GLOBAL_WORKSPACE = `\n mutation CreateGlobalWorkspace($input: CreateWorkspaceInput!) {\n createWorkspace(input: $input) {\n id\n name\n slug\n type\n status\n tenantId\n organizationId\n createdAt\n }\n }\n`;\n\n/**\n * Hook to create a new workspace\n *\n * Creates workspace via global-tenant-svc (global gateway), which then\n * automatically syncs to wspace-workspace-svc. This ensures proper\n * tenant/org hierarchy management in the global layer.\n *\n * Required input fields:\n * - tenantId: Select from myTenants query\n * - organizationId: Select from myOrganizations query\n * - name: Display name\n * - slug: URL-friendly identifier (unique within tenant)\n */\nexport const useCreateWorkspace = () => {\n const { authToken, onWorkspaceCreate } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n\n return useMutation({\n mutationFn: async (input: CreateWorkspaceInput): Promise<Workspace> => {\n // Call global gateway for workspace creation\n const result = await graphqlFetch<{ createWorkspace: Workspace }>({\n gateway: 'global', // Use global gateway, not workspace gateway\n authToken: authToken || undefined,\n query: CREATE_GLOBAL_WORKSPACE,\n variables: { input },\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'Failed to create workspace');\n }\n\n return result.data!.createWorkspace;\n },\n onSuccess: (workspace) => {\n // Invalidate both global and workspace layer queries\n queryClient.invalidateQueries({ queryKey: ['workspaces'] });\n queryClient.invalidateQueries({ queryKey: ['myWorkspaces'] });\n queryClient.invalidateQueries({ queryKey: ['myTenants'] });\n queryClient.invalidateQueries({ queryKey: ['myOrganizations'] });\n emit('workspace.created', { workspaceId: workspace.id, source: 'microfe-workspaces' });\n if (onWorkspaceCreate) {\n onWorkspaceCreate(workspace);\n }\n },\n onError: (err) => {\n emit('workspace.create_failed', {\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to update an existing workspace\n */\nexport const useUpdateWorkspace = () => {\n const { authToken } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n\n return useMutation({\n mutationFn: async ({\n id,\n input,\n }: {\n id: string;\n input: UpdateWorkspaceInput;\n }): Promise<Workspace> => {\n const result = await graphqlFetch<{ updateWorkspace: Workspace }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(UpdateWorkspaceDocument),\n variables: { id, input },\n workspaceToken: true, // Required by gateway RBAC for wspace-scoped operations\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.updateWorkspace;\n },\n onSuccess: (workspace) => {\n queryClient.invalidateQueries({ queryKey: ['workspaces'] });\n queryClient.invalidateQueries({ queryKey: ['workspace', workspace.id] });\n queryClient.invalidateQueries({ queryKey: ['myWorkspaces'] });\n emit('workspace.updated', { workspaceId: workspace.id, source: 'microfe-workspaces' });\n },\n onError: (err, variables) => {\n emit('workspace.update_failed', {\n workspaceId: variables?.id,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to delete a workspace\n */\nexport const useDeleteWorkspace = () => {\n const { authToken } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n\n return useMutation({\n mutationFn: async (id: string): Promise<boolean> => {\n const result = await graphqlFetch<{ deleteWorkspace: boolean }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(DeleteWorkspaceDocument),\n variables: { id },\n workspaceToken: true, // Required by gateway RBAC for wspace-scoped operations\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.deleteWorkspace;\n },\n onSuccess: (_, id) => {\n queryClient.invalidateQueries({ queryKey: ['workspaces'] });\n queryClient.invalidateQueries({ queryKey: ['workspace', id] });\n queryClient.invalidateQueries({ queryKey: ['myWorkspaces'] });\n emit('workspace.deleted', { workspaceId: id, source: 'microfe-workspaces' });\n },\n onError: (err, id) => {\n emit('workspace.delete_failed', {\n workspaceId: id,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to archive a workspace\n */\nexport const useArchiveWorkspace = () => {\n const { authToken } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n\n return useMutation({\n mutationFn: async (id: string): Promise<Workspace> => {\n const result = await graphqlFetch<{ updateWorkspace: Workspace }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(ArchiveWorkspaceDocument),\n variables: { id },\n workspaceToken: true, // Required by gateway RBAC for wspace-scoped operations\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.updateWorkspace;\n },\n onSuccess: (workspace) => {\n queryClient.invalidateQueries({ queryKey: ['workspaces'] });\n queryClient.invalidateQueries({ queryKey: ['workspace', workspace.id] });\n queryClient.invalidateQueries({ queryKey: ['myWorkspaces'] });\n emit('workspace.archived', { workspaceId: workspace.id, source: 'microfe-workspaces' });\n },\n onError: (err, id) => {\n emit('workspace.archive_failed', {\n workspaceId: id,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to reactivate an archived workspace\n */\nexport const useReactivateWorkspace = () => {\n const { authToken } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n\n return useMutation({\n mutationFn: async (id: string): Promise<Workspace> => {\n const result = await graphqlFetch<{ updateWorkspace: Workspace }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(ReactivateWorkspaceDocument),\n variables: { id },\n workspaceToken: true, // Required by gateway RBAC for wspace-scoped operations\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.updateWorkspace;\n },\n onSuccess: (workspace) => {\n queryClient.invalidateQueries({ queryKey: ['workspaces'] });\n queryClient.invalidateQueries({ queryKey: ['workspace', workspace.id] });\n queryClient.invalidateQueries({ queryKey: ['myWorkspaces'] });\n emit('workspace.reactivated', { workspaceId: workspace.id, source: 'microfe-workspaces' });\n },\n onError: (err, id) => {\n emit('workspace.reactivate_failed', {\n workspaceId: id,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n"],"mappings":";;;;;;;;AAkBA,IAAM,IAA0B,8OA4BnB,UAA2B;CAC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AAkB,EAAE,UAAU,CAAC,eAAe,EAAE,CAAC,EAC7D,EAAK,yBAAyB;IAAE,aAAa,EAAU;IAAI,QAAQ;IAAsB,CAAC;;EAE5F,UAAU,GAAK,MAAO;AACpB,KAAK,+BAA+B;IAClC,aAAa;IACb,QAAQ;IACR,cAAc,EAAmB,EAAI;IACtC,CAAC;;EAEL,CAAC"}
|
|
1
|
+
{"version":3,"file":"useWorkspaceMutations.js","names":[],"sources":["../../src/hooks/useWorkspaceMutations.ts"],"sourcesContent":["import { useMutation, useQueryClient, type QueryClient } from '@tanstack/react-query';\nimport { print } from 'graphql';\nimport { graphqlFetch } from '@burdenoff/fe-libs/shared/graphql';\nimport { useWorkspacesContext } from '../providers/WorkspacesProvider';\nimport { useWorkspacesEventEmitter } from './useWorkspacesEventEmitter';\nimport {\n UpdateWorkspaceDocument,\n DeleteWorkspaceDocument,\n ArchiveWorkspaceDocument,\n ReactivateWorkspaceDocument,\n} from '../generated/wspace-operations';\nimport type { CreateWorkspaceInput, UpdateWorkspaceInput, Workspace } from '../types';\nimport { safeTelemetryError } from '../utils/telemetryError';\n\n/**\n * GraphQL mutation to create workspace via global-tenant-svc\n * This creates workspace in global layer, which then syncs to wspace layer\n */\nconst CREATE_GLOBAL_WORKSPACE = `\n mutation CreateGlobalWorkspace($input: CreateWorkspaceInput!) {\n createWorkspace(input: $input) {\n id\n name\n slug\n type\n status\n tenantId\n organizationId\n createdAt\n }\n }\n`;\n\nfunction invalidateWorkspaceViews(queryClient: QueryClient, workspaceId?: string) {\n queryClient.invalidateQueries({ queryKey: ['workspaces'] });\n if (workspaceId) {\n queryClient.invalidateQueries({ queryKey: ['workspace', workspaceId] });\n queryClient.invalidateQueries({ queryKey: ['dashboard', 'workspace', workspaceId] });\n }\n queryClient.invalidateQueries({ queryKey: ['myWorkspaces'] });\n queryClient.invalidateQueries({ queryKey: ['myTenants'] });\n queryClient.invalidateQueries({ queryKey: ['myOrganizations'] });\n queryClient.invalidateQueries({ queryKey: ['dashboard', 'global'] });\n}\n\n/**\n * Hook to create a new workspace\n *\n * Creates workspace via global-tenant-svc (global gateway), which then\n * automatically syncs to wspace-workspace-svc. This ensures proper\n * tenant/org hierarchy management in the global layer.\n *\n * Required input fields:\n * - tenantId: Select from myTenants query\n * - organizationId: Select from myOrganizations query\n * - name: Display name\n * - slug: URL-friendly identifier (unique within tenant)\n */\nexport const useCreateWorkspace = () => {\n const { authToken, onWorkspaceCreate } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n\n return useMutation({\n mutationFn: async (input: CreateWorkspaceInput): Promise<Workspace> => {\n // Call global gateway for workspace creation\n const result = await graphqlFetch<{ createWorkspace: Workspace }>({\n gateway: 'global', // Use global gateway, not workspace gateway\n authToken: authToken || undefined,\n query: CREATE_GLOBAL_WORKSPACE,\n variables: { input },\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'Failed to create workspace');\n }\n\n return result.data!.createWorkspace;\n },\n onSuccess: (workspace) => {\n // Invalidate both global and workspace layer queries\n invalidateWorkspaceViews(queryClient, workspace.id);\n emit('workspace.created', { workspaceId: workspace.id, source: 'microfe-workspaces' });\n if (onWorkspaceCreate) {\n onWorkspaceCreate(workspace);\n }\n },\n onError: (err) => {\n emit('workspace.create_failed', {\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to update an existing workspace\n */\nexport const useUpdateWorkspace = () => {\n const { authToken } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n\n return useMutation({\n mutationFn: async ({\n id,\n input,\n }: {\n id: string;\n input: UpdateWorkspaceInput;\n }): Promise<Workspace> => {\n const result = await graphqlFetch<{ updateWorkspace: Workspace }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(UpdateWorkspaceDocument),\n variables: { id, input },\n workspaceToken: true, // Required by gateway RBAC for wspace-scoped operations\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.updateWorkspace;\n },\n onSuccess: (workspace) => {\n invalidateWorkspaceViews(queryClient, workspace.id);\n emit('workspace.updated', { workspaceId: workspace.id, source: 'microfe-workspaces' });\n },\n onError: (err, variables) => {\n emit('workspace.update_failed', {\n workspaceId: variables?.id,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to delete a workspace\n */\nexport const useDeleteWorkspace = () => {\n const { authToken } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n\n return useMutation({\n mutationFn: async (id: string): Promise<boolean> => {\n const result = await graphqlFetch<{ deleteWorkspace: boolean }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(DeleteWorkspaceDocument),\n variables: { id },\n workspaceToken: true, // Required by gateway RBAC for wspace-scoped operations\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.deleteWorkspace;\n },\n onSuccess: (_, id) => {\n invalidateWorkspaceViews(queryClient, id);\n emit('workspace.deleted', { workspaceId: id, source: 'microfe-workspaces' });\n },\n onError: (err, id) => {\n emit('workspace.delete_failed', {\n workspaceId: id,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to archive a workspace\n */\nexport const useArchiveWorkspace = () => {\n const { authToken } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n\n return useMutation({\n mutationFn: async (id: string): Promise<Workspace> => {\n const result = await graphqlFetch<{ updateWorkspace: Workspace }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(ArchiveWorkspaceDocument),\n variables: { id },\n workspaceToken: true, // Required by gateway RBAC for wspace-scoped operations\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.updateWorkspace;\n },\n onSuccess: (workspace) => {\n invalidateWorkspaceViews(queryClient, workspace.id);\n emit('workspace.archived', { workspaceId: workspace.id, source: 'microfe-workspaces' });\n },\n onError: (err, id) => {\n emit('workspace.archive_failed', {\n workspaceId: id,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n\n/**\n * Hook to reactivate an archived workspace\n */\nexport const useReactivateWorkspace = () => {\n const { authToken } = useWorkspacesContext();\n const queryClient = useQueryClient();\n const { emit } = useWorkspacesEventEmitter();\n\n return useMutation({\n mutationFn: async (id: string): Promise<Workspace> => {\n const result = await graphqlFetch<{ updateWorkspace: Workspace }>({\n gateway: 'workspace',\n authToken: authToken || undefined,\n query: print(ReactivateWorkspaceDocument),\n variables: { id },\n workspaceToken: true, // Required by gateway RBAC for wspace-scoped operations\n });\n\n if (result.errors?.length) {\n throw new Error(result.errors[0]?.message || 'GraphQL error');\n }\n\n return result.data!.updateWorkspace;\n },\n onSuccess: (workspace) => {\n invalidateWorkspaceViews(queryClient, workspace.id);\n emit('workspace.reactivated', { workspaceId: workspace.id, source: 'microfe-workspaces' });\n },\n onError: (err, id) => {\n emit('workspace.reactivate_failed', {\n workspaceId: id,\n source: 'microfe-workspaces',\n errorMessage: safeTelemetryError(err),\n });\n },\n });\n};\n"],"mappings":";;;;;;;;AAkBA,IAAM,IAA0B;AAehC,SAAS,EAAyB,GAA0B,GAAsB;AAShF,CARA,EAAY,kBAAkB,EAAE,UAAU,CAAC,aAAa,EAAE,CAAC,EACvD,MACF,EAAY,kBAAkB,EAAE,UAAU,CAAC,aAAa,EAAY,EAAE,CAAC,EACvE,EAAY,kBAAkB,EAAE,UAAU;EAAC;EAAa;EAAa;EAAY,EAAE,CAAC,GAEtF,EAAY,kBAAkB,EAAE,UAAU,CAAC,eAAe,EAAE,CAAC,EAC7D,EAAY,kBAAkB,EAAE,UAAU,CAAC,YAAY,EAAE,CAAC,EAC1D,EAAY,kBAAkB,EAAE,UAAU,CAAC,kBAAkB,EAA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