@go-avro/avro-js 0.0.4-beta.3 → 0.0.4-beta.30
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/client/QueryClient.d.ts +55 -2
- package/dist/client/QueryClient.js +29 -7
- package/dist/client/hooks/catalog_items.js +8 -1
- package/dist/client/hooks/jobs.js +7 -3
- package/dist/client/hooks/prepayments.js +60 -1
- package/dist/client/hooks/proposal.js +8 -1
- package/dist/client/hooks/routes.js +13 -8
- package/dist/client/hooks/users.js +15 -1
- package/dist/client/hooks/waivers.d.ts +1 -0
- package/dist/client/hooks/waivers.js +123 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/types/api/AdditionalCharge.d.ts +5 -0
- package/dist/types/api/AdditionalCharge.js +1 -0
- package/dist/types/api/Avro.d.ts +11 -0
- package/dist/types/api/Avro.js +1 -0
- package/dist/types/api/Bill.d.ts +27 -0
- package/dist/types/api/Bill.js +1 -0
- package/dist/types/api/BillPayment.d.ts +13 -0
- package/dist/types/api/BillPayment.js +1 -0
- package/dist/types/api/BillUser.d.ts +11 -0
- package/dist/types/api/BillUser.js +1 -0
- package/dist/types/api/Break.d.ts +7 -0
- package/dist/types/api/Break.js +1 -0
- package/dist/types/api/CatalogItem.d.ts +16 -0
- package/dist/types/api/CatalogItem.js +1 -0
- package/dist/types/api/Chat.d.ts +12 -0
- package/dist/types/api/Chat.js +1 -0
- package/dist/types/api/Company.d.ts +58 -0
- package/dist/types/api/Company.js +1 -0
- package/dist/types/api/CustomLineItem.d.ts +4 -0
- package/dist/types/api/CustomLineItem.js +1 -0
- package/dist/types/api/Email.d.ts +21 -0
- package/dist/types/api/Email.js +1 -0
- package/dist/types/api/Friendship.d.ts +2 -0
- package/dist/types/api/Friendship.js +1 -0
- package/dist/types/api/Group.d.ts +12 -0
- package/dist/types/api/Group.js +1 -0
- package/dist/types/api/Job.d.ts +36 -0
- package/dist/types/api/Job.js +22 -0
- package/dist/types/api/Label.d.ts +7 -0
- package/dist/types/api/Label.js +1 -0
- package/dist/types/api/LineItem.d.ts +41 -0
- package/dist/types/api/LineItem.js +30 -0
- package/dist/types/api/MemberState.d.ts +7 -0
- package/dist/types/api/MemberState.js +1 -0
- package/dist/types/api/Message.d.ts +13 -0
- package/dist/types/api/Message.js +1 -0
- package/dist/types/api/PaymentMethod.d.ts +51 -0
- package/dist/types/api/PaymentMethod.js +1 -0
- package/dist/types/api/PaymentOption.d.ts +9 -0
- package/dist/types/api/PaymentOption.js +1 -0
- package/dist/types/api/PaymentType.d.ts +5 -0
- package/dist/types/api/PaymentType.js +5 -0
- package/dist/types/api/Plan.d.ts +13 -0
- package/dist/types/api/Plan.js +1 -0
- package/dist/types/api/PlanPayment.d.ts +10 -0
- package/dist/types/api/PlanPayment.js +1 -0
- package/dist/types/api/Prepayment.d.ts +15 -0
- package/dist/types/api/Prepayment.js +7 -0
- package/dist/types/api/Reaction.d.ts +8 -0
- package/dist/types/api/Reaction.js +1 -0
- package/dist/types/api/Route.d.ts +37 -0
- package/dist/types/api/Route.js +82 -0
- package/dist/types/api/RouteJob.d.ts +15 -0
- package/dist/types/api/RouteJob.js +5 -0
- package/dist/types/api/ServiceMonth.d.ts +7 -0
- package/dist/types/api/ServiceMonth.js +1 -0
- package/dist/types/api/Session.d.ts +13 -0
- package/dist/types/api/Session.js +1 -0
- package/dist/types/api/Skill.d.ts +7 -0
- package/dist/types/api/Skill.js +1 -0
- package/dist/types/api/Subscription.d.ts +8 -0
- package/dist/types/api/Subscription.js +1 -0
- package/dist/types/api/Task.d.ts +57 -0
- package/dist/types/api/Task.js +74 -0
- package/dist/types/api/User.d.ts +23 -0
- package/dist/types/api/User.js +1 -0
- package/dist/types/api/UserCompanyAssociation.d.ts +71 -0
- package/dist/types/api/UserCompanyAssociation.js +53 -0
- package/dist/types/api/UserEvent.d.ts +13 -0
- package/dist/types/api/UserEvent.js +1 -0
- package/dist/types/api/Waiver.d.ts +9 -0
- package/dist/types/api/Waiver.js +1 -0
- package/dist/types/api/_Event.d.ts +19 -0
- package/dist/types/api/_Event.js +1 -0
- package/dist/types/api.d.ts +43 -587
- package/dist/types/api.js +37 -74
- package/dist/types/cache.d.ts +2 -2
- package/package.json +1 -1
|
@@ -16,8 +16,8 @@ export declare class AuthManager {
|
|
|
16
16
|
onTokenRefreshFailed(callback: () => void): void;
|
|
17
17
|
refreshTokens(): Promise<Tokens>;
|
|
18
18
|
setTokens(tokens: Tokens): Promise<void>;
|
|
19
|
-
setCache(data: Partial<CacheData>): Promise<void>;
|
|
20
|
-
getCache(key?: keyof CacheData): Promise<CacheData | string | null>;
|
|
19
|
+
setCache(data: Partial<CacheData> | Object): Promise<void>;
|
|
20
|
+
getCache(key?: keyof CacheData | string): Promise<CacheData[keyof CacheData] | Object | string | null>;
|
|
21
21
|
clearCache(): Promise<void>;
|
|
22
22
|
getCompanyId(): Promise<string | undefined>;
|
|
23
23
|
setCompanyId(companyId: string): Promise<void[]>;
|
|
@@ -6,6 +6,7 @@ import { AuthState, Tokens } from '../types/auth';
|
|
|
6
6
|
import { CancelToken, RetryStrategy } from '../types/client';
|
|
7
7
|
import { StandardError } from '../types/error';
|
|
8
8
|
import { CacheData } from '../types/cache';
|
|
9
|
+
import { Waiver } from '../types/api/Waiver';
|
|
9
10
|
export interface AvroQueryClientConfig {
|
|
10
11
|
baseUrl: string;
|
|
11
12
|
authManager: AuthManager;
|
|
@@ -106,6 +107,13 @@ declare module '../client/QueryClient' {
|
|
|
106
107
|
query?: string;
|
|
107
108
|
offset?: number;
|
|
108
109
|
}, total: number, onProgress?: (fraction: number) => void): UseQueryResult<Label[], StandardError>;
|
|
110
|
+
useGetWaivers(body: {
|
|
111
|
+
amt?: number;
|
|
112
|
+
known_ids?: string[];
|
|
113
|
+
unknown_ids?: string[];
|
|
114
|
+
query?: string;
|
|
115
|
+
offset?: number;
|
|
116
|
+
}, total: number, onProgress?: (fraction: number) => void): UseQueryResult<Waiver[], StandardError>;
|
|
109
117
|
useGetGroups(body: {
|
|
110
118
|
amt?: number;
|
|
111
119
|
known_ids?: string[];
|
|
@@ -143,6 +151,7 @@ declare module '../client/QueryClient' {
|
|
|
143
151
|
tasks: {
|
|
144
152
|
id: string;
|
|
145
153
|
status: string;
|
|
154
|
+
payment_option_id: string;
|
|
146
155
|
}[];
|
|
147
156
|
}>>;
|
|
148
157
|
useCreateProposal(): ReturnType<typeof useMutation<{
|
|
@@ -156,6 +165,11 @@ declare module '../client/QueryClient' {
|
|
|
156
165
|
}, StandardError, {
|
|
157
166
|
groupData: Partial<Group>;
|
|
158
167
|
}>>;
|
|
168
|
+
useCreateWaiver(): ReturnType<typeof useMutation<{
|
|
169
|
+
id: string;
|
|
170
|
+
}, StandardError, {
|
|
171
|
+
waiverData: Partial<Waiver>;
|
|
172
|
+
}>>;
|
|
159
173
|
useCreateLabel(): ReturnType<typeof useMutation<{
|
|
160
174
|
id: string;
|
|
161
175
|
}, StandardError, {
|
|
@@ -213,10 +227,24 @@ declare module '../client/QueryClient' {
|
|
|
213
227
|
useCreateSelf(): ReturnType<typeof useMutation<{
|
|
214
228
|
msg: string;
|
|
215
229
|
id?: string;
|
|
230
|
+
access_token?: string;
|
|
231
|
+
refresh_token?: string;
|
|
216
232
|
}, StandardError, Partial<User> & {
|
|
217
233
|
code?: string;
|
|
218
234
|
invite_token?: string;
|
|
219
235
|
password?: string;
|
|
236
|
+
company_id?: string;
|
|
237
|
+
}>>;
|
|
238
|
+
useCreateUser(): ReturnType<typeof useMutation<{
|
|
239
|
+
msg: string;
|
|
240
|
+
id?: string;
|
|
241
|
+
access_token?: string;
|
|
242
|
+
refresh_token?: string;
|
|
243
|
+
}, StandardError, Partial<User> & {
|
|
244
|
+
code?: string;
|
|
245
|
+
invite_token?: string;
|
|
246
|
+
password?: string;
|
|
247
|
+
company_id?: string;
|
|
220
248
|
}>>;
|
|
221
249
|
useCreateSessionBreak(): ReturnType<typeof useMutation<{
|
|
222
250
|
id: string;
|
|
@@ -261,6 +289,12 @@ declare module '../client/QueryClient' {
|
|
|
261
289
|
labelId: string;
|
|
262
290
|
labelData: Partial<Label>;
|
|
263
291
|
}>>;
|
|
292
|
+
useUpdateWaiver(): ReturnType<typeof useMutation<{
|
|
293
|
+
msg: string;
|
|
294
|
+
}, StandardError, {
|
|
295
|
+
waiverId: string;
|
|
296
|
+
updates: Partial<Waiver>;
|
|
297
|
+
}>>;
|
|
264
298
|
useUpdateCatalogItem(): ReturnType<typeof useMutation<{
|
|
265
299
|
msg: string;
|
|
266
300
|
}, StandardError, {
|
|
@@ -309,6 +343,12 @@ declare module '../client/QueryClient' {
|
|
|
309
343
|
})[];
|
|
310
344
|
action: "billed" | "paid";
|
|
311
345
|
}>>;
|
|
346
|
+
useUpdatePrepayments(): ReturnType<typeof useMutation<void, StandardError, {
|
|
347
|
+
prepayments: (Prepayment & {
|
|
348
|
+
page?: number;
|
|
349
|
+
})[];
|
|
350
|
+
action: "billed" | "paid";
|
|
351
|
+
}>>;
|
|
312
352
|
useUpdateUserCompany(): ReturnType<typeof useMutation<{
|
|
313
353
|
msg: string;
|
|
314
354
|
}, StandardError, {
|
|
@@ -363,6 +403,11 @@ declare module '../client/QueryClient' {
|
|
|
363
403
|
}, StandardError, {
|
|
364
404
|
groupId: string;
|
|
365
405
|
}>>;
|
|
406
|
+
useDeleteWaiver(): ReturnType<typeof useMutation<{
|
|
407
|
+
msg: string;
|
|
408
|
+
}, StandardError, {
|
|
409
|
+
waiverId: string;
|
|
410
|
+
}>>;
|
|
366
411
|
useDeleteLabel(): ReturnType<typeof useMutation<{
|
|
367
412
|
msg: string;
|
|
368
413
|
}, StandardError, {
|
|
@@ -418,6 +463,7 @@ export declare class AvroQueryClient {
|
|
|
418
463
|
post<T>(path: string, data: any, cancelToken?: CancelToken, headers?: Record<string, string>, progressUpdateCallback?: (loaded: number, total: number) => void): Promise<T>;
|
|
419
464
|
put<T>(path: string, data: any, cancelToken?: CancelToken, headers?: Record<string, string>, progressUpdateCallback?: (loaded: number, total: number) => void): Promise<T>;
|
|
420
465
|
delete<T>(path: string, cancelToken?: CancelToken, headers?: Record<string, string>, progressUpdateCallback?: (loaded: number, total: number) => void): Promise<T>;
|
|
466
|
+
loginSuccess(tokens: Tokens): Promise<void>;
|
|
421
467
|
useLogin(): ReturnType<typeof useMutation<LoginResponse, StandardError, {
|
|
422
468
|
username: string;
|
|
423
469
|
password?: string;
|
|
@@ -443,8 +489,8 @@ export declare class AvroQueryClient {
|
|
|
443
489
|
cancelToken?: CancelToken;
|
|
444
490
|
}>>;
|
|
445
491
|
setTokens(tokens: Tokens): Promise<void>;
|
|
446
|
-
setCache(data: Partial<CacheData>): Promise<void>;
|
|
447
|
-
getCache(key?: keyof CacheData |
|
|
492
|
+
setCache(data: Partial<CacheData> | Object): Promise<void>;
|
|
493
|
+
getCache(key?: keyof CacheData | string): Promise<CacheData[keyof CacheData] | Object | string | null>;
|
|
448
494
|
setCompanyId(companyId: string): Promise<void[]>;
|
|
449
495
|
getCompanyId(): Promise<string | undefined>;
|
|
450
496
|
clearCache(): Promise<void>;
|
|
@@ -488,6 +534,13 @@ export declare class AvroQueryClient {
|
|
|
488
534
|
paid?: boolean;
|
|
489
535
|
taskId?: string | null;
|
|
490
536
|
}, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<any>;
|
|
537
|
+
fetchWaivers(body?: {
|
|
538
|
+
amt?: number;
|
|
539
|
+
query?: string;
|
|
540
|
+
offset?: number;
|
|
541
|
+
known_ids?: string[];
|
|
542
|
+
unknown_ids?: string[];
|
|
543
|
+
}, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<any>;
|
|
491
544
|
fetchEvents(body?: {
|
|
492
545
|
amt?: number;
|
|
493
546
|
known_ids?: string[];
|
|
@@ -82,6 +82,14 @@ export class AvroQueryClient {
|
|
|
82
82
|
delete(path, cancelToken, headers = {}, progressUpdateCallback) {
|
|
83
83
|
return this._xhr('DELETE', path, null, cancelToken, headers, false, this.config.maxRetries, progressUpdateCallback);
|
|
84
84
|
}
|
|
85
|
+
loginSuccess(tokens) {
|
|
86
|
+
this.setAuthState(AuthState.AUTHENTICATED);
|
|
87
|
+
this.socket.auth = { token: tokens.access_token };
|
|
88
|
+
if (!this.socket.connected) {
|
|
89
|
+
this.socket.connect();
|
|
90
|
+
}
|
|
91
|
+
return this.config.authManager.setTokens(tokens);
|
|
92
|
+
}
|
|
85
93
|
useLogin() {
|
|
86
94
|
const queryClient = this.getQueryClient();
|
|
87
95
|
return useMutation({
|
|
@@ -93,12 +101,7 @@ export class AvroQueryClient {
|
|
|
93
101
|
}
|
|
94
102
|
throw new StandardError(401, 'Invalid login response');
|
|
95
103
|
}
|
|
96
|
-
this.
|
|
97
|
-
this.socket.auth = { token: resp.access_token };
|
|
98
|
-
if (!this.socket.connected) {
|
|
99
|
-
this.socket.connect();
|
|
100
|
-
}
|
|
101
|
-
await this.config.authManager.setTokens({ access_token: resp.access_token, refresh_token: resp.refresh_token });
|
|
104
|
+
await this.loginSuccess({ access_token: resp.access_token, refresh_token: resp.refresh_token });
|
|
102
105
|
return LoginResponse.SUCCESS;
|
|
103
106
|
},
|
|
104
107
|
onSettled: () => {
|
|
@@ -173,7 +176,7 @@ export class AvroQueryClient {
|
|
|
173
176
|
setCache(data) {
|
|
174
177
|
return this.config.authManager.setCache(data);
|
|
175
178
|
}
|
|
176
|
-
getCache(key) {
|
|
179
|
+
async getCache(key) {
|
|
177
180
|
return this.config.authManager.getCache(key);
|
|
178
181
|
}
|
|
179
182
|
setCompanyId(companyId) {
|
|
@@ -315,6 +318,25 @@ export class AvroQueryClient {
|
|
|
315
318
|
throw new StandardError(500, 'Failed to fetch prepayments');
|
|
316
319
|
});
|
|
317
320
|
}
|
|
321
|
+
async fetchWaivers(body = {}, cancelToken, headers = {}) {
|
|
322
|
+
if (!this.companyId || this.companyId.trim() === '') {
|
|
323
|
+
throw new StandardError(400, 'Company ID is required');
|
|
324
|
+
}
|
|
325
|
+
return this._fetch('POST', `/company/${this.companyId}/waivers`, JSON.stringify(body), cancelToken, {
|
|
326
|
+
...headers,
|
|
327
|
+
'Content-Type': 'application/json',
|
|
328
|
+
})
|
|
329
|
+
.then(response => {
|
|
330
|
+
if (!response || !Array.isArray(response)) {
|
|
331
|
+
throw new StandardError(400, 'Invalid waivers response');
|
|
332
|
+
}
|
|
333
|
+
return response;
|
|
334
|
+
})
|
|
335
|
+
.catch(err => {
|
|
336
|
+
console.error('Failed to fetch waivers:', err);
|
|
337
|
+
throw new StandardError(500, 'Failed to fetch waivers');
|
|
338
|
+
});
|
|
339
|
+
}
|
|
318
340
|
async fetchEvents(body = {}, cancelToken, headers = {}) {
|
|
319
341
|
if (!this.companyId || this.companyId.trim() === '') {
|
|
320
342
|
throw new StandardError(400, 'Company ID is required');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useMutation } from '@tanstack/react-query';
|
|
1
|
+
import { useQuery, useMutation } from '@tanstack/react-query';
|
|
2
2
|
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
3
|
AvroQueryClient.prototype.useCreateCatalogItem = function () {
|
|
4
4
|
const queryClient = this.getQueryClient();
|
|
@@ -67,6 +67,13 @@ AvroQueryClient.prototype.useUpdateCatalogItem = function () {
|
|
|
67
67
|
},
|
|
68
68
|
});
|
|
69
69
|
};
|
|
70
|
+
AvroQueryClient.prototype.useGetCatalogItem = function (catalogItemId) {
|
|
71
|
+
return useQuery({
|
|
72
|
+
queryKey: ['catalog_item', catalogItemId],
|
|
73
|
+
queryFn: () => this.get(`/catalog_item/${catalogItemId}`),
|
|
74
|
+
enabled: Boolean(catalogItemId),
|
|
75
|
+
});
|
|
76
|
+
};
|
|
70
77
|
AvroQueryClient.prototype.useDeleteCatalogItem = function () {
|
|
71
78
|
const queryClient = this.getQueryClient();
|
|
72
79
|
return useMutation({
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useMutation, useQuery, useInfiniteQuery } from '@tanstack/react-query';
|
|
2
2
|
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
|
+
import { Job } from '../../types/api';
|
|
3
4
|
AvroQueryClient.prototype.getJobsFromCache = function (queryClient) {
|
|
4
5
|
if (!queryClient) {
|
|
5
6
|
queryClient = this.getQueryClient();
|
|
@@ -25,7 +26,7 @@ AvroQueryClient.prototype.useGetJobs = function (params) {
|
|
|
25
26
|
return result;
|
|
26
27
|
}));
|
|
27
28
|
const pages = await Promise.all(trackedPromises);
|
|
28
|
-
const jobs = pages.flat();
|
|
29
|
+
const jobs = pages.flat().map((job) => new Job(job));
|
|
29
30
|
jobs.forEach((job) => {
|
|
30
31
|
job.current_event = job.tasks.reduce((latest, task) => {
|
|
31
32
|
return task.current_event && (!latest || task.current_event.time_started > latest.time_started) ? task.current_event : latest;
|
|
@@ -58,7 +59,7 @@ AvroQueryClient.prototype.useGetInfiniteJobs = function (body, onProgress) {
|
|
|
58
59
|
...body,
|
|
59
60
|
route_id: body.routeId,
|
|
60
61
|
offset: pageParam,
|
|
61
|
-
});
|
|
62
|
+
}).then((jobs) => jobs.map((job) => new Job(job)));
|
|
62
63
|
},
|
|
63
64
|
});
|
|
64
65
|
if (result.data) {
|
|
@@ -76,7 +77,10 @@ AvroQueryClient.prototype.useGetInfiniteJobs = function (body, onProgress) {
|
|
|
76
77
|
AvroQueryClient.prototype.useGetJob = function (jobId) {
|
|
77
78
|
return useQuery({
|
|
78
79
|
queryKey: ['job', jobId],
|
|
79
|
-
queryFn: () =>
|
|
80
|
+
queryFn: async () => {
|
|
81
|
+
const job = await this.get(`/job/${jobId}`);
|
|
82
|
+
return new Job(job);
|
|
83
|
+
},
|
|
80
84
|
enabled: Boolean(jobId),
|
|
81
85
|
});
|
|
82
86
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { useInfiniteQuery } from '@tanstack/react-query';
|
|
1
|
+
import { useInfiniteQuery, useMutation } from '@tanstack/react-query';
|
|
2
2
|
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
|
+
import { LineItemStatus } from '../../types/api';
|
|
3
4
|
AvroQueryClient.prototype.useGetPrepayments = function (body) {
|
|
4
5
|
const queryClient = this.getQueryClient();
|
|
5
6
|
const result = useInfiniteQuery({
|
|
@@ -34,3 +35,61 @@ AvroQueryClient.prototype.useGetPrepayments = function (body) {
|
|
|
34
35
|
}
|
|
35
36
|
return result;
|
|
36
37
|
};
|
|
38
|
+
AvroQueryClient.prototype.useUpdatePrepayments = function () {
|
|
39
|
+
const queryClient = this.getQueryClient();
|
|
40
|
+
return useMutation({
|
|
41
|
+
mutationFn: async ({ prepayments, action, }) => {
|
|
42
|
+
const prepaymentIds = prepayments.map(prepayment => prepayment.id);
|
|
43
|
+
return this.put(`/company/${this.companyId}/prepayments`, JSON.stringify({
|
|
44
|
+
prepayments: prepaymentIds,
|
|
45
|
+
status: action === "billed" ? LineItemStatus.EXTERNALLY_BILLED : LineItemStatus.EXTERNALLY_PAID,
|
|
46
|
+
}), undefined, {
|
|
47
|
+
"Content-Type": "application/json",
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
onMutate: async ({ prepayments, action }) => {
|
|
51
|
+
await queryClient.cancelQueries({ queryKey: ['prepayments'] });
|
|
52
|
+
await queryClient.cancelQueries({ queryKey: ['prepayment'] });
|
|
53
|
+
const previousPrepayments = queryClient.getQueryData(['prepayments']);
|
|
54
|
+
const previousPrepaymentObjs = prepayments.map(prepayment => queryClient.getQueryData(['prepayment', prepayment.id]));
|
|
55
|
+
const prepaymentIds = prepayments.map(prepayment => prepayment.id);
|
|
56
|
+
prepaymentIds.forEach((prepaymentId, idx) => {
|
|
57
|
+
queryClient.setQueryData(['prepayment', prepaymentId], (oldData) => {
|
|
58
|
+
return oldData
|
|
59
|
+
? { ...oldData, status: action === "billed" ? LineItemStatus.EXTERNALLY_BILLED : LineItemStatus.EXTERNALLY_PAID }
|
|
60
|
+
: oldData;
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
queryClient.setQueriesData({ queryKey: ['prepayments'] }, (oldData) => {
|
|
64
|
+
if (!oldData)
|
|
65
|
+
return oldData;
|
|
66
|
+
if (oldData.pages) {
|
|
67
|
+
const updatedPages = oldData.pages.map((page) => page.map((prepayment) => prepaymentIds.includes(prepayment.id)
|
|
68
|
+
? { ...prepayment, status: action === "billed" ? LineItemStatus.EXTERNALLY_BILLED : LineItemStatus.EXTERNALLY_PAID }
|
|
69
|
+
: prepayment));
|
|
70
|
+
return { ...oldData, pages: updatedPages };
|
|
71
|
+
}
|
|
72
|
+
if (Array.isArray(oldData)) {
|
|
73
|
+
return oldData.map((prepayment) => prepaymentIds.includes(prepayment.id)
|
|
74
|
+
? { ...prepayment, status: action === "billed" ? LineItemStatus.EXTERNALLY_BILLED : LineItemStatus.EXTERNALLY_PAID }
|
|
75
|
+
: prepayment);
|
|
76
|
+
}
|
|
77
|
+
return oldData;
|
|
78
|
+
});
|
|
79
|
+
return { previousPrepayments, previousPrepaymentObjs };
|
|
80
|
+
},
|
|
81
|
+
onError: (err, variables, context) => {
|
|
82
|
+
if (context) {
|
|
83
|
+
queryClient.setQueryData(['prepayments'], context.previousPrepayments);
|
|
84
|
+
context.previousPrepaymentObjs.forEach((prepaymentObj) => {
|
|
85
|
+
queryClient.setQueryData(['prepayment', prepaymentObj.id], prepaymentObj);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
onSettled: () => {
|
|
90
|
+
queryClient.invalidateQueries({ queryKey: ['prepayments'] });
|
|
91
|
+
queryClient.invalidateQueries({ queryKey: ['prepayment'] });
|
|
92
|
+
queryClient.invalidateQueries({ queryKey: ['company'] });
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useMutation, useQuery } from "@tanstack/react-query";
|
|
2
2
|
import { AvroQueryClient } from "../../client/QueryClient";
|
|
3
|
+
import { Task } from "../../types/api/Task";
|
|
3
4
|
AvroQueryClient.prototype.useCreateProposal = function () {
|
|
4
5
|
return useMutation({
|
|
5
6
|
mutationFn: async ({ job_id, data }) => {
|
|
@@ -17,6 +18,12 @@ AvroQueryClient.prototype.useAcceptProposal = function (proposal_id) {
|
|
|
17
18
|
AvroQueryClient.prototype.useGetProposal = function (proposal_id) {
|
|
18
19
|
return useQuery({
|
|
19
20
|
queryKey: ['proposal', proposal_id],
|
|
20
|
-
queryFn: async () =>
|
|
21
|
+
queryFn: async () => {
|
|
22
|
+
const proposal = await this.get(`/proposal/${proposal_id}`);
|
|
23
|
+
if (proposal && Array.isArray(proposal.tasks)) {
|
|
24
|
+
proposal.tasks = proposal.tasks.map((task) => new Task(task));
|
|
25
|
+
}
|
|
26
|
+
return proposal;
|
|
27
|
+
},
|
|
21
28
|
});
|
|
22
29
|
};
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { useMutation, useQuery } from '@tanstack/react-query';
|
|
2
2
|
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
|
+
import { Route } from '../../types/api';
|
|
3
4
|
AvroQueryClient.prototype.useGetRoutes = function (body, total, onProgress) {
|
|
4
5
|
return useQuery({
|
|
5
6
|
queryKey: ['routes', this.companyId, body.amt ?? 50, body.query ?? "", total ?? "all"],
|
|
6
7
|
queryFn: async () => {
|
|
7
8
|
if (typeof total !== "number") {
|
|
8
|
-
|
|
9
|
+
const routes = await this.fetchRoutes({ ...body, offset: 0 });
|
|
10
|
+
return routes.map((route) => new Route(route));
|
|
9
11
|
}
|
|
10
12
|
onProgress?.(0);
|
|
11
13
|
const pageCount = body.amt ? Math.ceil(total / body.amt) + 1 : 1;
|
|
@@ -21,7 +23,7 @@ AvroQueryClient.prototype.useGetRoutes = function (body, total, onProgress) {
|
|
|
21
23
|
return result;
|
|
22
24
|
}));
|
|
23
25
|
const pages = await Promise.all(trackedPromises);
|
|
24
|
-
const routes = pages.flat();
|
|
26
|
+
const routes = pages.flat().map((route) => new Route(route));
|
|
25
27
|
return routes;
|
|
26
28
|
},
|
|
27
29
|
});
|
|
@@ -30,7 +32,10 @@ AvroQueryClient.prototype.useGetRoute = function (routeId) {
|
|
|
30
32
|
const queryClient = this.getQueryClient();
|
|
31
33
|
return useQuery({
|
|
32
34
|
queryKey: ['route', routeId],
|
|
33
|
-
queryFn: () =>
|
|
35
|
+
queryFn: async () => {
|
|
36
|
+
const route = await this.get(`/route/${routeId}`);
|
|
37
|
+
return new Route(route);
|
|
38
|
+
},
|
|
34
39
|
enabled: Boolean(routeId) && routeId.length > 0,
|
|
35
40
|
});
|
|
36
41
|
};
|
|
@@ -50,13 +55,13 @@ AvroQueryClient.prototype.useCreateRoute = function () {
|
|
|
50
55
|
return {
|
|
51
56
|
...oldData,
|
|
52
57
|
pages: [
|
|
53
|
-
[{ ...routeData, id: 'temp-id' }],
|
|
58
|
+
[new Route({ ...routeData, id: 'temp-id' })],
|
|
54
59
|
...oldData.pages,
|
|
55
60
|
],
|
|
56
61
|
};
|
|
57
62
|
}
|
|
58
63
|
if (Array.isArray(oldData)) {
|
|
59
|
-
return [{ ...routeData, id: 'temp-id' }, ...oldData];
|
|
64
|
+
return [new Route({ ...routeData, id: 'temp-id' }), ...oldData];
|
|
60
65
|
}
|
|
61
66
|
return oldData;
|
|
62
67
|
});
|
|
@@ -93,18 +98,18 @@ AvroQueryClient.prototype.useUpdateRoute = function () {
|
|
|
93
98
|
await queryClient.cancelQueries({ queryKey: ['routes'] });
|
|
94
99
|
const previousRoute = queryClient.getQueryData(['route', routeId]);
|
|
95
100
|
const previousRoutes = queryClient.getQueryData(['routes']);
|
|
96
|
-
queryClient.setQueryData(['route', routeId], (oldData) => oldData ? { ...oldData, ...updates } : undefined);
|
|
101
|
+
queryClient.setQueryData(['route', routeId], (oldData) => oldData ? new Route({ ...oldData, ...updates }) : undefined);
|
|
97
102
|
queryClient.setQueriesData({ queryKey: ['routes'] }, (oldData) => {
|
|
98
103
|
if (!oldData)
|
|
99
104
|
return oldData;
|
|
100
105
|
if (oldData.pages) {
|
|
101
106
|
return {
|
|
102
107
|
...oldData,
|
|
103
|
-
pages: oldData.pages.map((page) => page.map((route) => route.id === routeId ? { ...route, ...updates } : route)),
|
|
108
|
+
pages: oldData.pages.map((page) => page.map((route) => route.id === routeId ? new Route({ ...route, ...updates }) : route)),
|
|
104
109
|
};
|
|
105
110
|
}
|
|
106
111
|
if (Array.isArray(oldData)) {
|
|
107
|
-
return oldData.map((route) => route.id === routeId ? { ...route, ...updates } : route);
|
|
112
|
+
return oldData.map((route) => route.id === routeId ? new Route({ ...route, ...updates }) : route);
|
|
108
113
|
}
|
|
109
114
|
return oldData;
|
|
110
115
|
});
|
|
@@ -32,7 +32,21 @@ AvroQueryClient.prototype.useCreateSelf = function () {
|
|
|
32
32
|
mutationFn: async (data) => {
|
|
33
33
|
return this.post('/user', JSON.stringify(data), undefined, { "Content-Type": "application/json" });
|
|
34
34
|
},
|
|
35
|
-
onSettled: () => {
|
|
35
|
+
onSettled: (data) => {
|
|
36
|
+
queryClient.invalidateQueries({ queryKey: ['user'] });
|
|
37
|
+
if (data?.access_token && data?.refresh_token) {
|
|
38
|
+
return this.loginSuccess({ access_token: data.access_token, refresh_token: data.refresh_token });
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
AvroQueryClient.prototype.useCreateUser = function () {
|
|
44
|
+
const queryClient = this.getQueryClient();
|
|
45
|
+
return useMutation({
|
|
46
|
+
mutationFn: async (data) => {
|
|
47
|
+
return this.post('/user', JSON.stringify(data), undefined, { "Content-Type": "application/json" });
|
|
48
|
+
},
|
|
49
|
+
onSettled: (data) => {
|
|
36
50
|
queryClient.invalidateQueries({ queryKey: ['user'] });
|
|
37
51
|
},
|
|
38
52
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { useMutation, useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
|
+
AvroQueryClient.prototype.useCreateWaiver = function () {
|
|
4
|
+
const queryClient = this.getQueryClient();
|
|
5
|
+
return useMutation({
|
|
6
|
+
mutationFn: async ({ waiverData }) => {
|
|
7
|
+
return this.post(`/company/${this.companyId}/waiver`, JSON.stringify(waiverData), undefined, {
|
|
8
|
+
"Content-Type": "application/json",
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
onSettled: () => {
|
|
12
|
+
queryClient.invalidateQueries({ queryKey: ['company'] });
|
|
13
|
+
queryClient.invalidateQueries({ queryKey: ['waivers'] });
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
AvroQueryClient.prototype.useGetWaivers = function (body, total, onProgress) {
|
|
18
|
+
return useQuery({
|
|
19
|
+
queryKey: ['waivers', this.companyId, body.amt ?? 50, body.known_ids ?? [], body.unknown_ids ?? [], body.offset ?? 0, body.query ?? "", total ?? "all"],
|
|
20
|
+
queryFn: async () => {
|
|
21
|
+
if (typeof total !== "number") {
|
|
22
|
+
return this.fetchWaivers({ ...body, offset: 0 });
|
|
23
|
+
}
|
|
24
|
+
onProgress?.(0);
|
|
25
|
+
const pageCount = body.amt ? Math.ceil(total / body.amt) + 1 : 1;
|
|
26
|
+
let completed = 0;
|
|
27
|
+
const promises = Array.from({ length: pageCount }, (_, i) => this.fetchWaivers({
|
|
28
|
+
...body,
|
|
29
|
+
offset: i * (body.amt ?? 1),
|
|
30
|
+
}));
|
|
31
|
+
const trackedPromises = promises.map((promise) => promise.then((result) => {
|
|
32
|
+
completed++;
|
|
33
|
+
const fraction = completed / pageCount;
|
|
34
|
+
onProgress?.(fraction);
|
|
35
|
+
return result;
|
|
36
|
+
}));
|
|
37
|
+
const pages = await Promise.all(trackedPromises);
|
|
38
|
+
const waivers = pages.flat();
|
|
39
|
+
return waivers;
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
AvroQueryClient.prototype.useUpdateWaiver = function () {
|
|
44
|
+
const queryClient = this.getQueryClient();
|
|
45
|
+
return useMutation({
|
|
46
|
+
mutationFn: async ({ waiverId, updates }) => {
|
|
47
|
+
return this.put(`/waiver/${waiverId}`, JSON.stringify(updates), undefined, {
|
|
48
|
+
"Content-Type": "application/json",
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
onMutate: async ({ waiverId, updates }) => {
|
|
52
|
+
await queryClient.cancelQueries({ queryKey: ['waivers'] });
|
|
53
|
+
await queryClient.cancelQueries({ queryKey: ['waiver', waiverId] });
|
|
54
|
+
const previousWaivers = queryClient.getQueryData(['waivers']);
|
|
55
|
+
const previousWaiver = queryClient.getQueryData(['waiver', waiverId]);
|
|
56
|
+
queryClient.setQueryData(['waiver', waiverId], (oldData) => {
|
|
57
|
+
if (!oldData)
|
|
58
|
+
return oldData;
|
|
59
|
+
return { ...oldData, ...updates };
|
|
60
|
+
});
|
|
61
|
+
queryClient.setQueriesData({ queryKey: ['waivers'] }, (oldData) => {
|
|
62
|
+
if (!oldData)
|
|
63
|
+
return oldData;
|
|
64
|
+
if (oldData.pages) {
|
|
65
|
+
const updatedPages = oldData.pages.map((page) => page.map((waiver) => waiver.id === waiverId ? { ...waiver, ...updates } : waiver));
|
|
66
|
+
return { ...oldData, pages: updatedPages };
|
|
67
|
+
}
|
|
68
|
+
if (Array.isArray(oldData)) {
|
|
69
|
+
return oldData.map((waiver) => waiver.id === waiverId ? { ...waiver, ...updates } : waiver);
|
|
70
|
+
}
|
|
71
|
+
return oldData;
|
|
72
|
+
});
|
|
73
|
+
return { previousWaivers, previousWaiver };
|
|
74
|
+
},
|
|
75
|
+
onError: (_err, variables, context) => {
|
|
76
|
+
const { waiverId } = variables;
|
|
77
|
+
if (context?.previousWaivers) {
|
|
78
|
+
queryClient.setQueryData(['waivers'], context.previousWaivers);
|
|
79
|
+
}
|
|
80
|
+
if (context?.previousWaiver) {
|
|
81
|
+
queryClient.setQueryData(['waiver', waiverId], context.previousWaiver);
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
onSettled: (_data, _error, variables) => {
|
|
85
|
+
const { waiverId } = variables;
|
|
86
|
+
queryClient.invalidateQueries({ queryKey: ['waivers'] });
|
|
87
|
+
queryClient.invalidateQueries({ queryKey: ['waiver', waiverId] });
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
AvroQueryClient.prototype.useDeleteWaiver = function () {
|
|
92
|
+
const queryClient = this.getQueryClient();
|
|
93
|
+
return useMutation({
|
|
94
|
+
mutationFn: async ({ waiverId }) => {
|
|
95
|
+
return this.delete(`/waiver/${waiverId}`);
|
|
96
|
+
},
|
|
97
|
+
onMutate: async ({ waiverId }) => {
|
|
98
|
+
await queryClient.cancelQueries({ queryKey: ['waivers'] });
|
|
99
|
+
const previousWaivers = queryClient.getQueryData(['waivers']);
|
|
100
|
+
queryClient.setQueriesData({ queryKey: ['waivers'] }, (oldData) => {
|
|
101
|
+
if (!oldData)
|
|
102
|
+
return oldData;
|
|
103
|
+
if (oldData.pages) {
|
|
104
|
+
const updatedPages = oldData.pages.map((page) => page.filter((waiver) => waiver.id !== waiverId));
|
|
105
|
+
return { ...oldData, pages: updatedPages };
|
|
106
|
+
}
|
|
107
|
+
if (Array.isArray(oldData)) {
|
|
108
|
+
return oldData.filter((waiver) => waiver.id !== waiverId);
|
|
109
|
+
}
|
|
110
|
+
return oldData;
|
|
111
|
+
});
|
|
112
|
+
return { previousWaivers };
|
|
113
|
+
},
|
|
114
|
+
onError: (_err, variables, context) => {
|
|
115
|
+
if (context?.previousWaivers) {
|
|
116
|
+
queryClient.setQueryData(['waivers'], context.previousWaivers);
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
onSettled: () => {
|
|
120
|
+
queryClient.invalidateQueries({ queryKey: ['waivers'] });
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ import './client/hooks/labels';
|
|
|
26
26
|
import './client/hooks/groups';
|
|
27
27
|
import './client/hooks/skills';
|
|
28
28
|
import './client/hooks/proposal';
|
|
29
|
+
import './client/hooks/waivers';
|
|
29
30
|
export * from './types/api';
|
|
30
31
|
export * from './types/auth';
|
|
31
32
|
export * from './types/cache';
|
package/dist/index.js
CHANGED
|
@@ -26,6 +26,7 @@ import './client/hooks/labels';
|
|
|
26
26
|
import './client/hooks/groups';
|
|
27
27
|
import './client/hooks/skills';
|
|
28
28
|
import './client/hooks/proposal';
|
|
29
|
+
import './client/hooks/waivers';
|
|
29
30
|
export * from './types/api';
|
|
30
31
|
export * from './types/auth';
|
|
31
32
|
export * from './types/cache';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { BillPayment } from "../../types/api/BillPayment";
|
|
2
|
+
import { BillUser } from "../../types/api/BillUser";
|
|
3
|
+
import { CustomLineItem } from "../../types/api/CustomLineItem";
|
|
4
|
+
import { PaymentType } from "../../types/api/PaymentType";
|
|
5
|
+
export interface Bill {
|
|
6
|
+
id: string;
|
|
7
|
+
invoice_id: number;
|
|
8
|
+
intuit_id: string | null;
|
|
9
|
+
name: string;
|
|
10
|
+
amount: number;
|
|
11
|
+
billed_by: string;
|
|
12
|
+
customer_email: string | null;
|
|
13
|
+
manual_emails: string[][];
|
|
14
|
+
users: BillUser[];
|
|
15
|
+
status: "SENT" | "PAID" | "PARTIALLY_PAID" | "MANUALLY_PAID";
|
|
16
|
+
enabled_payment_methods: PaymentType[];
|
|
17
|
+
time_created: number;
|
|
18
|
+
time_updated: number;
|
|
19
|
+
events: string[];
|
|
20
|
+
intent_created_at: number;
|
|
21
|
+
intent_last_created_at: number;
|
|
22
|
+
payments: BillPayment[];
|
|
23
|
+
line_items: CustomLineItem[];
|
|
24
|
+
prepayments: string[];
|
|
25
|
+
months: string[];
|
|
26
|
+
due_date: number;
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|