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