@go-avro/avro-js 0.0.37 → 0.0.39
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 +505 -391
- 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,11 +1,15 @@
|
|
|
1
|
-
import { useMutation, useQuery, useInfiniteQuery } from
|
|
2
|
-
import { AvroQueryClient } from
|
|
3
|
-
import { Job } from
|
|
1
|
+
import { useMutation, useQuery, useInfiniteQuery, } from "@tanstack/react-query";
|
|
2
|
+
import { AvroQueryClient } from "../../client/QueryClient";
|
|
3
|
+
import { Job } from "../../types/api";
|
|
4
4
|
AvroQueryClient.prototype.getJobsFromCache = function (queryClient) {
|
|
5
5
|
if (!queryClient) {
|
|
6
6
|
queryClient = this.getQueryClient();
|
|
7
7
|
}
|
|
8
|
-
return (queryClient.getQueryData([
|
|
8
|
+
return (queryClient.getQueryData([
|
|
9
|
+
"jobs",
|
|
10
|
+
this.companyId,
|
|
11
|
+
this.company?.num_jobs,
|
|
12
|
+
]) ?? []);
|
|
9
13
|
};
|
|
10
14
|
AvroQueryClient.prototype.useGetJobs = function (params) {
|
|
11
15
|
const queryClient = this.getQueryClient();
|
|
@@ -13,7 +17,7 @@ AvroQueryClient.prototype.useGetJobs = function (params) {
|
|
|
13
17
|
const company_id = params?.companyId ?? this.companyId;
|
|
14
18
|
const num_jobs = params?.numJobs ?? this.company?.num_jobs ?? 0;
|
|
15
19
|
return useQuery({
|
|
16
|
-
queryKey: [
|
|
20
|
+
queryKey: ["jobs", company_id, num_jobs],
|
|
17
21
|
queryFn: async () => {
|
|
18
22
|
params?.onProgress?.(0);
|
|
19
23
|
const pageCount = amt ? Math.ceil((num_jobs ?? 0) / amt) + 1 : 1;
|
|
@@ -29,12 +33,19 @@ AvroQueryClient.prototype.useGetJobs = function (params) {
|
|
|
29
33
|
const jobs = pages.flat().map((job) => new Job(job));
|
|
30
34
|
jobs.forEach((job) => {
|
|
31
35
|
job.current_event = job.tasks.reduce((latest, task) => {
|
|
32
|
-
return task.current_event &&
|
|
36
|
+
return task.current_event &&
|
|
37
|
+
(!latest || task.current_event.time_started > latest.time_started)
|
|
38
|
+
? task.current_event
|
|
39
|
+
: latest;
|
|
33
40
|
}, job.current_event);
|
|
34
41
|
job.last_completed_event = job.tasks.reduce((latest, task) => {
|
|
35
|
-
return task.last_completed_event &&
|
|
42
|
+
return task.last_completed_event &&
|
|
43
|
+
(!latest ||
|
|
44
|
+
task.last_completed_event.time_started > latest.time_started)
|
|
45
|
+
? task.last_completed_event
|
|
46
|
+
: latest;
|
|
36
47
|
}, job.last_completed_event);
|
|
37
|
-
queryClient.setQueryData([
|
|
48
|
+
queryClient.setQueryData(["jobs", job.id], job);
|
|
38
49
|
});
|
|
39
50
|
return jobs;
|
|
40
51
|
},
|
|
@@ -44,7 +55,14 @@ AvroQueryClient.prototype.useGetJobs = function (params) {
|
|
|
44
55
|
AvroQueryClient.prototype.useGetInfiniteJobs = function (body, onProgress) {
|
|
45
56
|
const queryClient = this.getQueryClient();
|
|
46
57
|
const result = useInfiniteQuery({
|
|
47
|
-
queryKey: [
|
|
58
|
+
queryKey: [
|
|
59
|
+
"infinite",
|
|
60
|
+
"jobs",
|
|
61
|
+
this.companyId,
|
|
62
|
+
body.amt ?? 50,
|
|
63
|
+
body.query ?? "",
|
|
64
|
+
body.routeId ?? "",
|
|
65
|
+
],
|
|
48
66
|
initialPageParam: 0,
|
|
49
67
|
getNextPageParam: (lastPage, allPages) => {
|
|
50
68
|
if (lastPage.length < (body.amt ?? 50))
|
|
@@ -63,7 +81,7 @@ AvroQueryClient.prototype.useGetInfiniteJobs = function (body, onProgress) {
|
|
|
63
81
|
if (result.data) {
|
|
64
82
|
result.data.pages.forEach((data_page) => {
|
|
65
83
|
data_page.forEach((job) => {
|
|
66
|
-
queryClient.setQueryData([
|
|
84
|
+
queryClient.setQueryData(["jobs", job.id], job);
|
|
67
85
|
});
|
|
68
86
|
});
|
|
69
87
|
}
|
|
@@ -71,10 +89,10 @@ AvroQueryClient.prototype.useGetInfiniteJobs = function (body, onProgress) {
|
|
|
71
89
|
};
|
|
72
90
|
AvroQueryClient.prototype.useGetJob = function (jobId) {
|
|
73
91
|
return useQuery({
|
|
74
|
-
queryKey: [
|
|
92
|
+
queryKey: ["jobs", jobId],
|
|
75
93
|
queryFn: async () => {
|
|
76
94
|
const job = await this.get({
|
|
77
|
-
path: `/job/${jobId}
|
|
95
|
+
path: `/job/${jobId}`,
|
|
78
96
|
});
|
|
79
97
|
return new Job(job);
|
|
80
98
|
},
|
|
@@ -88,7 +106,16 @@ AvroQueryClient.prototype.useCreateJob = function () {
|
|
|
88
106
|
return this.post({
|
|
89
107
|
path: `/company/${this.companyId}/job`,
|
|
90
108
|
data: JSON.stringify(jobData),
|
|
91
|
-
headers: { "Content-Type": "application/json" }
|
|
109
|
+
headers: { "Content-Type": "application/json" },
|
|
110
|
+
});
|
|
111
|
+
},
|
|
112
|
+
onSuccess: async (result) => {
|
|
113
|
+
await this._syncEntity(queryClient, {
|
|
114
|
+
action: "create",
|
|
115
|
+
entityKey: "jobs",
|
|
116
|
+
id: result.id,
|
|
117
|
+
fetchPath: `/job/${result.id}`,
|
|
118
|
+
construct: (d) => new Job(d),
|
|
92
119
|
});
|
|
93
120
|
},
|
|
94
121
|
});
|
|
@@ -100,19 +127,32 @@ AvroQueryClient.prototype.useManageJobs = function () {
|
|
|
100
127
|
return this.post({
|
|
101
128
|
path: `/company/${this.companyId}/jobs/manage`,
|
|
102
129
|
data: JSON.stringify({ jobs }),
|
|
103
|
-
headers: { "Content-Type": "application/json" }
|
|
130
|
+
headers: { "Content-Type": "application/json" },
|
|
104
131
|
});
|
|
105
132
|
},
|
|
133
|
+
onSuccess: () => {
|
|
134
|
+
queryClient.invalidateQueries({ queryKey: ["jobs"] });
|
|
135
|
+
queryClient.invalidateQueries({ queryKey: ["infinite", "jobs"] });
|
|
136
|
+
},
|
|
106
137
|
});
|
|
107
138
|
};
|
|
108
139
|
AvroQueryClient.prototype.useUpdateJob = function () {
|
|
109
140
|
const queryClient = this.getQueryClient();
|
|
110
141
|
return useMutation({
|
|
111
|
-
mutationFn: ({ jobId, updates }) => {
|
|
142
|
+
mutationFn: ({ jobId, updates, }) => {
|
|
112
143
|
return this.put({
|
|
113
144
|
path: `/job/${jobId}`,
|
|
114
145
|
data: JSON.stringify(updates),
|
|
115
|
-
headers: { "Content-Type": "application/json" }
|
|
146
|
+
headers: { "Content-Type": "application/json" },
|
|
147
|
+
});
|
|
148
|
+
},
|
|
149
|
+
onSuccess: async (_result, { jobId }) => {
|
|
150
|
+
await this._syncEntity(queryClient, {
|
|
151
|
+
action: "update",
|
|
152
|
+
entityKey: "jobs",
|
|
153
|
+
id: jobId,
|
|
154
|
+
fetchPath: `/job/${jobId}`,
|
|
155
|
+
construct: (d) => new Job(d),
|
|
116
156
|
});
|
|
117
157
|
},
|
|
118
158
|
});
|
|
@@ -124,9 +164,13 @@ AvroQueryClient.prototype.useDeleteJobs = function () {
|
|
|
124
164
|
return this.post({
|
|
125
165
|
path: `/company/${this.companyId}/jobs/delete`,
|
|
126
166
|
data: JSON.stringify({ ids }),
|
|
127
|
-
headers: { "Content-Type": "application/json" }
|
|
167
|
+
headers: { "Content-Type": "application/json" },
|
|
128
168
|
});
|
|
129
169
|
},
|
|
170
|
+
onSuccess: () => {
|
|
171
|
+
queryClient.invalidateQueries({ queryKey: ["jobs"] });
|
|
172
|
+
queryClient.invalidateQueries({ queryKey: ["infinite", "jobs"] });
|
|
173
|
+
},
|
|
130
174
|
});
|
|
131
175
|
};
|
|
132
176
|
AvroQueryClient.prototype.useDeleteJob = function () {
|
|
@@ -137,7 +181,14 @@ AvroQueryClient.prototype.useDeleteJob = function () {
|
|
|
137
181
|
path: `/job/${jobId}`,
|
|
138
182
|
headers: {
|
|
139
183
|
"Content-Type": "application/json",
|
|
140
|
-
}
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
},
|
|
187
|
+
onSuccess: async (_result, { jobId }) => {
|
|
188
|
+
await this._syncEntity(queryClient, {
|
|
189
|
+
action: "delete",
|
|
190
|
+
entityKey: "jobs",
|
|
191
|
+
id: jobId,
|
|
141
192
|
});
|
|
142
193
|
},
|
|
143
194
|
});
|
|
@@ -2,7 +2,13 @@ import { useMutation, useQuery } from "@tanstack/react-query";
|
|
|
2
2
|
import { AvroQueryClient } from "../../client/QueryClient";
|
|
3
3
|
AvroQueryClient.prototype.useGetLabels = function (body, total, onProgress) {
|
|
4
4
|
return useQuery({
|
|
5
|
-
queryKey: [
|
|
5
|
+
queryKey: [
|
|
6
|
+
"labels",
|
|
7
|
+
this.companyId,
|
|
8
|
+
body.amt ?? 50,
|
|
9
|
+
body.query ?? "",
|
|
10
|
+
total ?? "all",
|
|
11
|
+
],
|
|
6
12
|
queryFn: async () => {
|
|
7
13
|
if (typeof total !== "number") {
|
|
8
14
|
return this.fetchLabels({ ...body, offset: 0 });
|
|
@@ -33,32 +39,35 @@ AvroQueryClient.prototype.useCreateLabel = function () {
|
|
|
33
39
|
return this.post({
|
|
34
40
|
path: `/company/${this.companyId}/label`,
|
|
35
41
|
data: JSON.stringify(labelData),
|
|
36
|
-
headers: { "Content-Type": "application/json" }
|
|
42
|
+
headers: { "Content-Type": "application/json" },
|
|
37
43
|
});
|
|
38
44
|
},
|
|
45
|
+
onSuccess: () => {
|
|
46
|
+
queryClient.invalidateQueries({ queryKey: ["labels"] });
|
|
47
|
+
},
|
|
39
48
|
});
|
|
40
49
|
};
|
|
41
50
|
AvroQueryClient.prototype.useUpdateLabel = function () {
|
|
42
51
|
const queryClient = this.getQueryClient();
|
|
43
52
|
return useMutation({
|
|
44
|
-
mutationFn: async ({ labelId, labelData }) => {
|
|
53
|
+
mutationFn: async ({ labelId, labelData, }) => {
|
|
45
54
|
return this.put({
|
|
46
55
|
path: `/label/${labelId}`,
|
|
47
56
|
data: JSON.stringify(labelData),
|
|
48
|
-
headers: { "Content-Type": "application/json" }
|
|
57
|
+
headers: { "Content-Type": "application/json" },
|
|
49
58
|
});
|
|
50
59
|
},
|
|
51
60
|
onMutate: async ({ labelId, labelData }) => {
|
|
52
|
-
await queryClient.cancelQueries({ queryKey: [
|
|
53
|
-
await queryClient.cancelQueries({ queryKey: [
|
|
54
|
-
const previousLabels = queryClient.getQueryData([
|
|
55
|
-
const previousLabel = queryClient.getQueryData([
|
|
56
|
-
queryClient.setQueryData([
|
|
61
|
+
await queryClient.cancelQueries({ queryKey: ["labels"] });
|
|
62
|
+
await queryClient.cancelQueries({ queryKey: ["labels", labelId] });
|
|
63
|
+
const previousLabels = queryClient.getQueryData(["labels"]);
|
|
64
|
+
const previousLabel = queryClient.getQueryData(["labels", labelId]);
|
|
65
|
+
queryClient.setQueryData(["labels", labelId], (oldData) => {
|
|
57
66
|
if (!oldData)
|
|
58
67
|
return oldData;
|
|
59
68
|
return { ...oldData, ...labelData };
|
|
60
69
|
});
|
|
61
|
-
queryClient.setQueriesData({ queryKey: [
|
|
70
|
+
queryClient.setQueriesData({ queryKey: ["labels"] }, (oldData) => {
|
|
62
71
|
if (!oldData)
|
|
63
72
|
return oldData;
|
|
64
73
|
if (oldData.pages) {
|
|
@@ -72,13 +81,16 @@ AvroQueryClient.prototype.useUpdateLabel = function () {
|
|
|
72
81
|
});
|
|
73
82
|
return { previousLabels, previousLabel };
|
|
74
83
|
},
|
|
84
|
+
onSuccess: () => {
|
|
85
|
+
queryClient.invalidateQueries({ queryKey: ["labels"] });
|
|
86
|
+
},
|
|
75
87
|
onError: (_err, variables, context) => {
|
|
76
88
|
const { labelId } = variables;
|
|
77
89
|
if (context?.previousLabels) {
|
|
78
|
-
queryClient.setQueryData([
|
|
90
|
+
queryClient.setQueryData(["labels"], context.previousLabels);
|
|
79
91
|
}
|
|
80
92
|
if (context?.previousLabel) {
|
|
81
|
-
queryClient.setQueryData([
|
|
93
|
+
queryClient.setQueryData(["labels", labelId], context.previousLabel);
|
|
82
94
|
}
|
|
83
95
|
},
|
|
84
96
|
});
|
|
@@ -86,16 +98,16 @@ AvroQueryClient.prototype.useUpdateLabel = function () {
|
|
|
86
98
|
AvroQueryClient.prototype.useDeleteLabel = function () {
|
|
87
99
|
const queryClient = this.getQueryClient();
|
|
88
100
|
return useMutation({
|
|
89
|
-
mutationFn: async ({ labelId
|
|
101
|
+
mutationFn: async ({ labelId }) => {
|
|
90
102
|
return this.delete({ path: `/label/${labelId}` });
|
|
91
103
|
},
|
|
92
104
|
onMutate: async ({ labelId }) => {
|
|
93
|
-
await queryClient.cancelQueries({ queryKey: [
|
|
94
|
-
await queryClient.cancelQueries({ queryKey: [
|
|
95
|
-
const previousLabels = queryClient.getQueryData([
|
|
96
|
-
const previousLabel = queryClient.getQueryData([
|
|
97
|
-
queryClient.setQueryData([
|
|
98
|
-
queryClient.setQueriesData({ queryKey: [
|
|
105
|
+
await queryClient.cancelQueries({ queryKey: ["labels"] });
|
|
106
|
+
await queryClient.cancelQueries({ queryKey: ["labels", labelId] });
|
|
107
|
+
const previousLabels = queryClient.getQueryData(["labels"]);
|
|
108
|
+
const previousLabel = queryClient.getQueryData(["labels", labelId]);
|
|
109
|
+
queryClient.setQueryData(["labels", labelId], undefined);
|
|
110
|
+
queryClient.setQueriesData({ queryKey: ["labels"] }, (oldData) => {
|
|
99
111
|
if (!oldData)
|
|
100
112
|
return oldData;
|
|
101
113
|
if (oldData.pages) {
|
|
@@ -109,13 +121,16 @@ AvroQueryClient.prototype.useDeleteLabel = function () {
|
|
|
109
121
|
});
|
|
110
122
|
return { previousLabels, previousLabel };
|
|
111
123
|
},
|
|
124
|
+
onSuccess: () => {
|
|
125
|
+
queryClient.invalidateQueries({ queryKey: ["labels"] });
|
|
126
|
+
},
|
|
112
127
|
onError: (_err, variables, context) => {
|
|
113
128
|
const { labelId } = variables;
|
|
114
129
|
if (context?.previousLabels) {
|
|
115
|
-
queryClient.setQueryData([
|
|
130
|
+
queryClient.setQueryData(["labels"], context.previousLabels);
|
|
116
131
|
}
|
|
117
132
|
if (context?.previousLabel) {
|
|
118
|
-
queryClient.setQueryData([
|
|
133
|
+
queryClient.setQueryData(["labels", labelId], context.previousLabel);
|
|
119
134
|
}
|
|
120
135
|
},
|
|
121
136
|
});
|
|
@@ -4,12 +4,12 @@ AvroQueryClient.prototype.useGetMessages = function (chatId, body) {
|
|
|
4
4
|
const queryClient = this.getQueryClient();
|
|
5
5
|
const result = useInfiniteQuery({
|
|
6
6
|
queryKey: [
|
|
7
|
-
|
|
7
|
+
"messages",
|
|
8
8
|
chatId,
|
|
9
9
|
body.amt ?? 50,
|
|
10
10
|
body.known_ids ?? [],
|
|
11
11
|
body.unknown_ids ?? [],
|
|
12
|
-
body.query ??
|
|
12
|
+
body.query ?? "",
|
|
13
13
|
],
|
|
14
14
|
initialPageParam: 0,
|
|
15
15
|
getNextPageParam: (lastPage, allPages) => {
|
|
@@ -17,12 +17,15 @@ AvroQueryClient.prototype.useGetMessages = function (chatId, body) {
|
|
|
17
17
|
return undefined;
|
|
18
18
|
return allPages.flat().length; // next offset
|
|
19
19
|
},
|
|
20
|
-
queryFn: ({ pageParam = 0 }) => this.fetchMessages(chatId, {
|
|
20
|
+
queryFn: ({ pageParam = 0 }) => this.fetchMessages(chatId, {
|
|
21
|
+
...body,
|
|
22
|
+
offset: pageParam,
|
|
23
|
+
}),
|
|
21
24
|
});
|
|
22
25
|
if (result.data) {
|
|
23
26
|
result.data.pages.forEach((data_page) => {
|
|
24
27
|
data_page.forEach((message) => {
|
|
25
|
-
queryClient.setQueryData([
|
|
28
|
+
queryClient.setQueryData(["message", message.id], message);
|
|
26
29
|
});
|
|
27
30
|
});
|
|
28
31
|
}
|
|
@@ -41,12 +44,12 @@ AvroQueryClient.prototype.useCreateMessage = function (chatId) {
|
|
|
41
44
|
id,
|
|
42
45
|
},
|
|
43
46
|
}),
|
|
44
|
-
headers: {
|
|
47
|
+
headers: { "Content-Type": "application/json" },
|
|
45
48
|
});
|
|
46
49
|
return message;
|
|
47
50
|
},
|
|
48
51
|
onSuccess: (message) => {
|
|
49
|
-
queryClient.setQueryData([
|
|
52
|
+
queryClient.setQueryData(["message", message.id], message);
|
|
50
53
|
},
|
|
51
54
|
});
|
|
52
55
|
};
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { useInfiniteQuery, useMutation } from
|
|
2
|
-
import { AvroQueryClient } from
|
|
3
|
-
import { LineItemStatus } from
|
|
1
|
+
import { useInfiniteQuery, useMutation } from "@tanstack/react-query";
|
|
2
|
+
import { AvroQueryClient } from "../../client/QueryClient";
|
|
3
|
+
import { LineItemStatus } from "../../types/api";
|
|
4
4
|
AvroQueryClient.prototype.useGetMonths = function (body) {
|
|
5
5
|
const queryClient = this.getQueryClient();
|
|
6
6
|
const result = useInfiniteQuery({
|
|
7
7
|
queryKey: [
|
|
8
|
-
|
|
8
|
+
"months",
|
|
9
9
|
this.companyId,
|
|
10
10
|
body.amt ?? 50,
|
|
11
11
|
body.known_ids ?? [],
|
|
12
12
|
body.unknown_ids ?? [],
|
|
13
|
-
body.query ??
|
|
13
|
+
body.query ?? "",
|
|
14
14
|
body.unbilled ?? true,
|
|
15
15
|
body.billed ?? true,
|
|
16
16
|
body.paid ?? true,
|
|
17
|
-
body.jobId ??
|
|
17
|
+
body.jobId ?? "",
|
|
18
18
|
body.enabled ?? true,
|
|
19
19
|
],
|
|
20
20
|
initialPageParam: 0,
|
|
@@ -29,7 +29,7 @@ AvroQueryClient.prototype.useGetMonths = function (body) {
|
|
|
29
29
|
if (result.data) {
|
|
30
30
|
result.data.pages.forEach((data_page) => {
|
|
31
31
|
data_page.forEach((month) => {
|
|
32
|
-
queryClient.setQueryData([
|
|
32
|
+
queryClient.setQueryData(["month", month.id], month);
|
|
33
33
|
});
|
|
34
34
|
});
|
|
35
35
|
}
|
|
@@ -39,54 +39,74 @@ AvroQueryClient.prototype.useUpdateMonths = function () {
|
|
|
39
39
|
const queryClient = this.getQueryClient();
|
|
40
40
|
return useMutation({
|
|
41
41
|
mutationFn: async ({ months, action, }) => {
|
|
42
|
-
const monthIds = months.map(month => month.id);
|
|
42
|
+
const monthIds = months.map((month) => month.id);
|
|
43
43
|
return this.put({
|
|
44
44
|
path: `/company/${this.companyId}/months`,
|
|
45
45
|
data: JSON.stringify({
|
|
46
46
|
months: monthIds,
|
|
47
|
-
status: action === "billed"
|
|
47
|
+
status: action === "billed"
|
|
48
|
+
? LineItemStatus.EXTERNALLY_BILLED
|
|
49
|
+
: LineItemStatus.EXTERNALLY_PAID,
|
|
48
50
|
}),
|
|
49
51
|
headers: {
|
|
50
52
|
"Content-Type": "application/json",
|
|
51
|
-
}
|
|
53
|
+
},
|
|
52
54
|
});
|
|
53
55
|
},
|
|
54
56
|
onMutate: async ({ months, action }) => {
|
|
55
|
-
await queryClient.cancelQueries({ queryKey: [
|
|
56
|
-
await queryClient.cancelQueries({ queryKey: [
|
|
57
|
-
const previousMonths = queryClient.getQueryData([
|
|
58
|
-
const previousMonthObjs = months.map(month => queryClient.getQueryData([
|
|
59
|
-
const monthIds = months.map(month => month.id);
|
|
57
|
+
await queryClient.cancelQueries({ queryKey: ["months"] });
|
|
58
|
+
await queryClient.cancelQueries({ queryKey: ["months"] });
|
|
59
|
+
const previousMonths = queryClient.getQueryData(["months"]);
|
|
60
|
+
const previousMonthObjs = months.map((month) => queryClient.getQueryData(["month", month.id]));
|
|
61
|
+
const monthIds = months.map((month) => month.id);
|
|
60
62
|
monthIds.forEach((monthId, idx) => {
|
|
61
|
-
queryClient.setQueryData([
|
|
63
|
+
queryClient.setQueryData(["month", monthId], (oldData) => {
|
|
62
64
|
return oldData
|
|
63
|
-
? {
|
|
65
|
+
? {
|
|
66
|
+
...oldData,
|
|
67
|
+
status: action === "billed"
|
|
68
|
+
? LineItemStatus.EXTERNALLY_BILLED
|
|
69
|
+
: LineItemStatus.EXTERNALLY_PAID,
|
|
70
|
+
}
|
|
64
71
|
: oldData;
|
|
65
72
|
});
|
|
66
73
|
});
|
|
67
|
-
queryClient.setQueriesData({ queryKey: [
|
|
74
|
+
queryClient.setQueriesData({ queryKey: ["months"] }, (oldData) => {
|
|
68
75
|
if (!oldData)
|
|
69
76
|
return oldData;
|
|
70
77
|
if (oldData.pages) {
|
|
71
78
|
const updatedPages = oldData.pages.map((page) => page.map((month) => monthIds.includes(month.id)
|
|
72
|
-
? {
|
|
79
|
+
? {
|
|
80
|
+
...month,
|
|
81
|
+
status: action === "billed"
|
|
82
|
+
? LineItemStatus.EXTERNALLY_BILLED
|
|
83
|
+
: LineItemStatus.EXTERNALLY_PAID,
|
|
84
|
+
}
|
|
73
85
|
: month));
|
|
74
86
|
return { ...oldData, pages: updatedPages };
|
|
75
87
|
}
|
|
76
88
|
if (Array.isArray(oldData)) {
|
|
77
89
|
return oldData.map((month) => monthIds.includes(month.id)
|
|
78
|
-
? {
|
|
90
|
+
? {
|
|
91
|
+
...month,
|
|
92
|
+
status: action === "billed"
|
|
93
|
+
? LineItemStatus.EXTERNALLY_BILLED
|
|
94
|
+
: LineItemStatus.EXTERNALLY_PAID,
|
|
95
|
+
}
|
|
79
96
|
: month);
|
|
80
97
|
}
|
|
81
98
|
return oldData;
|
|
82
99
|
});
|
|
83
100
|
return { previousMonths, previousMonthObjs };
|
|
84
101
|
},
|
|
102
|
+
onSuccess: () => {
|
|
103
|
+
queryClient.invalidateQueries({ queryKey: ["months"] });
|
|
104
|
+
},
|
|
85
105
|
onError: (err, variables, context) => {
|
|
86
106
|
if (context) {
|
|
87
|
-
queryClient.setQueryData([
|
|
107
|
+
queryClient.setQueryData(["months"], context.previousMonths);
|
|
88
108
|
context.previousMonthObjs.forEach((monthObj) => {
|
|
89
|
-
queryClient.setQueryData([
|
|
109
|
+
queryClient.setQueryData(["month", monthObj.id], monthObj);
|
|
90
110
|
});
|
|
91
111
|
}
|
|
92
112
|
},
|
|
@@ -2,7 +2,7 @@ import { useQuery } from "@tanstack/react-query";
|
|
|
2
2
|
import { AvroQueryClient } from "../../client/QueryClient";
|
|
3
3
|
AvroQueryClient.prototype.useGetPlans = function (code) {
|
|
4
4
|
return useQuery({
|
|
5
|
-
queryKey: [
|
|
6
|
-
queryFn: async () => this.get({ path: `/plans${code ? `?code=${code}` :
|
|
5
|
+
queryKey: ["plans", code],
|
|
6
|
+
queryFn: async () => this.get({ path: `/plans${code ? `?code=${code}` : ""}` }),
|
|
7
7
|
});
|
|
8
8
|
};
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { useInfiniteQuery, useMutation } from
|
|
2
|
-
import { AvroQueryClient } from
|
|
3
|
-
import { LineItemStatus } from
|
|
1
|
+
import { useInfiniteQuery, useMutation } from "@tanstack/react-query";
|
|
2
|
+
import { AvroQueryClient } from "../../client/QueryClient";
|
|
3
|
+
import { LineItemStatus } from "../../types/api";
|
|
4
4
|
AvroQueryClient.prototype.useGetPrepayments = function (body) {
|
|
5
5
|
const queryClient = this.getQueryClient();
|
|
6
6
|
const result = useInfiniteQuery({
|
|
7
7
|
queryKey: [
|
|
8
|
-
|
|
8
|
+
"prepayments",
|
|
9
9
|
this.companyId,
|
|
10
10
|
body.amt ?? 50,
|
|
11
11
|
body.known_ids ?? [],
|
|
12
12
|
body.unknown_ids ?? [],
|
|
13
|
-
body.query ??
|
|
13
|
+
body.query ?? "",
|
|
14
14
|
body.unbilled ?? true,
|
|
15
15
|
body.billed ?? true,
|
|
16
16
|
body.paid ?? true,
|
|
17
|
-
body.taskId ??
|
|
17
|
+
body.taskId ?? "",
|
|
18
18
|
body.enabled ?? true,
|
|
19
19
|
],
|
|
20
20
|
initialPageParam: 0,
|
|
@@ -29,7 +29,7 @@ AvroQueryClient.prototype.useGetPrepayments = function (body) {
|
|
|
29
29
|
if (result.data) {
|
|
30
30
|
result.data.pages.forEach((data_page) => {
|
|
31
31
|
data_page.forEach((prepayment) => {
|
|
32
|
-
queryClient.setQueryData([
|
|
32
|
+
queryClient.setQueryData(["prepayment", prepayment.id], prepayment);
|
|
33
33
|
});
|
|
34
34
|
});
|
|
35
35
|
}
|
|
@@ -39,54 +39,74 @@ AvroQueryClient.prototype.useUpdatePrepayments = function () {
|
|
|
39
39
|
const queryClient = this.getQueryClient();
|
|
40
40
|
return useMutation({
|
|
41
41
|
mutationFn: async ({ prepayments, action, }) => {
|
|
42
|
-
const prepaymentIds = prepayments.map(prepayment => prepayment.id);
|
|
42
|
+
const prepaymentIds = prepayments.map((prepayment) => prepayment.id);
|
|
43
43
|
return this.put({
|
|
44
44
|
path: `/company/${this.companyId}/prepayments`,
|
|
45
45
|
data: JSON.stringify({
|
|
46
46
|
prepayments: prepaymentIds,
|
|
47
|
-
status: action === "billed"
|
|
47
|
+
status: action === "billed"
|
|
48
|
+
? LineItemStatus.EXTERNALLY_BILLED
|
|
49
|
+
: LineItemStatus.EXTERNALLY_PAID,
|
|
48
50
|
}),
|
|
49
51
|
headers: {
|
|
50
52
|
"Content-Type": "application/json",
|
|
51
|
-
}
|
|
53
|
+
},
|
|
52
54
|
});
|
|
53
55
|
},
|
|
54
56
|
onMutate: async ({ prepayments, action }) => {
|
|
55
|
-
await queryClient.cancelQueries({ queryKey: [
|
|
56
|
-
await queryClient.cancelQueries({ queryKey: [
|
|
57
|
-
const previousPrepayments = queryClient.getQueryData([
|
|
58
|
-
const previousPrepaymentObjs = prepayments.map(prepayment => queryClient.getQueryData([
|
|
59
|
-
const prepaymentIds = prepayments.map(prepayment => prepayment.id);
|
|
57
|
+
await queryClient.cancelQueries({ queryKey: ["prepayments"] });
|
|
58
|
+
await queryClient.cancelQueries({ queryKey: ["prepayments"] });
|
|
59
|
+
const previousPrepayments = queryClient.getQueryData(["prepayments"]);
|
|
60
|
+
const previousPrepaymentObjs = prepayments.map((prepayment) => queryClient.getQueryData(["prepayment", prepayment.id]));
|
|
61
|
+
const prepaymentIds = prepayments.map((prepayment) => prepayment.id);
|
|
60
62
|
prepaymentIds.forEach((prepaymentId, idx) => {
|
|
61
|
-
queryClient.setQueryData([
|
|
63
|
+
queryClient.setQueryData(["prepayment", prepaymentId], (oldData) => {
|
|
62
64
|
return oldData
|
|
63
|
-
? {
|
|
65
|
+
? {
|
|
66
|
+
...oldData,
|
|
67
|
+
status: action === "billed"
|
|
68
|
+
? LineItemStatus.EXTERNALLY_BILLED
|
|
69
|
+
: LineItemStatus.EXTERNALLY_PAID,
|
|
70
|
+
}
|
|
64
71
|
: oldData;
|
|
65
72
|
});
|
|
66
73
|
});
|
|
67
|
-
queryClient.setQueriesData({ queryKey: [
|
|
74
|
+
queryClient.setQueriesData({ queryKey: ["prepayments"] }, (oldData) => {
|
|
68
75
|
if (!oldData)
|
|
69
76
|
return oldData;
|
|
70
77
|
if (oldData.pages) {
|
|
71
78
|
const updatedPages = oldData.pages.map((page) => page.map((prepayment) => prepaymentIds.includes(prepayment.id)
|
|
72
|
-
? {
|
|
79
|
+
? {
|
|
80
|
+
...prepayment,
|
|
81
|
+
status: action === "billed"
|
|
82
|
+
? LineItemStatus.EXTERNALLY_BILLED
|
|
83
|
+
: LineItemStatus.EXTERNALLY_PAID,
|
|
84
|
+
}
|
|
73
85
|
: prepayment));
|
|
74
86
|
return { ...oldData, pages: updatedPages };
|
|
75
87
|
}
|
|
76
88
|
if (Array.isArray(oldData)) {
|
|
77
89
|
return oldData.map((prepayment) => prepaymentIds.includes(prepayment.id)
|
|
78
|
-
? {
|
|
90
|
+
? {
|
|
91
|
+
...prepayment,
|
|
92
|
+
status: action === "billed"
|
|
93
|
+
? LineItemStatus.EXTERNALLY_BILLED
|
|
94
|
+
: LineItemStatus.EXTERNALLY_PAID,
|
|
95
|
+
}
|
|
79
96
|
: prepayment);
|
|
80
97
|
}
|
|
81
98
|
return oldData;
|
|
82
99
|
});
|
|
83
100
|
return { previousPrepayments, previousPrepaymentObjs };
|
|
84
101
|
},
|
|
102
|
+
onSuccess: () => {
|
|
103
|
+
queryClient.invalidateQueries({ queryKey: ["prepayments"] });
|
|
104
|
+
},
|
|
85
105
|
onError: (err, variables, context) => {
|
|
86
106
|
if (context) {
|
|
87
|
-
queryClient.setQueryData([
|
|
107
|
+
queryClient.setQueryData(["prepayments"], context.previousPrepayments);
|
|
88
108
|
context.previousPrepaymentObjs.forEach((prepaymentObj) => {
|
|
89
|
-
queryClient.setQueryData([
|
|
109
|
+
queryClient.setQueryData(["prepayment", prepaymentObj.id], prepaymentObj);
|
|
90
110
|
});
|
|
91
111
|
}
|
|
92
112
|
},
|
|
@@ -2,32 +2,48 @@ import { useMutation, useQuery } from "@tanstack/react-query";
|
|
|
2
2
|
import { AvroQueryClient } from "../../client/QueryClient";
|
|
3
3
|
import { Task } from "../../types/api/Task";
|
|
4
4
|
AvroQueryClient.prototype.useCreateProposal = function () {
|
|
5
|
+
const queryClient = this.getQueryClient();
|
|
5
6
|
return useMutation({
|
|
6
|
-
mutationFn: async ({ job_id, data }) => {
|
|
7
|
+
mutationFn: async ({ job_id, data, }) => {
|
|
7
8
|
return this.post({
|
|
8
9
|
path: `/job/${job_id}/proposal`,
|
|
9
10
|
data: JSON.stringify(data),
|
|
10
|
-
headers: { "Content-Type": "application/json" }
|
|
11
|
+
headers: { "Content-Type": "application/json" },
|
|
12
|
+
});
|
|
13
|
+
},
|
|
14
|
+
onSuccess: async (result) => {
|
|
15
|
+
await this._syncEntity(queryClient, {
|
|
16
|
+
action: "create",
|
|
17
|
+
entityKey: "proposals",
|
|
18
|
+
id: result.id,
|
|
19
|
+
fetchPath: `/proposal/${result.id}`,
|
|
11
20
|
});
|
|
12
21
|
},
|
|
13
22
|
});
|
|
14
23
|
};
|
|
15
24
|
AvroQueryClient.prototype.useReviewProposal = function (proposal_id) {
|
|
25
|
+
const queryClient = this.getQueryClient();
|
|
16
26
|
return useMutation({
|
|
17
27
|
mutationFn: async (data) => {
|
|
18
28
|
return this.post({
|
|
19
29
|
path: `/proposal/${proposal_id}/review`,
|
|
20
30
|
data: JSON.stringify(data),
|
|
21
|
-
headers: { "Content-Type": "application/json" }
|
|
31
|
+
headers: { "Content-Type": "application/json" },
|
|
22
32
|
});
|
|
23
33
|
},
|
|
34
|
+
onSuccess: () => {
|
|
35
|
+
queryClient.invalidateQueries({ queryKey: ["proposals"] });
|
|
36
|
+
queryClient.invalidateQueries({ queryKey: ["jobs"] });
|
|
37
|
+
},
|
|
24
38
|
});
|
|
25
39
|
};
|
|
26
40
|
AvroQueryClient.prototype.useGetProposal = function (proposal_id) {
|
|
27
41
|
return useQuery({
|
|
28
|
-
queryKey: [
|
|
42
|
+
queryKey: ["proposals", proposal_id],
|
|
29
43
|
queryFn: async () => {
|
|
30
|
-
const proposal = await this.get({
|
|
44
|
+
const proposal = await this.get({
|
|
45
|
+
path: `/proposal/${proposal_id}`,
|
|
46
|
+
});
|
|
31
47
|
if (proposal && Array.isArray(proposal.tasks)) {
|
|
32
48
|
proposal.tasks = proposal.tasks.map((task) => new Task(task));
|
|
33
49
|
}
|