@jsb188/graphql 1.1.8 → 1.1.11
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/cache/config.ts +66 -42
- package/cache/index.test.ts +881 -0
- package/cache/index.ts +1815 -979
- package/cache/persist.ts +721 -0
- package/cache/store.ts +437 -0
- package/client/data-table-realtime-subscriptions.test.ts +740 -0
- package/client/data-table-realtime-subscriptions.ts +955 -0
- package/client/data-table-realtime.test.ts +792 -0
- package/client/data-table-realtime.ts +1218 -0
- package/client/fragment-realtime-sequence.ts +52 -0
- package/client/index.ts +4 -2
- package/client/open-sheet.ts +137 -0
- package/client/request-managed-session.test.ts +574 -0
- package/client/request-no-store.test.ts +157 -0
- package/client/request.ts +973 -143
- package/client/sse-ticket.test.ts +26 -0
- package/deno.lock +170 -0
- package/deno.test.json +10 -0
- package/drafts/index.ts +149 -0
- package/drafts/store.ts +397 -0
- package/gql/eagerQueryMap.ts +12 -0
- package/gql/fragments/accountAuthFragments.ts +5 -0
- package/gql/fragments/accountFragments.ts +1 -3
- package/gql/fragments/accountSessionFragments.ts +16 -0
- package/gql/fragments/agentDocFragments.ts +46 -0
- package/gql/fragments/agentMemoryFragments.ts +19 -0
- package/gql/fragments/aiChatFragments.ts +17 -0
- package/gql/fragments/billingFragments.ts +0 -11
- package/gql/fragments/campaignFragments.ts +277 -0
- package/gql/fragments/dataTableFragments.ts +102 -0
- package/gql/fragments/emailFragments.ts +36 -0
- package/gql/fragments/fieldDocFragments.ts +82 -0
- package/gql/fragments/inboundContactFragments.ts +15 -0
- package/gql/fragments/integrationFragments.ts +22 -0
- package/gql/fragments/logFragments.ts +33 -64
- package/gql/fragments/organizationFragments.ts +94 -21
- package/gql/fragments/scheduleFragments.ts +155 -0
- package/gql/fragments/sheetFragments.ts +675 -0
- package/gql/fragments/storageFragments.ts +21 -1
- package/gql/fragments/workflowFragments.ts +67 -0
- package/gql/mutations/accountMutations.ts +24 -4
- package/gql/mutations/agentDocMutations.ts +177 -0
- package/gql/mutations/agentMemoryMutations.ts +36 -0
- package/gql/mutations/aiChatMutations.ts +43 -3
- package/gql/mutations/authMutations.ts +160 -19
- package/gql/mutations/campaignMutations.ts +215 -0
- package/gql/mutations/dataTableMutations.ts +106 -0
- package/gql/mutations/fieldDocMutations.ts +24 -0
- package/gql/mutations/inboundContactMutations.ts +24 -0
- package/gql/mutations/index.ts +17 -8
- package/gql/mutations/integrationMutations.ts +25 -0
- package/gql/mutations/logMutations.ts +10 -19
- package/gql/mutations/organizationMutations.ts +160 -2
- package/gql/mutations/scheduleMutations.ts +423 -0
- package/gql/mutations/sheetMutations.ts +385 -0
- package/gql/mutations/storageMutations.ts +21 -2
- package/gql/mutations/workflowMutations.ts +42 -0
- package/gql/queries/agentDocQueries.ts +120 -0
- package/gql/queries/agentMemoryQueries.ts +22 -0
- package/gql/queries/aiChatQueries.ts +18 -2
- package/gql/queries/authQueries.ts +41 -0
- package/gql/queries/billingQueries.ts +24 -1
- package/gql/queries/campaignQueries.ts +127 -0
- package/gql/queries/dataTableQueries.ts +134 -0
- package/gql/queries/emailQueries.ts +96 -0
- package/gql/queries/fieldDocQueries.ts +158 -0
- package/gql/queries/inboundContactQueries.ts +40 -0
- package/gql/queries/index.ts +17 -6
- package/gql/queries/logQueries.ts +42 -32
- package/gql/queries/organizationQueries.ts +113 -8
- package/gql/queries/scheduleQueries.ts +315 -0
- package/gql/queries/sheetQueries.ts +383 -0
- package/gql/queries/storageQueries.ts +38 -0
- package/gql/queries/workflowQueries.ts +99 -0
- package/hooks/index.ts +2104 -860
- package/hooks/use-account-mtn.ts +91 -48
- package/hooks/use-agentDoc-mtn.ts +285 -0
- package/hooks/use-agentDoc-qry.ts +208 -0
- package/hooks/use-agentMemory-mtn.ts +73 -0
- package/hooks/use-agentMemory-qry.ts +44 -0
- package/hooks/use-aiChat-mtn.ts +248 -97
- package/hooks/use-aiChat-qry.ts +501 -191
- package/hooks/use-app-qry.ts +14 -11
- package/hooks/use-auth-mtn.ts +410 -256
- package/hooks/use-auth-qry.ts +51 -0
- package/hooks/use-campaign-mtn.ts +377 -0
- package/hooks/use-campaign-qry.ts +257 -0
- package/hooks/use-dataTable-mtn.ts +170 -0
- package/hooks/use-dataTable-qry.ts +996 -0
- package/hooks/use-email-qry.ts +227 -0
- package/hooks/use-fieldDoc-mtn.ts +50 -0
- package/hooks/use-fieldDoc-qry.ts +180 -0
- package/hooks/use-inboundContact-mtn.ts +34 -0
- package/hooks/use-inboundContact-qry.ts +96 -0
- package/hooks/use-integration-mtn.ts +77 -0
- package/hooks/use-integration-qry.ts +30 -0
- package/hooks/use-log-mtn.ts +77 -61
- package/hooks/use-log-qry.ts +99 -72
- package/hooks/use-organization-mtn.ts +409 -80
- package/hooks/use-organization-qry.ts +211 -92
- package/hooks/use-schedule-mtn.ts +416 -0
- package/hooks/use-schedule-qry.ts +157 -0
- package/hooks/use-sheet-mtn.ts +367 -0
- package/hooks/use-sheet-qry.ts +440 -0
- package/hooks/use-storage-mtn.ts +83 -42
- package/hooks/use-storage-qry.ts +104 -13
- package/hooks/use-workflow-mtn.ts +55 -0
- package/hooks/use-workflow-qry.ts +230 -0
- package/loaders/campaign.ts +137 -0
- package/package.json +94 -52
- package/sse.ts +158 -105
- package/tsconfig.json +13 -0
- package/types.d.ts +60 -29
- package/utils.ts +77 -50
- package/gql/fragments/actionFragments.ts +0 -16
- package/gql/fragments/productFragments.ts +0 -63
- package/gql/fragments/reportFragments.ts +0 -48
- package/gql/mutations/billingMutations.ts +0 -34
- package/gql/queries/productQueries.ts +0 -70
- package/gql/queries/reportQueries.ts +0 -66
- package/hooks/use-product-qry.ts +0 -109
- package/hooks/use-report-qry.ts +0 -69
|
@@ -1,105 +1,434 @@
|
|
|
1
1
|
import type { UseMutationParams } from '@jsb188/graphql/types.d';
|
|
2
|
+
import {
|
|
3
|
+
checkACL,
|
|
4
|
+
type OperationName,
|
|
5
|
+
} from '@jsb188/mday/utils/organization.ts';
|
|
2
6
|
import { OpenModalPopUpFn, useCurrentAccount } from '@jsb188/react/states';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
import {
|
|
8
|
+
FRAGMENT_NAMES,
|
|
9
|
+
makeFragmentKey,
|
|
10
|
+
} from '@jsb188/mday/constants/graphqlReactivity.ts';
|
|
7
11
|
import { useMemo } from 'react';
|
|
8
|
-
import {
|
|
12
|
+
import { updateFragment } from '../cache/index.ts';
|
|
13
|
+
import {
|
|
14
|
+
deleteChildOrganizationMtn,
|
|
15
|
+
deleteComplianceDocumentMtn,
|
|
16
|
+
editChildOrganizationMtn,
|
|
17
|
+
editComplianceDocumentMtn,
|
|
18
|
+
editMembershipMtn,
|
|
19
|
+
editOrganizationMtn,
|
|
20
|
+
editOrganizationInboundEmailMtn,
|
|
21
|
+
editOrganizationSettingsMtn,
|
|
22
|
+
editSiteLocationMtn,
|
|
23
|
+
removeMembershipMtn,
|
|
24
|
+
switchOrganizationMtn,
|
|
25
|
+
} from '../gql/mutations/organizationMutations.ts';
|
|
26
|
+
import { useMutation } from './index.ts';
|
|
27
|
+
import { useOrgRelFromMyOrganizations } from './use-organization-qry.ts';
|
|
9
28
|
|
|
10
29
|
/**
|
|
11
30
|
* Fetch a single log entry,
|
|
12
31
|
* from cache first; only check server if cache is not found.
|
|
13
32
|
*/
|
|
14
33
|
|
|
15
|
-
export function useSwitchOrganization(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
34
|
+
export function useSwitchOrganization(
|
|
35
|
+
params: UseMutationParams = {},
|
|
36
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
37
|
+
) {
|
|
38
|
+
const { onCompleted, ...otherParams } = params;
|
|
39
|
+
// const navigate = useNavigate();
|
|
40
|
+
const { dispatchApp, account, primaryOrganizationId } = useCurrentAccount();
|
|
41
|
+
|
|
42
|
+
const [switchOrganization, mtnValues, mtnHandlers] = useMutation(
|
|
43
|
+
switchOrganizationMtn,
|
|
44
|
+
{
|
|
45
|
+
// checkMountedBeforeCallback: true,
|
|
46
|
+
openModalPopUp,
|
|
47
|
+
onCompleted: (data: any, error: any, variables: any) => {
|
|
48
|
+
const result = data?.switchOrganization;
|
|
49
|
+
if (result) {
|
|
50
|
+
// navigate('/app', { replace: true });
|
|
51
|
+
dispatchApp({
|
|
52
|
+
__type: 'APP_SWITCH_PRIMARY_ORGANIZATION',
|
|
53
|
+
data: {
|
|
54
|
+
primaryOrganizationId: variables.organizationId,
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
onCompleted?.(result, error);
|
|
60
|
+
},
|
|
61
|
+
...otherParams,
|
|
62
|
+
},
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
switchOrganization,
|
|
67
|
+
...mtnValues,
|
|
68
|
+
...mtnHandlers,
|
|
69
|
+
};
|
|
45
70
|
}
|
|
46
71
|
|
|
47
72
|
/**
|
|
48
73
|
* Delete a compliance document
|
|
49
74
|
*/
|
|
50
75
|
|
|
51
|
-
export function useDeleteComplianceDocument(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
76
|
+
export function useDeleteComplianceDocument(
|
|
77
|
+
params: UseMutationParams = {},
|
|
78
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
79
|
+
) {
|
|
80
|
+
const { onCompleted, ...otherParams } = params;
|
|
81
|
+
|
|
82
|
+
const [deleteComplianceDocument, mtnValues, mtnHandlers, updateObservers] =
|
|
83
|
+
useMutation(deleteComplianceDocumentMtn, {
|
|
84
|
+
// checkMountedBeforeCallback: true,
|
|
85
|
+
openModalPopUp,
|
|
86
|
+
onCompleted: (data, error, variables) => {
|
|
87
|
+
const deleted = data?.deleteComplianceDocument;
|
|
88
|
+
if (deleted) {
|
|
89
|
+
updateFragment(
|
|
90
|
+
makeFragmentKey(
|
|
91
|
+
FRAGMENT_NAMES.organizationCompliance,
|
|
92
|
+
variables.complianceId,
|
|
93
|
+
),
|
|
94
|
+
{ __deleted: true },
|
|
95
|
+
null,
|
|
96
|
+
false,
|
|
97
|
+
updateObservers,
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
onCompleted?.(deleted, error);
|
|
102
|
+
},
|
|
103
|
+
...otherParams,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
deleteComplianceDocument,
|
|
108
|
+
...mtnValues,
|
|
109
|
+
...mtnHandlers,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Edit a compliance document
|
|
115
|
+
*/
|
|
116
|
+
|
|
117
|
+
export function useEditComplianceDocument(
|
|
118
|
+
params: UseMutationParams = {},
|
|
119
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
120
|
+
) {
|
|
121
|
+
const [editComplianceDocument, mtnValues, mtnHandlers] = useMutation(
|
|
122
|
+
editComplianceDocumentMtn,
|
|
123
|
+
{
|
|
124
|
+
openModalPopUp,
|
|
125
|
+
...params,
|
|
126
|
+
},
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
return {
|
|
130
|
+
editComplianceDocument,
|
|
131
|
+
...mtnValues,
|
|
132
|
+
...mtnHandlers,
|
|
133
|
+
};
|
|
75
134
|
}
|
|
76
135
|
|
|
77
136
|
/**
|
|
78
|
-
* Edit
|
|
137
|
+
* Edit an organization
|
|
79
138
|
*/
|
|
80
139
|
|
|
81
140
|
export function useEditOrganization(
|
|
82
|
-
|
|
83
|
-
|
|
141
|
+
params?: UseMutationParams | null,
|
|
142
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
143
|
+
) {
|
|
144
|
+
const [editOrganization, mtnValues, mtnHandlers] = useMutation(
|
|
145
|
+
editOrganizationMtn,
|
|
146
|
+
{
|
|
147
|
+
// checkMountedBeforeCallback: true,
|
|
148
|
+
openModalPopUp,
|
|
149
|
+
...params,
|
|
150
|
+
},
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
return {
|
|
154
|
+
editOrganization,
|
|
155
|
+
...mtnValues,
|
|
156
|
+
...mtnHandlers,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/*
|
|
161
|
+
* Edit an organization's inbound email handle.
|
|
162
|
+
*/
|
|
163
|
+
|
|
164
|
+
export function useEditOrganizationInboundEmail(
|
|
165
|
+
params: UseMutationParams = {},
|
|
166
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
167
|
+
) {
|
|
168
|
+
const { onCompleted, ...rest } = params;
|
|
169
|
+
|
|
170
|
+
const [
|
|
171
|
+
editOrganizationInboundEmail,
|
|
172
|
+
mtnValues,
|
|
173
|
+
mtnHandlers,
|
|
174
|
+
updateObservers,
|
|
175
|
+
] = useMutation(editOrganizationInboundEmailMtn, {
|
|
176
|
+
openModalPopUp,
|
|
177
|
+
onCompleted: (data, error, variables) => {
|
|
178
|
+
const updatedOrganization = data?.editOrganizationInboundEmail;
|
|
179
|
+
|
|
180
|
+
if (updatedOrganization?.id) {
|
|
181
|
+
updateFragment(
|
|
182
|
+
makeFragmentKey(FRAGMENT_NAMES.organization, updatedOrganization.id),
|
|
183
|
+
updatedOrganization,
|
|
184
|
+
null,
|
|
185
|
+
false,
|
|
186
|
+
updateObservers,
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
onCompleted?.(updatedOrganization, error, variables);
|
|
191
|
+
},
|
|
192
|
+
...rest,
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
return {
|
|
196
|
+
editOrganizationInboundEmail,
|
|
197
|
+
...mtnValues,
|
|
198
|
+
...mtnHandlers,
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/*
|
|
203
|
+
* Edit an organization's settings.
|
|
204
|
+
*/
|
|
205
|
+
export function useEditOrganizationSettings(
|
|
206
|
+
params?: UseMutationParams | null,
|
|
207
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
208
|
+
) {
|
|
209
|
+
const [editOrganizationSettings, mtnValues, mtnHandlers] = useMutation(
|
|
210
|
+
editOrganizationSettingsMtn,
|
|
211
|
+
{
|
|
212
|
+
openModalPopUp,
|
|
213
|
+
...params,
|
|
214
|
+
},
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
return {
|
|
218
|
+
editOrganizationSettings,
|
|
219
|
+
...mtnValues,
|
|
220
|
+
...mtnHandlers,
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Edit a child organization from parent organization context
|
|
226
|
+
*/
|
|
227
|
+
|
|
228
|
+
export function useEditChildOrganization(
|
|
229
|
+
params?: UseMutationParams | null,
|
|
230
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
84
231
|
) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
232
|
+
const [editChildOrganization, mtnValues, mtnHandlers] = useMutation(
|
|
233
|
+
editChildOrganizationMtn,
|
|
234
|
+
{
|
|
235
|
+
openModalPopUp,
|
|
236
|
+
...params,
|
|
237
|
+
},
|
|
90
238
|
);
|
|
91
239
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
240
|
+
return {
|
|
241
|
+
editChildOrganization,
|
|
242
|
+
...mtnValues,
|
|
243
|
+
...mtnHandlers,
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Delete a child organization from an organization directory.
|
|
249
|
+
*/
|
|
250
|
+
|
|
251
|
+
export function useDeleteChildOrganization(
|
|
252
|
+
params: UseMutationParams = {},
|
|
253
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
254
|
+
) {
|
|
255
|
+
const { onCompleted, ...rest } = params;
|
|
256
|
+
|
|
257
|
+
const [deleteChildOrganization, mtnValues, mtnHandlers, updateObservers] =
|
|
258
|
+
useMutation(deleteChildOrganizationMtn, {
|
|
259
|
+
openModalPopUp,
|
|
260
|
+
onCompleted: (data, error, variables) => {
|
|
261
|
+
const deleted = data?.deleteChildOrganization;
|
|
262
|
+
if (deleted && variables?.childId) {
|
|
263
|
+
updateFragment(
|
|
264
|
+
makeFragmentKey(
|
|
265
|
+
FRAGMENT_NAMES.organizationChild,
|
|
266
|
+
variables.childId,
|
|
267
|
+
),
|
|
268
|
+
{ __deleted: true },
|
|
269
|
+
null,
|
|
270
|
+
false,
|
|
271
|
+
updateObservers,
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
onCompleted?.(deleted, error, variables);
|
|
276
|
+
},
|
|
277
|
+
...rest,
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
return {
|
|
281
|
+
deleteChildOrganization,
|
|
282
|
+
...mtnValues,
|
|
283
|
+
...mtnHandlers,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Edit an organization site location.
|
|
289
|
+
*/
|
|
290
|
+
|
|
291
|
+
export function useEditSiteLocation(
|
|
292
|
+
params: UseMutationParams = {},
|
|
293
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
294
|
+
) {
|
|
295
|
+
const { onCompleted, ...rest } = params;
|
|
296
|
+
|
|
297
|
+
const [editSiteLocation, mtnValues, mtnHandlers, updateObservers] =
|
|
298
|
+
useMutation(editSiteLocationMtn, {
|
|
299
|
+
openModalPopUp,
|
|
300
|
+
onCompleted: (data, error, variables) => {
|
|
301
|
+
const updatedSiteLocation = data?.editSiteLocation;
|
|
302
|
+
|
|
303
|
+
if (updatedSiteLocation?.id) {
|
|
304
|
+
updateFragment(
|
|
305
|
+
makeFragmentKey(
|
|
306
|
+
FRAGMENT_NAMES.organizationSite,
|
|
307
|
+
updatedSiteLocation.id,
|
|
308
|
+
),
|
|
309
|
+
updatedSiteLocation,
|
|
310
|
+
null,
|
|
311
|
+
false,
|
|
312
|
+
updateObservers,
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
onCompleted?.(updatedSiteLocation, error, variables);
|
|
317
|
+
},
|
|
318
|
+
...rest,
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
return {
|
|
322
|
+
editSiteLocation,
|
|
323
|
+
...mtnValues,
|
|
324
|
+
...mtnHandlers,
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Edit logged in user's organization with ACL permission check
|
|
330
|
+
*/
|
|
331
|
+
|
|
332
|
+
export function useEditOrganizationWithACL(
|
|
333
|
+
params?: UseMutationParams | null,
|
|
334
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
335
|
+
aclOpName: OperationName = 'org_management',
|
|
336
|
+
) {
|
|
337
|
+
const { primaryOrganizationId } = useCurrentAccount();
|
|
338
|
+
const { organizationRelationship } = useOrgRelFromMyOrganizations(
|
|
339
|
+
primaryOrganizationId,
|
|
340
|
+
);
|
|
341
|
+
const mtnHook = useEditOrganization(params, openModalPopUp);
|
|
342
|
+
|
|
343
|
+
const allowEdit = useMemo(() => {
|
|
344
|
+
return checkACL(organizationRelationship, aclOpName);
|
|
345
|
+
}, [organizationRelationship?.acl, organizationRelationship?.role]);
|
|
346
|
+
|
|
347
|
+
return {
|
|
348
|
+
allowEdit,
|
|
349
|
+
organizationRelationship,
|
|
350
|
+
...mtnHook,
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Edit a membership on an organization
|
|
356
|
+
*/
|
|
357
|
+
|
|
358
|
+
export function useEditMembership(
|
|
359
|
+
params: UseMutationParams = {},
|
|
360
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
361
|
+
) {
|
|
362
|
+
const { onCompleted, ...rest } = params;
|
|
363
|
+
|
|
364
|
+
const [editMembership, mtnValues, mtnHandlers, updateObservers] = useMutation(
|
|
365
|
+
editMembershipMtn,
|
|
366
|
+
{
|
|
367
|
+
openModalPopUp,
|
|
368
|
+
onCompleted: (data, error, variables) => {
|
|
369
|
+
const updatedMembership = data?.editMembership;
|
|
370
|
+
|
|
371
|
+
if (updatedMembership?.id) {
|
|
372
|
+
updateFragment(
|
|
373
|
+
makeFragmentKey(
|
|
374
|
+
FRAGMENT_NAMES.organizationRelationship,
|
|
375
|
+
updatedMembership.id,
|
|
376
|
+
),
|
|
377
|
+
updatedMembership,
|
|
378
|
+
null,
|
|
379
|
+
false,
|
|
380
|
+
updateObservers,
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
onCompleted?.(updatedMembership, error, variables);
|
|
385
|
+
},
|
|
386
|
+
...rest,
|
|
387
|
+
},
|
|
388
|
+
);
|
|
389
|
+
|
|
390
|
+
return {
|
|
391
|
+
editMembership,
|
|
392
|
+
...mtnValues,
|
|
393
|
+
...mtnHandlers,
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Remove a membership on an organization
|
|
399
|
+
*/
|
|
400
|
+
|
|
401
|
+
export function useRemoveMembership(
|
|
402
|
+
params: UseMutationParams = {},
|
|
403
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
404
|
+
) {
|
|
405
|
+
const { onCompleted, ...rest } = params;
|
|
406
|
+
|
|
407
|
+
const [removeMembership, mtnValues, mtnHandlers, updateObservers] =
|
|
408
|
+
useMutation(removeMembershipMtn, {
|
|
409
|
+
openModalPopUp,
|
|
410
|
+
onCompleted: (data, error, variables) => {
|
|
411
|
+
const removed = data?.removeMembership;
|
|
412
|
+
if (removed) {
|
|
413
|
+
updateFragment(
|
|
414
|
+
makeFragmentKey(
|
|
415
|
+
FRAGMENT_NAMES.organizationRelationship,
|
|
416
|
+
variables.membershipId,
|
|
417
|
+
),
|
|
418
|
+
{ __deleted: true },
|
|
419
|
+
null,
|
|
420
|
+
false,
|
|
421
|
+
updateObservers,
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
onCompleted?.(removed, error, variables);
|
|
425
|
+
},
|
|
426
|
+
...rest,
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
return {
|
|
430
|
+
removeMembership,
|
|
431
|
+
...mtnValues,
|
|
432
|
+
...mtnHandlers,
|
|
433
|
+
};
|
|
105
434
|
}
|