@go-avro/avro-js 0.0.2-beta.72 → 0.0.2-beta.74

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';
@@ -128,6 +128,8 @@ declare module '../client/QueryClient' {
128
128
  email: string;
129
129
  password: string;
130
130
  phone_number: string;
131
+ code: string;
132
+ invite_token: string;
131
133
  }>>;
132
134
  useCreateSessionBreak(): ReturnType<typeof useMutation<{
133
135
  id: string;
@@ -172,6 +174,12 @@ declare module '../client/QueryClient' {
172
174
  })[];
173
175
  action: "billed" | "paid";
174
176
  }>>;
177
+ useUpdateTeam(): ReturnType<typeof useMutation<{
178
+ msg: string;
179
+ }, StandardError, {
180
+ teamId: string;
181
+ teamData: Partial<Team>;
182
+ }>>;
175
183
  useUpdateMonths(): ReturnType<typeof useMutation<void, StandardError, {
176
184
  companyId: string;
177
185
  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 routes = pages.flat();
25
- return routes;
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({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.2-beta.72",
3
+ "version": "0.0.2-beta.74",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",