@go-avro/avro-js 0.0.2-beta.43 → 0.0.2-beta.45
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 +11 -1
- package/dist/client/hooks/bills.js +1 -1
- package/dist/client/hooks/companies.js +1 -1
- package/dist/client/hooks/events.js +1 -1
- package/dist/client/hooks/jobs.js +1 -1
- package/dist/client/hooks/months.js +1 -1
- package/dist/client/hooks/root.js +1 -1
- package/dist/client/hooks/routes.js +1 -1
- package/dist/client/hooks/sessions.js +70 -1
- package/dist/client/hooks/users.js +1 -1
- package/dist/types/api.d.ts +2 -2
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { InfiniteData, UseInfiniteQueryResult, useMutation, useQuery, UseQueryResult } from '@tanstack/react-query';
|
|
1
2
|
import { AuthManager } from '../auth/AuthManager';
|
|
2
3
|
import { _Event, Bill, Company, Job, LineItem, ServiceMonth, Session, User } from '../types/api';
|
|
3
4
|
import { CancelToken, RetryStrategy } from '../types/client';
|
|
4
5
|
import { StandardError } from '../types/error';
|
|
5
|
-
import { InfiniteData, UseInfiniteQueryResult, useMutation, useQuery, UseQueryResult } from '@tanstack/react-query';
|
|
6
6
|
export interface AvroQueryClientConfig {
|
|
7
7
|
baseUrl: string;
|
|
8
8
|
authManager: AuthManager;
|
|
@@ -62,6 +62,12 @@ declare module '../client/QueryClient' {
|
|
|
62
62
|
useGetSelf(): UseQueryResult<User, StandardError>;
|
|
63
63
|
useGetBill(billId: string): UseQueryResult<Bill, StandardError>;
|
|
64
64
|
useGetUserSessions(): UseQueryResult<Session[], StandardError>;
|
|
65
|
+
useCreateUserSession(): ReturnType<typeof useMutation<{
|
|
66
|
+
id: string;
|
|
67
|
+
}, StandardError, {
|
|
68
|
+
companyId: string;
|
|
69
|
+
sessionData: Partial<Session>;
|
|
70
|
+
}>>;
|
|
65
71
|
useCreateBill(): ReturnType<typeof useMutation<{
|
|
66
72
|
id: string;
|
|
67
73
|
invoice_id: number;
|
|
@@ -80,6 +86,10 @@ declare module '../client/QueryClient' {
|
|
|
80
86
|
companyId: string;
|
|
81
87
|
jobData: Partial<Job>;
|
|
82
88
|
}>>;
|
|
89
|
+
useUpdateUserSession(): ReturnType<typeof useMutation<void, StandardError, {
|
|
90
|
+
sessionId: string;
|
|
91
|
+
updates: Partial<Session>;
|
|
92
|
+
}>>;
|
|
83
93
|
useUpdateJob(): ReturnType<typeof useMutation<{
|
|
84
94
|
msg: string;
|
|
85
95
|
}, StandardError, {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AvroQueryClient } from '../../client/QueryClient';
|
|
2
1
|
import { useQueryClient, useInfiniteQuery, useQuery, useMutation } from '@tanstack/react-query';
|
|
2
|
+
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
3
|
AvroQueryClient.prototype.useGetBills = function (companyGuid, body) {
|
|
4
4
|
const queryClient = useQueryClient();
|
|
5
5
|
const result = useInfiniteQuery({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AvroQueryClient } from '../../client/QueryClient';
|
|
2
1
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
3
|
AvroQueryClient.prototype.useGetCompanies = function (options = {}) {
|
|
4
4
|
return useQuery({
|
|
5
5
|
queryKey: ['/company/list'],
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AvroQueryClient } from '../../client/QueryClient';
|
|
2
1
|
import { useQueryClient, useInfiniteQuery, useQuery, useMutation } from '@tanstack/react-query';
|
|
2
|
+
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
3
|
AvroQueryClient.prototype.useGetEvents = function (companyGuid, body) {
|
|
4
4
|
const queryClient = useQueryClient();
|
|
5
5
|
const result = useInfiniteQuery({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AvroQueryClient } from '../../client/QueryClient';
|
|
2
1
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
3
|
AvroQueryClient.prototype.useGetJobs = function (companyGuid, body, total = 0, onProgress, isMainLoad = false) {
|
|
4
4
|
const queryClient = useQueryClient();
|
|
5
5
|
return useQuery({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AvroQueryClient } from '../../client/QueryClient';
|
|
2
1
|
import { useQueryClient, useInfiniteQuery, useMutation } from '@tanstack/react-query';
|
|
2
|
+
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
3
|
AvroQueryClient.prototype.useGetMonths = function (companyGuid, body) {
|
|
4
4
|
const queryClient = useQueryClient();
|
|
5
5
|
const result = useInfiniteQuery({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AvroQueryClient } from '../../client/QueryClient';
|
|
2
1
|
import { useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
3
|
AvroQueryClient.prototype.useGetRoot = function () {
|
|
4
4
|
return useQuery({
|
|
5
5
|
queryKey: ['health'],
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AvroQueryClient } from '../../client/QueryClient';
|
|
2
1
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
3
|
AvroQueryClient.prototype.useGetRoutes = function (companyGuid, body, total = 0, onProgress) {
|
|
4
4
|
const queryClient = useQueryClient();
|
|
5
5
|
return useQuery({
|
|
@@ -1,8 +1,77 @@
|
|
|
1
|
+
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
1
2
|
import { AvroQueryClient } from "../../client/QueryClient";
|
|
2
|
-
import { useQuery } from "@tanstack/react-query";
|
|
3
3
|
AvroQueryClient.prototype.useGetUserSessions = function () {
|
|
4
4
|
return useQuery({
|
|
5
5
|
queryKey: ['sessions'],
|
|
6
6
|
queryFn: () => this.get('/session'),
|
|
7
7
|
});
|
|
8
8
|
};
|
|
9
|
+
AvroQueryClient.prototype.useCreateUserSession = function () {
|
|
10
|
+
const queryClient = useQueryClient();
|
|
11
|
+
return useMutation({
|
|
12
|
+
mutationFn: ({ companyId, sessionData }) => {
|
|
13
|
+
return this.post(`/company/${companyId}/session`, JSON.stringify(sessionData), undefined, {
|
|
14
|
+
"Content-Type": "application/json",
|
|
15
|
+
});
|
|
16
|
+
},
|
|
17
|
+
onMutate: async ({ companyId, sessionData }) => {
|
|
18
|
+
await queryClient.cancelQueries({ queryKey: ['sessions'] });
|
|
19
|
+
const previousSessions = queryClient.getQueryData(['sessions']);
|
|
20
|
+
queryClient.setQueryData(['sessions'], (oldData) => {
|
|
21
|
+
if (!oldData)
|
|
22
|
+
return [];
|
|
23
|
+
if (Array.isArray(oldData)) {
|
|
24
|
+
return [
|
|
25
|
+
...oldData,
|
|
26
|
+
{
|
|
27
|
+
...sessionData,
|
|
28
|
+
id: Math.random().toString(36).substr(2, 9),
|
|
29
|
+
company_id: companyId,
|
|
30
|
+
}
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
return oldData;
|
|
34
|
+
});
|
|
35
|
+
return { previousSessions };
|
|
36
|
+
},
|
|
37
|
+
onError: (err, variables, context) => {
|
|
38
|
+
if (context?.previousSessions) {
|
|
39
|
+
queryClient.setQueryData(['sessions'], context.previousSessions);
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
onSettled: () => {
|
|
43
|
+
queryClient.invalidateQueries({ queryKey: ['sessions'] });
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
AvroQueryClient.prototype.useUpdateUserSession = function () {
|
|
48
|
+
const queryClient = useQueryClient();
|
|
49
|
+
return useMutation({
|
|
50
|
+
mutationFn: ({ sessionId, updates }) => {
|
|
51
|
+
return this.put(`/session/${sessionId}`, JSON.stringify(updates), undefined, {
|
|
52
|
+
"Content-Type": "application/json",
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
onMutate: async ({ sessionId, updates }) => {
|
|
56
|
+
await queryClient.cancelQueries({ queryKey: ['sessions'] });
|
|
57
|
+
const previousSessions = queryClient.getQueryData(['sessions']);
|
|
58
|
+
queryClient.setQueryData(['sessions'], (oldData) => {
|
|
59
|
+
if (!oldData)
|
|
60
|
+
return oldData;
|
|
61
|
+
if (Array.isArray(oldData)) {
|
|
62
|
+
return oldData.map((session) => session.id === sessionId ? { ...session, ...updates } : session);
|
|
63
|
+
}
|
|
64
|
+
return oldData;
|
|
65
|
+
});
|
|
66
|
+
return { previousSessions };
|
|
67
|
+
},
|
|
68
|
+
onError: (err, variables, context) => {
|
|
69
|
+
if (context?.previousSessions) {
|
|
70
|
+
queryClient.setQueryData(['sessions'], context.previousSessions);
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
onSettled: () => {
|
|
74
|
+
queryClient.invalidateQueries({ queryKey: ['sessions'] });
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AvroQueryClient } from "../../client/QueryClient";
|
|
2
1
|
import { useQuery } from "@tanstack/react-query";
|
|
2
|
+
import { AvroQueryClient } from "../../client/QueryClient";
|
|
3
3
|
AvroQueryClient.prototype.useGetUser = function (userId) {
|
|
4
4
|
return useQuery({
|
|
5
5
|
queryKey: ['user', userId],
|
package/dist/types/api.d.ts
CHANGED
|
@@ -226,7 +226,7 @@ export interface ServiceMonth extends LineItem {
|
|
|
226
226
|
time_updated: number | null;
|
|
227
227
|
}
|
|
228
228
|
export interface Session {
|
|
229
|
-
|
|
229
|
+
id: string;
|
|
230
230
|
user_id: string;
|
|
231
231
|
company_id: string;
|
|
232
232
|
time_started: number;
|
|
@@ -234,7 +234,7 @@ export interface Session {
|
|
|
234
234
|
break_id: string;
|
|
235
235
|
is_paused: boolean;
|
|
236
236
|
team_id: string;
|
|
237
|
-
|
|
237
|
+
route_id: string;
|
|
238
238
|
breaks: Break[];
|
|
239
239
|
}
|
|
240
240
|
export interface Group {
|