@go-avro/avro-js 0.0.42 → 0.0.44
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/auth/AuthManager.d.ts +3 -3
- package/dist/auth/AuthManager.js +24 -24
- package/dist/auth/storage.d.ts +1 -1
- package/dist/auth/storage.js +3 -3
- package/dist/client/AvroQueryClientProvider.d.ts +4 -4
- package/dist/client/AvroQueryClientProvider.js +3 -3
- package/dist/client/QueryClient.d.ts +15 -15
- package/dist/client/QueryClient.js +239 -259
- package/dist/client/core/fetch.js +9 -9
- package/dist/client/core/utils.js +4 -4
- package/dist/client/core/xhr.js +21 -21
- package/dist/client/hooks/analytics.js +12 -12
- package/dist/client/hooks/avro.js +4 -4
- package/dist/client/hooks/bills.js +36 -39
- package/dist/client/hooks/catalog_items.js +25 -31
- package/dist/client/hooks/chats.js +6 -6
- package/dist/client/hooks/companies.js +45 -57
- package/dist/client/hooks/email.d.ts +3 -3
- package/dist/client/hooks/email.js +5 -5
- package/dist/client/hooks/events.js +71 -81
- package/dist/client/hooks/groups.js +25 -31
- package/dist/client/hooks/jobs.js +29 -34
- package/dist/client/hooks/labels.js +25 -31
- package/dist/client/hooks/messages.js +7 -7
- package/dist/client/hooks/months.js +21 -21
- package/dist/client/hooks/plans.js +4 -4
- package/dist/client/hooks/prepayments.js +21 -21
- package/dist/client/hooks/proposal.js +11 -11
- package/dist/client/hooks/root.js +4 -4
- package/dist/client/hooks/routes.js +42 -53
- package/dist/client/hooks/sessions.js +33 -45
- package/dist/client/hooks/skills.js +22 -28
- package/dist/client/hooks/teams.js +26 -32
- package/dist/client/hooks/timecards.js +13 -13
- package/dist/client/hooks/users.js +39 -42
- package/dist/client/hooks/waivers.js +23 -23
- package/dist/index.d.ts +38 -38
- package/dist/index.js +37 -37
- package/dist/types/api/AdditionalCharge.d.ts +2 -2
- package/dist/types/api/Avro.d.ts +1 -1
- package/dist/types/api/Bill.d.ts +4 -4
- package/dist/types/api/Bill.js +4 -4
- package/dist/types/api/BillPayment.d.ts +2 -2
- package/dist/types/api/BillUser.d.ts +1 -1
- package/dist/types/api/CatalogItem.d.ts +1 -1
- package/dist/types/api/Chat.d.ts +2 -2
- package/dist/types/api/Company.d.ts +12 -12
- package/dist/types/api/CustomLineItem.d.ts +2 -2
- package/dist/types/api/Email.d.ts +2 -2
- package/dist/types/api/EmailNotification.d.ts +2 -2
- package/dist/types/api/Group.d.ts +1 -1
- package/dist/types/api/Job.d.ts +6 -6
- package/dist/types/api/Job.js +12 -12
- package/dist/types/api/LineItem.d.ts +1 -1
- package/dist/types/api/LineItem.js +12 -12
- package/dist/types/api/MemberState.d.ts +1 -1
- package/dist/types/api/Message.d.ts +1 -1
- package/dist/types/api/PaymentMethod.d.ts +1 -1
- package/dist/types/api/PaymentOption.d.ts +1 -1
- package/dist/types/api/PaymentType.js +2 -2
- package/dist/types/api/PlanPayment.d.ts +1 -1
- package/dist/types/api/Prepayment.d.ts +4 -4
- package/dist/types/api/Prepayment.js +1 -1
- package/dist/types/api/Route.d.ts +2 -2
- package/dist/types/api/Route.js +7 -7
- package/dist/types/api/RouteJob.d.ts +1 -1
- package/dist/types/api/ServiceMonth.d.ts +2 -2
- package/dist/types/api/Session.d.ts +2 -2
- package/dist/types/api/Task.d.ts +7 -7
- package/dist/types/api/Task.js +20 -22
- package/dist/types/api/Timecard.d.ts +1 -1
- package/dist/types/api/Timecard.js +4 -4
- package/dist/types/api/TimecardAction.js +6 -6
- package/dist/types/api/User.d.ts +4 -4
- package/dist/types/api/UserCompanyAssociation.d.ts +2 -2
- package/dist/types/api/UserCompanyAssociation.js +45 -45
- package/dist/types/api/_Event.d.ts +5 -5
- package/dist/types/api/_Event.js +1 -1
- package/dist/types/api.d.ts +44 -44
- package/dist/types/api.js +42 -42
- package/dist/types/cache.d.ts +1 -1
- package/dist/types/client.d.ts +1 -1
- package/package.json +2 -1
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { useInfiniteQuery, useQuery, useMutation } from
|
|
2
|
-
import { AvroQueryClient } from
|
|
3
|
-
import { _Event, Job, LineItemStatus } from
|
|
1
|
+
import { useInfiniteQuery, useQuery, useMutation } from '@tanstack/react-query';
|
|
2
|
+
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
|
+
import { _Event, Job, LineItemStatus } from '../../types/api';
|
|
4
4
|
/** Predicate that matches all 'jobs' queries (list and individual, but NOT 'infinite'). */
|
|
5
|
-
const isJobsQuery = (q) => q.queryKey[0] ===
|
|
5
|
+
const isJobsQuery = (q) => q.queryKey[0] === 'jobs';
|
|
6
6
|
/** Predicate that matches all 'events' queries (list and individual). */
|
|
7
|
-
const isEventsQuery = (q) => q.queryKey[0] ===
|
|
7
|
+
const isEventsQuery = (q) => q.queryKey[0] === 'events';
|
|
8
8
|
AvroQueryClient.prototype.useGetEvents = function (body) {
|
|
9
9
|
const queryClient = this.getQueryClient();
|
|
10
10
|
const result = useInfiniteQuery({
|
|
11
11
|
queryKey: [
|
|
12
|
-
|
|
12
|
+
'events',
|
|
13
13
|
this.companyId,
|
|
14
14
|
body.amt ?? 50,
|
|
15
15
|
body.known_ids ?? [],
|
|
16
16
|
body.unknown_ids ?? [],
|
|
17
|
-
body.query ??
|
|
17
|
+
body.query ?? '',
|
|
18
18
|
body.unbilled ?? true,
|
|
19
19
|
body.billed ?? true,
|
|
20
20
|
body.paid ?? true,
|
|
21
|
-
body.jobId ??
|
|
21
|
+
body.jobId ?? '',
|
|
22
22
|
body.enabled ?? true,
|
|
23
23
|
],
|
|
24
24
|
initialPageParam: 0,
|
|
@@ -37,7 +37,7 @@ AvroQueryClient.prototype.useGetEvents = function (body) {
|
|
|
37
37
|
if (result.data) {
|
|
38
38
|
result.data.pages.forEach((data_page) => {
|
|
39
39
|
data_page.forEach((event) => {
|
|
40
|
-
queryClient.setQueryData([
|
|
40
|
+
queryClient.setQueryData(['events', event.id], event);
|
|
41
41
|
});
|
|
42
42
|
});
|
|
43
43
|
}
|
|
@@ -45,7 +45,7 @@ AvroQueryClient.prototype.useGetEvents = function (body) {
|
|
|
45
45
|
};
|
|
46
46
|
AvroQueryClient.prototype.useGetEvent = function (eventId) {
|
|
47
47
|
return useQuery({
|
|
48
|
-
queryKey: [
|
|
48
|
+
queryKey: ['events', eventId],
|
|
49
49
|
queryFn: () => this.get({ path: `/event/${eventId}` }).then((event) => new _Event(event)),
|
|
50
50
|
enabled: Boolean(eventId),
|
|
51
51
|
});
|
|
@@ -57,13 +57,13 @@ AvroQueryClient.prototype.useCreateEvent = function () {
|
|
|
57
57
|
return this.post({
|
|
58
58
|
path: `/company/${this.companyId}/event`,
|
|
59
59
|
data: JSON.stringify(eventData),
|
|
60
|
-
headers: {
|
|
60
|
+
headers: { 'Content-Type': 'application/json' },
|
|
61
61
|
});
|
|
62
62
|
},
|
|
63
63
|
onMutate: async ({ eventData }) => {
|
|
64
|
-
await queryClient.cancelQueries({ queryKey: [
|
|
64
|
+
await queryClient.cancelQueries({ queryKey: ['events'] });
|
|
65
65
|
const previousJob = queryClient.getQueryData([
|
|
66
|
-
|
|
66
|
+
'jobs',
|
|
67
67
|
eventData.job_id,
|
|
68
68
|
]);
|
|
69
69
|
const optimisticEvent = new _Event({
|
|
@@ -79,7 +79,7 @@ AvroQueryClient.prototype.useCreateEvent = function () {
|
|
|
79
79
|
? optimisticEvent
|
|
80
80
|
: previousJob.last_completed_event,
|
|
81
81
|
tasks: previousJob.tasks.map((task) => {
|
|
82
|
-
if (eventData.tasks?.includes(task.id ??
|
|
82
|
+
if (eventData.tasks?.includes(task.id ?? '')) {
|
|
83
83
|
return {
|
|
84
84
|
...task,
|
|
85
85
|
current_event: optimisticEvent,
|
|
@@ -92,28 +92,25 @@ AvroQueryClient.prototype.useCreateEvent = function () {
|
|
|
92
92
|
}),
|
|
93
93
|
});
|
|
94
94
|
// Update individual job cache AND every active jobs list/query
|
|
95
|
-
queryClient.setQueriesData({ predicate: isJobsQuery, type:
|
|
95
|
+
queryClient.setQueriesData({ predicate: isJobsQuery, type: 'active' }, (old) => {
|
|
96
96
|
if (!old)
|
|
97
97
|
return old;
|
|
98
98
|
if (Array.isArray(old))
|
|
99
|
-
return old.map((j) => j?.id === updatedJob.id ? updatedJob : j);
|
|
99
|
+
return old.map((j) => (j?.id === updatedJob.id ? updatedJob : j));
|
|
100
100
|
if (old?.id === updatedJob.id)
|
|
101
101
|
return updatedJob;
|
|
102
102
|
return old;
|
|
103
103
|
});
|
|
104
104
|
}
|
|
105
105
|
// Add optimistic event to all active events queries
|
|
106
|
-
queryClient.setQueriesData({ predicate: isEventsQuery, type:
|
|
106
|
+
queryClient.setQueriesData({ predicate: isEventsQuery, type: 'active' }, (oldData) => {
|
|
107
107
|
if (!oldData)
|
|
108
108
|
return oldData;
|
|
109
109
|
if (oldData.pages) {
|
|
110
110
|
const firstPage = oldData.pages[0] || [];
|
|
111
111
|
return {
|
|
112
112
|
...oldData,
|
|
113
|
-
pages: [
|
|
114
|
-
[optimisticEvent, ...firstPage],
|
|
115
|
-
...oldData.pages.slice(1),
|
|
116
|
-
],
|
|
113
|
+
pages: [[optimisticEvent, ...firstPage], ...oldData.pages.slice(1)],
|
|
117
114
|
};
|
|
118
115
|
}
|
|
119
116
|
if (Array.isArray(oldData)) {
|
|
@@ -125,15 +122,15 @@ AvroQueryClient.prototype.useCreateEvent = function () {
|
|
|
125
122
|
},
|
|
126
123
|
onSuccess: async (result, { eventData }) => {
|
|
127
124
|
const item = await this._syncEntity(queryClient, {
|
|
128
|
-
action:
|
|
129
|
-
entityKey:
|
|
125
|
+
action: 'create',
|
|
126
|
+
entityKey: 'events',
|
|
130
127
|
id: result.id,
|
|
131
128
|
fetchPath: `/event/${result.id}`,
|
|
132
129
|
});
|
|
133
130
|
if (eventData.job_id) {
|
|
134
131
|
await this._syncEntity(queryClient, {
|
|
135
|
-
action:
|
|
136
|
-
entityKey:
|
|
132
|
+
action: 'update',
|
|
133
|
+
entityKey: 'jobs',
|
|
137
134
|
id: eventData.job_id,
|
|
138
135
|
fetchPath: `/job/${eventData.job_id}`,
|
|
139
136
|
construct: (d) => new Job(d),
|
|
@@ -143,7 +140,7 @@ AvroQueryClient.prototype.useCreateEvent = function () {
|
|
|
143
140
|
onError: (err, variables, context) => {
|
|
144
141
|
// Restore individual job; invalidate lists to refetch clean state
|
|
145
142
|
if (context?.previousJob) {
|
|
146
|
-
queryClient.setQueryData([
|
|
143
|
+
queryClient.setQueryData(['jobs', context.previousJob.id], context.previousJob);
|
|
147
144
|
}
|
|
148
145
|
queryClient.invalidateQueries({ predicate: isJobsQuery });
|
|
149
146
|
queryClient.invalidateQueries({ predicate: isEventsQuery });
|
|
@@ -153,21 +150,18 @@ AvroQueryClient.prototype.useCreateEvent = function () {
|
|
|
153
150
|
AvroQueryClient.prototype.useUpdateEvent = function () {
|
|
154
151
|
const queryClient = this.getQueryClient();
|
|
155
152
|
return useMutation({
|
|
156
|
-
mutationFn: ({ eventId, updates
|
|
153
|
+
mutationFn: ({ eventId, updates }) => {
|
|
157
154
|
return this.put({
|
|
158
155
|
path: `/event/${eventId}`,
|
|
159
156
|
data: JSON.stringify(updates),
|
|
160
|
-
headers: {
|
|
157
|
+
headers: { 'Content-Type': 'application/json' },
|
|
161
158
|
});
|
|
162
159
|
},
|
|
163
160
|
onMutate: async ({ eventId, updates }) => {
|
|
164
|
-
await queryClient.cancelQueries({ queryKey: [
|
|
165
|
-
await queryClient.cancelQueries({ queryKey: [
|
|
161
|
+
await queryClient.cancelQueries({ queryKey: ['events', eventId] });
|
|
162
|
+
await queryClient.cancelQueries({ queryKey: ['events'] });
|
|
166
163
|
// Try individual cache first; fall back to scanning all active events queries
|
|
167
|
-
let previousEvent = queryClient.getQueryData([
|
|
168
|
-
"events",
|
|
169
|
-
eventId,
|
|
170
|
-
]);
|
|
164
|
+
let previousEvent = queryClient.getQueryData(['events', eventId]);
|
|
171
165
|
if (!previousEvent) {
|
|
172
166
|
const allEventsData = queryClient.getQueriesData({
|
|
173
167
|
predicate: isEventsQuery,
|
|
@@ -187,7 +181,7 @@ AvroQueryClient.prototype.useUpdateEvent = function () {
|
|
|
187
181
|
}
|
|
188
182
|
}
|
|
189
183
|
const previousJob = queryClient.getQueryData([
|
|
190
|
-
|
|
184
|
+
'jobs',
|
|
191
185
|
previousEvent?.job_id,
|
|
192
186
|
]);
|
|
193
187
|
if (previousJob) {
|
|
@@ -197,14 +191,10 @@ AvroQueryClient.prototype.useUpdateEvent = function () {
|
|
|
197
191
|
: null;
|
|
198
192
|
const updatedJob = new Job({
|
|
199
193
|
...previousJob,
|
|
200
|
-
current_event: isEnding
|
|
201
|
-
|
|
202
|
-
: (mergedEvent ?? previousJob.current_event),
|
|
203
|
-
last_completed_event: isEnding && mergedEvent
|
|
204
|
-
? mergedEvent
|
|
205
|
-
: previousJob.last_completed_event,
|
|
194
|
+
current_event: isEnding ? null : (mergedEvent ?? previousJob.current_event),
|
|
195
|
+
last_completed_event: isEnding && mergedEvent ? mergedEvent : previousJob.last_completed_event,
|
|
206
196
|
tasks: previousJob.tasks.map((task) => {
|
|
207
|
-
if (updates.tasks?.includes(task.id ??
|
|
197
|
+
if (updates.tasks?.includes(task.id ?? '')) {
|
|
208
198
|
return {
|
|
209
199
|
...task,
|
|
210
200
|
current_event: isEnding
|
|
@@ -225,18 +215,18 @@ AvroQueryClient.prototype.useUpdateEvent = function () {
|
|
|
225
215
|
return task;
|
|
226
216
|
}),
|
|
227
217
|
});
|
|
228
|
-
queryClient.setQueriesData({ predicate: isJobsQuery, type:
|
|
218
|
+
queryClient.setQueriesData({ predicate: isJobsQuery, type: 'active' }, (old) => {
|
|
229
219
|
if (!old)
|
|
230
220
|
return old;
|
|
231
221
|
if (Array.isArray(old))
|
|
232
|
-
return old.map((j) => j?.id === updatedJob.id ? updatedJob : j);
|
|
222
|
+
return old.map((j) => (j?.id === updatedJob.id ? updatedJob : j));
|
|
233
223
|
if (old?.id === updatedJob.id)
|
|
234
224
|
return updatedJob;
|
|
235
225
|
return old;
|
|
236
226
|
});
|
|
237
227
|
}
|
|
238
|
-
queryClient.setQueryData([
|
|
239
|
-
queryClient.setQueriesData({ queryKey: [
|
|
228
|
+
queryClient.setQueryData(['events', eventId], (oldData) => oldData ? { ...oldData, ...updates } : undefined);
|
|
229
|
+
queryClient.setQueriesData({ queryKey: ['events'] }, (oldData) => {
|
|
240
230
|
if (!oldData)
|
|
241
231
|
return oldData;
|
|
242
232
|
if (oldData.pages) {
|
|
@@ -252,15 +242,15 @@ AvroQueryClient.prototype.useUpdateEvent = function () {
|
|
|
252
242
|
},
|
|
253
243
|
onSuccess: async (_result, { eventId }) => {
|
|
254
244
|
const item = await this._syncEntity(queryClient, {
|
|
255
|
-
action:
|
|
256
|
-
entityKey:
|
|
245
|
+
action: 'update',
|
|
246
|
+
entityKey: 'events',
|
|
257
247
|
id: eventId,
|
|
258
248
|
fetchPath: `/event/${eventId}`,
|
|
259
249
|
});
|
|
260
250
|
if (item?.job_id) {
|
|
261
251
|
await this._syncEntity(queryClient, {
|
|
262
|
-
action:
|
|
263
|
-
entityKey:
|
|
252
|
+
action: 'update',
|
|
253
|
+
entityKey: 'jobs',
|
|
264
254
|
id: item.job_id,
|
|
265
255
|
fetchPath: `/job/${item.job_id}`,
|
|
266
256
|
construct: (d) => new Job(d),
|
|
@@ -270,10 +260,10 @@ AvroQueryClient.prototype.useUpdateEvent = function () {
|
|
|
270
260
|
onError: (_err, variables, context) => {
|
|
271
261
|
const { eventId } = variables;
|
|
272
262
|
if (context?.previousEvent) {
|
|
273
|
-
queryClient.setQueryData([
|
|
263
|
+
queryClient.setQueryData(['events', eventId], context.previousEvent);
|
|
274
264
|
}
|
|
275
265
|
if (context?.previousJob) {
|
|
276
|
-
queryClient.setQueryData([
|
|
266
|
+
queryClient.setQueryData(['jobs', context.previousJob.id], context.previousJob);
|
|
277
267
|
}
|
|
278
268
|
queryClient.invalidateQueries({ predicate: isJobsQuery });
|
|
279
269
|
queryClient.invalidateQueries({ predicate: isEventsQuery });
|
|
@@ -290,27 +280,27 @@ AvroQueryClient.prototype.useUpdateEvents = function () {
|
|
|
290
280
|
data: JSON.stringify({
|
|
291
281
|
events: eventIds,
|
|
292
282
|
billed: true,
|
|
293
|
-
status: action ===
|
|
283
|
+
status: action === 'billed'
|
|
294
284
|
? LineItemStatus.EXTERNALLY_BILLED
|
|
295
285
|
: LineItemStatus.EXTERNALLY_PAID,
|
|
296
286
|
}),
|
|
297
|
-
headers: {
|
|
287
|
+
headers: { 'Content-Type': 'application/json' },
|
|
298
288
|
});
|
|
299
289
|
},
|
|
300
290
|
onMutate: async ({ events, action }) => {
|
|
301
|
-
await queryClient.cancelQueries({ queryKey: [
|
|
302
|
-
await queryClient.cancelQueries({ queryKey: [
|
|
303
|
-
const previousEvents = queryClient.getQueryData([
|
|
304
|
-
const previousEventObjs = events.map((event) => queryClient.getQueryData([
|
|
291
|
+
await queryClient.cancelQueries({ queryKey: ['events'] });
|
|
292
|
+
await queryClient.cancelQueries({ queryKey: ['events'] });
|
|
293
|
+
const previousEvents = queryClient.getQueryData(['events']);
|
|
294
|
+
const previousEventObjs = events.map((event) => queryClient.getQueryData(['events', event.id]));
|
|
305
295
|
const eventIds = events.map((event) => event.id);
|
|
306
296
|
// Optimistically update individual event cache
|
|
307
297
|
eventIds.forEach((eventId, idx) => {
|
|
308
|
-
queryClient.setQueryData([
|
|
298
|
+
queryClient.setQueryData(['events', eventId], (oldData) => {
|
|
309
299
|
return oldData
|
|
310
300
|
? {
|
|
311
301
|
...oldData,
|
|
312
302
|
billed: true,
|
|
313
|
-
status: action ===
|
|
303
|
+
status: action === 'billed'
|
|
314
304
|
? LineItemStatus.EXTERNALLY_BILLED
|
|
315
305
|
: LineItemStatus.EXTERNALLY_PAID,
|
|
316
306
|
}
|
|
@@ -318,7 +308,7 @@ AvroQueryClient.prototype.useUpdateEvents = function () {
|
|
|
318
308
|
});
|
|
319
309
|
});
|
|
320
310
|
// Optimistically update events list cache
|
|
321
|
-
queryClient.setQueriesData({ queryKey: [
|
|
311
|
+
queryClient.setQueriesData({ queryKey: ['events'] }, (oldData) => {
|
|
322
312
|
if (!oldData)
|
|
323
313
|
return oldData;
|
|
324
314
|
if (oldData.pages) {
|
|
@@ -326,7 +316,7 @@ AvroQueryClient.prototype.useUpdateEvents = function () {
|
|
|
326
316
|
? {
|
|
327
317
|
...event,
|
|
328
318
|
billed: true,
|
|
329
|
-
status: action ===
|
|
319
|
+
status: action === 'billed'
|
|
330
320
|
? LineItemStatus.EXTERNALLY_BILLED
|
|
331
321
|
: LineItemStatus.EXTERNALLY_PAID,
|
|
332
322
|
}
|
|
@@ -338,7 +328,7 @@ AvroQueryClient.prototype.useUpdateEvents = function () {
|
|
|
338
328
|
? {
|
|
339
329
|
...event,
|
|
340
330
|
billed: true,
|
|
341
|
-
status: action ===
|
|
331
|
+
status: action === 'billed'
|
|
342
332
|
? LineItemStatus.EXTERNALLY_BILLED
|
|
343
333
|
: LineItemStatus.EXTERNALLY_PAID,
|
|
344
334
|
}
|
|
@@ -349,15 +339,15 @@ AvroQueryClient.prototype.useUpdateEvents = function () {
|
|
|
349
339
|
return { previousEvents, previousEventObjs };
|
|
350
340
|
},
|
|
351
341
|
onSuccess: () => {
|
|
352
|
-
queryClient.invalidateQueries({ queryKey: [
|
|
342
|
+
queryClient.invalidateQueries({ queryKey: ['events'] });
|
|
353
343
|
},
|
|
354
344
|
onError: (err, variables, context) => {
|
|
355
345
|
if (context?.previousEvents) {
|
|
356
|
-
queryClient.setQueryData([
|
|
346
|
+
queryClient.setQueryData(['events'], context.previousEvents);
|
|
357
347
|
}
|
|
358
348
|
if (context?.previousEventObjs) {
|
|
359
349
|
context.previousEventObjs.forEach((eventObj) => {
|
|
360
|
-
queryClient.setQueryData([
|
|
350
|
+
queryClient.setQueryData(['events', eventObj.id], eventObj);
|
|
361
351
|
});
|
|
362
352
|
}
|
|
363
353
|
},
|
|
@@ -369,16 +359,16 @@ AvroQueryClient.prototype.useDeleteEvent = function () {
|
|
|
369
359
|
mutationFn: async ({ eventId }) => {
|
|
370
360
|
return this.delete({
|
|
371
361
|
path: `/event/${eventId}`,
|
|
372
|
-
headers: {
|
|
362
|
+
headers: { 'Content-Type': 'application/json' },
|
|
373
363
|
});
|
|
374
364
|
},
|
|
375
365
|
onMutate: async ({ eventId }) => {
|
|
376
|
-
await queryClient.cancelQueries({ queryKey: [
|
|
377
|
-
await queryClient.cancelQueries({ queryKey: [
|
|
378
|
-
const previousEvents = queryClient.getQueryData([
|
|
379
|
-
const previousEvent = queryClient.getQueryData([
|
|
380
|
-
queryClient.setQueryData([
|
|
381
|
-
queryClient.setQueriesData({ queryKey: [
|
|
366
|
+
await queryClient.cancelQueries({ queryKey: ['events'] });
|
|
367
|
+
await queryClient.cancelQueries({ queryKey: ['events', eventId] });
|
|
368
|
+
const previousEvents = queryClient.getQueryData(['events']);
|
|
369
|
+
const previousEvent = queryClient.getQueryData(['events', eventId]);
|
|
370
|
+
queryClient.setQueryData(['events', eventId], undefined);
|
|
371
|
+
queryClient.setQueriesData({ queryKey: ['events'] }, (oldData) => {
|
|
382
372
|
if (!oldData)
|
|
383
373
|
return oldData;
|
|
384
374
|
if (oldData.pages) {
|
|
@@ -394,16 +384,16 @@ AvroQueryClient.prototype.useDeleteEvent = function () {
|
|
|
394
384
|
},
|
|
395
385
|
onSuccess: async (_result, { eventId }, context) => {
|
|
396
386
|
await this._syncEntity(queryClient, {
|
|
397
|
-
action:
|
|
398
|
-
entityKey:
|
|
387
|
+
action: 'delete',
|
|
388
|
+
entityKey: 'events',
|
|
399
389
|
id: eventId,
|
|
400
390
|
});
|
|
401
|
-
const jobId = context
|
|
402
|
-
?.
|
|
391
|
+
const jobId = context?.previousEvent
|
|
392
|
+
?.job_id;
|
|
403
393
|
if (jobId) {
|
|
404
394
|
await this._syncEntity(queryClient, {
|
|
405
|
-
action:
|
|
406
|
-
entityKey:
|
|
395
|
+
action: 'update',
|
|
396
|
+
entityKey: 'jobs',
|
|
407
397
|
id: jobId,
|
|
408
398
|
fetchPath: `/job/${jobId}`,
|
|
409
399
|
construct: (d) => new Job(d),
|
|
@@ -413,10 +403,10 @@ AvroQueryClient.prototype.useDeleteEvent = function () {
|
|
|
413
403
|
onError: (_err, variables, context) => {
|
|
414
404
|
const { eventId } = variables;
|
|
415
405
|
if (context?.previousEvents) {
|
|
416
|
-
queryClient.setQueryData([
|
|
406
|
+
queryClient.setQueryData(['events'], context.previousEvents);
|
|
417
407
|
}
|
|
418
408
|
if (context?.previousEvent) {
|
|
419
|
-
queryClient.setQueryData([
|
|
409
|
+
queryClient.setQueryData(['events', eventId], context.previousEvent);
|
|
420
410
|
}
|
|
421
411
|
},
|
|
422
412
|
});
|
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
import { useMutation, useQuery } from
|
|
2
|
-
import { AvroQueryClient } from
|
|
1
|
+
import { useMutation, useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
3
|
AvroQueryClient.prototype.useGetGroups = function (body, total, onProgress) {
|
|
4
4
|
return useQuery({
|
|
5
|
-
queryKey: [
|
|
6
|
-
"groups",
|
|
7
|
-
this.companyId,
|
|
8
|
-
body.amt ?? 50,
|
|
9
|
-
body.query ?? "",
|
|
10
|
-
total ?? "all",
|
|
11
|
-
],
|
|
5
|
+
queryKey: ['groups', this.companyId, body.amt ?? 50, body.query ?? '', total ?? 'all'],
|
|
12
6
|
queryFn: async () => {
|
|
13
|
-
if (typeof total !==
|
|
7
|
+
if (typeof total !== 'number') {
|
|
14
8
|
return this.fetchGroups({ ...body, offset: 0 });
|
|
15
9
|
}
|
|
16
10
|
onProgress?.(0);
|
|
@@ -39,11 +33,11 @@ AvroQueryClient.prototype.useCreateGroup = function () {
|
|
|
39
33
|
return this.post({
|
|
40
34
|
path: `/company/${this.companyId}/group`,
|
|
41
35
|
data: JSON.stringify(groupData),
|
|
42
|
-
headers: {
|
|
36
|
+
headers: { 'Content-Type': 'application/json' },
|
|
43
37
|
});
|
|
44
38
|
},
|
|
45
39
|
onSuccess: () => {
|
|
46
|
-
queryClient.invalidateQueries({ queryKey: [
|
|
40
|
+
queryClient.invalidateQueries({ queryKey: ['groups'] });
|
|
47
41
|
},
|
|
48
42
|
});
|
|
49
43
|
};
|
|
@@ -54,20 +48,20 @@ AvroQueryClient.prototype.useUpdateGroup = function () {
|
|
|
54
48
|
return this.put({
|
|
55
49
|
path: `/group/${groupId}`,
|
|
56
50
|
data: JSON.stringify(groupData),
|
|
57
|
-
headers: {
|
|
51
|
+
headers: { 'Content-Type': 'application/json' },
|
|
58
52
|
});
|
|
59
53
|
},
|
|
60
54
|
onMutate: async ({ groupId, groupData }) => {
|
|
61
|
-
await queryClient.cancelQueries({ queryKey: [
|
|
62
|
-
await queryClient.cancelQueries({ queryKey: [
|
|
63
|
-
const previousGroups = queryClient.getQueryData([
|
|
64
|
-
const previousGroup = queryClient.getQueryData([
|
|
65
|
-
queryClient.setQueryData([
|
|
55
|
+
await queryClient.cancelQueries({ queryKey: ['groups'] });
|
|
56
|
+
await queryClient.cancelQueries({ queryKey: ['groups', groupId] });
|
|
57
|
+
const previousGroups = queryClient.getQueryData(['groups']);
|
|
58
|
+
const previousGroup = queryClient.getQueryData(['groups', groupId]);
|
|
59
|
+
queryClient.setQueryData(['groups', groupId], (oldData) => {
|
|
66
60
|
if (!oldData)
|
|
67
61
|
return oldData;
|
|
68
62
|
return { ...oldData, ...groupData };
|
|
69
63
|
});
|
|
70
|
-
queryClient.setQueriesData({ queryKey: [
|
|
64
|
+
queryClient.setQueriesData({ queryKey: ['groups'] }, (oldData) => {
|
|
71
65
|
if (!oldData)
|
|
72
66
|
return oldData;
|
|
73
67
|
if (oldData.pages) {
|
|
@@ -82,15 +76,15 @@ AvroQueryClient.prototype.useUpdateGroup = function () {
|
|
|
82
76
|
return { previousGroups, previousGroup };
|
|
83
77
|
},
|
|
84
78
|
onSuccess: () => {
|
|
85
|
-
queryClient.invalidateQueries({ queryKey: [
|
|
79
|
+
queryClient.invalidateQueries({ queryKey: ['groups'] });
|
|
86
80
|
},
|
|
87
81
|
onError: (_err, variables, context) => {
|
|
88
82
|
const { groupId } = variables;
|
|
89
83
|
if (context?.previousGroups) {
|
|
90
|
-
queryClient.setQueryData([
|
|
84
|
+
queryClient.setQueryData(['groups'], context.previousGroups);
|
|
91
85
|
}
|
|
92
86
|
if (context?.previousGroup) {
|
|
93
|
-
queryClient.setQueryData([
|
|
87
|
+
queryClient.setQueryData(['groups', groupId], context.previousGroup);
|
|
94
88
|
}
|
|
95
89
|
},
|
|
96
90
|
});
|
|
@@ -104,12 +98,12 @@ AvroQueryClient.prototype.useDeleteGroup = function () {
|
|
|
104
98
|
});
|
|
105
99
|
},
|
|
106
100
|
onMutate: async ({ groupId }) => {
|
|
107
|
-
await queryClient.cancelQueries({ queryKey: [
|
|
108
|
-
await queryClient.cancelQueries({ queryKey: [
|
|
109
|
-
const previousGroups = queryClient.getQueryData([
|
|
110
|
-
const previousGroup = queryClient.getQueryData([
|
|
111
|
-
queryClient.setQueryData([
|
|
112
|
-
queryClient.setQueriesData({ queryKey: [
|
|
101
|
+
await queryClient.cancelQueries({ queryKey: ['groups'] });
|
|
102
|
+
await queryClient.cancelQueries({ queryKey: ['groups', groupId] });
|
|
103
|
+
const previousGroups = queryClient.getQueryData(['groups']);
|
|
104
|
+
const previousGroup = queryClient.getQueryData(['groups', groupId]);
|
|
105
|
+
queryClient.setQueryData(['groups', groupId], undefined);
|
|
106
|
+
queryClient.setQueriesData({ queryKey: ['groups'] }, (oldData) => {
|
|
113
107
|
if (!oldData)
|
|
114
108
|
return oldData;
|
|
115
109
|
if (oldData.pages) {
|
|
@@ -124,15 +118,15 @@ AvroQueryClient.prototype.useDeleteGroup = function () {
|
|
|
124
118
|
return { previousGroups, previousGroup };
|
|
125
119
|
},
|
|
126
120
|
onSuccess: () => {
|
|
127
|
-
queryClient.invalidateQueries({ queryKey: [
|
|
121
|
+
queryClient.invalidateQueries({ queryKey: ['groups'] });
|
|
128
122
|
},
|
|
129
123
|
onError: (_err, variables, context) => {
|
|
130
124
|
const { groupId } = variables;
|
|
131
125
|
if (context?.previousGroups) {
|
|
132
|
-
queryClient.setQueryData([
|
|
126
|
+
queryClient.setQueryData(['groups'], context.previousGroups);
|
|
133
127
|
}
|
|
134
128
|
if (context?.previousGroup) {
|
|
135
|
-
queryClient.setQueryData([
|
|
129
|
+
queryClient.setQueryData(['groups', groupId], context.previousGroup);
|
|
136
130
|
}
|
|
137
131
|
},
|
|
138
132
|
});
|