@go-avro/avro-js 0.0.2-beta.69 → 0.0.2-beta.70
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.
|
@@ -26,6 +26,10 @@ declare module '../client/QueryClient' {
|
|
|
26
26
|
amt?: number;
|
|
27
27
|
query?: string;
|
|
28
28
|
}, total: number, onProgress?: (fraction: number) => void): UseQueryResult<any[], StandardError>;
|
|
29
|
+
useGetTeams(companyGuid: string, body: {
|
|
30
|
+
amt?: number;
|
|
31
|
+
query?: string;
|
|
32
|
+
}, total: number, onProgress?: (fraction: number) => void): UseQueryResult<any[], StandardError>;
|
|
29
33
|
useGetEvents(companyGuid: string, body: {
|
|
30
34
|
amt?: number;
|
|
31
35
|
known_ids?: string[];
|
|
@@ -224,6 +228,11 @@ declare module '../client/QueryClient' {
|
|
|
224
228
|
}, StandardError, {
|
|
225
229
|
companyId: string;
|
|
226
230
|
}>>;
|
|
231
|
+
useDeleteTeam(): ReturnType<typeof useMutation<{
|
|
232
|
+
msg: string;
|
|
233
|
+
}, StandardError, {
|
|
234
|
+
teamId: string;
|
|
235
|
+
}>>;
|
|
227
236
|
}
|
|
228
237
|
}
|
|
229
238
|
export declare class AvroQueryClient {
|
|
@@ -303,6 +312,13 @@ export declare class AvroQueryClient {
|
|
|
303
312
|
query?: string;
|
|
304
313
|
offset?: number;
|
|
305
314
|
}, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<any>;
|
|
315
|
+
fetchTeams(companyGuid: string, body?: {
|
|
316
|
+
amt?: number;
|
|
317
|
+
known_ids?: string[];
|
|
318
|
+
unknown_ids?: string[];
|
|
319
|
+
query?: string;
|
|
320
|
+
offset?: number;
|
|
321
|
+
}, cancelToken?: CancelToken, headers?: Record<string, string>): Promise<any>;
|
|
306
322
|
sendEmail(emailId: string, formData: FormData, progressUpdateCallback?: (loaded: number, total: number) => void): Promise<void>;
|
|
307
323
|
createBill(companyGuid: string, data: {
|
|
308
324
|
line_items: LineItem[];
|
|
@@ -221,6 +221,22 @@ export class AvroQueryClient {
|
|
|
221
221
|
throw new StandardError(500, 'Failed to fetch routes');
|
|
222
222
|
});
|
|
223
223
|
}
|
|
224
|
+
fetchTeams(companyGuid, body = {}, cancelToken, headers = {}) {
|
|
225
|
+
if (!companyGuid || companyGuid.trim() === '') {
|
|
226
|
+
return Promise.reject(new StandardError(400, 'Company GUID is required'));
|
|
227
|
+
}
|
|
228
|
+
return this._fetch('POST', `/company/${companyGuid}/teams`, body, cancelToken, headers)
|
|
229
|
+
.then(response => {
|
|
230
|
+
if (!response || !Array.isArray(response)) {
|
|
231
|
+
throw new StandardError(400, 'Invalid teams response');
|
|
232
|
+
}
|
|
233
|
+
return response;
|
|
234
|
+
})
|
|
235
|
+
.catch(err => {
|
|
236
|
+
console.error('Failed to fetch teams:', err);
|
|
237
|
+
throw new StandardError(500, 'Failed to fetch teams');
|
|
238
|
+
});
|
|
239
|
+
}
|
|
224
240
|
sendEmail(emailId, formData, progressUpdateCallback) {
|
|
225
241
|
try {
|
|
226
242
|
return this.post(`/email/${emailId}`, formData, undefined, {}, progressUpdateCallback);
|
|
@@ -85,9 +85,7 @@ AvroQueryClient.prototype.useDeleteRoute = function () {
|
|
|
85
85
|
const queryClient = useQueryClient();
|
|
86
86
|
return useMutation({
|
|
87
87
|
mutationFn: async ({ routeId, }) => {
|
|
88
|
-
return this.delete(`/route/${routeId}
|
|
89
|
-
"Content-Type": "application/json",
|
|
90
|
-
});
|
|
88
|
+
return this.delete(`/route/${routeId}`);
|
|
91
89
|
},
|
|
92
90
|
onMutate: async ({ routeId }) => {
|
|
93
91
|
await queryClient.cancelQueries({ queryKey: ['routes'] });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { AvroQueryClient } from "../../client/QueryClient";
|
|
2
|
+
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
3
|
+
AvroQueryClient.prototype.useGetTeams = function (companyGuid, body, total = 0, onProgress) {
|
|
4
|
+
const queryClient = useQueryClient();
|
|
5
|
+
return useQuery({
|
|
6
|
+
queryKey: ['teams', companyGuid, body.amt ?? 50, body.query ?? ""],
|
|
7
|
+
queryFn: async () => {
|
|
8
|
+
if (total === 0) {
|
|
9
|
+
onProgress?.(1);
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
onProgress?.(0);
|
|
13
|
+
const pageCount = body.amt ? Math.ceil(total / body.amt) : 0;
|
|
14
|
+
let completed = 0;
|
|
15
|
+
const promises = Array.from({ length: pageCount }, (_, i) => this.fetchTeams(companyGuid, {
|
|
16
|
+
...body,
|
|
17
|
+
offset: i * (body.amt ?? 0),
|
|
18
|
+
}));
|
|
19
|
+
const trackedPromises = promises.map((promise) => promise.then((result) => {
|
|
20
|
+
completed++;
|
|
21
|
+
const fraction = completed / pageCount;
|
|
22
|
+
onProgress?.(fraction);
|
|
23
|
+
return result;
|
|
24
|
+
}));
|
|
25
|
+
const pages = await Promise.all(trackedPromises);
|
|
26
|
+
const routes = pages.flat();
|
|
27
|
+
return routes;
|
|
28
|
+
},
|
|
29
|
+
enabled: Boolean(companyGuid) && companyGuid.length > 0 && Boolean(total) && total >= 0,
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
AvroQueryClient.prototype.useDeleteTeam = function () {
|
|
33
|
+
const queryClient = useQueryClient();
|
|
34
|
+
return useMutation({
|
|
35
|
+
mutationFn: async ({ teamId, }) => {
|
|
36
|
+
return this.delete(`/team/${teamId}`);
|
|
37
|
+
},
|
|
38
|
+
onMutate: async ({ teamId }) => {
|
|
39
|
+
await queryClient.cancelQueries({ queryKey: ['teams'] });
|
|
40
|
+
await queryClient.cancelQueries({ queryKey: ['team', teamId] });
|
|
41
|
+
const previousRoutes = queryClient.getQueryData(['teams']);
|
|
42
|
+
const previousRoute = queryClient.getQueryData(['team', teamId]);
|
|
43
|
+
queryClient.setQueryData(['team', teamId], undefined);
|
|
44
|
+
queryClient.setQueriesData({ queryKey: ['teams'] }, (oldData) => {
|
|
45
|
+
if (!oldData)
|
|
46
|
+
return oldData;
|
|
47
|
+
if (oldData.pages) {
|
|
48
|
+
const updatedPages = oldData.pages.map((page) => page.filter((team) => team.id !== teamId));
|
|
49
|
+
return { ...oldData, pages: updatedPages };
|
|
50
|
+
}
|
|
51
|
+
if (Array.isArray(oldData)) {
|
|
52
|
+
return oldData.filter((team) => team.id !== teamId);
|
|
53
|
+
}
|
|
54
|
+
return oldData;
|
|
55
|
+
});
|
|
56
|
+
return { previousRoutes, previousRoute };
|
|
57
|
+
},
|
|
58
|
+
onError: (_err, variables, context) => {
|
|
59
|
+
const { teamId } = variables;
|
|
60
|
+
if (context?.previousRoutes) {
|
|
61
|
+
queryClient.setQueryData(['teams'], context.previousRoutes);
|
|
62
|
+
}
|
|
63
|
+
if (context?.previousRoute) {
|
|
64
|
+
queryClient.setQueryData(['team', teamId], context.previousRoute);
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
onSettled: (_data, _error, variables) => {
|
|
68
|
+
const { teamId } = variables;
|
|
69
|
+
queryClient.invalidateQueries({ queryKey: ['teams'] });
|
|
70
|
+
queryClient.invalidateQueries({ queryKey: ['team', teamId] });
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ import './client/hooks/messages';
|
|
|
18
18
|
import './client/hooks/plans';
|
|
19
19
|
import './client/hooks/analytics';
|
|
20
20
|
import './client/hooks/avro';
|
|
21
|
+
import './client/hooks/teams';
|
|
21
22
|
export * from './types/api';
|
|
22
23
|
export * from './types/auth';
|
|
23
24
|
export * from './types/error';
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,7 @@ import './client/hooks/messages';
|
|
|
18
18
|
import './client/hooks/plans';
|
|
19
19
|
import './client/hooks/analytics';
|
|
20
20
|
import './client/hooks/avro';
|
|
21
|
+
import './client/hooks/teams';
|
|
21
22
|
export * from './types/api';
|
|
22
23
|
export * from './types/auth';
|
|
23
24
|
export * from './types/error';
|