@go-avro/avro-js 0.0.2-beta.72 → 0.0.2-beta.73
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,7 +1,7 @@
|
|
|
1
1
|
import { Socket } from 'socket.io-client';
|
|
2
2
|
import { InfiniteData, UseInfiniteQueryResult, useMutation, UseQueryResult } from '@tanstack/react-query';
|
|
3
3
|
import { AuthManager } from '../auth/AuthManager';
|
|
4
|
-
import { _Event, ApiInfo, Avro, Bill, Break, Chat, Company, Job, LineItem, LoginResponse, Message, Plan, Route, ServiceMonth, Session, User, UserCompanyAssociation } from '../types/api';
|
|
4
|
+
import { _Event, ApiInfo, Avro, Bill, Break, Chat, Company, Job, LineItem, LoginResponse, Message, Plan, Route, ServiceMonth, Session, Team, User, UserCompanyAssociation } from '../types/api';
|
|
5
5
|
import { Tokens } from '../types/auth';
|
|
6
6
|
import { CancelToken, RetryStrategy } from '../types/client';
|
|
7
7
|
import { StandardError } from '../types/error';
|
|
@@ -172,6 +172,12 @@ declare module '../client/QueryClient' {
|
|
|
172
172
|
})[];
|
|
173
173
|
action: "billed" | "paid";
|
|
174
174
|
}>>;
|
|
175
|
+
useUpdateTeam(): ReturnType<typeof useMutation<{
|
|
176
|
+
msg: string;
|
|
177
|
+
}, StandardError, {
|
|
178
|
+
teamId: string;
|
|
179
|
+
teamData: Partial<Team>;
|
|
180
|
+
}>>;
|
|
175
181
|
useUpdateMonths(): ReturnType<typeof useMutation<void, StandardError, {
|
|
176
182
|
companyId: string;
|
|
177
183
|
months: (ServiceMonth & {
|
|
@@ -21,12 +21,58 @@ AvroQueryClient.prototype.useGetTeams = function (companyGuid, body, total, onPr
|
|
|
21
21
|
return result;
|
|
22
22
|
}));
|
|
23
23
|
const pages = await Promise.all(trackedPromises);
|
|
24
|
-
const
|
|
25
|
-
return
|
|
24
|
+
const teams = pages.flat();
|
|
25
|
+
return teams;
|
|
26
26
|
},
|
|
27
27
|
enabled: Boolean(companyGuid) && companyGuid.length > 0,
|
|
28
28
|
});
|
|
29
29
|
};
|
|
30
|
+
AvroQueryClient.prototype.useUpdateTeam = function () {
|
|
31
|
+
const queryClient = useQueryClient();
|
|
32
|
+
return useMutation({
|
|
33
|
+
mutationFn: async ({ teamId, teamData }) => {
|
|
34
|
+
return this.put(`/team/${teamId}`, JSON.stringify(teamData), undefined, { "Content-Type": "application/json" });
|
|
35
|
+
},
|
|
36
|
+
onMutate: async ({ teamId, teamData }) => {
|
|
37
|
+
await queryClient.cancelQueries({ queryKey: ['teams'] });
|
|
38
|
+
await queryClient.cancelQueries({ queryKey: ['team', teamId] });
|
|
39
|
+
const previousTeams = queryClient.getQueryData(['teams']);
|
|
40
|
+
const previousTeam = queryClient.getQueryData(['team', teamId]);
|
|
41
|
+
queryClient.setQueryData(['team', teamId], (oldData) => {
|
|
42
|
+
if (!oldData)
|
|
43
|
+
return oldData;
|
|
44
|
+
return { ...oldData, ...teamData };
|
|
45
|
+
});
|
|
46
|
+
queryClient.setQueriesData({ queryKey: ['teams'] }, (oldData) => {
|
|
47
|
+
if (!oldData)
|
|
48
|
+
return oldData;
|
|
49
|
+
if (oldData.pages) {
|
|
50
|
+
const updatedPages = oldData.pages.map((page) => page.map((team) => team.id === teamId ? { ...team, ...teamData } : team));
|
|
51
|
+
return { ...oldData, pages: updatedPages };
|
|
52
|
+
}
|
|
53
|
+
if (Array.isArray(oldData)) {
|
|
54
|
+
return oldData.map((team) => team.id === teamId ? { ...team, ...teamData } : team);
|
|
55
|
+
}
|
|
56
|
+
return oldData;
|
|
57
|
+
});
|
|
58
|
+
return { previousTeams, previousTeam };
|
|
59
|
+
},
|
|
60
|
+
onError: (_err, variables, context) => {
|
|
61
|
+
const { teamId } = variables;
|
|
62
|
+
if (context?.previousTeams) {
|
|
63
|
+
queryClient.setQueryData(['teams'], context.previousTeams);
|
|
64
|
+
}
|
|
65
|
+
if (context?.previousTeam) {
|
|
66
|
+
queryClient.setQueryData(['team', teamId], context.previousTeam);
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
onSettled: (_data, _error, variables) => {
|
|
70
|
+
const { teamId } = variables;
|
|
71
|
+
queryClient.invalidateQueries({ queryKey: ['teams'] });
|
|
72
|
+
queryClient.invalidateQueries({ queryKey: ['team', teamId] });
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
};
|
|
30
76
|
AvroQueryClient.prototype.useDeleteTeam = function () {
|
|
31
77
|
const queryClient = useQueryClient();
|
|
32
78
|
return useMutation({
|