@go-avro/avro-js 0.0.2-beta.46 → 0.0.2-beta.48
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { InfiniteData, UseInfiniteQueryResult, useMutation,
|
|
1
|
+
import { InfiniteData, UseInfiniteQueryResult, useMutation, UseQueryResult } from '@tanstack/react-query';
|
|
2
2
|
import { AuthManager } from '../auth/AuthManager';
|
|
3
|
-
import { _Event, Bill, Company, Job, LineItem, ServiceMonth, Session, User } from '../types/api';
|
|
3
|
+
import { _Event, ApiInfo, Bill, Company, Job, LineItem, Route, ServiceMonth, Session, User } from '../types/api';
|
|
4
4
|
import { CancelToken, RetryStrategy } from '../types/client';
|
|
5
5
|
import { StandardError } from '../types/error';
|
|
6
6
|
export interface AvroQueryClientConfig {
|
|
@@ -15,7 +15,7 @@ declare module '../client/QueryClient' {
|
|
|
15
15
|
_xhr<T>(method: string, path: string, body: any, cancelToken?: CancelToken, headers?: Record<string, string>, isIdempotent?: boolean, retryCount?: number): Promise<T>;
|
|
16
16
|
_fetch<T>(method: string, path: string, body: any, cancelToken?: CancelToken, headers?: Record<string, string>, isIdempotent?: boolean, retryCount?: number): Promise<T>;
|
|
17
17
|
getDelay(strategy: RetryStrategy, attempt: number): number;
|
|
18
|
-
useGetRoot():
|
|
18
|
+
useGetRoot(): UseQueryResult<ApiInfo, StandardError>;
|
|
19
19
|
useGetJobs(companyGuid: string, body: {
|
|
20
20
|
amt?: number;
|
|
21
21
|
query?: string;
|
|
@@ -61,6 +61,7 @@ declare module '../client/QueryClient' {
|
|
|
61
61
|
useGetUser(userId: string): UseQueryResult<User, StandardError>;
|
|
62
62
|
useGetSelf(): UseQueryResult<User, StandardError>;
|
|
63
63
|
useGetBill(billId: string): UseQueryResult<Bill, StandardError>;
|
|
64
|
+
useGetRoute(routeId: string): UseQueryResult<Route, StandardError>;
|
|
64
65
|
useGetUserSessions(): UseQueryResult<Session[], StandardError>;
|
|
65
66
|
useCreateUserSession(): ReturnType<typeof useMutation<{
|
|
66
67
|
id: string;
|
|
@@ -104,6 +105,12 @@ declare module '../client/QueryClient' {
|
|
|
104
105
|
billId: string;
|
|
105
106
|
updates: Partial<Bill>;
|
|
106
107
|
}>>;
|
|
108
|
+
useUpdateRoute(): ReturnType<typeof useMutation<{
|
|
109
|
+
msg: string;
|
|
110
|
+
}, StandardError, {
|
|
111
|
+
routeId: string;
|
|
112
|
+
updates: Partial<Route>;
|
|
113
|
+
}>>;
|
|
107
114
|
useUpdateEvents(): ReturnType<typeof useMutation<void, StandardError, {
|
|
108
115
|
companyId: string;
|
|
109
116
|
events: (_Event & {
|
|
@@ -3,6 +3,6 @@ import { AvroQueryClient } from '../../client/QueryClient';
|
|
|
3
3
|
AvroQueryClient.prototype.useGetRoot = function () {
|
|
4
4
|
return useQuery({
|
|
5
5
|
queryKey: ['health'],
|
|
6
|
-
queryFn: () => this.get('/',
|
|
6
|
+
queryFn: () => this.get('/'),
|
|
7
7
|
});
|
|
8
8
|
};
|
|
@@ -29,6 +29,58 @@ AvroQueryClient.prototype.useGetRoutes = function (companyGuid, body, total = 0,
|
|
|
29
29
|
enabled: Boolean(companyGuid) && companyGuid.length > 0 && Boolean(total) && total >= 0,
|
|
30
30
|
});
|
|
31
31
|
};
|
|
32
|
+
AvroQueryClient.prototype.useGetRoute = function (routeId) {
|
|
33
|
+
const queryClient = useQueryClient();
|
|
34
|
+
return useQuery({
|
|
35
|
+
queryKey: ['route', routeId],
|
|
36
|
+
queryFn: () => this.get(`/route/${routeId}`),
|
|
37
|
+
enabled: Boolean(routeId) && routeId.length > 0,
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
AvroQueryClient.prototype.useUpdateRoute = function () {
|
|
41
|
+
const queryClient = useQueryClient();
|
|
42
|
+
return useMutation({
|
|
43
|
+
mutationFn: async ({ routeId, updates, }) => {
|
|
44
|
+
return this.put(`/route/${routeId}`, JSON.stringify(updates), undefined, { "Content-Type": "application/json" });
|
|
45
|
+
},
|
|
46
|
+
onMutate: async ({ routeId, updates }) => {
|
|
47
|
+
await queryClient.cancelQueries({ queryKey: ['route', routeId] });
|
|
48
|
+
await queryClient.cancelQueries({ queryKey: ['routes'] });
|
|
49
|
+
const previousRoute = queryClient.getQueryData(['route', routeId]);
|
|
50
|
+
const previousRoutes = queryClient.getQueryData(['routes']);
|
|
51
|
+
queryClient.setQueryData(['route', routeId], (oldData) => oldData ? { ...oldData, ...updates } : undefined);
|
|
52
|
+
queryClient.setQueriesData({ queryKey: ['routes'] }, (oldData) => {
|
|
53
|
+
if (!oldData)
|
|
54
|
+
return oldData;
|
|
55
|
+
if (oldData.pages) {
|
|
56
|
+
return {
|
|
57
|
+
...oldData,
|
|
58
|
+
pages: oldData.pages.map((page) => page.map((route) => route.id === routeId ? { ...route, ...updates } : route)),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (Array.isArray(oldData)) {
|
|
62
|
+
return oldData.map((route) => route.id === routeId ? { ...route, ...updates } : route);
|
|
63
|
+
}
|
|
64
|
+
return oldData;
|
|
65
|
+
});
|
|
66
|
+
return { previousRoute, previousRoutes };
|
|
67
|
+
},
|
|
68
|
+
onError: (_err, variables, context) => {
|
|
69
|
+
const { routeId } = variables;
|
|
70
|
+
if (context?.previousRoute) {
|
|
71
|
+
queryClient.setQueryData(['route', routeId], context.previousRoute);
|
|
72
|
+
}
|
|
73
|
+
if (context?.previousRoutes) {
|
|
74
|
+
queryClient.setQueryData(['routes'], context.previousRoutes);
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
onSettled: (_data, _error, variables) => {
|
|
78
|
+
const { routeId } = variables;
|
|
79
|
+
queryClient.invalidateQueries({ queryKey: ['route', routeId] });
|
|
80
|
+
queryClient.invalidateQueries({ queryKey: ['routes'] });
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
};
|
|
32
84
|
AvroQueryClient.prototype.useDeleteRoute = function () {
|
|
33
85
|
const queryClient = useQueryClient();
|
|
34
86
|
return useMutation({
|
package/dist/types/api.d.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
export interface ApiInfo {
|
|
2
|
+
app_semver: string;
|
|
3
|
+
db_healthy: boolean;
|
|
4
|
+
logged_in_as: string;
|
|
5
|
+
ors_healthy: string;
|
|
6
|
+
pelias_healthy: boolean;
|
|
7
|
+
version: string;
|
|
8
|
+
vroom_healthy: boolean;
|
|
9
|
+
}
|
|
1
10
|
export interface PaymentMethod {
|
|
2
11
|
allow_redisplay: string;
|
|
3
12
|
autopay: boolean;
|