@go-avro/avro-js 0.0.2-beta.57 → 0.0.2-beta.58
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,6 +1,6 @@
|
|
|
1
1
|
import { InfiniteData, UseInfiniteQueryResult, useMutation, UseQueryResult } from '@tanstack/react-query';
|
|
2
2
|
import { AuthManager } from '../auth/AuthManager';
|
|
3
|
-
import { _Event, ApiInfo, Bill, Company, Job, LineItem, Route, ServiceMonth, Session, User } from '../types/api';
|
|
3
|
+
import { _Event, ApiInfo, Bill, Company, Job, LineItem, Route, ServiceMonth, Session, User, UserCompanyAssociation } from '../types/api';
|
|
4
4
|
import { Tokens } from '../types/auth';
|
|
5
5
|
import { CancelToken, RetryStrategy } from '../types/client';
|
|
6
6
|
import { StandardError } from '../types/error';
|
|
@@ -147,6 +147,13 @@ declare module '../client/QueryClient' {
|
|
|
147
147
|
})[];
|
|
148
148
|
action: "billed" | "paid";
|
|
149
149
|
}>>;
|
|
150
|
+
useUpdateUserCompany(): ReturnType<typeof useMutation<{
|
|
151
|
+
msg: string;
|
|
152
|
+
}, StandardError, {
|
|
153
|
+
company_id: string;
|
|
154
|
+
user_id: string;
|
|
155
|
+
data: Partial<UserCompanyAssociation>;
|
|
156
|
+
}>>;
|
|
150
157
|
useDeleteJob(): ReturnType<typeof useMutation<{
|
|
151
158
|
msg: string;
|
|
152
159
|
}, StandardError, {
|
|
@@ -25,6 +25,50 @@ AvroQueryClient.prototype.useCreateSelf = function () {
|
|
|
25
25
|
},
|
|
26
26
|
});
|
|
27
27
|
};
|
|
28
|
+
AvroQueryClient.prototype.useUpdateUserCompany = function () {
|
|
29
|
+
const queryClient = useQueryClient();
|
|
30
|
+
return useMutation({
|
|
31
|
+
mutationFn: async ({ company_id, user_id, data }) => {
|
|
32
|
+
return this.put(`/company/${company_id}/user/${user_id}`, JSON.stringify(data), undefined, { "Content-Type": "application/json" });
|
|
33
|
+
},
|
|
34
|
+
// Optimistically update the user data and company data in the cache
|
|
35
|
+
onMutate: async (data) => {
|
|
36
|
+
await queryClient.cancelQueries({ queryKey: ['user'] });
|
|
37
|
+
await queryClient.cancelQueries({ queryKey: ['company', data.company_id] });
|
|
38
|
+
const previousUser = queryClient.getQueryData(['user']);
|
|
39
|
+
const previousCompany = queryClient.getQueryData(['company', data.company_id]);
|
|
40
|
+
if (previousUser) {
|
|
41
|
+
let oldUserCompany = previousUser.companies?.find(c => c.company === data.company_id);
|
|
42
|
+
if (oldUserCompany) {
|
|
43
|
+
oldUserCompany = { ...oldUserCompany, ...data.data };
|
|
44
|
+
const newCompanies = previousUser.companies?.map(c => c.company === data.company_id ? oldUserCompany : c) ?? [];
|
|
45
|
+
queryClient.setQueryData(['user'], { ...previousUser, companies: newCompanies });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (previousCompany) {
|
|
49
|
+
let oldCompanyUser = previousCompany.users?.find((u) => u.user.id === data.user_id);
|
|
50
|
+
if (oldCompanyUser) {
|
|
51
|
+
oldCompanyUser = { ...oldCompanyUser, ...data.data };
|
|
52
|
+
const newUsers = previousCompany.users?.map((u) => u.user.id === data.user_id ? oldCompanyUser : u) ?? [];
|
|
53
|
+
queryClient.setQueryData(['company', data.company_id], { ...previousCompany, users: newUsers });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return { previousUser, previousCompany };
|
|
57
|
+
},
|
|
58
|
+
onError: (err, _, context) => {
|
|
59
|
+
if (context?.previousUser) {
|
|
60
|
+
queryClient.setQueryData(['user'], context.previousUser);
|
|
61
|
+
}
|
|
62
|
+
if (context?.previousCompany) {
|
|
63
|
+
queryClient.setQueryData(['company'], context.previousCompany);
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
onSettled: (data, error, variables) => {
|
|
67
|
+
queryClient.invalidateQueries({ queryKey: ['user'] });
|
|
68
|
+
queryClient.invalidateQueries({ queryKey: ['company', variables.company_id] });
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
};
|
|
28
72
|
AvroQueryClient.prototype.useDeleteSelf = function () {
|
|
29
73
|
const queryClient = useQueryClient();
|
|
30
74
|
return useMutation({
|
package/dist/types/api.d.ts
CHANGED
|
@@ -257,6 +257,12 @@ export interface Group {
|
|
|
257
257
|
time_created: number;
|
|
258
258
|
time_updated: number;
|
|
259
259
|
}
|
|
260
|
+
export declare const NotificationLevel: Readonly<{
|
|
261
|
+
IN_APP: 0;
|
|
262
|
+
EMAIL: 1;
|
|
263
|
+
SMS: 2;
|
|
264
|
+
PUSH: 3;
|
|
265
|
+
}>;
|
|
260
266
|
export interface UserCompanyAssociation {
|
|
261
267
|
id: string;
|
|
262
268
|
user: User;
|
|
@@ -267,7 +273,7 @@ export interface UserCompanyAssociation {
|
|
|
267
273
|
time_updated: number | null;
|
|
268
274
|
notification_setting: number[];
|
|
269
275
|
share_email_company_wide: boolean;
|
|
270
|
-
notifications:
|
|
276
|
+
notifications: Notification[];
|
|
271
277
|
groups: string[];
|
|
272
278
|
}
|
|
273
279
|
export interface Email {
|
package/dist/types/api.js
CHANGED