@go-avro/avro-js 0.0.118 → 0.0.120
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/client/QueryClient.d.ts +7 -27
- package/dist/client/QueryClient.js +67 -729
- package/dist/client/hooks/bills.js +29 -72
- package/dist/client/hooks/catalog_items.js +6 -20
- package/dist/client/hooks/chats.js +7 -8
- package/dist/client/hooks/checkins.js +3 -15
- package/dist/client/hooks/companies.js +8 -24
- package/dist/client/hooks/events.js +25 -85
- package/dist/client/hooks/groups.js +9 -4
- package/dist/client/hooks/jobs.js +15 -35
- package/dist/client/hooks/labels.js +9 -4
- package/dist/client/hooks/messages.js +7 -8
- package/dist/client/hooks/months.js +13 -15
- package/dist/client/hooks/payouts.js +13 -14
- package/dist/client/hooks/prepayments.js +13 -15
- package/dist/client/hooks/proposal.js +3 -9
- package/dist/client/hooks/routes.js +13 -38
- package/dist/client/hooks/skills.js +9 -4
- package/dist/client/hooks/teams.js +9 -4
- package/dist/client/hooks/waivers.js +12 -13
- package/dist/client/realtime.d.ts +64 -0
- package/dist/client/realtime.js +470 -0
- package/dist/types/api/Job.d.ts +1 -1
- package/dist/types/api/Task.d.ts +2 -1
- package/dist/types/api/Task.js +2 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
import { useInfiniteQuery, useQuery, useMutation } from '@tanstack/react-query';
|
|
2
2
|
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
|
+
import { keys } from '../../client/realtime';
|
|
3
4
|
import { Bill } from '../../types/api';
|
|
4
5
|
AvroQueryClient.prototype.useGetBills = function (body) {
|
|
5
6
|
const queryClient = this.getQueryClient();
|
|
6
7
|
const result = useInfiniteQuery({
|
|
7
|
-
queryKey:
|
|
8
|
-
'
|
|
9
|
-
|
|
10
|
-
body.
|
|
11
|
-
body.
|
|
12
|
-
body.
|
|
13
|
-
body.
|
|
14
|
-
body.
|
|
15
|
-
body.
|
|
16
|
-
body.
|
|
17
|
-
body.
|
|
18
|
-
body.
|
|
19
|
-
body.
|
|
20
|
-
body.
|
|
21
|
-
|
|
22
|
-
body.direction ?? null,
|
|
23
|
-
],
|
|
8
|
+
queryKey: keys.infinite('bills', this.companyId, {
|
|
9
|
+
query: body.query ?? '',
|
|
10
|
+
known_ids: body.known_ids ?? [],
|
|
11
|
+
unknown_ids: body.unknown_ids ?? [],
|
|
12
|
+
paid: body.paid ?? false,
|
|
13
|
+
created_from: body.created_from ?? null,
|
|
14
|
+
created_to: body.created_to ?? null,
|
|
15
|
+
paid_from: body.paid_from ?? null,
|
|
16
|
+
paid_to: body.paid_to ?? null,
|
|
17
|
+
amount_min: body.amount_min ?? null,
|
|
18
|
+
amount_max: body.amount_max ?? null,
|
|
19
|
+
labels: body.labels ?? [],
|
|
20
|
+
sort_by: body.sort_by ?? null,
|
|
21
|
+
direction: body.direction ?? null,
|
|
22
|
+
}),
|
|
24
23
|
initialPageParam: 0,
|
|
25
24
|
getNextPageParam: (lastPage, allPages) => {
|
|
26
25
|
if (lastPage.length < (body.amt ?? 50))
|
|
@@ -76,14 +75,8 @@ AvroQueryClient.prototype.useCreateBill = function () {
|
|
|
76
75
|
// TODO: Create a fake bill object for optimistic update and update events and months accordingly
|
|
77
76
|
return { previousBills };
|
|
78
77
|
},
|
|
79
|
-
onSuccess:
|
|
80
|
-
|
|
81
|
-
action: 'create',
|
|
82
|
-
entityKey: 'bills',
|
|
83
|
-
id: result.id,
|
|
84
|
-
fetchPath: `/bill/${result.id}`,
|
|
85
|
-
construct: (d) => new Bill(d),
|
|
86
|
-
});
|
|
78
|
+
onSuccess: () => {
|
|
79
|
+
this.syncAfterMutation('bill');
|
|
87
80
|
},
|
|
88
81
|
onError: (_err, _variables, context) => {
|
|
89
82
|
if (context?.previousBills) {
|
|
@@ -126,14 +119,8 @@ AvroQueryClient.prototype.useUpdateBill = function () {
|
|
|
126
119
|
});
|
|
127
120
|
return { previousBills, previousBill };
|
|
128
121
|
},
|
|
129
|
-
onSuccess:
|
|
130
|
-
|
|
131
|
-
action: 'update',
|
|
132
|
-
entityKey: 'bills',
|
|
133
|
-
id: billId,
|
|
134
|
-
fetchPath: `/bill/${billId}`,
|
|
135
|
-
construct: (d) => new Bill(d),
|
|
136
|
-
});
|
|
122
|
+
onSuccess: () => {
|
|
123
|
+
this.syncAfterMutation('bill');
|
|
137
124
|
},
|
|
138
125
|
onError: (err, variables, context) => {
|
|
139
126
|
const { billId } = variables;
|
|
@@ -158,19 +145,8 @@ AvroQueryClient.prototype.useUpdateBillLineItemStatus = function () {
|
|
|
158
145
|
},
|
|
159
146
|
});
|
|
160
147
|
},
|
|
161
|
-
onSuccess:
|
|
162
|
-
|
|
163
|
-
action: 'update',
|
|
164
|
-
entityKey: 'bills',
|
|
165
|
-
id: billId,
|
|
166
|
-
fetchPath: `/bill/${billId}`,
|
|
167
|
-
construct: (d) => new Bill(d),
|
|
168
|
-
});
|
|
169
|
-
// Item paid state also lives on the underlying events,
|
|
170
|
-
// service months and prepayments
|
|
171
|
-
await queryClient.invalidateQueries({ queryKey: ['events'] });
|
|
172
|
-
await queryClient.invalidateQueries({ queryKey: ['months'] });
|
|
173
|
-
await queryClient.invalidateQueries({ queryKey: ['prepayments'] });
|
|
148
|
+
onSuccess: () => {
|
|
149
|
+
this.syncAfterMutation('bill', 'event', 'month', 'prepayment');
|
|
174
150
|
},
|
|
175
151
|
});
|
|
176
152
|
};
|
|
@@ -186,12 +162,8 @@ AvroQueryClient.prototype.useDeleteBill = function () {
|
|
|
186
162
|
// TODO: Create a fake bill object for optimistic update and update events and months accordingly
|
|
187
163
|
return { previousBills };
|
|
188
164
|
},
|
|
189
|
-
onSuccess:
|
|
190
|
-
|
|
191
|
-
action: 'delete',
|
|
192
|
-
entityKey: 'bills',
|
|
193
|
-
id: billId,
|
|
194
|
-
});
|
|
165
|
+
onSuccess: () => {
|
|
166
|
+
this.syncAfterMutation('bill');
|
|
195
167
|
},
|
|
196
168
|
onError: (_err, _variables, context) => {
|
|
197
169
|
if (context?.previousBills) {
|
|
@@ -209,7 +181,7 @@ AvroQueryClient.prototype.useCancelBillPayment = function () {
|
|
|
209
181
|
});
|
|
210
182
|
},
|
|
211
183
|
onSuccess: () => {
|
|
212
|
-
|
|
184
|
+
this.syncAfterMutation('bill');
|
|
213
185
|
},
|
|
214
186
|
});
|
|
215
187
|
};
|
|
@@ -227,7 +199,7 @@ AvroQueryClient.prototype.useSyncBillToIntuit = function () {
|
|
|
227
199
|
return { previousBill };
|
|
228
200
|
},
|
|
229
201
|
onSuccess: () => {
|
|
230
|
-
|
|
202
|
+
this.syncAfterMutation('bill');
|
|
231
203
|
},
|
|
232
204
|
onError: (_err, variables, context) => {
|
|
233
205
|
const { billId } = variables;
|
|
@@ -246,7 +218,7 @@ AvroQueryClient.prototype.useImportBillsFromIntuit = function () {
|
|
|
246
218
|
});
|
|
247
219
|
},
|
|
248
220
|
onSuccess: () => {
|
|
249
|
-
|
|
221
|
+
this.syncAfterMutation('bill');
|
|
250
222
|
},
|
|
251
223
|
});
|
|
252
224
|
};
|
|
@@ -269,23 +241,8 @@ AvroQueryClient.prototype.useBulkDeleteBills = function () {
|
|
|
269
241
|
},
|
|
270
242
|
});
|
|
271
243
|
},
|
|
272
|
-
onSuccess:
|
|
273
|
-
|
|
274
|
-
// refused to delete (returned in `errors`) stay in cache.
|
|
275
|
-
const failedIds = new Set(result.errors.map((e) => e.bill_id));
|
|
276
|
-
const deletedIds = billIds.filter((id) => !failedIds.has(id));
|
|
277
|
-
for (const id of deletedIds) {
|
|
278
|
-
await this._syncEntity(queryClient, {
|
|
279
|
-
action: 'delete',
|
|
280
|
-
entityKey: 'bills',
|
|
281
|
-
id,
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
// Backend also emits update_events / update_months — but be
|
|
285
|
-
// defensive in case the socket round-trip is slow.
|
|
286
|
-
queryClient.invalidateQueries({ queryKey: ['events'] });
|
|
287
|
-
queryClient.invalidateQueries({ queryKey: ['months'] });
|
|
288
|
-
queryClient.invalidateQueries({ queryKey: ['prepayments'] });
|
|
244
|
+
onSuccess: () => {
|
|
245
|
+
this.syncAfterMutation('bill', 'event', 'month', 'prepayment');
|
|
289
246
|
},
|
|
290
247
|
});
|
|
291
248
|
};
|
|
@@ -19,13 +19,8 @@ AvroQueryClient.prototype.useCreateCatalogItem = function () {
|
|
|
19
19
|
const previousItems = queryClient.getQueryData(['catalog_items', this.companyId]);
|
|
20
20
|
return { previousItems };
|
|
21
21
|
},
|
|
22
|
-
onSuccess:
|
|
23
|
-
|
|
24
|
-
action: 'create',
|
|
25
|
-
entityKey: 'catalog_items',
|
|
26
|
-
id: result.id,
|
|
27
|
-
fetchPath: `/catalog_item/${result.id}`,
|
|
28
|
-
});
|
|
22
|
+
onSuccess: () => {
|
|
23
|
+
this.syncAfterMutation('catalog_item');
|
|
29
24
|
},
|
|
30
25
|
onError: (_err, _variables, context) => {
|
|
31
26
|
if (context?.previousItems) {
|
|
@@ -70,13 +65,8 @@ AvroQueryClient.prototype.useUpdateCatalogItem = function () {
|
|
|
70
65
|
});
|
|
71
66
|
return { previousItems, previousItem };
|
|
72
67
|
},
|
|
73
|
-
onSuccess:
|
|
74
|
-
|
|
75
|
-
action: 'update',
|
|
76
|
-
entityKey: 'catalog_items',
|
|
77
|
-
id: catalogItemId,
|
|
78
|
-
fetchPath: `/catalog_item/${catalogItemId}`,
|
|
79
|
-
});
|
|
68
|
+
onSuccess: () => {
|
|
69
|
+
this.syncAfterMutation('catalog_item');
|
|
80
70
|
},
|
|
81
71
|
onError: (err, variables, context) => {
|
|
82
72
|
const { catalogItemId } = variables;
|
|
@@ -109,12 +99,8 @@ AvroQueryClient.prototype.useDeleteCatalogItem = function () {
|
|
|
109
99
|
const previousItems = queryClient.getQueryData(['catalog_items']);
|
|
110
100
|
return { previousItems };
|
|
111
101
|
},
|
|
112
|
-
onSuccess:
|
|
113
|
-
|
|
114
|
-
action: 'delete',
|
|
115
|
-
entityKey: 'catalog_items',
|
|
116
|
-
id: catalogItemId,
|
|
117
|
-
});
|
|
102
|
+
onSuccess: () => {
|
|
103
|
+
this.syncAfterMutation('catalog_item');
|
|
118
104
|
},
|
|
119
105
|
onError: (_err, _variables, context) => {
|
|
120
106
|
if (context?.previousItems) {
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { useInfiniteQuery, useQuery } from '@tanstack/react-query';
|
|
2
2
|
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
|
+
import { keys } from '../../client/realtime';
|
|
3
4
|
AvroQueryClient.prototype.useGetChats = function (body) {
|
|
4
5
|
const queryClient = this.getQueryClient();
|
|
5
6
|
const result = useInfiniteQuery({
|
|
6
|
-
queryKey:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
body.
|
|
10
|
-
body.
|
|
11
|
-
|
|
12
|
-
body.query ?? '',
|
|
13
|
-
],
|
|
7
|
+
queryKey: keys.infinite('chats', this.companyId, {
|
|
8
|
+
amt: body.amt ?? 50,
|
|
9
|
+
known_ids: body.known_ids ?? [],
|
|
10
|
+
unknown_ids: body.unknown_ids ?? [],
|
|
11
|
+
query: body.query ?? '',
|
|
12
|
+
}),
|
|
14
13
|
initialPageParam: 0,
|
|
15
14
|
getNextPageParam: (lastPage, allPages) => {
|
|
16
15
|
if (lastPage.length < (body.amt ?? 50))
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { useMutation, useQuery } from '@tanstack/react-query';
|
|
2
2
|
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
|
-
import { Job } from '../../types/api/Job';
|
|
4
3
|
/**
|
|
5
4
|
* Refresh the caches a check-in mutation touches. Socket events cover
|
|
6
5
|
* connected clients, but the raw helpers run headless (background
|
|
@@ -10,21 +9,10 @@ const syncCheckinCaches = async (client, jobId) => {
|
|
|
10
9
|
const queryClient = client.peekQueryClient();
|
|
11
10
|
if (!queryClient)
|
|
12
11
|
return;
|
|
12
|
+
// Headless path (background location task) has no live socket.
|
|
13
13
|
queryClient.invalidateQueries({ queryKey: ['checkins'] });
|
|
14
|
-
if (
|
|
15
|
-
|
|
16
|
-
try {
|
|
17
|
-
await client._syncEntity(queryClient, {
|
|
18
|
-
action: 'update',
|
|
19
|
-
entityKey: 'jobs',
|
|
20
|
-
id: jobId,
|
|
21
|
-
fetchPath: `/job/${jobId}`,
|
|
22
|
-
construct: (d) => new Job(d),
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
catch {
|
|
26
|
-
// Cache sync is best-effort; the mutation itself succeeded
|
|
27
|
-
}
|
|
14
|
+
if (jobId)
|
|
15
|
+
queryClient.invalidateQueries({ queryKey: ['jobs', jobId] });
|
|
28
16
|
};
|
|
29
17
|
AvroQueryClient.prototype.useJobCheckins = function (jobId, params) {
|
|
30
18
|
return useQuery({
|
|
@@ -74,13 +74,8 @@ AvroQueryClient.prototype.useCreateCompany = function () {
|
|
|
74
74
|
headers: { 'Content-Type': 'application/json' },
|
|
75
75
|
});
|
|
76
76
|
},
|
|
77
|
-
onSuccess:
|
|
78
|
-
|
|
79
|
-
action: 'create',
|
|
80
|
-
entityKey: 'companies',
|
|
81
|
-
id: result.id,
|
|
82
|
-
fetchPath: `/company/${result.id}`,
|
|
83
|
-
});
|
|
77
|
+
onSuccess: () => {
|
|
78
|
+
this.syncAfterMutation('company');
|
|
84
79
|
},
|
|
85
80
|
});
|
|
86
81
|
};
|
|
@@ -109,13 +104,8 @@ AvroQueryClient.prototype.useUpdateCompany = function () {
|
|
|
109
104
|
});
|
|
110
105
|
return { previousCompany, previousCompanyList };
|
|
111
106
|
},
|
|
112
|
-
onSuccess:
|
|
113
|
-
|
|
114
|
-
action: 'update',
|
|
115
|
-
entityKey: 'companies',
|
|
116
|
-
id: companyId,
|
|
117
|
-
fetchPath: `/company/${companyId}`,
|
|
118
|
-
});
|
|
107
|
+
onSuccess: () => {
|
|
108
|
+
this.syncAfterMutation('company');
|
|
119
109
|
},
|
|
120
110
|
onError: (_err, variables, context) => {
|
|
121
111
|
const { companyId } = variables;
|
|
@@ -151,8 +141,7 @@ AvroQueryClient.prototype.useCreateUserCompany = function () {
|
|
|
151
141
|
return { previousCompany };
|
|
152
142
|
},
|
|
153
143
|
onSuccess: () => {
|
|
154
|
-
|
|
155
|
-
queryClient.invalidateQueries({ queryKey: ['users'] });
|
|
144
|
+
this.syncAfterMutation('member', 'company');
|
|
156
145
|
},
|
|
157
146
|
onError: (err, variables, context) => {
|
|
158
147
|
if (context?.previousCompany) {
|
|
@@ -178,8 +167,7 @@ AvroQueryClient.prototype.useRemoveUserCompany = function () {
|
|
|
178
167
|
return { previousCompany };
|
|
179
168
|
},
|
|
180
169
|
onSuccess: () => {
|
|
181
|
-
|
|
182
|
-
queryClient.invalidateQueries({ queryKey: ['users'] });
|
|
170
|
+
this.syncAfterMutation('member', 'company');
|
|
183
171
|
},
|
|
184
172
|
onError: (err, variables, context) => {
|
|
185
173
|
if (context?.previousCompany) {
|
|
@@ -209,12 +197,8 @@ AvroQueryClient.prototype.useDeleteCompany = function () {
|
|
|
209
197
|
});
|
|
210
198
|
return { previousCompanyList };
|
|
211
199
|
},
|
|
212
|
-
onSuccess:
|
|
213
|
-
|
|
214
|
-
action: 'delete',
|
|
215
|
-
entityKey: 'companies',
|
|
216
|
-
id: companyId,
|
|
217
|
-
});
|
|
200
|
+
onSuccess: () => {
|
|
201
|
+
this.syncAfterMutation('company');
|
|
218
202
|
},
|
|
219
203
|
onError: (err, companyId, context) => {
|
|
220
204
|
if (context?.previousCompanyList) {
|
|
@@ -1,29 +1,26 @@
|
|
|
1
1
|
import { useInfiniteQuery, useQuery, useMutation } from '@tanstack/react-query';
|
|
2
|
-
import { AvroQueryClient
|
|
2
|
+
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
|
+
import { keys, matchesList } from '../../client/realtime';
|
|
3
4
|
import { constructEvent, DelayEvent, Job, LineItemStatus, } from '../../types/api';
|
|
4
5
|
const isJobsQuery = (q) => q.queryKey[0] === 'jobs';
|
|
5
6
|
const isEventsQuery = (q) => q.queryKey[0] === 'events';
|
|
6
|
-
const isEventsQueryFor = (item) => (q) => q.queryKey[0] === 'events' &&
|
|
7
|
+
const isEventsQueryFor = (item) => (q) => q.queryKey[0] === 'events' && matchesList('event', q.queryKey, item) === 'match';
|
|
7
8
|
AvroQueryClient.prototype.useGetEvents = function (body) {
|
|
8
9
|
const queryClient = this.getQueryClient();
|
|
9
10
|
const result = useInfiniteQuery({
|
|
10
|
-
queryKey:
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
body.
|
|
14
|
-
body.
|
|
15
|
-
body.
|
|
16
|
-
body.
|
|
17
|
-
body.
|
|
18
|
-
body.
|
|
19
|
-
body.
|
|
20
|
-
body.
|
|
21
|
-
body.
|
|
22
|
-
|
|
23
|
-
body.direction ?? null,
|
|
24
|
-
// Index 13 — read positionally by matchesEventsListQuery.
|
|
25
|
-
body.line_item_types ?? null,
|
|
26
|
-
],
|
|
11
|
+
queryKey: keys.infinite('events', this.companyId, {
|
|
12
|
+
amt: body.amt ?? 50,
|
|
13
|
+
known_ids: body.known_ids ?? [],
|
|
14
|
+
unknown_ids: body.unknown_ids ?? [],
|
|
15
|
+
query: body.query ?? '',
|
|
16
|
+
unbilled: body.unbilled ?? true,
|
|
17
|
+
billed: body.billed ?? true,
|
|
18
|
+
paid: body.paid ?? true,
|
|
19
|
+
jobId: body.jobId ?? '',
|
|
20
|
+
sort_by: body.sort_by ?? null,
|
|
21
|
+
direction: body.direction ?? null,
|
|
22
|
+
line_item_types: body.line_item_types ?? null,
|
|
23
|
+
}),
|
|
27
24
|
initialPageParam: 0,
|
|
28
25
|
getNextPageParam: (lastPage, allPages) => {
|
|
29
26
|
if (lastPage.length < (body.amt ?? 50))
|
|
@@ -122,22 +119,8 @@ AvroQueryClient.prototype.useCreateEvent = function () {
|
|
|
122
119
|
});
|
|
123
120
|
return { previousJob };
|
|
124
121
|
},
|
|
125
|
-
onSuccess:
|
|
126
|
-
|
|
127
|
-
action: 'create',
|
|
128
|
-
entityKey: 'events',
|
|
129
|
-
id: result.id,
|
|
130
|
-
fetchPath: `/event/${result.id}`,
|
|
131
|
-
});
|
|
132
|
-
if (eventData.job_id) {
|
|
133
|
-
await this._syncEntity(queryClient, {
|
|
134
|
-
action: 'update',
|
|
135
|
-
entityKey: 'jobs',
|
|
136
|
-
id: eventData.job_id,
|
|
137
|
-
fetchPath: `/job/${eventData.job_id}`,
|
|
138
|
-
construct: (d) => new Job(d),
|
|
139
|
-
});
|
|
140
|
-
}
|
|
122
|
+
onSuccess: () => {
|
|
123
|
+
this.syncAfterMutation('event', 'job');
|
|
141
124
|
},
|
|
142
125
|
onError: (err, variables, context) => {
|
|
143
126
|
// Restore individual job; invalidate lists to refetch clean state
|
|
@@ -220,22 +203,8 @@ AvroQueryClient.prototype.useCreateDelayEvent = function () {
|
|
|
220
203
|
});
|
|
221
204
|
return { previousJob };
|
|
222
205
|
},
|
|
223
|
-
onSuccess:
|
|
224
|
-
|
|
225
|
-
action: 'create',
|
|
226
|
-
entityKey: 'events',
|
|
227
|
-
id: result.id,
|
|
228
|
-
fetchPath: `/event/${result.id}`,
|
|
229
|
-
construct: (d) => constructEvent(d),
|
|
230
|
-
matchesQuery: matchesEventsListQuery,
|
|
231
|
-
});
|
|
232
|
-
await this._syncEntity(queryClient, {
|
|
233
|
-
action: 'update',
|
|
234
|
-
entityKey: 'jobs',
|
|
235
|
-
id: delayData.job_id,
|
|
236
|
-
fetchPath: `/job/${delayData.job_id}`,
|
|
237
|
-
construct: (d) => new Job(d),
|
|
238
|
-
});
|
|
206
|
+
onSuccess: () => {
|
|
207
|
+
this.syncAfterMutation('event', 'job');
|
|
239
208
|
},
|
|
240
209
|
onError: (_err, _variables, context) => {
|
|
241
210
|
if (context?.previousJob) {
|
|
@@ -343,22 +312,8 @@ AvroQueryClient.prototype.useUpdateEvent = function () {
|
|
|
343
312
|
});
|
|
344
313
|
return { previousEvent, previousJob };
|
|
345
314
|
},
|
|
346
|
-
onSuccess:
|
|
347
|
-
|
|
348
|
-
action: 'update',
|
|
349
|
-
entityKey: 'events',
|
|
350
|
-
id: eventId,
|
|
351
|
-
fetchPath: `/event/${eventId}`,
|
|
352
|
-
});
|
|
353
|
-
if (item?.job_id) {
|
|
354
|
-
await this._syncEntity(queryClient, {
|
|
355
|
-
action: 'update',
|
|
356
|
-
entityKey: 'jobs',
|
|
357
|
-
id: item.job_id,
|
|
358
|
-
fetchPath: `/job/${item.job_id}`,
|
|
359
|
-
construct: (d) => new Job(d),
|
|
360
|
-
});
|
|
361
|
-
}
|
|
315
|
+
onSuccess: () => {
|
|
316
|
+
this.syncAfterMutation('event', 'job');
|
|
362
317
|
},
|
|
363
318
|
onError: (_err, variables, context) => {
|
|
364
319
|
const { eventId } = variables;
|
|
@@ -447,7 +402,7 @@ AvroQueryClient.prototype.useUpdateEvents = function () {
|
|
|
447
402
|
return { previousEvents, previousEventObjs };
|
|
448
403
|
},
|
|
449
404
|
onSuccess: () => {
|
|
450
|
-
|
|
405
|
+
this.syncAfterMutation('event');
|
|
451
406
|
},
|
|
452
407
|
onError: (err, variables, context) => {
|
|
453
408
|
if (context?.previousEvents) {
|
|
@@ -490,23 +445,8 @@ AvroQueryClient.prototype.useDeleteEvent = function () {
|
|
|
490
445
|
});
|
|
491
446
|
return { previousEvents, previousEvent };
|
|
492
447
|
},
|
|
493
|
-
onSuccess:
|
|
494
|
-
|
|
495
|
-
action: 'delete',
|
|
496
|
-
entityKey: 'events',
|
|
497
|
-
id: eventId,
|
|
498
|
-
});
|
|
499
|
-
const jobId = context?.previousEvent
|
|
500
|
-
?.job_id;
|
|
501
|
-
if (jobId) {
|
|
502
|
-
await this._syncEntity(queryClient, {
|
|
503
|
-
action: 'update',
|
|
504
|
-
entityKey: 'jobs',
|
|
505
|
-
id: jobId,
|
|
506
|
-
fetchPath: `/job/${jobId}`,
|
|
507
|
-
construct: (d) => new Job(d),
|
|
508
|
-
});
|
|
509
|
-
}
|
|
448
|
+
onSuccess: () => {
|
|
449
|
+
this.syncAfterMutation('event', 'job');
|
|
510
450
|
},
|
|
511
451
|
onError: (_err, variables, context) => {
|
|
512
452
|
const { eventId } = variables;
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { useMutation, useQuery } from '@tanstack/react-query';
|
|
2
2
|
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
|
+
import { keys } from '../../client/realtime';
|
|
3
4
|
AvroQueryClient.prototype.useGetGroups = function (body, total, onProgress) {
|
|
4
5
|
return useQuery({
|
|
5
|
-
queryKey:
|
|
6
|
+
queryKey: keys.list('groups', this.companyId, {
|
|
7
|
+
amt: body.amt ?? 50,
|
|
8
|
+
query: body.query ?? '',
|
|
9
|
+
total: total ?? 'all',
|
|
10
|
+
}),
|
|
6
11
|
queryFn: async () => {
|
|
7
12
|
if (typeof total !== 'number') {
|
|
8
13
|
return this.fetchGroups({ ...body, offset: 0 });
|
|
@@ -37,7 +42,7 @@ AvroQueryClient.prototype.useCreateGroup = function () {
|
|
|
37
42
|
});
|
|
38
43
|
},
|
|
39
44
|
onSuccess: () => {
|
|
40
|
-
|
|
45
|
+
this.syncAfterMutation('group');
|
|
41
46
|
},
|
|
42
47
|
});
|
|
43
48
|
};
|
|
@@ -76,7 +81,7 @@ AvroQueryClient.prototype.useUpdateGroup = function () {
|
|
|
76
81
|
return { previousGroups, previousGroup };
|
|
77
82
|
},
|
|
78
83
|
onSuccess: () => {
|
|
79
|
-
|
|
84
|
+
this.syncAfterMutation('group');
|
|
80
85
|
},
|
|
81
86
|
onError: (_err, variables, context) => {
|
|
82
87
|
const { groupId } = variables;
|
|
@@ -118,7 +123,7 @@ AvroQueryClient.prototype.useDeleteGroup = function () {
|
|
|
118
123
|
return { previousGroups, previousGroup };
|
|
119
124
|
},
|
|
120
125
|
onSuccess: () => {
|
|
121
|
-
|
|
126
|
+
this.syncAfterMutation('group');
|
|
122
127
|
},
|
|
123
128
|
onError: (_err, variables, context) => {
|
|
124
129
|
const { groupId } = variables;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useMutation, useQuery, useInfiniteQuery } from '@tanstack/react-query';
|
|
2
2
|
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
|
+
import { keys } from '../../client/realtime';
|
|
3
4
|
import { Job } from '../../types/api';
|
|
4
5
|
AvroQueryClient.prototype.getJobsFromCache = function (queryClient) {
|
|
5
6
|
const client = queryClient ?? this.peekQueryClient();
|
|
@@ -14,7 +15,7 @@ AvroQueryClient.prototype.useGetJobs = function (params) {
|
|
|
14
15
|
const company_id = params?.companyId ?? this.companyId;
|
|
15
16
|
const num_jobs = params?.numJobs ?? this.company?.num_jobs ?? 0;
|
|
16
17
|
return useQuery({
|
|
17
|
-
queryKey:
|
|
18
|
+
queryKey: keys.list('jobs', company_id, { numJobs: num_jobs }),
|
|
18
19
|
queryFn: async () => {
|
|
19
20
|
params?.onProgress?.(0);
|
|
20
21
|
const pageCount = amt ? Math.ceil((num_jobs ?? 0) / amt) + 1 : 1;
|
|
@@ -51,14 +52,11 @@ AvroQueryClient.prototype.useGetJobs = function (params) {
|
|
|
51
52
|
AvroQueryClient.prototype.useGetInfiniteJobs = function (body, onProgress) {
|
|
52
53
|
const queryClient = this.getQueryClient();
|
|
53
54
|
const result = useInfiniteQuery({
|
|
54
|
-
queryKey:
|
|
55
|
-
|
|
56
|
-
'
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
body.query ?? '',
|
|
60
|
-
body.routeId ?? '',
|
|
61
|
-
],
|
|
55
|
+
queryKey: keys.infinite('jobs', this.companyId, {
|
|
56
|
+
amt: body.amt ?? 50,
|
|
57
|
+
query: body.query ?? '',
|
|
58
|
+
routeId: body.routeId ?? '',
|
|
59
|
+
}),
|
|
62
60
|
initialPageParam: 0,
|
|
63
61
|
getNextPageParam: (lastPage, allPages) => {
|
|
64
62
|
if (lastPage.length < (body.amt ?? 50))
|
|
@@ -105,14 +103,8 @@ AvroQueryClient.prototype.useCreateJob = function () {
|
|
|
105
103
|
headers: { 'Content-Type': 'application/json' },
|
|
106
104
|
});
|
|
107
105
|
},
|
|
108
|
-
onSuccess:
|
|
109
|
-
|
|
110
|
-
action: 'create',
|
|
111
|
-
entityKey: 'jobs',
|
|
112
|
-
id: result.id,
|
|
113
|
-
fetchPath: `/job/${result.id}`,
|
|
114
|
-
construct: (d) => new Job(d),
|
|
115
|
-
});
|
|
106
|
+
onSuccess: () => {
|
|
107
|
+
this.syncAfterMutation('job');
|
|
116
108
|
},
|
|
117
109
|
});
|
|
118
110
|
};
|
|
@@ -127,8 +119,7 @@ AvroQueryClient.prototype.useManageJobs = function () {
|
|
|
127
119
|
});
|
|
128
120
|
},
|
|
129
121
|
onSuccess: () => {
|
|
130
|
-
|
|
131
|
-
queryClient.invalidateQueries({ queryKey: ['infinite', 'jobs'] });
|
|
122
|
+
this.syncAfterMutation('job');
|
|
132
123
|
},
|
|
133
124
|
});
|
|
134
125
|
};
|
|
@@ -142,14 +133,8 @@ AvroQueryClient.prototype.useUpdateJob = function () {
|
|
|
142
133
|
headers: { 'Content-Type': 'application/json' },
|
|
143
134
|
});
|
|
144
135
|
},
|
|
145
|
-
onSuccess:
|
|
146
|
-
|
|
147
|
-
action: 'update',
|
|
148
|
-
entityKey: 'jobs',
|
|
149
|
-
id: jobId,
|
|
150
|
-
fetchPath: `/job/${jobId}`,
|
|
151
|
-
construct: (d) => new Job(d),
|
|
152
|
-
});
|
|
136
|
+
onSuccess: () => {
|
|
137
|
+
this.syncAfterMutation('job');
|
|
153
138
|
},
|
|
154
139
|
});
|
|
155
140
|
};
|
|
@@ -164,8 +149,7 @@ AvroQueryClient.prototype.useDeleteJobs = function () {
|
|
|
164
149
|
});
|
|
165
150
|
},
|
|
166
151
|
onSuccess: () => {
|
|
167
|
-
|
|
168
|
-
queryClient.invalidateQueries({ queryKey: ['infinite', 'jobs'] });
|
|
152
|
+
this.syncAfterMutation('job');
|
|
169
153
|
},
|
|
170
154
|
});
|
|
171
155
|
};
|
|
@@ -180,12 +164,8 @@ AvroQueryClient.prototype.useDeleteJob = function () {
|
|
|
180
164
|
},
|
|
181
165
|
});
|
|
182
166
|
},
|
|
183
|
-
onSuccess:
|
|
184
|
-
|
|
185
|
-
action: 'delete',
|
|
186
|
-
entityKey: 'jobs',
|
|
187
|
-
id: jobId,
|
|
188
|
-
});
|
|
167
|
+
onSuccess: () => {
|
|
168
|
+
this.syncAfterMutation('job');
|
|
189
169
|
},
|
|
190
170
|
});
|
|
191
171
|
};
|