@go-avro/avro-js 0.0.2-beta.57 → 0.0.2-beta.59
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';
|
|
@@ -103,6 +103,15 @@ declare module '../client/QueryClient' {
|
|
|
103
103
|
password: string;
|
|
104
104
|
phone_number: string;
|
|
105
105
|
}>>;
|
|
106
|
+
useCreateSessionBreak(): ReturnType<typeof useMutation<{
|
|
107
|
+
id: string;
|
|
108
|
+
}, StandardError, {
|
|
109
|
+
sessionId: string;
|
|
110
|
+
breakData: {
|
|
111
|
+
start_time: string;
|
|
112
|
+
end_time?: string;
|
|
113
|
+
};
|
|
114
|
+
}>>;
|
|
106
115
|
useUpdateEvent(): ReturnType<typeof useMutation<{
|
|
107
116
|
msg: string;
|
|
108
117
|
}, StandardError, {
|
|
@@ -147,6 +156,22 @@ declare module '../client/QueryClient' {
|
|
|
147
156
|
})[];
|
|
148
157
|
action: "billed" | "paid";
|
|
149
158
|
}>>;
|
|
159
|
+
useUpdateUserCompany(): ReturnType<typeof useMutation<{
|
|
160
|
+
msg: string;
|
|
161
|
+
}, StandardError, {
|
|
162
|
+
company_id: string;
|
|
163
|
+
user_id: string;
|
|
164
|
+
data: Partial<UserCompanyAssociation>;
|
|
165
|
+
}>>;
|
|
166
|
+
useUpdateSessionBreak(): ReturnType<typeof useMutation<{
|
|
167
|
+
msg: string;
|
|
168
|
+
}, StandardError, {
|
|
169
|
+
breakId: string;
|
|
170
|
+
updates: {
|
|
171
|
+
start_time?: string;
|
|
172
|
+
end_time?: string;
|
|
173
|
+
};
|
|
174
|
+
}>>;
|
|
150
175
|
useDeleteJob(): ReturnType<typeof useMutation<{
|
|
151
176
|
msg: string;
|
|
152
177
|
}, StandardError, {
|
|
@@ -44,6 +44,49 @@ AvroQueryClient.prototype.useCreateUserSession = function () {
|
|
|
44
44
|
},
|
|
45
45
|
});
|
|
46
46
|
};
|
|
47
|
+
AvroQueryClient.prototype.useCreateSessionBreak = function () {
|
|
48
|
+
const queryClient = useQueryClient();
|
|
49
|
+
return useMutation({
|
|
50
|
+
mutationFn: ({ sessionId, breakData }) => {
|
|
51
|
+
return this.post(`/session/${sessionId}/break`, JSON.stringify(breakData), undefined, {
|
|
52
|
+
"Content-Type": "application/json",
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
onMutate: async ({ sessionId, breakData }) => {
|
|
56
|
+
await queryClient.cancelQueries({ queryKey: ['sessions'] });
|
|
57
|
+
const previousSessions = queryClient.getQueryData(['sessions']);
|
|
58
|
+
queryClient.setQueryData(['sessions'], (oldData) => {
|
|
59
|
+
if (!oldData)
|
|
60
|
+
return oldData;
|
|
61
|
+
if (Array.isArray(oldData)) {
|
|
62
|
+
return oldData.map((session) => session.id === sessionId
|
|
63
|
+
? {
|
|
64
|
+
...session,
|
|
65
|
+
breaks: [
|
|
66
|
+
...(session.breaks || []),
|
|
67
|
+
{
|
|
68
|
+
...breakData,
|
|
69
|
+
id: Math.random().toString(36).substr(2, 9),
|
|
70
|
+
session_id: sessionId,
|
|
71
|
+
}
|
|
72
|
+
]
|
|
73
|
+
}
|
|
74
|
+
: session);
|
|
75
|
+
}
|
|
76
|
+
return oldData;
|
|
77
|
+
});
|
|
78
|
+
return { previousSessions };
|
|
79
|
+
},
|
|
80
|
+
onError: (err, variables, context) => {
|
|
81
|
+
if (context?.previousSessions) {
|
|
82
|
+
queryClient.setQueryData(['sessions'], context.previousSessions);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
onSettled: () => {
|
|
86
|
+
queryClient.invalidateQueries({ queryKey: ['sessions'] });
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
};
|
|
47
90
|
AvroQueryClient.prototype.useUpdateUserSession = function () {
|
|
48
91
|
const queryClient = useQueryClient();
|
|
49
92
|
return useMutation({
|
|
@@ -75,3 +118,37 @@ AvroQueryClient.prototype.useUpdateUserSession = function () {
|
|
|
75
118
|
},
|
|
76
119
|
});
|
|
77
120
|
};
|
|
121
|
+
AvroQueryClient.prototype.useUpdateSessionBreak = function () {
|
|
122
|
+
const queryClient = useQueryClient();
|
|
123
|
+
return useMutation({
|
|
124
|
+
mutationFn: ({ breakId, updates }) => {
|
|
125
|
+
return this.put(`/break/${breakId}`, JSON.stringify(updates), undefined, {
|
|
126
|
+
"Content-Type": "application/json",
|
|
127
|
+
});
|
|
128
|
+
},
|
|
129
|
+
onMutate: async ({ breakId, updates }) => {
|
|
130
|
+
await queryClient.cancelQueries({ queryKey: ['sessions'] });
|
|
131
|
+
const previousSessions = queryClient.getQueryData(['sessions']);
|
|
132
|
+
queryClient.setQueryData(['sessions'], (oldData) => {
|
|
133
|
+
if (!oldData)
|
|
134
|
+
return oldData;
|
|
135
|
+
if (Array.isArray(oldData)) {
|
|
136
|
+
return oldData.map((session) => ({
|
|
137
|
+
...session,
|
|
138
|
+
breaks: session.breaks?.map(b => b.id === breakId ? { ...b, ...updates } : b)
|
|
139
|
+
}));
|
|
140
|
+
}
|
|
141
|
+
return oldData;
|
|
142
|
+
});
|
|
143
|
+
return { previousSessions };
|
|
144
|
+
},
|
|
145
|
+
onError: (err, variables, context) => {
|
|
146
|
+
if (context?.previousSessions) {
|
|
147
|
+
queryClient.setQueryData(['sessions'], context.previousSessions);
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
onSettled: () => {
|
|
151
|
+
queryClient.invalidateQueries({ queryKey: ['sessions'] });
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
};
|
|
@@ -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