@jsb188/graphql 1.1.10 → 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 +64 -50
- package/cache/index.test.ts +671 -109
- package/cache/index.ts +1700 -1240
- 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 +2 -0
- 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 +954 -163
- package/client/sse-ticket.test.ts +26 -0
- package/deno.lock +170 -0
- package/deno.test.json +8 -4
- 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 +0 -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 +16 -0
- package/gql/fragments/billingFragments.ts +0 -11
- package/gql/fragments/campaignFragments.ts +277 -0
- package/gql/fragments/dataTableFragments.ts +18 -128
- package/gql/fragments/emailFragments.ts +19 -9
- package/gql/fragments/fieldDocFragments.ts +82 -0
- package/gql/fragments/logFragments.ts +20 -79
- package/gql/fragments/organizationFragments.ts +43 -5
- package/gql/fragments/scheduleFragments.ts +155 -0
- package/gql/fragments/sheetFragments.ts +552 -22
- package/gql/fragments/storageFragments.ts +21 -0
- package/gql/fragments/workflowFragments.ts +28 -4
- package/gql/mutations/accountMutations.ts +0 -2
- package/gql/mutations/agentDocMutations.ts +177 -0
- package/gql/mutations/agentMemoryMutations.ts +36 -0
- package/gql/mutations/aiChatMutations.ts +17 -4
- package/gql/mutations/authMutations.ts +158 -17
- package/gql/mutations/campaignMutations.ts +215 -0
- package/gql/mutations/dataTableMutations.ts +48 -26
- package/gql/mutations/fieldDocMutations.ts +24 -0
- package/gql/mutations/index.ts +6 -1
- package/gql/mutations/logMutations.ts +6 -29
- package/gql/mutations/organizationMutations.ts +13 -4
- package/gql/mutations/scheduleMutations.ts +423 -0
- package/gql/mutations/sheetMutations.ts +273 -56
- package/gql/mutations/storageMutations.ts +20 -0
- 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 +23 -0
- package/gql/queries/campaignQueries.ts +127 -0
- package/gql/queries/dataTableQueries.ts +100 -11
- package/gql/queries/emailQueries.ts +55 -3
- package/gql/queries/fieldDocQueries.ts +158 -0
- package/gql/queries/index.ts +8 -2
- package/gql/queries/logQueries.ts +11 -28
- package/gql/queries/organizationQueries.ts +52 -1
- package/gql/queries/scheduleQueries.ts +315 -0
- package/gql/queries/sheetQueries.ts +336 -25
- package/gql/queries/storageQueries.ts +38 -0
- package/gql/queries/workflowQueries.ts +72 -3
- package/hooks/index.ts +2065 -971
- package/hooks/use-account-mtn.ts +76 -81
- 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 +232 -137
- package/hooks/use-aiChat-qry.ts +480 -222
- package/hooks/use-app-qry.ts +12 -9
- package/hooks/use-auth-mtn.ts +406 -252
- 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 +116 -33
- package/hooks/use-dataTable-qry.ts +859 -35
- package/hooks/use-email-qry.ts +194 -79
- package/hooks/use-fieldDoc-mtn.ts +50 -0
- package/hooks/use-fieldDoc-qry.ts +180 -0
- package/hooks/use-inboundContact-mtn.ts +19 -16
- package/hooks/use-inboundContact-qry.ts +63 -55
- package/hooks/use-integration-mtn.ts +56 -38
- package/hooks/use-integration-qry.ts +24 -9
- package/hooks/use-log-mtn.ts +72 -56
- package/hooks/use-log-qry.ts +93 -69
- package/hooks/use-organization-mtn.ts +334 -277
- package/hooks/use-organization-qry.ts +199 -129
- package/hooks/use-schedule-mtn.ts +416 -0
- package/hooks/use-schedule-qry.ts +157 -0
- package/hooks/use-sheet-mtn.ts +233 -47
- package/hooks/use-sheet-qry.ts +353 -70
- package/hooks/use-storage-mtn.ts +81 -41
- package/hooks/use-storage-qry.ts +104 -13
- package/hooks/use-workflow-mtn.ts +55 -0
- package/hooks/use-workflow-qry.ts +206 -48
- package/loaders/campaign.ts +137 -0
- package/package.json +94 -71
- package/sse.ts +157 -104
- package/tsconfig.json +11 -10
- package/types.d.ts +60 -30
- package/utils.ts +78 -49
- package/gql/fragments/productFragments.ts +0 -39
- package/gql/fragments/reportFragments.ts +0 -90
- package/gql/mutations/billingMutations.ts +0 -34
- package/gql/queries/productQueries.ts +0 -31
- package/gql/queries/reportQueries.ts +0 -134
- package/hooks/use-product-qry.ts +0 -67
- package/hooks/use-report-qry.ts +0 -153
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
import type { UseMutationParams } from '@jsb188/graphql/types.d';
|
|
2
|
+
import {
|
|
3
|
+
FRAGMENT_NAMES,
|
|
4
|
+
makeFragmentKey,
|
|
5
|
+
} from '@jsb188/mday/constants/graphqlReactivity.ts';
|
|
6
|
+
import type { OpenModalPopUpFn } from '@jsb188/react/states';
|
|
7
|
+
import { updateFragment } from '../cache/index.ts';
|
|
8
|
+
import {
|
|
9
|
+
assignScheduleOccurrenceMtn,
|
|
10
|
+
cancelScheduleOccurrenceMtn,
|
|
11
|
+
claimScheduleRequestMtn,
|
|
12
|
+
declineScheduleRequestMtn,
|
|
13
|
+
createScheduleFeedTokenMtn,
|
|
14
|
+
createScheduleOccurrenceMtn,
|
|
15
|
+
createScheduleRequestMtn,
|
|
16
|
+
decideScheduleRequestMtn,
|
|
17
|
+
deleteScheduleOccurrenceMtn,
|
|
18
|
+
publishScheduleMtn,
|
|
19
|
+
releaseScheduleAssignmentMtn,
|
|
20
|
+
revokeScheduleFeedTokenMtn,
|
|
21
|
+
updateScheduleOccurrenceMtn,
|
|
22
|
+
withdrawScheduleRequestMtn,
|
|
23
|
+
} from '../gql/mutations/scheduleMutations.ts';
|
|
24
|
+
import { useMutation } from './index.ts';
|
|
25
|
+
|
|
26
|
+
/*
|
|
27
|
+
* Patch the issuing client's own cached occurrence.
|
|
28
|
+
*
|
|
29
|
+
* The server deliberately excludes the originating socket from its realtime
|
|
30
|
+
* emit — that socket already holds the mutation response — so the issuer has
|
|
31
|
+
* to refresh its own fragment or it would be the last client to see its own
|
|
32
|
+
* edit.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
function patchOccurrenceFragment(occurrence: any, updateObservers: any) {
|
|
36
|
+
if (!occurrence?.id) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
updateFragment(
|
|
41
|
+
makeFragmentKey(FRAGMENT_NAMES.scheduleOccurrence, occurrence.id),
|
|
42
|
+
occurrence,
|
|
43
|
+
null,
|
|
44
|
+
false,
|
|
45
|
+
updateObservers,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/*
|
|
50
|
+
* Patch the issuing client's own cached request, for the same reason.
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
function patchRequestFragment(request: any, updateObservers: any) {
|
|
54
|
+
if (!request?.id) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
updateFragment(
|
|
59
|
+
makeFragmentKey(FRAGMENT_NAMES.scheduleRequest, request.id),
|
|
60
|
+
request,
|
|
61
|
+
null,
|
|
62
|
+
false,
|
|
63
|
+
updateObservers,
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/*
|
|
68
|
+
* Create one occurrence.
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
export function useCreateScheduleOccurrence(
|
|
72
|
+
params: UseMutationParams = {},
|
|
73
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
74
|
+
) {
|
|
75
|
+
const [createScheduleOccurrence, mtnValues, mtnHandlers, updateObservers] =
|
|
76
|
+
useMutation(createScheduleOccurrenceMtn, { openModalPopUp, ...params });
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
createScheduleOccurrence,
|
|
80
|
+
updateObservers,
|
|
81
|
+
...mtnValues,
|
|
82
|
+
...mtnHandlers,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/*
|
|
87
|
+
* Update one occurrence.
|
|
88
|
+
*
|
|
89
|
+
* Callers must pass the "version" they read from the occurrence. It is the
|
|
90
|
+
* optimistic-lock token: the server rejects the write if somebody else has
|
|
91
|
+
* edited the row since, which is what stops two managers dragging the same
|
|
92
|
+
* shift from silently overwriting each other.
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
export function useUpdateScheduleOccurrence(
|
|
96
|
+
params: UseMutationParams = {},
|
|
97
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
98
|
+
) {
|
|
99
|
+
const { onCompleted, ...rest } = params;
|
|
100
|
+
|
|
101
|
+
const [updateScheduleOccurrence, mtnValues, mtnHandlers, updateObservers] =
|
|
102
|
+
useMutation(updateScheduleOccurrenceMtn, {
|
|
103
|
+
openModalPopUp,
|
|
104
|
+
onCompleted: (data: any, error: any, variables: any) => {
|
|
105
|
+
patchOccurrenceFragment(
|
|
106
|
+
data?.updateScheduleOccurrence,
|
|
107
|
+
updateObservers,
|
|
108
|
+
);
|
|
109
|
+
onCompleted?.(data?.updateScheduleOccurrence, error, variables);
|
|
110
|
+
},
|
|
111
|
+
...rest,
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
updateScheduleOccurrence,
|
|
116
|
+
updateObservers,
|
|
117
|
+
...mtnValues,
|
|
118
|
+
...mtnHandlers,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/*
|
|
123
|
+
* Cancel one occurrence. The row survives, struck through on the calendar.
|
|
124
|
+
*/
|
|
125
|
+
|
|
126
|
+
export function useCancelScheduleOccurrence(
|
|
127
|
+
params: UseMutationParams = {},
|
|
128
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
129
|
+
) {
|
|
130
|
+
const { onCompleted, ...rest } = params;
|
|
131
|
+
|
|
132
|
+
const [cancelScheduleOccurrence, mtnValues, mtnHandlers, updateObservers] =
|
|
133
|
+
useMutation(cancelScheduleOccurrenceMtn, {
|
|
134
|
+
openModalPopUp,
|
|
135
|
+
onCompleted: (data: any, error: any, variables: any) => {
|
|
136
|
+
patchOccurrenceFragment(
|
|
137
|
+
data?.cancelScheduleOccurrence,
|
|
138
|
+
updateObservers,
|
|
139
|
+
);
|
|
140
|
+
onCompleted?.(data?.cancelScheduleOccurrence, error, variables);
|
|
141
|
+
},
|
|
142
|
+
...rest,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
cancelScheduleOccurrence,
|
|
147
|
+
updateObservers,
|
|
148
|
+
...mtnValues,
|
|
149
|
+
...mtnHandlers,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/*
|
|
154
|
+
* Delete one occurrence outright.
|
|
155
|
+
*/
|
|
156
|
+
|
|
157
|
+
export function useDeleteScheduleOccurrence(
|
|
158
|
+
params: UseMutationParams = {},
|
|
159
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
160
|
+
) {
|
|
161
|
+
const [deleteScheduleOccurrence, mtnValues, mtnHandlers, updateObservers] =
|
|
162
|
+
useMutation(deleteScheduleOccurrenceMtn, { openModalPopUp, ...params });
|
|
163
|
+
|
|
164
|
+
return {
|
|
165
|
+
deleteScheduleOccurrence,
|
|
166
|
+
updateObservers,
|
|
167
|
+
...mtnValues,
|
|
168
|
+
...mtnHandlers,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/*
|
|
173
|
+
* Assign somebody to one occurrence.
|
|
174
|
+
*/
|
|
175
|
+
|
|
176
|
+
export function useAssignScheduleOccurrence(
|
|
177
|
+
params: UseMutationParams = {},
|
|
178
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
179
|
+
) {
|
|
180
|
+
const [assignScheduleOccurrence, mtnValues, mtnHandlers, updateObservers] =
|
|
181
|
+
useMutation(assignScheduleOccurrenceMtn, { openModalPopUp, ...params });
|
|
182
|
+
|
|
183
|
+
return {
|
|
184
|
+
assignScheduleOccurrence,
|
|
185
|
+
updateObservers,
|
|
186
|
+
...mtnValues,
|
|
187
|
+
...mtnHandlers,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/*
|
|
192
|
+
* Release one assignment, keeping the row as history.
|
|
193
|
+
*/
|
|
194
|
+
|
|
195
|
+
export function useReleaseScheduleAssignment(
|
|
196
|
+
params: UseMutationParams = {},
|
|
197
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
198
|
+
) {
|
|
199
|
+
const [releaseScheduleAssignment, mtnValues, mtnHandlers, updateObservers] =
|
|
200
|
+
useMutation(releaseScheduleAssignmentMtn, { openModalPopUp, ...params });
|
|
201
|
+
|
|
202
|
+
return {
|
|
203
|
+
releaseScheduleAssignment,
|
|
204
|
+
updateObservers,
|
|
205
|
+
...mtnValues,
|
|
206
|
+
...mtnHandlers,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/*
|
|
211
|
+
* Publish a window.
|
|
212
|
+
*
|
|
213
|
+
* Two-phase: the server re-evaluates and refuses on a blocking breach unless
|
|
214
|
+
* that exact violation key was acknowledged, so the caller sends back the keys
|
|
215
|
+
* it actually showed the publisher rather than a blanket override.
|
|
216
|
+
*/
|
|
217
|
+
|
|
218
|
+
export function usePublishSchedule(
|
|
219
|
+
params: UseMutationParams = {},
|
|
220
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
221
|
+
) {
|
|
222
|
+
const [publishSchedule, mtnValues, mtnHandlers, updateObservers] =
|
|
223
|
+
useMutation(publishScheduleMtn, { openModalPopUp, ...params });
|
|
224
|
+
|
|
225
|
+
return {
|
|
226
|
+
publishSchedule,
|
|
227
|
+
updateObservers,
|
|
228
|
+
...mtnValues,
|
|
229
|
+
...mtnHandlers,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/*
|
|
234
|
+
* Open a request (give away a shift, ask for time off, propose a swap).
|
|
235
|
+
*/
|
|
236
|
+
|
|
237
|
+
export function useCreateScheduleRequest(
|
|
238
|
+
params: UseMutationParams = {},
|
|
239
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
240
|
+
) {
|
|
241
|
+
const { onCompleted, ...rest } = params;
|
|
242
|
+
|
|
243
|
+
const [createScheduleRequest, mtnValues, mtnHandlers, updateObservers] =
|
|
244
|
+
useMutation(createScheduleRequestMtn, {
|
|
245
|
+
openModalPopUp,
|
|
246
|
+
onCompleted: (data: any, error: any, variables: any) => {
|
|
247
|
+
patchRequestFragment(data?.createScheduleRequest, updateObservers);
|
|
248
|
+
onCompleted?.(data?.createScheduleRequest, error, variables);
|
|
249
|
+
},
|
|
250
|
+
...rest,
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
return {
|
|
254
|
+
createScheduleRequest,
|
|
255
|
+
updateObservers,
|
|
256
|
+
...mtnValues,
|
|
257
|
+
...mtnHandlers,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/*
|
|
262
|
+
* Claim an open shift.
|
|
263
|
+
*
|
|
264
|
+
* First accept wins. A losing claimant gets error 20154, which is an ORDINARY
|
|
265
|
+
* outcome — somebody took the shift a moment ago — so callers should report it
|
|
266
|
+
* as news rather than as a failure.
|
|
267
|
+
*/
|
|
268
|
+
|
|
269
|
+
export function useClaimScheduleRequest(
|
|
270
|
+
params: UseMutationParams = {},
|
|
271
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
272
|
+
) {
|
|
273
|
+
const { onCompleted, ...rest } = params;
|
|
274
|
+
|
|
275
|
+
const [claimScheduleRequest, mtnValues, mtnHandlers, updateObservers] =
|
|
276
|
+
useMutation(claimScheduleRequestMtn, {
|
|
277
|
+
openModalPopUp,
|
|
278
|
+
onCompleted: (data: any, error: any, variables: any) => {
|
|
279
|
+
patchRequestFragment(data?.claimScheduleRequest, updateObservers);
|
|
280
|
+
onCompleted?.(data?.claimScheduleRequest, error, variables);
|
|
281
|
+
},
|
|
282
|
+
...rest,
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
return {
|
|
286
|
+
claimScheduleRequest,
|
|
287
|
+
updateObservers,
|
|
288
|
+
...mtnValues,
|
|
289
|
+
...mtnHandlers,
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/*
|
|
294
|
+
* Decline one swap, as the colleague it was addressed to.
|
|
295
|
+
*/
|
|
296
|
+
|
|
297
|
+
export function useDeclineScheduleRequest(
|
|
298
|
+
params: UseMutationParams = {},
|
|
299
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
300
|
+
) {
|
|
301
|
+
const { onCompleted, ...rest } = params;
|
|
302
|
+
|
|
303
|
+
const [declineScheduleRequest, mtnValues, mtnHandlers, updateObservers] =
|
|
304
|
+
useMutation(declineScheduleRequestMtn, {
|
|
305
|
+
openModalPopUp,
|
|
306
|
+
onCompleted: (data: any, error: any, variables: any) => {
|
|
307
|
+
patchRequestFragment(data?.declineScheduleRequest, updateObservers);
|
|
308
|
+
onCompleted?.(data?.declineScheduleRequest, error, variables);
|
|
309
|
+
},
|
|
310
|
+
...rest,
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
return {
|
|
314
|
+
declineScheduleRequest,
|
|
315
|
+
updateObservers,
|
|
316
|
+
...mtnValues,
|
|
317
|
+
...mtnHandlers,
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/*
|
|
322
|
+
* Withdraw one's own request.
|
|
323
|
+
*/
|
|
324
|
+
|
|
325
|
+
export function useWithdrawScheduleRequest(
|
|
326
|
+
params: UseMutationParams = {},
|
|
327
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
328
|
+
) {
|
|
329
|
+
const { onCompleted, ...rest } = params;
|
|
330
|
+
|
|
331
|
+
const [withdrawScheduleRequest, mtnValues, mtnHandlers, updateObservers] =
|
|
332
|
+
useMutation(withdrawScheduleRequestMtn, {
|
|
333
|
+
openModalPopUp,
|
|
334
|
+
onCompleted: (data: any, error: any, variables: any) => {
|
|
335
|
+
patchRequestFragment(data?.withdrawScheduleRequest, updateObservers);
|
|
336
|
+
onCompleted?.(data?.withdrawScheduleRequest, error, variables);
|
|
337
|
+
},
|
|
338
|
+
...rest,
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
return {
|
|
342
|
+
withdrawScheduleRequest,
|
|
343
|
+
updateObservers,
|
|
344
|
+
...mtnValues,
|
|
345
|
+
...mtnHandlers,
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/*
|
|
350
|
+
* Approve or deny one request.
|
|
351
|
+
*/
|
|
352
|
+
|
|
353
|
+
export function useDecideScheduleRequest(
|
|
354
|
+
params: UseMutationParams = {},
|
|
355
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
356
|
+
) {
|
|
357
|
+
const { onCompleted, ...rest } = params;
|
|
358
|
+
|
|
359
|
+
const [decideScheduleRequest, mtnValues, mtnHandlers, updateObservers] =
|
|
360
|
+
useMutation(decideScheduleRequestMtn, {
|
|
361
|
+
openModalPopUp,
|
|
362
|
+
onCompleted: (data: any, error: any, variables: any) => {
|
|
363
|
+
patchRequestFragment(data?.decideScheduleRequest, updateObservers);
|
|
364
|
+
onCompleted?.(data?.decideScheduleRequest, error, variables);
|
|
365
|
+
},
|
|
366
|
+
...rest,
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
return {
|
|
370
|
+
decideScheduleRequest,
|
|
371
|
+
updateObservers,
|
|
372
|
+
...mtnValues,
|
|
373
|
+
...mtnHandlers,
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/*
|
|
378
|
+
* Issue one calendar subscription token.
|
|
379
|
+
*
|
|
380
|
+
* The raw token comes back exactly once — only a hash is stored — so the
|
|
381
|
+
* caller must show it immediately or the subscription is unusable.
|
|
382
|
+
*/
|
|
383
|
+
|
|
384
|
+
export function useCreateScheduleFeedToken(
|
|
385
|
+
params: UseMutationParams = {},
|
|
386
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
387
|
+
) {
|
|
388
|
+
const [createScheduleFeedToken, mtnValues, mtnHandlers, updateObservers] =
|
|
389
|
+
useMutation(createScheduleFeedTokenMtn, { openModalPopUp, ...params });
|
|
390
|
+
|
|
391
|
+
return {
|
|
392
|
+
createScheduleFeedToken,
|
|
393
|
+
updateObservers,
|
|
394
|
+
...mtnValues,
|
|
395
|
+
...mtnHandlers,
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/*
|
|
400
|
+
* Revoke one calendar subscription token.
|
|
401
|
+
*/
|
|
402
|
+
|
|
403
|
+
export function useRevokeScheduleFeedToken(
|
|
404
|
+
params: UseMutationParams = {},
|
|
405
|
+
openModalPopUp?: OpenModalPopUpFn,
|
|
406
|
+
) {
|
|
407
|
+
const [revokeScheduleFeedToken, mtnValues, mtnHandlers, updateObservers] =
|
|
408
|
+
useMutation(revokeScheduleFeedTokenMtn, { openModalPopUp, ...params });
|
|
409
|
+
|
|
410
|
+
return {
|
|
411
|
+
revokeScheduleFeedToken,
|
|
412
|
+
updateObservers,
|
|
413
|
+
...mtnValues,
|
|
414
|
+
...mtnHandlers,
|
|
415
|
+
};
|
|
416
|
+
}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { useQuery } from '@jsb188/graphql/client';
|
|
2
|
+
import {
|
|
3
|
+
scheduleCalendarsQry,
|
|
4
|
+
scheduleEvaluationQry,
|
|
5
|
+
scheduleOccurrencesQry,
|
|
6
|
+
scheduleRequestsQry,
|
|
7
|
+
} from '../gql/queries/scheduleQueries.ts';
|
|
8
|
+
import type { UseQueryParams } from '../types.d.ts';
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
* Fetch the calendars one organization can see, optionally including the ones
|
|
12
|
+
* its network shares with it.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export function useScheduleCalendars(
|
|
16
|
+
organizationId?: string | null,
|
|
17
|
+
includeNetwork?: boolean,
|
|
18
|
+
params: UseQueryParams = {},
|
|
19
|
+
) {
|
|
20
|
+
const { data, ...rest } = useQuery(scheduleCalendarsQry, {
|
|
21
|
+
variables: {
|
|
22
|
+
organizationId,
|
|
23
|
+
includeNetwork: !!includeNetwork,
|
|
24
|
+
},
|
|
25
|
+
...params,
|
|
26
|
+
skip: !organizationId || !!params.skip,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
...rest,
|
|
31
|
+
scheduleCalendars: data?.scheduleCalendars || null,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/*
|
|
36
|
+
* Fetch every occurrence overlapping one window on one calendar.
|
|
37
|
+
*
|
|
38
|
+
* Deliberately one calendar per call rather than a list: the realtime reset
|
|
39
|
+
* key matches on an exact per-variable value, so a change on one calendar
|
|
40
|
+
* leaves every other overlaid calendar's cached window untouched. A page
|
|
41
|
+
* showing three calendars runs three of these.
|
|
42
|
+
*
|
|
43
|
+
* The window bounds are passed as ISO strings so the cache key is stable —
|
|
44
|
+
* two Date objects for the same instant are different cache keys.
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
export function useScheduleOccurrences(
|
|
48
|
+
p: {
|
|
49
|
+
organizationId?: string | null;
|
|
50
|
+
calendarId?: string | null;
|
|
51
|
+
fromISO?: string | null;
|
|
52
|
+
toISO?: string | null;
|
|
53
|
+
publishedOnly?: boolean;
|
|
54
|
+
mineOnly?: boolean;
|
|
55
|
+
limit?: number | null;
|
|
56
|
+
},
|
|
57
|
+
params: UseQueryParams = {},
|
|
58
|
+
) {
|
|
59
|
+
const { data, ...rest } = useQuery(scheduleOccurrencesQry, {
|
|
60
|
+
variables: {
|
|
61
|
+
organizationId: p.organizationId,
|
|
62
|
+
calendarId: p.calendarId,
|
|
63
|
+
from: p.fromISO,
|
|
64
|
+
to: p.toISO,
|
|
65
|
+
publishedOnly: !!p.publishedOnly,
|
|
66
|
+
mineOnly: !!p.mineOnly,
|
|
67
|
+
limit: p.limit ?? null,
|
|
68
|
+
},
|
|
69
|
+
...params,
|
|
70
|
+
skip:
|
|
71
|
+
!p.organizationId ||
|
|
72
|
+
!p.calendarId ||
|
|
73
|
+
!p.fromISO ||
|
|
74
|
+
!p.toISO ||
|
|
75
|
+
!!params.skip,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
...rest,
|
|
80
|
+
scheduleOccurrences: data?.scheduleOccurrences || null,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/*
|
|
85
|
+
* Evaluate one calendar window for constraint breaches.
|
|
86
|
+
*
|
|
87
|
+
* Never cached: the entire value of this query is that it reflects the
|
|
88
|
+
* schedule as it stands right now, so a stale verdict is worse than no
|
|
89
|
+
* verdict — it would tell a manager the roster is legal after somebody else
|
|
90
|
+
* broke it.
|
|
91
|
+
*/
|
|
92
|
+
|
|
93
|
+
export function useScheduleEvaluation(
|
|
94
|
+
p: {
|
|
95
|
+
organizationId?: string | null;
|
|
96
|
+
calendarId?: string | null;
|
|
97
|
+
fromISO?: string | null;
|
|
98
|
+
toISO?: string | null;
|
|
99
|
+
},
|
|
100
|
+
params: UseQueryParams = {},
|
|
101
|
+
) {
|
|
102
|
+
const { data, ...rest } = useQuery(scheduleEvaluationQry, {
|
|
103
|
+
variables: {
|
|
104
|
+
organizationId: p.organizationId,
|
|
105
|
+
calendarId: p.calendarId,
|
|
106
|
+
from: p.fromISO,
|
|
107
|
+
to: p.toISO,
|
|
108
|
+
},
|
|
109
|
+
...params,
|
|
110
|
+
skip:
|
|
111
|
+
!p.organizationId ||
|
|
112
|
+
!p.calendarId ||
|
|
113
|
+
!p.fromISO ||
|
|
114
|
+
!p.toISO ||
|
|
115
|
+
!!params.skip,
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
...rest,
|
|
120
|
+
scheduleEvaluation: data?.scheduleEvaluation || null,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/*
|
|
125
|
+
* Fetch schedule requests: the approval queue, one's own, or the open shifts
|
|
126
|
+
* offered to the viewer.
|
|
127
|
+
*/
|
|
128
|
+
|
|
129
|
+
export function useScheduleRequests(
|
|
130
|
+
p: {
|
|
131
|
+
organizationId?: string | null;
|
|
132
|
+
calendarId?: string | null;
|
|
133
|
+
statuses?: string[] | null;
|
|
134
|
+
mineOnly?: boolean;
|
|
135
|
+
offeredToMe?: boolean;
|
|
136
|
+
limit?: number | null;
|
|
137
|
+
},
|
|
138
|
+
params: UseQueryParams = {},
|
|
139
|
+
) {
|
|
140
|
+
const { data, ...rest } = useQuery(scheduleRequestsQry, {
|
|
141
|
+
variables: {
|
|
142
|
+
organizationId: p.organizationId,
|
|
143
|
+
calendarId: p.calendarId ?? null,
|
|
144
|
+
statuses: p.statuses ?? null,
|
|
145
|
+
mineOnly: !!p.mineOnly,
|
|
146
|
+
offeredToMe: !!p.offeredToMe,
|
|
147
|
+
limit: p.limit ?? null,
|
|
148
|
+
},
|
|
149
|
+
...params,
|
|
150
|
+
skip: !p.organizationId || !!params.skip,
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
return {
|
|
154
|
+
...rest,
|
|
155
|
+
scheduleRequests: data?.scheduleRequests || null,
|
|
156
|
+
};
|
|
157
|
+
}
|