@go-avro/avro-js 0.0.42 → 0.0.44
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/auth/AuthManager.d.ts +3 -3
- package/dist/auth/AuthManager.js +24 -24
- package/dist/auth/storage.d.ts +1 -1
- package/dist/auth/storage.js +3 -3
- package/dist/client/AvroQueryClientProvider.d.ts +4 -4
- package/dist/client/AvroQueryClientProvider.js +3 -3
- package/dist/client/QueryClient.d.ts +15 -15
- package/dist/client/QueryClient.js +239 -259
- package/dist/client/core/fetch.js +9 -9
- package/dist/client/core/utils.js +4 -4
- package/dist/client/core/xhr.js +21 -21
- package/dist/client/hooks/analytics.js +12 -12
- package/dist/client/hooks/avro.js +4 -4
- package/dist/client/hooks/bills.js +36 -39
- package/dist/client/hooks/catalog_items.js +25 -31
- package/dist/client/hooks/chats.js +6 -6
- package/dist/client/hooks/companies.js +45 -57
- package/dist/client/hooks/email.d.ts +3 -3
- package/dist/client/hooks/email.js +5 -5
- package/dist/client/hooks/events.js +71 -81
- package/dist/client/hooks/groups.js +25 -31
- package/dist/client/hooks/jobs.js +29 -34
- package/dist/client/hooks/labels.js +25 -31
- package/dist/client/hooks/messages.js +7 -7
- package/dist/client/hooks/months.js +21 -21
- package/dist/client/hooks/plans.js +4 -4
- package/dist/client/hooks/prepayments.js +21 -21
- package/dist/client/hooks/proposal.js +11 -11
- package/dist/client/hooks/root.js +4 -4
- package/dist/client/hooks/routes.js +42 -53
- package/dist/client/hooks/sessions.js +33 -45
- package/dist/client/hooks/skills.js +22 -28
- package/dist/client/hooks/teams.js +26 -32
- package/dist/client/hooks/timecards.js +13 -13
- package/dist/client/hooks/users.js +39 -42
- package/dist/client/hooks/waivers.js +23 -23
- package/dist/index.d.ts +38 -38
- package/dist/index.js +37 -37
- package/dist/types/api/AdditionalCharge.d.ts +2 -2
- package/dist/types/api/Avro.d.ts +1 -1
- package/dist/types/api/Bill.d.ts +4 -4
- package/dist/types/api/Bill.js +4 -4
- package/dist/types/api/BillPayment.d.ts +2 -2
- package/dist/types/api/BillUser.d.ts +1 -1
- package/dist/types/api/CatalogItem.d.ts +1 -1
- package/dist/types/api/Chat.d.ts +2 -2
- package/dist/types/api/Company.d.ts +12 -12
- package/dist/types/api/CustomLineItem.d.ts +2 -2
- package/dist/types/api/Email.d.ts +2 -2
- package/dist/types/api/EmailNotification.d.ts +2 -2
- package/dist/types/api/Group.d.ts +1 -1
- package/dist/types/api/Job.d.ts +6 -6
- package/dist/types/api/Job.js +12 -12
- package/dist/types/api/LineItem.d.ts +1 -1
- package/dist/types/api/LineItem.js +12 -12
- package/dist/types/api/MemberState.d.ts +1 -1
- package/dist/types/api/Message.d.ts +1 -1
- package/dist/types/api/PaymentMethod.d.ts +1 -1
- package/dist/types/api/PaymentOption.d.ts +1 -1
- package/dist/types/api/PaymentType.js +2 -2
- package/dist/types/api/PlanPayment.d.ts +1 -1
- package/dist/types/api/Prepayment.d.ts +4 -4
- package/dist/types/api/Prepayment.js +1 -1
- package/dist/types/api/Route.d.ts +2 -2
- package/dist/types/api/Route.js +7 -7
- package/dist/types/api/RouteJob.d.ts +1 -1
- package/dist/types/api/ServiceMonth.d.ts +2 -2
- package/dist/types/api/Session.d.ts +2 -2
- package/dist/types/api/Task.d.ts +7 -7
- package/dist/types/api/Task.js +20 -22
- package/dist/types/api/Timecard.d.ts +1 -1
- package/dist/types/api/Timecard.js +4 -4
- package/dist/types/api/TimecardAction.js +6 -6
- package/dist/types/api/User.d.ts +4 -4
- package/dist/types/api/UserCompanyAssociation.d.ts +2 -2
- package/dist/types/api/UserCompanyAssociation.js +45 -45
- package/dist/types/api/_Event.d.ts +5 -5
- package/dist/types/api/_Event.js +1 -1
- package/dist/types/api.d.ts +44 -44
- package/dist/types/api.js +42 -42
- package/dist/types/cache.d.ts +1 -1
- package/dist/types/client.d.ts +1 -1
- package/package.json +2 -1
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
import { useMutation, useQuery } from
|
|
2
|
-
import { AvroQueryClient } from
|
|
3
|
-
import { Route } from
|
|
1
|
+
import { useMutation, useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
|
+
import { Route } from '../../types/api';
|
|
4
4
|
AvroQueryClient.prototype.useGetRoutes = function (body, total, onProgress) {
|
|
5
5
|
return useQuery({
|
|
6
|
-
queryKey: [
|
|
7
|
-
"routes",
|
|
8
|
-
this.companyId,
|
|
9
|
-
body.amt ?? 50,
|
|
10
|
-
body.query ?? "",
|
|
11
|
-
total ?? "all",
|
|
12
|
-
],
|
|
6
|
+
queryKey: ['routes', this.companyId, body.amt ?? 50, body.query ?? '', total ?? 'all'],
|
|
13
7
|
queryFn: async () => {
|
|
14
|
-
if (typeof total !==
|
|
8
|
+
if (typeof total !== 'number') {
|
|
15
9
|
const routes = await this.fetchRoutes({ ...body, offset: 0 });
|
|
16
10
|
return routes.map((route) => new Route(route));
|
|
17
11
|
}
|
|
@@ -37,7 +31,7 @@ AvroQueryClient.prototype.useGetRoutes = function (body, total, onProgress) {
|
|
|
37
31
|
AvroQueryClient.prototype.useGetRoute = function (routeId) {
|
|
38
32
|
const queryClient = this.getQueryClient();
|
|
39
33
|
return useQuery({
|
|
40
|
-
queryKey: [
|
|
34
|
+
queryKey: ['routes', routeId],
|
|
41
35
|
queryFn: async () => {
|
|
42
36
|
const route = await this.get({ path: `/route/${routeId}` });
|
|
43
37
|
return new Route(route);
|
|
@@ -52,13 +46,13 @@ AvroQueryClient.prototype.useCreateRoute = function () {
|
|
|
52
46
|
return this.post({
|
|
53
47
|
path: `/company/${this.companyId}/route`,
|
|
54
48
|
data: JSON.stringify(routeData),
|
|
55
|
-
headers: {
|
|
49
|
+
headers: { 'Content-Type': 'application/json' },
|
|
56
50
|
});
|
|
57
51
|
},
|
|
58
52
|
onMutate: async ({ routeData }) => {
|
|
59
|
-
await queryClient.cancelQueries({ queryKey: [
|
|
60
|
-
const previousRoutes = queryClient.getQueryData([
|
|
61
|
-
queryClient.setQueriesData({ queryKey: [
|
|
53
|
+
await queryClient.cancelQueries({ queryKey: ['routes'] });
|
|
54
|
+
const previousRoutes = queryClient.getQueryData(['routes']);
|
|
55
|
+
queryClient.setQueriesData({ queryKey: ['routes'] }, (oldData) => {
|
|
62
56
|
if (!oldData)
|
|
63
57
|
return oldData;
|
|
64
58
|
if (oldData.pages) {
|
|
@@ -68,7 +62,7 @@ AvroQueryClient.prototype.useCreateRoute = function () {
|
|
|
68
62
|
[
|
|
69
63
|
new Route({
|
|
70
64
|
...routeData,
|
|
71
|
-
id:
|
|
65
|
+
id: 'temp-id',
|
|
72
66
|
}),
|
|
73
67
|
],
|
|
74
68
|
...oldData.pages,
|
|
@@ -76,10 +70,7 @@ AvroQueryClient.prototype.useCreateRoute = function () {
|
|
|
76
70
|
};
|
|
77
71
|
}
|
|
78
72
|
if (Array.isArray(oldData)) {
|
|
79
|
-
return [
|
|
80
|
-
new Route({ ...routeData, id: "temp-id" }),
|
|
81
|
-
...oldData,
|
|
82
|
-
];
|
|
73
|
+
return [new Route({ ...routeData, id: 'temp-id' }), ...oldData];
|
|
83
74
|
}
|
|
84
75
|
return oldData;
|
|
85
76
|
});
|
|
@@ -87,15 +78,15 @@ AvroQueryClient.prototype.useCreateRoute = function () {
|
|
|
87
78
|
},
|
|
88
79
|
onSuccess: async (result) => {
|
|
89
80
|
await this._syncEntity(queryClient, {
|
|
90
|
-
action:
|
|
91
|
-
entityKey:
|
|
81
|
+
action: 'create',
|
|
82
|
+
entityKey: 'routes',
|
|
92
83
|
id: result.id,
|
|
93
84
|
fetchPath: `/route/${result.id}`,
|
|
94
85
|
});
|
|
95
86
|
},
|
|
96
87
|
onError: (_err, _variables, context) => {
|
|
97
88
|
if (context?.previousRoutes) {
|
|
98
|
-
queryClient.setQueryData([
|
|
89
|
+
queryClient.setQueryData(['routes'], context.previousRoutes);
|
|
99
90
|
}
|
|
100
91
|
},
|
|
101
92
|
});
|
|
@@ -107,41 +98,39 @@ AvroQueryClient.prototype.useScheduleRoutes = function () {
|
|
|
107
98
|
return this.post({
|
|
108
99
|
path: `/company/${this.companyId}/schedule`,
|
|
109
100
|
data: JSON.stringify(schedule),
|
|
110
|
-
headers: {
|
|
101
|
+
headers: { 'Content-Type': 'application/json' },
|
|
111
102
|
});
|
|
112
103
|
},
|
|
113
104
|
onSuccess: () => {
|
|
114
|
-
queryClient.invalidateQueries({ queryKey: [
|
|
115
|
-
queryClient.invalidateQueries({ queryKey: [
|
|
116
|
-
queryClient.invalidateQueries({ queryKey: [
|
|
105
|
+
queryClient.invalidateQueries({ queryKey: ['routes'] });
|
|
106
|
+
queryClient.invalidateQueries({ queryKey: ['jobs'] });
|
|
107
|
+
queryClient.invalidateQueries({ queryKey: ['infinite', 'jobs'] });
|
|
117
108
|
},
|
|
118
109
|
});
|
|
119
110
|
};
|
|
120
111
|
AvroQueryClient.prototype.useUpdateRoute = function () {
|
|
121
112
|
const queryClient = this.getQueryClient();
|
|
122
113
|
return useMutation({
|
|
123
|
-
mutationFn: async ({ routeId, updates
|
|
114
|
+
mutationFn: async ({ routeId, updates }) => {
|
|
124
115
|
return this.put({
|
|
125
116
|
path: `/route/${routeId}`,
|
|
126
117
|
data: JSON.stringify(updates),
|
|
127
|
-
headers: {
|
|
118
|
+
headers: { 'Content-Type': 'application/json' },
|
|
128
119
|
});
|
|
129
120
|
},
|
|
130
121
|
onMutate: async ({ routeId, updates }) => {
|
|
131
|
-
await queryClient.cancelQueries({ queryKey: [
|
|
132
|
-
await queryClient.cancelQueries({ queryKey: [
|
|
133
|
-
const previousRoute = queryClient.getQueryData([
|
|
134
|
-
const previousRoutes = queryClient.getQueryData([
|
|
135
|
-
queryClient.setQueryData([
|
|
136
|
-
queryClient.setQueriesData({ queryKey: [
|
|
122
|
+
await queryClient.cancelQueries({ queryKey: ['routes', routeId] });
|
|
123
|
+
await queryClient.cancelQueries({ queryKey: ['routes'] });
|
|
124
|
+
const previousRoute = queryClient.getQueryData(['routes', routeId]);
|
|
125
|
+
const previousRoutes = queryClient.getQueryData(['routes']);
|
|
126
|
+
queryClient.setQueryData(['routes', routeId], (oldData) => oldData ? new Route({ ...oldData, ...updates }) : undefined);
|
|
127
|
+
queryClient.setQueriesData({ queryKey: ['routes'] }, (oldData) => {
|
|
137
128
|
if (!oldData)
|
|
138
129
|
return oldData;
|
|
139
130
|
if (oldData.pages) {
|
|
140
131
|
return {
|
|
141
132
|
...oldData,
|
|
142
|
-
pages: oldData.pages.map((page) => page.map((route) => route.id === routeId
|
|
143
|
-
? new Route({ ...route, ...updates })
|
|
144
|
-
: route)),
|
|
133
|
+
pages: oldData.pages.map((page) => page.map((route) => route.id === routeId ? new Route({ ...route, ...updates }) : route)),
|
|
145
134
|
};
|
|
146
135
|
}
|
|
147
136
|
if (Array.isArray(oldData)) {
|
|
@@ -153,8 +142,8 @@ AvroQueryClient.prototype.useUpdateRoute = function () {
|
|
|
153
142
|
},
|
|
154
143
|
onSuccess: async (_result, { routeId }) => {
|
|
155
144
|
await this._syncEntity(queryClient, {
|
|
156
|
-
action:
|
|
157
|
-
entityKey:
|
|
145
|
+
action: 'update',
|
|
146
|
+
entityKey: 'routes',
|
|
158
147
|
id: routeId,
|
|
159
148
|
fetchPath: `/route/${routeId}`,
|
|
160
149
|
});
|
|
@@ -162,10 +151,10 @@ AvroQueryClient.prototype.useUpdateRoute = function () {
|
|
|
162
151
|
onError: (_err, variables, context) => {
|
|
163
152
|
const { routeId } = variables;
|
|
164
153
|
if (context?.previousRoute) {
|
|
165
|
-
queryClient.setQueryData([
|
|
154
|
+
queryClient.setQueryData(['routes', routeId], context.previousRoute);
|
|
166
155
|
}
|
|
167
156
|
if (context?.previousRoutes) {
|
|
168
|
-
queryClient.setQueryData([
|
|
157
|
+
queryClient.setQueryData(['routes'], context.previousRoutes);
|
|
169
158
|
}
|
|
170
159
|
},
|
|
171
160
|
});
|
|
@@ -177,12 +166,12 @@ AvroQueryClient.prototype.useDeleteRoute = function () {
|
|
|
177
166
|
return this.delete({ path: `/route/${routeId}` });
|
|
178
167
|
},
|
|
179
168
|
onMutate: async ({ routeId }) => {
|
|
180
|
-
await queryClient.cancelQueries({ queryKey: [
|
|
181
|
-
await queryClient.cancelQueries({ queryKey: [
|
|
182
|
-
const previousRoutes = queryClient.getQueryData([
|
|
183
|
-
const previousRoute = queryClient.getQueryData([
|
|
184
|
-
queryClient.setQueryData([
|
|
185
|
-
queryClient.setQueriesData({ queryKey: [
|
|
169
|
+
await queryClient.cancelQueries({ queryKey: ['routes'] });
|
|
170
|
+
await queryClient.cancelQueries({ queryKey: ['routes', routeId] });
|
|
171
|
+
const previousRoutes = queryClient.getQueryData(['routes']);
|
|
172
|
+
const previousRoute = queryClient.getQueryData(['routes', routeId]);
|
|
173
|
+
queryClient.setQueryData(['routes', routeId], undefined);
|
|
174
|
+
queryClient.setQueriesData({ queryKey: ['routes'] }, (oldData) => {
|
|
186
175
|
if (!oldData)
|
|
187
176
|
return oldData;
|
|
188
177
|
if (oldData.pages) {
|
|
@@ -198,18 +187,18 @@ AvroQueryClient.prototype.useDeleteRoute = function () {
|
|
|
198
187
|
},
|
|
199
188
|
onSuccess: async (_result, { routeId }) => {
|
|
200
189
|
await this._syncEntity(queryClient, {
|
|
201
|
-
action:
|
|
202
|
-
entityKey:
|
|
190
|
+
action: 'delete',
|
|
191
|
+
entityKey: 'routes',
|
|
203
192
|
id: routeId,
|
|
204
193
|
});
|
|
205
194
|
},
|
|
206
195
|
onError: (_err, variables, context) => {
|
|
207
196
|
const { routeId } = variables;
|
|
208
197
|
if (context?.previousRoutes) {
|
|
209
|
-
queryClient.setQueryData([
|
|
198
|
+
queryClient.setQueryData(['routes'], context.previousRoutes);
|
|
210
199
|
}
|
|
211
200
|
if (context?.previousRoute) {
|
|
212
|
-
queryClient.setQueryData([
|
|
201
|
+
queryClient.setQueryData(['routes', routeId], context.previousRoute);
|
|
213
202
|
}
|
|
214
203
|
},
|
|
215
204
|
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { useMutation, useQuery, useInfiniteQuery } from
|
|
2
|
-
import { AvroQueryClient } from
|
|
1
|
+
import { useMutation, useQuery, useInfiniteQuery } from '@tanstack/react-query';
|
|
2
|
+
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
3
|
AvroQueryClient.prototype.useGetUserSessions = function () {
|
|
4
4
|
return useQuery({
|
|
5
|
-
queryKey: [
|
|
6
|
-
queryFn: () => this.get({ path:
|
|
5
|
+
queryKey: ['sessions', this.companyId],
|
|
6
|
+
queryFn: () => this.get({ path: '/session' }),
|
|
7
7
|
enabled: Boolean(this.companyId),
|
|
8
8
|
});
|
|
9
9
|
};
|
|
@@ -14,18 +14,15 @@ AvroQueryClient.prototype.useCreateUserSession = function () {
|
|
|
14
14
|
return this.post({
|
|
15
15
|
path: `/company/${this.companyId}/session`,
|
|
16
16
|
data: JSON.stringify(sessionData),
|
|
17
|
-
headers: {
|
|
17
|
+
headers: { 'Content-Type': 'application/json' },
|
|
18
18
|
});
|
|
19
19
|
},
|
|
20
20
|
onMutate: async ({ sessionData }) => {
|
|
21
21
|
await queryClient.cancelQueries({
|
|
22
|
-
queryKey: [
|
|
22
|
+
queryKey: ['sessions', this.companyId],
|
|
23
23
|
});
|
|
24
|
-
const previousSessions = queryClient.getQueryData([
|
|
25
|
-
|
|
26
|
-
this.companyId,
|
|
27
|
-
]);
|
|
28
|
-
queryClient.setQueryData(["sessions", this.companyId], (oldData) => {
|
|
24
|
+
const previousSessions = queryClient.getQueryData(['sessions', this.companyId]);
|
|
25
|
+
queryClient.setQueryData(['sessions', this.companyId], (oldData) => {
|
|
29
26
|
if (!oldData)
|
|
30
27
|
return [];
|
|
31
28
|
if (Array.isArray(oldData)) {
|
|
@@ -43,11 +40,11 @@ AvroQueryClient.prototype.useCreateUserSession = function () {
|
|
|
43
40
|
return { previousSessions };
|
|
44
41
|
},
|
|
45
42
|
onSuccess: () => {
|
|
46
|
-
queryClient.invalidateQueries({ queryKey: [
|
|
43
|
+
queryClient.invalidateQueries({ queryKey: ['sessions'] });
|
|
47
44
|
},
|
|
48
45
|
onError: (err, variables, context) => {
|
|
49
46
|
if (context?.previousSessions) {
|
|
50
|
-
queryClient.setQueryData([
|
|
47
|
+
queryClient.setQueryData(['sessions', this.companyId], context.previousSessions);
|
|
51
48
|
}
|
|
52
49
|
},
|
|
53
50
|
});
|
|
@@ -59,18 +56,15 @@ AvroQueryClient.prototype.useCreateSessionBreak = function () {
|
|
|
59
56
|
return this.post({
|
|
60
57
|
path: `/session/${sessionId}/break`,
|
|
61
58
|
data: JSON.stringify(breakData),
|
|
62
|
-
headers: {
|
|
59
|
+
headers: { 'Content-Type': 'application/json' },
|
|
63
60
|
});
|
|
64
61
|
},
|
|
65
62
|
onMutate: async ({ sessionId, breakData, }) => {
|
|
66
63
|
await queryClient.cancelQueries({
|
|
67
|
-
queryKey: [
|
|
64
|
+
queryKey: ['sessions', this.companyId],
|
|
68
65
|
});
|
|
69
|
-
const previousSessions = queryClient.getQueryData([
|
|
70
|
-
|
|
71
|
-
this.companyId,
|
|
72
|
-
]);
|
|
73
|
-
queryClient.setQueryData(["sessions", this.companyId], (oldData) => {
|
|
66
|
+
const previousSessions = queryClient.getQueryData(['sessions', this.companyId]);
|
|
67
|
+
queryClient.setQueryData(['sessions', this.companyId], (oldData) => {
|
|
74
68
|
if (!oldData)
|
|
75
69
|
return oldData;
|
|
76
70
|
if (Array.isArray(oldData)) {
|
|
@@ -93,11 +87,11 @@ AvroQueryClient.prototype.useCreateSessionBreak = function () {
|
|
|
93
87
|
return { previousSessions };
|
|
94
88
|
},
|
|
95
89
|
onSuccess: () => {
|
|
96
|
-
queryClient.invalidateQueries({ queryKey: [
|
|
90
|
+
queryClient.invalidateQueries({ queryKey: ['sessions'] });
|
|
97
91
|
},
|
|
98
92
|
onError: (err, variables, context) => {
|
|
99
93
|
if (context?.previousSessions) {
|
|
100
|
-
queryClient.setQueryData([
|
|
94
|
+
queryClient.setQueryData(['sessions', this.companyId], context.previousSessions);
|
|
101
95
|
}
|
|
102
96
|
},
|
|
103
97
|
});
|
|
@@ -105,22 +99,19 @@ AvroQueryClient.prototype.useCreateSessionBreak = function () {
|
|
|
105
99
|
AvroQueryClient.prototype.useUpdateUserSession = function () {
|
|
106
100
|
const queryClient = this.getQueryClient();
|
|
107
101
|
return useMutation({
|
|
108
|
-
mutationFn: ({ sessionId, updates
|
|
102
|
+
mutationFn: ({ sessionId, updates }) => {
|
|
109
103
|
return this.put({
|
|
110
104
|
path: `/session/${sessionId}`,
|
|
111
105
|
data: JSON.stringify(updates),
|
|
112
|
-
headers: {
|
|
106
|
+
headers: { 'Content-Type': 'application/json' },
|
|
113
107
|
});
|
|
114
108
|
},
|
|
115
109
|
onMutate: async ({ sessionId, updates, }) => {
|
|
116
110
|
await queryClient.cancelQueries({
|
|
117
|
-
queryKey: [
|
|
111
|
+
queryKey: ['sessions', this.companyId],
|
|
118
112
|
});
|
|
119
|
-
const previousSessions = queryClient.getQueryData([
|
|
120
|
-
|
|
121
|
-
this.companyId,
|
|
122
|
-
]);
|
|
123
|
-
queryClient.setQueryData(["sessions", this.companyId], (oldData) => {
|
|
113
|
+
const previousSessions = queryClient.getQueryData(['sessions', this.companyId]);
|
|
114
|
+
queryClient.setQueryData(['sessions', this.companyId], (oldData) => {
|
|
124
115
|
if (!oldData)
|
|
125
116
|
return oldData;
|
|
126
117
|
if (Array.isArray(oldData)) {
|
|
@@ -131,11 +122,11 @@ AvroQueryClient.prototype.useUpdateUserSession = function () {
|
|
|
131
122
|
return { previousSessions };
|
|
132
123
|
},
|
|
133
124
|
onSuccess: () => {
|
|
134
|
-
queryClient.invalidateQueries({ queryKey: [
|
|
125
|
+
queryClient.invalidateQueries({ queryKey: ['sessions'] });
|
|
135
126
|
},
|
|
136
127
|
onError: (err, variables, context) => {
|
|
137
128
|
if (context?.previousSessions) {
|
|
138
|
-
queryClient.setQueryData([
|
|
129
|
+
queryClient.setQueryData(['sessions', this.companyId], context.previousSessions);
|
|
139
130
|
}
|
|
140
131
|
},
|
|
141
132
|
});
|
|
@@ -143,22 +134,19 @@ AvroQueryClient.prototype.useUpdateUserSession = function () {
|
|
|
143
134
|
AvroQueryClient.prototype.useUpdateSessionBreak = function () {
|
|
144
135
|
const queryClient = this.getQueryClient();
|
|
145
136
|
return useMutation({
|
|
146
|
-
mutationFn: ({ breakId, updates
|
|
137
|
+
mutationFn: ({ breakId, updates }) => {
|
|
147
138
|
return this.put({
|
|
148
139
|
path: `/break/${breakId}`,
|
|
149
140
|
data: JSON.stringify(updates),
|
|
150
|
-
headers: {
|
|
141
|
+
headers: { 'Content-Type': 'application/json' },
|
|
151
142
|
});
|
|
152
143
|
},
|
|
153
|
-
onMutate: async ({ breakId, updates
|
|
144
|
+
onMutate: async ({ breakId, updates }) => {
|
|
154
145
|
await queryClient.cancelQueries({
|
|
155
|
-
queryKey: [
|
|
146
|
+
queryKey: ['sessions', this.companyId],
|
|
156
147
|
});
|
|
157
|
-
const previousSessions = queryClient.getQueryData([
|
|
158
|
-
|
|
159
|
-
this.companyId,
|
|
160
|
-
]);
|
|
161
|
-
queryClient.setQueryData(["sessions", this.companyId], (oldData) => {
|
|
148
|
+
const previousSessions = queryClient.getQueryData(['sessions', this.companyId]);
|
|
149
|
+
queryClient.setQueryData(['sessions', this.companyId], (oldData) => {
|
|
162
150
|
if (!oldData)
|
|
163
151
|
return oldData;
|
|
164
152
|
if (Array.isArray(oldData)) {
|
|
@@ -172,11 +160,11 @@ AvroQueryClient.prototype.useUpdateSessionBreak = function () {
|
|
|
172
160
|
return { previousSessions };
|
|
173
161
|
},
|
|
174
162
|
onSuccess: () => {
|
|
175
|
-
queryClient.invalidateQueries({ queryKey: [
|
|
163
|
+
queryClient.invalidateQueries({ queryKey: ['sessions'] });
|
|
176
164
|
},
|
|
177
165
|
onError: (err, variables, context) => {
|
|
178
166
|
if (context?.previousSessions) {
|
|
179
|
-
queryClient.setQueryData([
|
|
167
|
+
queryClient.setQueryData(['sessions', this.companyId], context.previousSessions);
|
|
180
168
|
}
|
|
181
169
|
},
|
|
182
170
|
});
|
|
@@ -184,7 +172,7 @@ AvroQueryClient.prototype.useUpdateSessionBreak = function () {
|
|
|
184
172
|
AvroQueryClient.prototype.useGetSessions = function (body) {
|
|
185
173
|
const queryClient = this.getQueryClient();
|
|
186
174
|
const result = useInfiniteQuery({
|
|
187
|
-
queryKey: [
|
|
175
|
+
queryKey: ['sessions', this.companyId, body.amt ?? 50, body.query ?? ''],
|
|
188
176
|
initialPageParam: 0,
|
|
189
177
|
getNextPageParam: (lastPage, allPages) => {
|
|
190
178
|
if (lastPage.length < (body.amt ?? 50))
|
|
@@ -196,7 +184,7 @@ AvroQueryClient.prototype.useGetSessions = function (body) {
|
|
|
196
184
|
if (result.data) {
|
|
197
185
|
result.data.pages.forEach((data_page) => {
|
|
198
186
|
data_page.forEach((session) => {
|
|
199
|
-
queryClient.setQueryData([
|
|
187
|
+
queryClient.setQueryData(['session', session.id], session);
|
|
200
188
|
});
|
|
201
189
|
});
|
|
202
190
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useMutation, useQuery } from
|
|
2
|
-
import { AvroQueryClient } from
|
|
1
|
+
import { useMutation, useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
3
|
AvroQueryClient.prototype.useCreateSkill = function () {
|
|
4
4
|
const queryClient = this.getQueryClient();
|
|
5
5
|
return useMutation({
|
|
@@ -7,25 +7,19 @@ AvroQueryClient.prototype.useCreateSkill = function () {
|
|
|
7
7
|
return this.post({
|
|
8
8
|
path: `/company/${this.companyId}/skill`,
|
|
9
9
|
data: JSON.stringify(skillData),
|
|
10
|
-
headers: {
|
|
10
|
+
headers: { 'Content-Type': 'application/json' },
|
|
11
11
|
});
|
|
12
12
|
},
|
|
13
13
|
onSuccess: () => {
|
|
14
|
-
queryClient.invalidateQueries({ queryKey: [
|
|
14
|
+
queryClient.invalidateQueries({ queryKey: ['skills'] });
|
|
15
15
|
},
|
|
16
16
|
});
|
|
17
17
|
};
|
|
18
18
|
AvroQueryClient.prototype.useGetSkills = function (body, total, onProgress) {
|
|
19
19
|
return useQuery({
|
|
20
|
-
queryKey: [
|
|
21
|
-
"skills",
|
|
22
|
-
this.companyId,
|
|
23
|
-
body.amt ?? 50,
|
|
24
|
-
body.query ?? "",
|
|
25
|
-
total ?? "all",
|
|
26
|
-
],
|
|
20
|
+
queryKey: ['skills', this.companyId, body.amt ?? 50, body.query ?? '', total ?? 'all'],
|
|
27
21
|
queryFn: async () => {
|
|
28
|
-
if (typeof total !==
|
|
22
|
+
if (typeof total !== 'number') {
|
|
29
23
|
return this.fetchSkills({ ...body, offset: 0 });
|
|
30
24
|
}
|
|
31
25
|
onProgress?.(0);
|
|
@@ -50,24 +44,24 @@ AvroQueryClient.prototype.useGetSkills = function (body, total, onProgress) {
|
|
|
50
44
|
AvroQueryClient.prototype.useUpdateSkill = function () {
|
|
51
45
|
const queryClient = this.getQueryClient();
|
|
52
46
|
return useMutation({
|
|
53
|
-
mutationFn: async ({ skillId, updates
|
|
47
|
+
mutationFn: async ({ skillId, updates }) => {
|
|
54
48
|
return this.put({
|
|
55
49
|
path: `/skill/${skillId}`,
|
|
56
50
|
data: JSON.stringify(updates),
|
|
57
|
-
headers: {
|
|
51
|
+
headers: { 'Content-Type': 'application/json' },
|
|
58
52
|
});
|
|
59
53
|
},
|
|
60
54
|
onMutate: async ({ skillId, updates }) => {
|
|
61
|
-
await queryClient.cancelQueries({ queryKey: [
|
|
62
|
-
await queryClient.cancelQueries({ queryKey: [
|
|
63
|
-
const previousSkills = queryClient.getQueryData([
|
|
64
|
-
const previousSkill = queryClient.getQueryData([
|
|
65
|
-
queryClient.setQueryData([
|
|
55
|
+
await queryClient.cancelQueries({ queryKey: ['skills'] });
|
|
56
|
+
await queryClient.cancelQueries({ queryKey: ['skills', skillId] });
|
|
57
|
+
const previousSkills = queryClient.getQueryData(['skills']);
|
|
58
|
+
const previousSkill = queryClient.getQueryData(['skills', skillId]);
|
|
59
|
+
queryClient.setQueryData(['skills', skillId], (oldData) => {
|
|
66
60
|
if (!oldData)
|
|
67
61
|
return oldData;
|
|
68
62
|
return { ...oldData, ...updates };
|
|
69
63
|
});
|
|
70
|
-
queryClient.setQueriesData({ queryKey: [
|
|
64
|
+
queryClient.setQueriesData({ queryKey: ['skills'] }, (oldData) => {
|
|
71
65
|
if (!oldData)
|
|
72
66
|
return oldData;
|
|
73
67
|
if (oldData.pages) {
|
|
@@ -82,15 +76,15 @@ AvroQueryClient.prototype.useUpdateSkill = function () {
|
|
|
82
76
|
return { previousSkills, previousSkill };
|
|
83
77
|
},
|
|
84
78
|
onSuccess: () => {
|
|
85
|
-
queryClient.invalidateQueries({ queryKey: [
|
|
79
|
+
queryClient.invalidateQueries({ queryKey: ['skills'] });
|
|
86
80
|
},
|
|
87
81
|
onError: (_err, variables, context) => {
|
|
88
82
|
const { skillId } = variables;
|
|
89
83
|
if (context?.previousSkills) {
|
|
90
|
-
queryClient.setQueryData([
|
|
84
|
+
queryClient.setQueryData(['skills'], context.previousSkills);
|
|
91
85
|
}
|
|
92
86
|
if (context?.previousSkill) {
|
|
93
|
-
queryClient.setQueryData([
|
|
87
|
+
queryClient.setQueryData(['skills', skillId], context.previousSkill);
|
|
94
88
|
}
|
|
95
89
|
},
|
|
96
90
|
});
|
|
@@ -102,9 +96,9 @@ AvroQueryClient.prototype.useDeleteSkill = function () {
|
|
|
102
96
|
return this.delete({ path: `/skill/${skillId}` });
|
|
103
97
|
},
|
|
104
98
|
onMutate: async ({ skillId }) => {
|
|
105
|
-
await queryClient.cancelQueries({ queryKey: [
|
|
106
|
-
const previousSkills = queryClient.getQueryData([
|
|
107
|
-
queryClient.setQueriesData({ queryKey: [
|
|
99
|
+
await queryClient.cancelQueries({ queryKey: ['skills'] });
|
|
100
|
+
const previousSkills = queryClient.getQueryData(['skills']);
|
|
101
|
+
queryClient.setQueriesData({ queryKey: ['skills'] }, (oldData) => {
|
|
108
102
|
if (!oldData)
|
|
109
103
|
return oldData;
|
|
110
104
|
if (oldData.pages) {
|
|
@@ -119,11 +113,11 @@ AvroQueryClient.prototype.useDeleteSkill = function () {
|
|
|
119
113
|
return { previousSkills };
|
|
120
114
|
},
|
|
121
115
|
onSuccess: () => {
|
|
122
|
-
queryClient.invalidateQueries({ queryKey: [
|
|
116
|
+
queryClient.invalidateQueries({ queryKey: ['skills'] });
|
|
123
117
|
},
|
|
124
118
|
onError: (_err, variables, context) => {
|
|
125
119
|
if (context?.previousSkills) {
|
|
126
|
-
queryClient.setQueryData([
|
|
120
|
+
queryClient.setQueryData(['skills'], context.previousSkills);
|
|
127
121
|
}
|
|
128
122
|
},
|
|
129
123
|
});
|
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
import { useMutation, useQuery } from
|
|
2
|
-
import { AvroQueryClient } from
|
|
1
|
+
import { useMutation, useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { AvroQueryClient } from '../../client/QueryClient';
|
|
3
3
|
AvroQueryClient.prototype.useGetTeams = function (body, total, onProgress) {
|
|
4
4
|
return useQuery({
|
|
5
|
-
queryKey: [
|
|
6
|
-
"teams",
|
|
7
|
-
this.companyId,
|
|
8
|
-
body.amt ?? 50,
|
|
9
|
-
body.query ?? "",
|
|
10
|
-
total ?? "all",
|
|
11
|
-
],
|
|
5
|
+
queryKey: ['teams', this.companyId, body.amt ?? 50, body.query ?? '', total ?? 'all'],
|
|
12
6
|
queryFn: async () => {
|
|
13
|
-
if (typeof total !==
|
|
7
|
+
if (typeof total !== 'number') {
|
|
14
8
|
return this.fetchTeams({ ...body, offset: 0 });
|
|
15
9
|
}
|
|
16
10
|
onProgress?.(0);
|
|
@@ -39,35 +33,35 @@ AvroQueryClient.prototype.useCreateTeam = function () {
|
|
|
39
33
|
return this.post({
|
|
40
34
|
path: `/company/${this.companyId}/team`,
|
|
41
35
|
data: JSON.stringify(teamData),
|
|
42
|
-
headers: {
|
|
36
|
+
headers: { 'Content-Type': 'application/json' },
|
|
43
37
|
});
|
|
44
38
|
},
|
|
45
39
|
onSuccess: () => {
|
|
46
|
-
queryClient.invalidateQueries({ queryKey: [
|
|
40
|
+
queryClient.invalidateQueries({ queryKey: ['teams'] });
|
|
47
41
|
},
|
|
48
42
|
});
|
|
49
43
|
};
|
|
50
44
|
AvroQueryClient.prototype.useUpdateTeam = function () {
|
|
51
45
|
const queryClient = this.getQueryClient();
|
|
52
46
|
return useMutation({
|
|
53
|
-
mutationFn: async ({ teamId, teamData
|
|
47
|
+
mutationFn: async ({ teamId, teamData }) => {
|
|
54
48
|
return this.put({
|
|
55
49
|
path: `/team/${teamId}`,
|
|
56
50
|
data: JSON.stringify(teamData),
|
|
57
|
-
headers: {
|
|
51
|
+
headers: { 'Content-Type': 'application/json' },
|
|
58
52
|
});
|
|
59
53
|
},
|
|
60
54
|
onMutate: async ({ teamId, teamData }) => {
|
|
61
|
-
await queryClient.cancelQueries({ queryKey: [
|
|
62
|
-
await queryClient.cancelQueries({ queryKey: [
|
|
63
|
-
const previousTeams = queryClient.getQueryData([
|
|
64
|
-
const previousTeam = queryClient.getQueryData([
|
|
65
|
-
queryClient.setQueryData([
|
|
55
|
+
await queryClient.cancelQueries({ queryKey: ['teams'] });
|
|
56
|
+
await queryClient.cancelQueries({ queryKey: ['teams', teamId] });
|
|
57
|
+
const previousTeams = queryClient.getQueryData(['teams']);
|
|
58
|
+
const previousTeam = queryClient.getQueryData(['teams', teamId]);
|
|
59
|
+
queryClient.setQueryData(['teams', teamId], (oldData) => {
|
|
66
60
|
if (!oldData)
|
|
67
61
|
return oldData;
|
|
68
62
|
return { ...oldData, ...teamData };
|
|
69
63
|
});
|
|
70
|
-
queryClient.setQueriesData({ queryKey: [
|
|
64
|
+
queryClient.setQueriesData({ queryKey: ['teams'] }, (oldData) => {
|
|
71
65
|
if (!oldData)
|
|
72
66
|
return oldData;
|
|
73
67
|
if (oldData.pages) {
|
|
@@ -82,15 +76,15 @@ AvroQueryClient.prototype.useUpdateTeam = function () {
|
|
|
82
76
|
return { previousTeams, previousTeam };
|
|
83
77
|
},
|
|
84
78
|
onSuccess: () => {
|
|
85
|
-
queryClient.invalidateQueries({ queryKey: [
|
|
79
|
+
queryClient.invalidateQueries({ queryKey: ['teams'] });
|
|
86
80
|
},
|
|
87
81
|
onError: (_err, variables, context) => {
|
|
88
82
|
const { teamId } = variables;
|
|
89
83
|
if (context?.previousTeams) {
|
|
90
|
-
queryClient.setQueryData([
|
|
84
|
+
queryClient.setQueryData(['teams'], context.previousTeams);
|
|
91
85
|
}
|
|
92
86
|
if (context?.previousTeam) {
|
|
93
|
-
queryClient.setQueryData([
|
|
87
|
+
queryClient.setQueryData(['teams', teamId], context.previousTeam);
|
|
94
88
|
}
|
|
95
89
|
},
|
|
96
90
|
});
|
|
@@ -102,12 +96,12 @@ AvroQueryClient.prototype.useDeleteTeam = function () {
|
|
|
102
96
|
return this.delete({ path: `/team/${teamId}` });
|
|
103
97
|
},
|
|
104
98
|
onMutate: async ({ teamId }) => {
|
|
105
|
-
await queryClient.cancelQueries({ queryKey: [
|
|
106
|
-
await queryClient.cancelQueries({ queryKey: [
|
|
107
|
-
const previousRoutes = queryClient.getQueryData([
|
|
108
|
-
const previousRoute = queryClient.getQueryData([
|
|
109
|
-
queryClient.setQueryData([
|
|
110
|
-
queryClient.setQueriesData({ queryKey: [
|
|
99
|
+
await queryClient.cancelQueries({ queryKey: ['teams'] });
|
|
100
|
+
await queryClient.cancelQueries({ queryKey: ['teams', teamId] });
|
|
101
|
+
const previousRoutes = queryClient.getQueryData(['teams']);
|
|
102
|
+
const previousRoute = queryClient.getQueryData(['teams', teamId]);
|
|
103
|
+
queryClient.setQueryData(['teams', teamId], undefined);
|
|
104
|
+
queryClient.setQueriesData({ queryKey: ['teams'] }, (oldData) => {
|
|
111
105
|
if (!oldData)
|
|
112
106
|
return oldData;
|
|
113
107
|
if (oldData.pages) {
|
|
@@ -122,15 +116,15 @@ AvroQueryClient.prototype.useDeleteTeam = function () {
|
|
|
122
116
|
return { previousRoutes, previousRoute };
|
|
123
117
|
},
|
|
124
118
|
onSuccess: () => {
|
|
125
|
-
queryClient.invalidateQueries({ queryKey: [
|
|
119
|
+
queryClient.invalidateQueries({ queryKey: ['teams'] });
|
|
126
120
|
},
|
|
127
121
|
onError: (_err, variables, context) => {
|
|
128
122
|
const { teamId } = variables;
|
|
129
123
|
if (context?.previousRoutes) {
|
|
130
|
-
queryClient.setQueryData([
|
|
124
|
+
queryClient.setQueryData(['teams'], context.previousRoutes);
|
|
131
125
|
}
|
|
132
126
|
if (context?.previousRoute) {
|
|
133
|
-
queryClient.setQueryData([
|
|
127
|
+
queryClient.setQueryData(['teams', teamId], context.previousRoute);
|
|
134
128
|
}
|
|
135
129
|
},
|
|
136
130
|
});
|