@go-avro/avro-js 0.0.36 → 0.0.38
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 +2 -2
- package/dist/auth/AuthManager.js +37 -32
- package/dist/auth/storage.d.ts +1 -1
- package/dist/auth/storage.js +6 -6
- package/dist/client/AvroQueryClientProvider.js +1 -1
- package/dist/client/QueryClient.d.ts +35 -17
- package/dist/client/QueryClient.js +486 -384
- package/dist/client/core/fetch.js +16 -11
- package/dist/client/core/utils.js +5 -5
- package/dist/client/core/xhr.js +28 -23
- package/dist/client/hooks/analytics.js +14 -14
- package/dist/client/hooks/avro.js +2 -2
- package/dist/client/hooks/bills.js +66 -30
- package/dist/client/hooks/catalog_items.js +57 -22
- package/dist/client/hooks/chats.js +4 -4
- package/dist/client/hooks/companies.js +96 -39
- package/dist/client/hooks/email.js +1 -1
- package/dist/client/hooks/events.js +174 -63
- package/dist/client/hooks/groups.js +37 -22
- package/dist/client/hooks/jobs.js +69 -18
- package/dist/client/hooks/labels.js +36 -21
- package/dist/client/hooks/messages.js +9 -6
- package/dist/client/hooks/months.js +42 -22
- package/dist/client/hooks/plans.js +2 -2
- package/dist/client/hooks/prepayments.js +42 -22
- package/dist/client/hooks/proposal.js +21 -5
- package/dist/client/hooks/root.js +4 -4
- package/dist/client/hooks/routes.js +77 -32
- package/dist/client/hooks/sessions.js +66 -34
- package/dist/client/hooks/skills.js +33 -18
- package/dist/client/hooks/teams.js +36 -21
- package/dist/client/hooks/timecards.js +6 -0
- package/dist/client/hooks/users.js +61 -29
- package/dist/client/hooks/waivers.js +41 -19
- package/dist/index.d.ts +38 -38
- package/dist/index.js +37 -37
- package/dist/types/api/Bill.d.ts +1 -1
- package/dist/types/api/Bill.js +1 -1
- package/dist/types/api/Job.d.ts +1 -1
- package/dist/types/api/Job.js +14 -14
- package/dist/types/api/LineItem.d.ts +3 -3
- package/dist/types/api/LineItem.js +5 -2
- package/dist/types/api/PaymentType.d.ts +1 -1
- package/dist/types/api/Prepayment.d.ts +1 -1
- package/dist/types/api/Route.d.ts +3 -3
- package/dist/types/api/Route.js +4 -2
- package/dist/types/api/RouteJob.d.ts +1 -1
- package/dist/types/api/Task.d.ts +2 -2
- package/dist/types/api/Task.js +12 -7
- package/dist/types/api/Timecard.d.ts +1 -1
- package/dist/types/api/TimecardAction.d.ts +1 -1
- package/dist/types/api/UserCompanyAssociation.d.ts +2 -2
- package/dist/types/api/UserCompanyAssociation.js +1 -1
- package/dist/types/api/_Event.d.ts +1 -1
- package/dist/types/api/_Event.js +1 -1
- package/dist/types/api.d.ts +1 -1
- package/dist/types/auth.d.ts +1 -1
- package/dist/types/client.d.ts +1 -1
- package/package.json +3 -2
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import { useMutation, useQuery } from
|
|
2
|
-
import { AvroQueryClient } from
|
|
3
|
-
import { AuthState } from
|
|
1
|
+
import { useMutation, useQuery } from "@tanstack/react-query";
|
|
2
|
+
import { AvroQueryClient } from "../../client/QueryClient";
|
|
3
|
+
import { AuthState } from "../../types/auth";
|
|
4
4
|
AvroQueryClient.prototype.useGetCompanies = function (options = {}) {
|
|
5
5
|
return useQuery({
|
|
6
|
-
queryKey: [
|
|
6
|
+
queryKey: ["/company/list"],
|
|
7
7
|
queryFn: () => {
|
|
8
|
-
const companiesPromise = this.get({
|
|
8
|
+
const companiesPromise = this.get({
|
|
9
|
+
path: `/company/list`,
|
|
10
|
+
});
|
|
9
11
|
companiesPromise.then((companies) => {
|
|
10
|
-
if (!companies.find((c) => c.id === this.companyId) &&
|
|
12
|
+
if (!companies.find((c) => c.id === this.companyId) &&
|
|
13
|
+
companies.length > 0) {
|
|
11
14
|
this.companyId = companies[0].id;
|
|
12
15
|
}
|
|
13
16
|
});
|
|
@@ -19,20 +22,22 @@ AvroQueryClient.prototype.useGetCompanies = function (options = {}) {
|
|
|
19
22
|
};
|
|
20
23
|
AvroQueryClient.prototype.useGetCompany = function (companyId) {
|
|
21
24
|
return useQuery({
|
|
22
|
-
queryKey: [
|
|
25
|
+
queryKey: ["companies", companyId],
|
|
23
26
|
queryFn: () => this.get({ path: `/company/${companyId}` }),
|
|
24
27
|
enabled: Boolean(companyId),
|
|
25
28
|
});
|
|
26
29
|
};
|
|
27
30
|
AvroQueryClient.prototype.useGetCurrentCompany = function () {
|
|
28
31
|
return useQuery({
|
|
29
|
-
queryKey: [
|
|
32
|
+
queryKey: ["companies", "current"],
|
|
30
33
|
queryFn: async () => {
|
|
31
34
|
if (!this.companyId) {
|
|
32
35
|
this.companyId = await this.config.authManager.getCompanyId();
|
|
33
36
|
}
|
|
34
37
|
if (!this.companyId) {
|
|
35
|
-
const companyList = await this.get({
|
|
38
|
+
const companyList = await this.get({
|
|
39
|
+
path: `/company/list`,
|
|
40
|
+
});
|
|
36
41
|
if (companyList.length > 0) {
|
|
37
42
|
this.companyId = companyList[0].id;
|
|
38
43
|
}
|
|
@@ -40,7 +45,9 @@ AvroQueryClient.prototype.useGetCurrentCompany = function () {
|
|
|
40
45
|
throw new Error("No company ID set and no companies available");
|
|
41
46
|
}
|
|
42
47
|
}
|
|
43
|
-
this.company = await this.get({
|
|
48
|
+
this.company = await this.get({
|
|
49
|
+
path: `/company/${this.companyId}`,
|
|
50
|
+
});
|
|
44
51
|
return this.company;
|
|
45
52
|
},
|
|
46
53
|
enabled: this.getAuthState() === AuthState.AUTHENTICATED,
|
|
@@ -49,11 +56,19 @@ AvroQueryClient.prototype.useGetCurrentCompany = function () {
|
|
|
49
56
|
AvroQueryClient.prototype.useCreateCompany = function () {
|
|
50
57
|
const queryClient = this.getQueryClient();
|
|
51
58
|
return useMutation({
|
|
52
|
-
mutationFn: async ({ companyData }) => {
|
|
59
|
+
mutationFn: async ({ companyData, }) => {
|
|
53
60
|
return this.post({
|
|
54
61
|
path: `/company`,
|
|
55
62
|
data: JSON.stringify(companyData),
|
|
56
|
-
headers: { "Content-Type": "application/json" }
|
|
63
|
+
headers: { "Content-Type": "application/json" },
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
onSuccess: async (result) => {
|
|
67
|
+
await this._syncEntity(queryClient, {
|
|
68
|
+
action: "create",
|
|
69
|
+
entityKey: "companies",
|
|
70
|
+
id: result.id,
|
|
71
|
+
fetchPath: `/company/${result.id}`,
|
|
57
72
|
});
|
|
58
73
|
},
|
|
59
74
|
});
|
|
@@ -65,29 +80,44 @@ AvroQueryClient.prototype.useUpdateCompany = function () {
|
|
|
65
80
|
return this.put({
|
|
66
81
|
path: `/company/${companyId}`,
|
|
67
82
|
data: JSON.stringify(companyData),
|
|
68
|
-
headers: { "Content-Type": "application/json" }
|
|
83
|
+
headers: { "Content-Type": "application/json" },
|
|
69
84
|
});
|
|
70
85
|
},
|
|
71
86
|
onMutate: async ({ companyId, companyData }) => {
|
|
72
|
-
await queryClient.cancelQueries({
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
queryClient.
|
|
77
|
-
|
|
87
|
+
await queryClient.cancelQueries({
|
|
88
|
+
queryKey: ["companies", companyId],
|
|
89
|
+
});
|
|
90
|
+
await queryClient.cancelQueries({ queryKey: ["/company/list"] });
|
|
91
|
+
const previousCompany = queryClient.getQueryData([
|
|
92
|
+
"companies",
|
|
93
|
+
companyId,
|
|
94
|
+
]);
|
|
95
|
+
const previousCompanyList = queryClient.getQueryData(["/company/list"]);
|
|
96
|
+
queryClient.setQueryData(["companies", companyId], (oldData) => oldData ? { ...oldData, ...companyData } : undefined);
|
|
97
|
+
queryClient.setQueryData(["/company/list"], (oldList) => {
|
|
78
98
|
if (!oldList)
|
|
79
99
|
return oldList;
|
|
80
|
-
return oldList.map((company) => company?.id === companyId
|
|
100
|
+
return oldList.map((company) => company?.id === companyId
|
|
101
|
+
? { ...company, ...companyData }
|
|
102
|
+
: company);
|
|
81
103
|
});
|
|
82
104
|
return { previousCompany, previousCompanyList };
|
|
83
105
|
},
|
|
106
|
+
onSuccess: async (_result, { companyId }) => {
|
|
107
|
+
await this._syncEntity(queryClient, {
|
|
108
|
+
action: "update",
|
|
109
|
+
entityKey: "companies",
|
|
110
|
+
id: companyId,
|
|
111
|
+
fetchPath: `/company/${companyId}`,
|
|
112
|
+
});
|
|
113
|
+
},
|
|
84
114
|
onError: (_err, variables, context) => {
|
|
85
115
|
const { companyId } = variables;
|
|
86
116
|
if (context?.previousCompany) {
|
|
87
|
-
queryClient.setQueryData([
|
|
117
|
+
queryClient.setQueryData(["companies", companyId], context.previousCompany);
|
|
88
118
|
}
|
|
89
119
|
if (context?.previousCompanyList) {
|
|
90
|
-
queryClient.setQueryData([
|
|
120
|
+
queryClient.setQueryData(["/company/list"], context.previousCompanyList);
|
|
91
121
|
}
|
|
92
122
|
},
|
|
93
123
|
});
|
|
@@ -95,20 +125,25 @@ AvroQueryClient.prototype.useUpdateCompany = function () {
|
|
|
95
125
|
AvroQueryClient.prototype.useCreateUserCompany = function () {
|
|
96
126
|
const queryClient = this.getQueryClient();
|
|
97
127
|
return useMutation({
|
|
98
|
-
mutationFn: async ({ user_id, data }) => {
|
|
128
|
+
mutationFn: async ({ user_id, data, }) => {
|
|
99
129
|
if (!user_id) {
|
|
100
130
|
throw new Error("Both userId and companyId are required");
|
|
101
131
|
}
|
|
102
132
|
return this.post({
|
|
103
133
|
path: `/company/${this.companyId}/user/${user_id}`,
|
|
104
134
|
data: JSON.stringify(data),
|
|
105
|
-
headers: { "Content-Type": "application/json" }
|
|
135
|
+
headers: { "Content-Type": "application/json" },
|
|
106
136
|
});
|
|
107
137
|
},
|
|
108
138
|
onMutate: async ({ user_id }) => {
|
|
109
|
-
await queryClient.cancelQueries({
|
|
110
|
-
|
|
111
|
-
|
|
139
|
+
await queryClient.cancelQueries({
|
|
140
|
+
queryKey: ["companies", this.companyId],
|
|
141
|
+
});
|
|
142
|
+
const previousCompany = queryClient.getQueryData([
|
|
143
|
+
"companies",
|
|
144
|
+
this.companyId,
|
|
145
|
+
]);
|
|
146
|
+
queryClient.setQueryData(["companies", this.companyId], (oldData) => {
|
|
112
147
|
if (!oldData)
|
|
113
148
|
return oldData;
|
|
114
149
|
return {
|
|
@@ -118,9 +153,13 @@ AvroQueryClient.prototype.useCreateUserCompany = function () {
|
|
|
118
153
|
});
|
|
119
154
|
return { previousCompany };
|
|
120
155
|
},
|
|
156
|
+
onSuccess: () => {
|
|
157
|
+
queryClient.invalidateQueries({ queryKey: ["companies"] });
|
|
158
|
+
queryClient.invalidateQueries({ queryKey: ["users"] });
|
|
159
|
+
},
|
|
121
160
|
onError: (err, variables, context) => {
|
|
122
161
|
if (context?.previousCompany) {
|
|
123
|
-
queryClient.setQueryData([
|
|
162
|
+
queryClient.setQueryData(["companies", this.companyId], context.previousCompany);
|
|
124
163
|
}
|
|
125
164
|
},
|
|
126
165
|
});
|
|
@@ -130,13 +169,18 @@ AvroQueryClient.prototype.useRemoveUserCompany = function () {
|
|
|
130
169
|
return useMutation({
|
|
131
170
|
mutationFn: async ({ userId }) => {
|
|
132
171
|
return this.delete({
|
|
133
|
-
path: `/company/${this.companyId}/user/${userId}
|
|
172
|
+
path: `/company/${this.companyId}/user/${userId}`,
|
|
134
173
|
});
|
|
135
174
|
},
|
|
136
175
|
onMutate: async ({ userId }) => {
|
|
137
|
-
await queryClient.cancelQueries({
|
|
138
|
-
|
|
139
|
-
|
|
176
|
+
await queryClient.cancelQueries({
|
|
177
|
+
queryKey: ["companies", this.companyId],
|
|
178
|
+
});
|
|
179
|
+
const previousCompany = queryClient.getQueryData([
|
|
180
|
+
"companies",
|
|
181
|
+
this.companyId,
|
|
182
|
+
]);
|
|
183
|
+
queryClient.setQueryData(["companies", this.companyId], (oldData) => {
|
|
140
184
|
if (!oldData)
|
|
141
185
|
return oldData;
|
|
142
186
|
return {
|
|
@@ -146,9 +190,13 @@ AvroQueryClient.prototype.useRemoveUserCompany = function () {
|
|
|
146
190
|
});
|
|
147
191
|
return { previousCompany };
|
|
148
192
|
},
|
|
193
|
+
onSuccess: () => {
|
|
194
|
+
queryClient.invalidateQueries({ queryKey: ["companies"] });
|
|
195
|
+
queryClient.invalidateQueries({ queryKey: ["users"] });
|
|
196
|
+
},
|
|
149
197
|
onError: (err, variables, context) => {
|
|
150
198
|
if (context?.previousCompany) {
|
|
151
|
-
queryClient.setQueryData([
|
|
199
|
+
queryClient.setQueryData(["companies", this.companyId], context.previousCompany);
|
|
152
200
|
}
|
|
153
201
|
},
|
|
154
202
|
});
|
|
@@ -158,23 +206,32 @@ AvroQueryClient.prototype.useDeleteCompany = function () {
|
|
|
158
206
|
return useMutation({
|
|
159
207
|
mutationFn: async ({ companyId }) => {
|
|
160
208
|
return this.delete({
|
|
161
|
-
path: `/company/${companyId}
|
|
209
|
+
path: `/company/${companyId}`,
|
|
162
210
|
});
|
|
163
211
|
},
|
|
164
212
|
onMutate: async ({ companyId }) => {
|
|
165
|
-
await queryClient.cancelQueries({ queryKey: [
|
|
166
|
-
await queryClient.cancelQueries({
|
|
167
|
-
|
|
168
|
-
|
|
213
|
+
await queryClient.cancelQueries({ queryKey: ["/company/list"] });
|
|
214
|
+
await queryClient.cancelQueries({
|
|
215
|
+
queryKey: ["companies", companyId],
|
|
216
|
+
});
|
|
217
|
+
const previousCompanyList = queryClient.getQueryData(["/company/list"]);
|
|
218
|
+
queryClient.setQueryData(["/company/list"], (oldList) => {
|
|
169
219
|
if (!oldList)
|
|
170
220
|
return oldList;
|
|
171
221
|
return oldList.filter((company) => company?.id !== companyId);
|
|
172
222
|
});
|
|
173
223
|
return { previousCompanyList };
|
|
174
224
|
},
|
|
225
|
+
onSuccess: async (_result, { companyId }) => {
|
|
226
|
+
await this._syncEntity(queryClient, {
|
|
227
|
+
action: "delete",
|
|
228
|
+
entityKey: "companies",
|
|
229
|
+
id: companyId,
|
|
230
|
+
});
|
|
231
|
+
},
|
|
175
232
|
onError: (err, companyId, context) => {
|
|
176
233
|
if (context?.previousCompanyList) {
|
|
177
|
-
queryClient.setQueryData([
|
|
234
|
+
queryClient.setQueryData(["/company/list"], context.previousCompanyList);
|
|
178
235
|
}
|
|
179
236
|
},
|
|
180
237
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useCallback, useRef, useState } from "react";
|
|
2
2
|
import { useAvroQueryClient } from "../../client/AvroQueryClientProvider";
|
|
3
3
|
/* ──────────────────────────────────────────────────────────────────────── */
|
|
4
|
-
/* Hook
|
|
4
|
+
/* Hook */
|
|
5
5
|
/* ──────────────────────────────────────────────────────────────────────── */
|
|
6
6
|
/**
|
|
7
7
|
* Subscribe to backend email delivery notifications via Socket.IO.
|