@go-avro/avro-js 0.0.20 → 0.0.22
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/client/AvroQueryClientProvider.d.ts +1 -0
- package/dist/client/AvroQueryClientProvider.js +28 -2
- package/dist/client/QueryClient.d.ts +13 -0
- package/dist/client/QueryClient.js +131 -0
- package/dist/client/hooks/bills.js +12 -13
- package/dist/client/hooks/catalog_items.js +5 -6
- package/dist/client/hooks/chats.js +2 -2
- package/dist/client/hooks/companies.js +20 -20
- package/dist/client/hooks/events.js +21 -26
- package/dist/client/hooks/groups.js +11 -13
- package/dist/client/hooks/jobs.js +4 -11
- package/dist/client/hooks/labels.js +11 -13
- package/dist/client/hooks/months.js +2 -3
- package/dist/client/hooks/prepayments.js +2 -3
- package/dist/client/hooks/proposal.js +1 -1
- package/dist/client/hooks/routes.js +10 -15
- package/dist/client/hooks/skills.js +5 -6
- package/dist/client/hooks/teams.js +9 -11
- package/dist/client/hooks/timecards.js +1 -2
- package/dist/client/hooks/users.js +7 -7
- package/dist/client/hooks/waivers.js +5 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +6 -2
|
@@ -11,4 +11,5 @@ export interface AvroQueryClientProviderProps {
|
|
|
11
11
|
}
|
|
12
12
|
export declare const AvroQueryClientProvider: ({ baseUrl, authManager, configOverrides, children, }: AvroQueryClientProviderProps) => React.JSX.Element;
|
|
13
13
|
export declare const useAvroQueryClient: () => AvroQueryClient;
|
|
14
|
+
export declare const useSocketEvent: (eventName: string, callback: (data: Record<string, unknown>) => void) => void;
|
|
14
15
|
export default AvroQueryClientProvider;
|
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
import React, { createContext, useContext, useMemo, useEffect } from "react";
|
|
1
|
+
import React, { createContext, useContext, useMemo, useEffect, useRef, useCallback } from "react";
|
|
2
|
+
import { useQueryClient } from "@tanstack/react-query";
|
|
2
3
|
import { AvroQueryClient } from "./QueryClient";
|
|
3
4
|
const AvroQueryClientContext = createContext(null);
|
|
5
|
+
const SocketInvalidationBridge = ({ client }) => {
|
|
6
|
+
const queryClient = useQueryClient();
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
client.setupSocketInvalidation(queryClient);
|
|
9
|
+
return () => {
|
|
10
|
+
client.teardownSocketInvalidation();
|
|
11
|
+
};
|
|
12
|
+
}, [client, queryClient]);
|
|
13
|
+
return null;
|
|
14
|
+
};
|
|
4
15
|
export const AvroQueryClientProvider = ({ baseUrl, authManager, configOverrides, children, }) => {
|
|
5
16
|
const client = useMemo(() => {
|
|
6
17
|
const cfg = {
|
|
@@ -13,6 +24,7 @@ export const AvroQueryClientProvider = ({ baseUrl, authManager, configOverrides,
|
|
|
13
24
|
useEffect(() => {
|
|
14
25
|
return () => {
|
|
15
26
|
try {
|
|
27
|
+
client.teardownSocketInvalidation();
|
|
16
28
|
client.socket?.disconnect();
|
|
17
29
|
}
|
|
18
30
|
catch (e) {
|
|
@@ -20,7 +32,9 @@ export const AvroQueryClientProvider = ({ baseUrl, authManager, configOverrides,
|
|
|
20
32
|
}
|
|
21
33
|
};
|
|
22
34
|
}, [client]);
|
|
23
|
-
return (React.createElement(AvroQueryClientContext.Provider, { value: client },
|
|
35
|
+
return (React.createElement(AvroQueryClientContext.Provider, { value: client },
|
|
36
|
+
React.createElement(SocketInvalidationBridge, { client: client }),
|
|
37
|
+
children));
|
|
24
38
|
};
|
|
25
39
|
export const useAvroQueryClient = () => {
|
|
26
40
|
const ctx = useContext(AvroQueryClientContext);
|
|
@@ -29,4 +43,16 @@ export const useAvroQueryClient = () => {
|
|
|
29
43
|
}
|
|
30
44
|
return ctx;
|
|
31
45
|
};
|
|
46
|
+
export const useSocketEvent = (eventName, callback) => {
|
|
47
|
+
const client = useAvroQueryClient();
|
|
48
|
+
const callbackRef = useRef(callback);
|
|
49
|
+
callbackRef.current = callback;
|
|
50
|
+
const stableHandler = useCallback((data) => callbackRef.current(data), []);
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
client.on(eventName, stableHandler);
|
|
53
|
+
return () => {
|
|
54
|
+
client.off(eventName, stableHandler);
|
|
55
|
+
};
|
|
56
|
+
}, [client, eventName, stableHandler]);
|
|
57
|
+
};
|
|
32
58
|
export default AvroQueryClientProvider;
|
|
@@ -513,10 +513,23 @@ export declare class AvroQueryClient {
|
|
|
513
513
|
companyId: string | undefined;
|
|
514
514
|
company: Company | undefined;
|
|
515
515
|
private authStateListeners;
|
|
516
|
+
private _queryClient;
|
|
517
|
+
private _socketInvalidationCleanup;
|
|
516
518
|
constructor(config: AvroQueryClientConfig);
|
|
517
519
|
emit(eventName: string, data: unknown): void;
|
|
518
520
|
on<T>(eventName: string, callback: (data: T) => void): void;
|
|
519
521
|
off(eventName: string, callback?: Function): void;
|
|
522
|
+
/**
|
|
523
|
+
* Wire up automatic query invalidation for socket events.
|
|
524
|
+
* Called once from AvroQueryClientProvider when the tanstack
|
|
525
|
+
* QueryClient is available. Also handles auto-joining the
|
|
526
|
+
* company room on connect so consumer apps don't have to.
|
|
527
|
+
*/
|
|
528
|
+
setupSocketInvalidation(queryClient: QueryClient): void;
|
|
529
|
+
/**
|
|
530
|
+
* Remove all invalidation listeners. Called on provider unmount.
|
|
531
|
+
*/
|
|
532
|
+
teardownSocketInvalidation(): void;
|
|
520
533
|
get<T>({ path, cancelToken, headers, progressUpdateCallback }: {
|
|
521
534
|
path: string;
|
|
522
535
|
cancelToken?: CancelToken;
|
|
@@ -3,12 +3,91 @@ import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
|
3
3
|
import { LoginResponse } from '../types/api';
|
|
4
4
|
import { AuthState } from '../types/auth';
|
|
5
5
|
import { StandardError } from '../types/error';
|
|
6
|
+
/**
|
|
7
|
+
* Maps socket event names to the query keys that should be invalidated
|
|
8
|
+
* when that event is received. Chat events are excluded — they carry
|
|
9
|
+
* their own data and are handled separately by consumer apps.
|
|
10
|
+
*/
|
|
11
|
+
const SOCKET_INVALIDATION_MAP = {
|
|
12
|
+
// Company
|
|
13
|
+
create_company: [['companies']],
|
|
14
|
+
update_company: [['companies']],
|
|
15
|
+
delete_company: [['companies']],
|
|
16
|
+
// Users
|
|
17
|
+
user_updated: [['users']],
|
|
18
|
+
update_users: [['users']],
|
|
19
|
+
// Jobs
|
|
20
|
+
create_job: [['jobs']],
|
|
21
|
+
update_job: [['jobs']],
|
|
22
|
+
update_jobs: [['jobs']],
|
|
23
|
+
delete_job: [['jobs']],
|
|
24
|
+
delete_jobs: [['jobs']],
|
|
25
|
+
// Routes
|
|
26
|
+
create_route: [['routes']],
|
|
27
|
+
update_route: [['routes']],
|
|
28
|
+
delete_route: [['routes']],
|
|
29
|
+
// Events
|
|
30
|
+
create_event: [['events']],
|
|
31
|
+
update_event: [['events']],
|
|
32
|
+
update_events: [['events']],
|
|
33
|
+
delete_event: [['events']],
|
|
34
|
+
// Teams
|
|
35
|
+
create_team: [['teams']],
|
|
36
|
+
update_team: [['teams']],
|
|
37
|
+
update_teams: [['teams']],
|
|
38
|
+
delete_team: [['teams']],
|
|
39
|
+
// Bills
|
|
40
|
+
create_bill: [['bills']],
|
|
41
|
+
update_bills: [['bills']],
|
|
42
|
+
delete_bill: [['bills']],
|
|
43
|
+
// Sessions
|
|
44
|
+
create_session: [['sessions']],
|
|
45
|
+
update_session: [['sessions']],
|
|
46
|
+
// Catalog
|
|
47
|
+
create_catalog_item: [['catalog_items']],
|
|
48
|
+
update_catalog_item: [['catalog_items']],
|
|
49
|
+
delete_catalog_item: [['catalog_items']],
|
|
50
|
+
// Groups
|
|
51
|
+
create_group: [['groups']],
|
|
52
|
+
update_group: [['groups']],
|
|
53
|
+
delete_group: [['groups']],
|
|
54
|
+
// Labels
|
|
55
|
+
create_label: [['labels']],
|
|
56
|
+
update_label: [['labels']],
|
|
57
|
+
delete_label: [['labels']],
|
|
58
|
+
// Skills
|
|
59
|
+
create_skill: [['skills']],
|
|
60
|
+
update_skill: [['skills']],
|
|
61
|
+
delete_skill: [['skills']],
|
|
62
|
+
// Proposals
|
|
63
|
+
create_proposal: [['proposals']],
|
|
64
|
+
update_proposal: [['proposals']],
|
|
65
|
+
delete_proposal: [['proposals']],
|
|
66
|
+
// Service Months
|
|
67
|
+
create_month: [['months']],
|
|
68
|
+
update_months: [['months']],
|
|
69
|
+
delete_months: [['months']],
|
|
70
|
+
// Tasks
|
|
71
|
+
create_task: [['jobs']],
|
|
72
|
+
update_task: [['jobs']],
|
|
73
|
+
delete_task: [['jobs']],
|
|
74
|
+
// Scheduling
|
|
75
|
+
schedule_complete: [['routes'], ['jobs']],
|
|
76
|
+
// Location
|
|
77
|
+
location_update: [['teams']],
|
|
78
|
+
// Prepayments
|
|
79
|
+
update_prepayments: [['prepayments']],
|
|
80
|
+
// Chats
|
|
81
|
+
new_message: [['chats'], ['messages']],
|
|
82
|
+
};
|
|
6
83
|
export class AvroQueryClient {
|
|
7
84
|
constructor(config) {
|
|
8
85
|
this._authState = AuthState.UNKNOWN;
|
|
9
86
|
this.companyId = undefined;
|
|
10
87
|
this.company = undefined;
|
|
11
88
|
this.authStateListeners = [];
|
|
89
|
+
this._queryClient = null;
|
|
90
|
+
this._socketInvalidationCleanup = null;
|
|
12
91
|
this.config = {
|
|
13
92
|
baseUrl: config.baseUrl,
|
|
14
93
|
authManager: config.authManager,
|
|
@@ -70,6 +149,58 @@ export class AvroQueryClient {
|
|
|
70
149
|
off(eventName, callback) {
|
|
71
150
|
this.socket?.off(eventName, callback);
|
|
72
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* Wire up automatic query invalidation for socket events.
|
|
154
|
+
* Called once from AvroQueryClientProvider when the tanstack
|
|
155
|
+
* QueryClient is available. Also handles auto-joining the
|
|
156
|
+
* company room on connect so consumer apps don't have to.
|
|
157
|
+
*/
|
|
158
|
+
setupSocketInvalidation(queryClient) {
|
|
159
|
+
// Prevent double-setup
|
|
160
|
+
if (this._queryClient)
|
|
161
|
+
return;
|
|
162
|
+
this._queryClient = queryClient;
|
|
163
|
+
const handlers = [];
|
|
164
|
+
// Register invalidation listeners for every mapped event
|
|
165
|
+
for (const [event, queryKeys] of Object.entries(SOCKET_INVALIDATION_MAP)) {
|
|
166
|
+
const handler = () => {
|
|
167
|
+
for (const key of queryKeys) {
|
|
168
|
+
queryClient.invalidateQueries({ queryKey: key });
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
this.socket.on(event, handler);
|
|
172
|
+
handlers.push({ event, handler });
|
|
173
|
+
}
|
|
174
|
+
// Auto join/leave company room
|
|
175
|
+
const joinCompanyRoom = () => {
|
|
176
|
+
if (this.companyId) {
|
|
177
|
+
this.socket.emit('join_company', { company_id: this.companyId });
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
this.socket.on('connect', joinCompanyRoom);
|
|
181
|
+
handlers.push({ event: 'connect', handler: joinCompanyRoom });
|
|
182
|
+
// If already connected, join immediately
|
|
183
|
+
if (this.socket.connected && this.companyId) {
|
|
184
|
+
joinCompanyRoom();
|
|
185
|
+
}
|
|
186
|
+
this._socketInvalidationCleanup = () => {
|
|
187
|
+
for (const { event, handler } of handlers) {
|
|
188
|
+
this.socket.off(event, handler);
|
|
189
|
+
}
|
|
190
|
+
// Leave company room on teardown
|
|
191
|
+
if (this.socket.connected && this.companyId) {
|
|
192
|
+
this.socket.emit('leave_company', { company_id: this.companyId });
|
|
193
|
+
}
|
|
194
|
+
this._queryClient = null;
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Remove all invalidation listeners. Called on provider unmount.
|
|
199
|
+
*/
|
|
200
|
+
teardownSocketInvalidation() {
|
|
201
|
+
this._socketInvalidationCleanup?.();
|
|
202
|
+
this._socketInvalidationCleanup = null;
|
|
203
|
+
}
|
|
73
204
|
get({ path, cancelToken, headers, progressUpdateCallback }) {
|
|
74
205
|
return this._xhr('GET', path, null, cancelToken, headers, true, this.config.maxRetries, progressUpdateCallback);
|
|
75
206
|
}
|
|
@@ -22,7 +22,7 @@ AvroQueryClient.prototype.useGetBills = function (body) {
|
|
|
22
22
|
if (result.data) {
|
|
23
23
|
result.data.pages.forEach((data_page) => {
|
|
24
24
|
data_page.forEach((bill) => {
|
|
25
|
-
queryClient.setQueryData(['
|
|
25
|
+
queryClient.setQueryData(['bills', bill.id], bill);
|
|
26
26
|
});
|
|
27
27
|
});
|
|
28
28
|
}
|
|
@@ -30,7 +30,7 @@ AvroQueryClient.prototype.useGetBills = function (body) {
|
|
|
30
30
|
};
|
|
31
31
|
AvroQueryClient.prototype.useGetBill = function (billId) {
|
|
32
32
|
return useQuery({
|
|
33
|
-
queryKey: ['
|
|
33
|
+
queryKey: ['bills', billId],
|
|
34
34
|
queryFn: () => this.get({ path: `/bill/${billId}` }),
|
|
35
35
|
enabled: Boolean(billId),
|
|
36
36
|
});
|
|
@@ -72,7 +72,7 @@ AvroQueryClient.prototype.useCreateBill = function () {
|
|
|
72
72
|
queryClient.invalidateQueries({ queryKey: ['bills', this.companyId] });
|
|
73
73
|
queryClient.invalidateQueries({ queryKey: ['events', this.companyId] });
|
|
74
74
|
queryClient.invalidateQueries({ queryKey: ['months', this.companyId] });
|
|
75
|
-
queryClient.invalidateQueries({ queryKey: ['
|
|
75
|
+
queryClient.invalidateQueries({ queryKey: ['companies'] });
|
|
76
76
|
},
|
|
77
77
|
});
|
|
78
78
|
};
|
|
@@ -90,10 +90,10 @@ AvroQueryClient.prototype.useUpdateBill = function () {
|
|
|
90
90
|
},
|
|
91
91
|
onMutate: async ({ billId, updates }) => {
|
|
92
92
|
await queryClient.cancelQueries({ queryKey: ['bills'] });
|
|
93
|
-
await queryClient.cancelQueries({ queryKey: ['
|
|
93
|
+
await queryClient.cancelQueries({ queryKey: ['bills', billId] });
|
|
94
94
|
const previousBills = queryClient.getQueryData(['bills']);
|
|
95
|
-
const previousBill = queryClient.getQueryData(['
|
|
96
|
-
queryClient.setQueryData(['
|
|
95
|
+
const previousBill = queryClient.getQueryData(['bills', billId]);
|
|
96
|
+
queryClient.setQueryData(['bills', billId], (oldData) => oldData ? { ...oldData, ...updates } : undefined);
|
|
97
97
|
queryClient.setQueriesData({ queryKey: ['bills'] }, (oldData) => {
|
|
98
98
|
if (!oldData)
|
|
99
99
|
return oldData;
|
|
@@ -116,13 +116,12 @@ AvroQueryClient.prototype.useUpdateBill = function () {
|
|
|
116
116
|
queryClient.setQueryData(['bills'], context.previousBills);
|
|
117
117
|
}
|
|
118
118
|
if (context?.previousBill) {
|
|
119
|
-
queryClient.setQueryData(['
|
|
119
|
+
queryClient.setQueryData(['bills', billId], context.previousBill);
|
|
120
120
|
}
|
|
121
121
|
},
|
|
122
122
|
onSettled: (data, error, variables) => {
|
|
123
123
|
const { billId } = variables;
|
|
124
124
|
queryClient.invalidateQueries({ queryKey: ['bills'] });
|
|
125
|
-
queryClient.invalidateQueries({ queryKey: ['bill', billId] });
|
|
126
125
|
},
|
|
127
126
|
});
|
|
128
127
|
};
|
|
@@ -159,19 +158,19 @@ AvroQueryClient.prototype.useSyncBillToIntuit = function () {
|
|
|
159
158
|
});
|
|
160
159
|
},
|
|
161
160
|
onMutate: async ({ billId }) => {
|
|
162
|
-
await queryClient.cancelQueries({ queryKey: ['
|
|
163
|
-
const previousBill = queryClient.getQueryData(['
|
|
161
|
+
await queryClient.cancelQueries({ queryKey: ['bills', billId] });
|
|
162
|
+
const previousBill = queryClient.getQueryData(['bills', billId]);
|
|
164
163
|
return { previousBill };
|
|
165
164
|
},
|
|
166
165
|
onError: (_err, variables, context) => {
|
|
167
166
|
const { billId } = variables;
|
|
168
167
|
if (context?.previousBill) {
|
|
169
|
-
queryClient.setQueryData(['
|
|
168
|
+
queryClient.setQueryData(['bills', billId], context.previousBill);
|
|
170
169
|
}
|
|
171
170
|
},
|
|
172
171
|
onSettled: (_data, _error, variables) => {
|
|
173
172
|
const { billId } = variables;
|
|
174
|
-
queryClient.invalidateQueries({ queryKey: ['
|
|
173
|
+
queryClient.invalidateQueries({ queryKey: ['bills', billId] });
|
|
175
174
|
},
|
|
176
175
|
});
|
|
177
176
|
};
|
|
@@ -185,7 +184,7 @@ AvroQueryClient.prototype.useImportBillsFromIntuit = function () {
|
|
|
185
184
|
},
|
|
186
185
|
onSettled: () => {
|
|
187
186
|
queryClient.invalidateQueries({ queryKey: ['bills', this.companyId] });
|
|
188
|
-
queryClient.invalidateQueries({ queryKey: ['
|
|
187
|
+
queryClient.invalidateQueries({ queryKey: ['companies', 'current'] });
|
|
189
188
|
},
|
|
190
189
|
});
|
|
191
190
|
};
|
|
@@ -41,10 +41,10 @@ AvroQueryClient.prototype.useUpdateCatalogItem = function () {
|
|
|
41
41
|
},
|
|
42
42
|
onMutate: async ({ catalogItemId, data }) => {
|
|
43
43
|
await queryClient.cancelQueries({ queryKey: ['catalog_items'] });
|
|
44
|
-
await queryClient.cancelQueries({ queryKey: ['
|
|
44
|
+
await queryClient.cancelQueries({ queryKey: ['catalog_items', catalogItemId] });
|
|
45
45
|
const previousItems = queryClient.getQueryData(['catalog_items']);
|
|
46
|
-
const previousItem = queryClient.getQueryData(['
|
|
47
|
-
queryClient.setQueryData(['
|
|
46
|
+
const previousItem = queryClient.getQueryData(['catalog_items', catalogItemId]);
|
|
47
|
+
queryClient.setQueryData(['catalog_items', catalogItemId], (oldData) => oldData ? { ...oldData, ...data } : undefined);
|
|
48
48
|
queryClient.setQueriesData({ queryKey: ['catalog_items'] }, (oldData) => {
|
|
49
49
|
if (!oldData)
|
|
50
50
|
return oldData;
|
|
@@ -67,19 +67,18 @@ AvroQueryClient.prototype.useUpdateCatalogItem = function () {
|
|
|
67
67
|
queryClient.setQueryData(['catalog_items'], context.previousItems);
|
|
68
68
|
}
|
|
69
69
|
if (context?.previousItem) {
|
|
70
|
-
queryClient.setQueryData(['
|
|
70
|
+
queryClient.setQueryData(['catalog_items', catalogItemId], context.previousItem);
|
|
71
71
|
}
|
|
72
72
|
},
|
|
73
73
|
onSettled: (_data, _error, variables) => {
|
|
74
74
|
const { catalogItemId } = variables;
|
|
75
75
|
queryClient.invalidateQueries({ queryKey: ['catalog_items'] });
|
|
76
|
-
queryClient.invalidateQueries({ queryKey: ['catalog_item', catalogItemId] });
|
|
77
76
|
},
|
|
78
77
|
});
|
|
79
78
|
};
|
|
80
79
|
AvroQueryClient.prototype.useGetCatalogItem = function (catalogItemId) {
|
|
81
80
|
return useQuery({
|
|
82
|
-
queryKey: ['
|
|
81
|
+
queryKey: ['catalog_items', catalogItemId],
|
|
83
82
|
queryFn: () => this.get({ path: `/catalog_item/${catalogItemId}` }),
|
|
84
83
|
enabled: Boolean(catalogItemId),
|
|
85
84
|
});
|
|
@@ -22,7 +22,7 @@ AvroQueryClient.prototype.useGetChats = function (body) {
|
|
|
22
22
|
if (result.data) {
|
|
23
23
|
result.data.pages.forEach((data_page) => {
|
|
24
24
|
data_page.forEach((chat) => {
|
|
25
|
-
queryClient.setQueryData(['
|
|
25
|
+
queryClient.setQueryData(['chats', chat.id], chat);
|
|
26
26
|
});
|
|
27
27
|
});
|
|
28
28
|
}
|
|
@@ -30,7 +30,7 @@ AvroQueryClient.prototype.useGetChats = function (body) {
|
|
|
30
30
|
};
|
|
31
31
|
AvroQueryClient.prototype.useGetChat = function (chatId) {
|
|
32
32
|
return useQuery({
|
|
33
|
-
queryKey: ['
|
|
33
|
+
queryKey: ['chats', chatId],
|
|
34
34
|
queryFn: () => this.get({ path: `/chat/${chatId}` }),
|
|
35
35
|
enabled: Boolean(chatId),
|
|
36
36
|
});
|
|
@@ -19,14 +19,14 @@ AvroQueryClient.prototype.useGetCompanies = function (options = {}) {
|
|
|
19
19
|
};
|
|
20
20
|
AvroQueryClient.prototype.useGetCompany = function (companyId) {
|
|
21
21
|
return useQuery({
|
|
22
|
-
queryKey: ['
|
|
22
|
+
queryKey: ['companies', companyId],
|
|
23
23
|
queryFn: () => this.get({ path: `/company/${companyId}` }),
|
|
24
24
|
enabled: Boolean(companyId),
|
|
25
25
|
});
|
|
26
26
|
};
|
|
27
27
|
AvroQueryClient.prototype.useGetCurrentCompany = function () {
|
|
28
28
|
return useQuery({
|
|
29
|
-
queryKey: ['
|
|
29
|
+
queryKey: ['companies', 'current'],
|
|
30
30
|
queryFn: async () => {
|
|
31
31
|
if (!this.companyId) {
|
|
32
32
|
this.companyId = await this.config.authManager.getCompanyId();
|
|
@@ -72,11 +72,11 @@ AvroQueryClient.prototype.useUpdateCompany = function () {
|
|
|
72
72
|
});
|
|
73
73
|
},
|
|
74
74
|
onMutate: async ({ companyId, companyData }) => {
|
|
75
|
-
await queryClient.cancelQueries({ queryKey: ['
|
|
75
|
+
await queryClient.cancelQueries({ queryKey: ['companies', companyId] });
|
|
76
76
|
await queryClient.cancelQueries({ queryKey: ['/company/list'] });
|
|
77
|
-
const previousCompany = queryClient.getQueryData(['
|
|
77
|
+
const previousCompany = queryClient.getQueryData(['companies', companyId]);
|
|
78
78
|
const previousCompanyList = queryClient.getQueryData(['/company/list']);
|
|
79
|
-
queryClient.setQueryData(['
|
|
79
|
+
queryClient.setQueryData(['companies', companyId], (oldData) => oldData ? { ...oldData, ...companyData } : undefined);
|
|
80
80
|
queryClient.setQueryData(['/company/list'], (oldList) => {
|
|
81
81
|
if (!oldList)
|
|
82
82
|
return oldList;
|
|
@@ -87,7 +87,7 @@ AvroQueryClient.prototype.useUpdateCompany = function () {
|
|
|
87
87
|
onError: (_err, variables, context) => {
|
|
88
88
|
const { companyId } = variables;
|
|
89
89
|
if (context?.previousCompany) {
|
|
90
|
-
queryClient.setQueryData(['
|
|
90
|
+
queryClient.setQueryData(['companies', companyId], context.previousCompany);
|
|
91
91
|
}
|
|
92
92
|
if (context?.previousCompanyList) {
|
|
93
93
|
queryClient.setQueryData(['/company/list'], context.previousCompanyList);
|
|
@@ -95,7 +95,7 @@ AvroQueryClient.prototype.useUpdateCompany = function () {
|
|
|
95
95
|
},
|
|
96
96
|
onSettled: (_data, _error, variables) => {
|
|
97
97
|
const { companyId } = variables;
|
|
98
|
-
queryClient.invalidateQueries({ queryKey: ['
|
|
98
|
+
queryClient.invalidateQueries({ queryKey: ['companies', companyId] });
|
|
99
99
|
queryClient.invalidateQueries({ queryKey: ['/company/list'] });
|
|
100
100
|
},
|
|
101
101
|
});
|
|
@@ -114,9 +114,9 @@ AvroQueryClient.prototype.useCreateUserCompany = function () {
|
|
|
114
114
|
});
|
|
115
115
|
},
|
|
116
116
|
onMutate: async ({ user_id }) => {
|
|
117
|
-
await queryClient.cancelQueries({ queryKey: ['
|
|
118
|
-
const previousCompany = queryClient.getQueryData(['
|
|
119
|
-
queryClient.setQueryData(['
|
|
117
|
+
await queryClient.cancelQueries({ queryKey: ['companies', this.companyId] });
|
|
118
|
+
const previousCompany = queryClient.getQueryData(['companies', this.companyId]);
|
|
119
|
+
queryClient.setQueryData(['companies', this.companyId], (oldData) => {
|
|
120
120
|
if (!oldData)
|
|
121
121
|
return oldData;
|
|
122
122
|
return {
|
|
@@ -128,13 +128,13 @@ AvroQueryClient.prototype.useCreateUserCompany = function () {
|
|
|
128
128
|
},
|
|
129
129
|
onError: (err, variables, context) => {
|
|
130
130
|
if (context?.previousCompany) {
|
|
131
|
-
queryClient.setQueryData(['
|
|
131
|
+
queryClient.setQueryData(['companies', this.companyId], context.previousCompany);
|
|
132
132
|
}
|
|
133
133
|
},
|
|
134
134
|
onSettled: (_data, _error, variables) => {
|
|
135
|
-
queryClient.invalidateQueries({ queryKey: ['
|
|
135
|
+
queryClient.invalidateQueries({ queryKey: ['companies', this.companyId] });
|
|
136
136
|
queryClient.invalidateQueries({ queryKey: ['/company/list'] });
|
|
137
|
-
queryClient.invalidateQueries({ queryKey: ['
|
|
137
|
+
queryClient.invalidateQueries({ queryKey: ['companies', 'current'] });
|
|
138
138
|
},
|
|
139
139
|
});
|
|
140
140
|
};
|
|
@@ -147,9 +147,9 @@ AvroQueryClient.prototype.useRemoveUserCompany = function () {
|
|
|
147
147
|
});
|
|
148
148
|
},
|
|
149
149
|
onMutate: async ({ userId }) => {
|
|
150
|
-
await queryClient.cancelQueries({ queryKey: ['
|
|
151
|
-
const previousCompany = queryClient.getQueryData(['
|
|
152
|
-
queryClient.setQueryData(['
|
|
150
|
+
await queryClient.cancelQueries({ queryKey: ['companies', this.companyId] });
|
|
151
|
+
const previousCompany = queryClient.getQueryData(['companies', this.companyId]);
|
|
152
|
+
queryClient.setQueryData(['companies', this.companyId], (oldData) => {
|
|
153
153
|
if (!oldData)
|
|
154
154
|
return oldData;
|
|
155
155
|
return {
|
|
@@ -161,11 +161,11 @@ AvroQueryClient.prototype.useRemoveUserCompany = function () {
|
|
|
161
161
|
},
|
|
162
162
|
onError: (err, variables, context) => {
|
|
163
163
|
if (context?.previousCompany) {
|
|
164
|
-
queryClient.setQueryData(['
|
|
164
|
+
queryClient.setQueryData(['companies', this.companyId], context.previousCompany);
|
|
165
165
|
}
|
|
166
166
|
},
|
|
167
167
|
onSettled: (_data, _error, variables) => {
|
|
168
|
-
queryClient.invalidateQueries({ queryKey: ['
|
|
168
|
+
queryClient.invalidateQueries({ queryKey: ['companies', this.companyId] });
|
|
169
169
|
},
|
|
170
170
|
});
|
|
171
171
|
};
|
|
@@ -179,7 +179,7 @@ AvroQueryClient.prototype.useDeleteCompany = function () {
|
|
|
179
179
|
},
|
|
180
180
|
onMutate: async ({ companyId }) => {
|
|
181
181
|
await queryClient.cancelQueries({ queryKey: ['/company/list'] });
|
|
182
|
-
await queryClient.cancelQueries({ queryKey: ['
|
|
182
|
+
await queryClient.cancelQueries({ queryKey: ['companies', companyId] });
|
|
183
183
|
const previousCompanyList = queryClient.getQueryData(['/company/list']);
|
|
184
184
|
queryClient.setQueryData(['/company/list'], (oldList) => {
|
|
185
185
|
if (!oldList)
|
|
@@ -195,7 +195,7 @@ AvroQueryClient.prototype.useDeleteCompany = function () {
|
|
|
195
195
|
},
|
|
196
196
|
onSettled: (_data, _error, companyId) => {
|
|
197
197
|
queryClient.invalidateQueries({ queryKey: ['/company/list'] });
|
|
198
|
-
queryClient.invalidateQueries({ queryKey: ['
|
|
198
|
+
queryClient.invalidateQueries({ queryKey: ['companies', companyId] });
|
|
199
199
|
},
|
|
200
200
|
});
|
|
201
201
|
};
|
|
@@ -29,7 +29,7 @@ AvroQueryClient.prototype.useGetEvents = function (body) {
|
|
|
29
29
|
if (result.data) {
|
|
30
30
|
result.data.pages.forEach((data_page) => {
|
|
31
31
|
data_page.forEach((event) => {
|
|
32
|
-
queryClient.setQueryData(['
|
|
32
|
+
queryClient.setQueryData(['events', event.id], event);
|
|
33
33
|
});
|
|
34
34
|
});
|
|
35
35
|
}
|
|
@@ -37,7 +37,7 @@ AvroQueryClient.prototype.useGetEvents = function (body) {
|
|
|
37
37
|
};
|
|
38
38
|
AvroQueryClient.prototype.useGetEvent = function (eventId) {
|
|
39
39
|
return useQuery({
|
|
40
|
-
queryKey: ['
|
|
40
|
+
queryKey: ['events', eventId],
|
|
41
41
|
queryFn: () => this.get({ path: `/event/${eventId}` }).then((event) => new _Event(event)),
|
|
42
42
|
enabled: Boolean(eventId),
|
|
43
43
|
});
|
|
@@ -55,7 +55,7 @@ AvroQueryClient.prototype.useCreateEvent = function () {
|
|
|
55
55
|
onMutate: async ({ eventData }) => {
|
|
56
56
|
await queryClient.cancelQueries({ queryKey: ['events'] });
|
|
57
57
|
const previousEvents = queryClient.getQueryData(['events']);
|
|
58
|
-
const previousJob = queryClient.getQueryData(['
|
|
58
|
+
const previousJob = queryClient.getQueryData(['jobs', eventData.job_id]);
|
|
59
59
|
const previousJobs = queryClient.getQueryData(['jobs']);
|
|
60
60
|
const optimisticEvent = new _Event({
|
|
61
61
|
...eventData,
|
|
@@ -79,7 +79,7 @@ AvroQueryClient.prototype.useCreateEvent = function () {
|
|
|
79
79
|
return task;
|
|
80
80
|
});
|
|
81
81
|
const updatedJobs = previousJobs?.map((job) => job.id === updatedJob.id ? updatedJob : job);
|
|
82
|
-
queryClient.setQueryData(['
|
|
82
|
+
queryClient.setQueryData(['jobs', previousJob.id], updatedJob);
|
|
83
83
|
queryClient.setQueryData(['jobs'], updatedJobs);
|
|
84
84
|
}
|
|
85
85
|
queryClient.setQueryData(['events'], (oldData) => {
|
|
@@ -113,7 +113,7 @@ AvroQueryClient.prototype.useCreateEvent = function () {
|
|
|
113
113
|
queryClient.setQueryData(['events'], context.previousEvents);
|
|
114
114
|
}
|
|
115
115
|
if (context?.previousJob) {
|
|
116
|
-
queryClient.setQueryData(['
|
|
116
|
+
queryClient.setQueryData(['jobs', context.previousJob.id], context.previousJob);
|
|
117
117
|
}
|
|
118
118
|
if (context?.previousJobs) {
|
|
119
119
|
queryClient.setQueryData(['jobs'], context.previousJobs);
|
|
@@ -121,9 +121,8 @@ AvroQueryClient.prototype.useCreateEvent = function () {
|
|
|
121
121
|
},
|
|
122
122
|
onSettled: () => {
|
|
123
123
|
queryClient.invalidateQueries({ queryKey: ['events'] });
|
|
124
|
-
queryClient.invalidateQueries({ queryKey: ['job'] });
|
|
125
124
|
queryClient.invalidateQueries({ queryKey: ['jobs'] });
|
|
126
|
-
queryClient.invalidateQueries({ queryKey: ['
|
|
125
|
+
queryClient.invalidateQueries({ queryKey: ['companies'] });
|
|
127
126
|
},
|
|
128
127
|
});
|
|
129
128
|
};
|
|
@@ -138,11 +137,11 @@ AvroQueryClient.prototype.useUpdateEvent = function () {
|
|
|
138
137
|
});
|
|
139
138
|
},
|
|
140
139
|
onMutate: async ({ eventId, updates }) => {
|
|
141
|
-
await queryClient.cancelQueries({ queryKey: ['
|
|
140
|
+
await queryClient.cancelQueries({ queryKey: ['events', eventId] });
|
|
142
141
|
await queryClient.cancelQueries({ queryKey: ['events'] });
|
|
143
|
-
const previousEvent = queryClient.getQueryData(['
|
|
142
|
+
const previousEvent = queryClient.getQueryData(['events', eventId]);
|
|
144
143
|
const previousEvents = queryClient.getQueryData(['events']);
|
|
145
|
-
const previousJob = queryClient.getQueryData(['
|
|
144
|
+
const previousJob = queryClient.getQueryData(['jobs', previousEvent?.job_id]);
|
|
146
145
|
const previousJobs = queryClient.getQueryData(['jobs']);
|
|
147
146
|
if (previousJob) {
|
|
148
147
|
const updatedJob = {
|
|
@@ -162,10 +161,10 @@ AvroQueryClient.prototype.useUpdateEvent = function () {
|
|
|
162
161
|
return task;
|
|
163
162
|
});
|
|
164
163
|
const updatedJobs = previousJobs?.map((job) => job.id === updatedJob.id ? updatedJob : job);
|
|
165
|
-
queryClient.setQueryData(['
|
|
164
|
+
queryClient.setQueryData(['jobs', previousJob.id], updatedJob);
|
|
166
165
|
queryClient.setQueryData(['jobs'], updatedJobs);
|
|
167
166
|
}
|
|
168
|
-
queryClient.setQueryData(['
|
|
167
|
+
queryClient.setQueryData(['events', eventId], (oldData) => oldData ? { ...oldData, ...updates } : undefined);
|
|
169
168
|
queryClient.setQueriesData({ queryKey: ['events'] }, (oldData) => {
|
|
170
169
|
if (!oldData)
|
|
171
170
|
return oldData;
|
|
@@ -183,13 +182,13 @@ AvroQueryClient.prototype.useUpdateEvent = function () {
|
|
|
183
182
|
onError: (_err, variables, context) => {
|
|
184
183
|
const { eventId } = variables;
|
|
185
184
|
if (context?.previousEvent) {
|
|
186
|
-
queryClient.setQueryData(['
|
|
185
|
+
queryClient.setQueryData(['events', eventId], context.previousEvent);
|
|
187
186
|
}
|
|
188
187
|
if (context?.previousEvents) {
|
|
189
188
|
queryClient.setQueryData(['events'], context.previousEvents);
|
|
190
189
|
}
|
|
191
190
|
if (context?.previousJob) {
|
|
192
|
-
queryClient.setQueryData(['
|
|
191
|
+
queryClient.setQueryData(['jobs', context.previousJob.id], context.previousJob);
|
|
193
192
|
}
|
|
194
193
|
if (context?.previousJobs) {
|
|
195
194
|
queryClient.setQueryData(['jobs'], context.previousJobs);
|
|
@@ -197,9 +196,7 @@ AvroQueryClient.prototype.useUpdateEvent = function () {
|
|
|
197
196
|
},
|
|
198
197
|
onSettled: (_data, _error, variables) => {
|
|
199
198
|
const { eventId } = variables;
|
|
200
|
-
queryClient.invalidateQueries({ queryKey: ['event', eventId] });
|
|
201
199
|
queryClient.invalidateQueries({ queryKey: ['events'] });
|
|
202
|
-
queryClient.invalidateQueries({ queryKey: ['job'] });
|
|
203
200
|
queryClient.invalidateQueries({ queryKey: ['jobs'] });
|
|
204
201
|
},
|
|
205
202
|
});
|
|
@@ -221,13 +218,13 @@ AvroQueryClient.prototype.useUpdateEvents = function () {
|
|
|
221
218
|
},
|
|
222
219
|
onMutate: async ({ events, action }) => {
|
|
223
220
|
await queryClient.cancelQueries({ queryKey: ['events'] });
|
|
224
|
-
await queryClient.cancelQueries({ queryKey: ['
|
|
221
|
+
await queryClient.cancelQueries({ queryKey: ['events'] });
|
|
225
222
|
const previousEvents = queryClient.getQueryData(['events']);
|
|
226
|
-
const previousEventObjs = events.map(event => queryClient.getQueryData(['
|
|
223
|
+
const previousEventObjs = events.map(event => queryClient.getQueryData(['events', event.id]));
|
|
227
224
|
const eventIds = events.map(event => event.id);
|
|
228
225
|
// Optimistically update individual event cache
|
|
229
226
|
eventIds.forEach((eventId, idx) => {
|
|
230
|
-
queryClient.setQueryData(['
|
|
227
|
+
queryClient.setQueryData(['events', eventId], (oldData) => {
|
|
231
228
|
return oldData
|
|
232
229
|
? { ...oldData, billed: true, status: action === "billed" ? LineItemStatus.EXTERNALLY_BILLED : LineItemStatus.EXTERNALLY_PAID }
|
|
233
230
|
: oldData;
|
|
@@ -258,13 +255,12 @@ AvroQueryClient.prototype.useUpdateEvents = function () {
|
|
|
258
255
|
}
|
|
259
256
|
if (context?.previousEventObjs) {
|
|
260
257
|
context.previousEventObjs.forEach((eventObj) => {
|
|
261
|
-
queryClient.setQueryData(['
|
|
258
|
+
queryClient.setQueryData(['events', eventObj.id], eventObj);
|
|
262
259
|
});
|
|
263
260
|
}
|
|
264
261
|
},
|
|
265
262
|
onSettled: () => {
|
|
266
263
|
queryClient.invalidateQueries({ queryKey: ['events'] });
|
|
267
|
-
queryClient.invalidateQueries({ queryKey: ['event'] });
|
|
268
264
|
},
|
|
269
265
|
});
|
|
270
266
|
};
|
|
@@ -279,10 +275,10 @@ AvroQueryClient.prototype.useDeleteEvent = function () {
|
|
|
279
275
|
},
|
|
280
276
|
onMutate: async ({ eventId }) => {
|
|
281
277
|
await queryClient.cancelQueries({ queryKey: ['events'] });
|
|
282
|
-
await queryClient.cancelQueries({ queryKey: ['
|
|
278
|
+
await queryClient.cancelQueries({ queryKey: ['events', eventId] });
|
|
283
279
|
const previousEvents = queryClient.getQueryData(['events']);
|
|
284
|
-
const previousEvent = queryClient.getQueryData(['
|
|
285
|
-
queryClient.setQueryData(['
|
|
280
|
+
const previousEvent = queryClient.getQueryData(['events', eventId]);
|
|
281
|
+
queryClient.setQueryData(['events', eventId], undefined);
|
|
286
282
|
queryClient.setQueriesData({ queryKey: ['events'] }, (oldData) => {
|
|
287
283
|
if (!oldData)
|
|
288
284
|
return oldData;
|
|
@@ -303,13 +299,12 @@ AvroQueryClient.prototype.useDeleteEvent = function () {
|
|
|
303
299
|
queryClient.setQueryData(['events'], context.previousEvents);
|
|
304
300
|
}
|
|
305
301
|
if (context?.previousEvent) {
|
|
306
|
-
queryClient.setQueryData(['
|
|
302
|
+
queryClient.setQueryData(['events', eventId], context.previousEvent);
|
|
307
303
|
}
|
|
308
304
|
},
|
|
309
305
|
onSettled: (_data, _error, variables) => {
|
|
310
306
|
const { eventId } = variables;
|
|
311
307
|
queryClient.invalidateQueries({ queryKey: ['events'] });
|
|
312
|
-
queryClient.invalidateQueries({ queryKey: ['event', eventId] });
|
|
313
308
|
},
|
|
314
309
|
});
|
|
315
310
|
};
|
|
@@ -37,7 +37,7 @@ AvroQueryClient.prototype.useCreateGroup = function () {
|
|
|
37
37
|
});
|
|
38
38
|
},
|
|
39
39
|
onSettled: () => {
|
|
40
|
-
queryClient.invalidateQueries({ queryKey: ['
|
|
40
|
+
queryClient.invalidateQueries({ queryKey: ['companies'] });
|
|
41
41
|
queryClient.invalidateQueries({ queryKey: ['groups'] });
|
|
42
42
|
},
|
|
43
43
|
});
|
|
@@ -54,10 +54,10 @@ AvroQueryClient.prototype.useUpdateGroup = function () {
|
|
|
54
54
|
},
|
|
55
55
|
onMutate: async ({ groupId, groupData }) => {
|
|
56
56
|
await queryClient.cancelQueries({ queryKey: ['groups'] });
|
|
57
|
-
await queryClient.cancelQueries({ queryKey: ['
|
|
57
|
+
await queryClient.cancelQueries({ queryKey: ['groups', groupId] });
|
|
58
58
|
const previousGroups = queryClient.getQueryData(['groups']);
|
|
59
|
-
const previousGroup = queryClient.getQueryData(['
|
|
60
|
-
queryClient.setQueryData(['
|
|
59
|
+
const previousGroup = queryClient.getQueryData(['groups', groupId]);
|
|
60
|
+
queryClient.setQueryData(['groups', groupId], (oldData) => {
|
|
61
61
|
if (!oldData)
|
|
62
62
|
return oldData;
|
|
63
63
|
return { ...oldData, ...groupData };
|
|
@@ -82,14 +82,13 @@ AvroQueryClient.prototype.useUpdateGroup = function () {
|
|
|
82
82
|
queryClient.setQueryData(['groups'], context.previousGroups);
|
|
83
83
|
}
|
|
84
84
|
if (context?.previousGroup) {
|
|
85
|
-
queryClient.setQueryData(['
|
|
85
|
+
queryClient.setQueryData(['groups', groupId], context.previousGroup);
|
|
86
86
|
}
|
|
87
87
|
},
|
|
88
88
|
onSettled: (_data, _error, variables) => {
|
|
89
89
|
const { groupId } = variables;
|
|
90
90
|
queryClient.invalidateQueries({ queryKey: ['groups'] });
|
|
91
|
-
queryClient.invalidateQueries({ queryKey: ['
|
|
92
|
-
queryClient.invalidateQueries({ queryKey: ['company'] });
|
|
91
|
+
queryClient.invalidateQueries({ queryKey: ['companies'] });
|
|
93
92
|
},
|
|
94
93
|
});
|
|
95
94
|
};
|
|
@@ -103,10 +102,10 @@ AvroQueryClient.prototype.useDeleteGroup = function () {
|
|
|
103
102
|
},
|
|
104
103
|
onMutate: async ({ groupId }) => {
|
|
105
104
|
await queryClient.cancelQueries({ queryKey: ['groups'] });
|
|
106
|
-
await queryClient.cancelQueries({ queryKey: ['
|
|
105
|
+
await queryClient.cancelQueries({ queryKey: ['groups', groupId] });
|
|
107
106
|
const previousGroups = queryClient.getQueryData(['groups']);
|
|
108
|
-
const previousGroup = queryClient.getQueryData(['
|
|
109
|
-
queryClient.setQueryData(['
|
|
107
|
+
const previousGroup = queryClient.getQueryData(['groups', groupId]);
|
|
108
|
+
queryClient.setQueryData(['groups', groupId], undefined);
|
|
110
109
|
queryClient.setQueriesData({ queryKey: ['groups'] }, (oldData) => {
|
|
111
110
|
if (!oldData)
|
|
112
111
|
return oldData;
|
|
@@ -127,14 +126,13 @@ AvroQueryClient.prototype.useDeleteGroup = function () {
|
|
|
127
126
|
queryClient.setQueryData(['groups'], context.previousGroups);
|
|
128
127
|
}
|
|
129
128
|
if (context?.previousGroup) {
|
|
130
|
-
queryClient.setQueryData(['
|
|
129
|
+
queryClient.setQueryData(['groups', groupId], context.previousGroup);
|
|
131
130
|
}
|
|
132
131
|
},
|
|
133
132
|
onSettled: (_data, _error, variables) => {
|
|
134
133
|
const { groupId } = variables;
|
|
135
134
|
queryClient.invalidateQueries({ queryKey: ['groups'] });
|
|
136
|
-
queryClient.invalidateQueries({ queryKey: ['
|
|
137
|
-
queryClient.invalidateQueries({ queryKey: ['company'] });
|
|
135
|
+
queryClient.invalidateQueries({ queryKey: ['companies'] });
|
|
138
136
|
},
|
|
139
137
|
});
|
|
140
138
|
};
|
|
@@ -34,7 +34,7 @@ AvroQueryClient.prototype.useGetJobs = function (params) {
|
|
|
34
34
|
job.last_completed_event = job.tasks.reduce((latest, task) => {
|
|
35
35
|
return task.last_completed_event && (!latest || task.last_completed_event.time_started > latest.time_started) ? task.last_completed_event : latest;
|
|
36
36
|
}, job.last_completed_event);
|
|
37
|
-
queryClient.setQueryData(['
|
|
37
|
+
queryClient.setQueryData(['jobs', job.id], job);
|
|
38
38
|
});
|
|
39
39
|
return jobs;
|
|
40
40
|
},
|
|
@@ -63,7 +63,7 @@ AvroQueryClient.prototype.useGetInfiniteJobs = function (body, onProgress) {
|
|
|
63
63
|
if (result.data) {
|
|
64
64
|
result.data.pages.forEach((data_page) => {
|
|
65
65
|
data_page.forEach((job) => {
|
|
66
|
-
queryClient.setQueryData(['
|
|
66
|
+
queryClient.setQueryData(['jobs', job.id], job);
|
|
67
67
|
});
|
|
68
68
|
});
|
|
69
69
|
}
|
|
@@ -71,7 +71,7 @@ AvroQueryClient.prototype.useGetInfiniteJobs = function (body, onProgress) {
|
|
|
71
71
|
};
|
|
72
72
|
AvroQueryClient.prototype.useGetJob = function (jobId) {
|
|
73
73
|
return useQuery({
|
|
74
|
-
queryKey: ['
|
|
74
|
+
queryKey: ['jobs', jobId],
|
|
75
75
|
queryFn: async () => {
|
|
76
76
|
const job = await this.get({
|
|
77
77
|
path: `/job/${jobId}`
|
|
@@ -94,8 +94,7 @@ AvroQueryClient.prototype.useCreateJob = function () {
|
|
|
94
94
|
onSettled: (data) => {
|
|
95
95
|
const { id: jobId } = data ?? {};
|
|
96
96
|
queryClient.invalidateQueries({ queryKey: ['jobs'] });
|
|
97
|
-
queryClient.invalidateQueries({ queryKey: ['
|
|
98
|
-
queryClient.invalidateQueries({ queryKey: ['company'] });
|
|
97
|
+
queryClient.invalidateQueries({ queryKey: ['companies'] });
|
|
99
98
|
},
|
|
100
99
|
});
|
|
101
100
|
};
|
|
@@ -111,7 +110,6 @@ AvroQueryClient.prototype.useManageJobs = function () {
|
|
|
111
110
|
},
|
|
112
111
|
onSettled: (_data, _error, _variables) => {
|
|
113
112
|
queryClient.invalidateQueries({ queryKey: ['jobs'] });
|
|
114
|
-
queryClient.invalidateQueries({ queryKey: ['job'] });
|
|
115
113
|
},
|
|
116
114
|
});
|
|
117
115
|
};
|
|
@@ -128,7 +126,6 @@ AvroQueryClient.prototype.useUpdateJob = function () {
|
|
|
128
126
|
onSettled: (data, error, variables) => {
|
|
129
127
|
const { jobId } = variables;
|
|
130
128
|
queryClient.invalidateQueries({ queryKey: ['jobs'] });
|
|
131
|
-
queryClient.invalidateQueries({ queryKey: ['job', jobId] });
|
|
132
129
|
},
|
|
133
130
|
});
|
|
134
131
|
};
|
|
@@ -145,8 +142,6 @@ AvroQueryClient.prototype.useDeleteJobs = function () {
|
|
|
145
142
|
onSettled: (_data, _error, _variables) => {
|
|
146
143
|
queryClient.invalidateQueries({ queryKey: ['jobs'] });
|
|
147
144
|
queryClient.invalidateQueries({ queryKey: ['routes'] });
|
|
148
|
-
queryClient.invalidateQueries({ queryKey: ['job'] });
|
|
149
|
-
queryClient.invalidateQueries({ queryKey: ['route'] });
|
|
150
145
|
},
|
|
151
146
|
});
|
|
152
147
|
};
|
|
@@ -165,8 +160,6 @@ AvroQueryClient.prototype.useDeleteJob = function () {
|
|
|
165
160
|
const { jobId } = variables;
|
|
166
161
|
queryClient.invalidateQueries({ queryKey: ['jobs'] });
|
|
167
162
|
queryClient.invalidateQueries({ queryKey: ['routes'] });
|
|
168
|
-
queryClient.invalidateQueries({ queryKey: ['job', jobId] });
|
|
169
|
-
queryClient.invalidateQueries({ queryKey: ['route'] });
|
|
170
163
|
},
|
|
171
164
|
});
|
|
172
165
|
};
|
|
@@ -37,7 +37,7 @@ AvroQueryClient.prototype.useCreateLabel = function () {
|
|
|
37
37
|
});
|
|
38
38
|
},
|
|
39
39
|
onSettled: () => {
|
|
40
|
-
queryClient.invalidateQueries({ queryKey: ['
|
|
40
|
+
queryClient.invalidateQueries({ queryKey: ['companies'] });
|
|
41
41
|
queryClient.invalidateQueries({ queryKey: ['labels'] });
|
|
42
42
|
},
|
|
43
43
|
});
|
|
@@ -54,10 +54,10 @@ AvroQueryClient.prototype.useUpdateLabel = function () {
|
|
|
54
54
|
},
|
|
55
55
|
onMutate: async ({ labelId, labelData }) => {
|
|
56
56
|
await queryClient.cancelQueries({ queryKey: ['labels'] });
|
|
57
|
-
await queryClient.cancelQueries({ queryKey: ['
|
|
57
|
+
await queryClient.cancelQueries({ queryKey: ['labels', labelId] });
|
|
58
58
|
const previousLabels = queryClient.getQueryData(['labels']);
|
|
59
|
-
const previousLabel = queryClient.getQueryData(['
|
|
60
|
-
queryClient.setQueryData(['
|
|
59
|
+
const previousLabel = queryClient.getQueryData(['labels', labelId]);
|
|
60
|
+
queryClient.setQueryData(['labels', labelId], (oldData) => {
|
|
61
61
|
if (!oldData)
|
|
62
62
|
return oldData;
|
|
63
63
|
return { ...oldData, ...labelData };
|
|
@@ -82,14 +82,13 @@ AvroQueryClient.prototype.useUpdateLabel = function () {
|
|
|
82
82
|
queryClient.setQueryData(['labels'], context.previousLabels);
|
|
83
83
|
}
|
|
84
84
|
if (context?.previousLabel) {
|
|
85
|
-
queryClient.setQueryData(['
|
|
85
|
+
queryClient.setQueryData(['labels', labelId], context.previousLabel);
|
|
86
86
|
}
|
|
87
87
|
},
|
|
88
88
|
onSettled: (_data, _error, variables) => {
|
|
89
89
|
const { labelId } = variables;
|
|
90
90
|
queryClient.invalidateQueries({ queryKey: ['labels'] });
|
|
91
|
-
queryClient.invalidateQueries({ queryKey: ['
|
|
92
|
-
queryClient.invalidateQueries({ queryKey: ['company'] });
|
|
91
|
+
queryClient.invalidateQueries({ queryKey: ['companies'] });
|
|
93
92
|
},
|
|
94
93
|
});
|
|
95
94
|
};
|
|
@@ -101,10 +100,10 @@ AvroQueryClient.prototype.useDeleteLabel = function () {
|
|
|
101
100
|
},
|
|
102
101
|
onMutate: async ({ labelId }) => {
|
|
103
102
|
await queryClient.cancelQueries({ queryKey: ['labels'] });
|
|
104
|
-
await queryClient.cancelQueries({ queryKey: ['
|
|
103
|
+
await queryClient.cancelQueries({ queryKey: ['labels', labelId] });
|
|
105
104
|
const previousLabels = queryClient.getQueryData(['labels']);
|
|
106
|
-
const previousLabel = queryClient.getQueryData(['
|
|
107
|
-
queryClient.setQueryData(['
|
|
105
|
+
const previousLabel = queryClient.getQueryData(['labels', labelId]);
|
|
106
|
+
queryClient.setQueryData(['labels', labelId], undefined);
|
|
108
107
|
queryClient.setQueriesData({ queryKey: ['labels'] }, (oldData) => {
|
|
109
108
|
if (!oldData)
|
|
110
109
|
return oldData;
|
|
@@ -125,14 +124,13 @@ AvroQueryClient.prototype.useDeleteLabel = function () {
|
|
|
125
124
|
queryClient.setQueryData(['labels'], context.previousLabels);
|
|
126
125
|
}
|
|
127
126
|
if (context?.previousLabel) {
|
|
128
|
-
queryClient.setQueryData(['
|
|
127
|
+
queryClient.setQueryData(['labels', labelId], context.previousLabel);
|
|
129
128
|
}
|
|
130
129
|
},
|
|
131
130
|
onSettled: (_data, _error, variables) => {
|
|
132
131
|
const { labelId } = variables;
|
|
133
132
|
queryClient.invalidateQueries({ queryKey: ['labels'] });
|
|
134
|
-
queryClient.invalidateQueries({ queryKey: ['
|
|
135
|
-
queryClient.invalidateQueries({ queryKey: ['company'] });
|
|
133
|
+
queryClient.invalidateQueries({ queryKey: ['companies'] });
|
|
136
134
|
},
|
|
137
135
|
});
|
|
138
136
|
};
|
|
@@ -53,7 +53,7 @@ AvroQueryClient.prototype.useUpdateMonths = function () {
|
|
|
53
53
|
},
|
|
54
54
|
onMutate: async ({ months, action }) => {
|
|
55
55
|
await queryClient.cancelQueries({ queryKey: ['months'] });
|
|
56
|
-
await queryClient.cancelQueries({ queryKey: ['
|
|
56
|
+
await queryClient.cancelQueries({ queryKey: ['months'] });
|
|
57
57
|
const previousMonths = queryClient.getQueryData(['months']);
|
|
58
58
|
const previousMonthObjs = months.map(month => queryClient.getQueryData(['month', month.id]));
|
|
59
59
|
const monthIds = months.map(month => month.id);
|
|
@@ -92,8 +92,7 @@ AvroQueryClient.prototype.useUpdateMonths = function () {
|
|
|
92
92
|
},
|
|
93
93
|
onSettled: () => {
|
|
94
94
|
queryClient.invalidateQueries({ queryKey: ['months'] });
|
|
95
|
-
queryClient.invalidateQueries({ queryKey: ['
|
|
96
|
-
queryClient.invalidateQueries({ queryKey: ['company'] });
|
|
95
|
+
queryClient.invalidateQueries({ queryKey: ['companies'] });
|
|
97
96
|
},
|
|
98
97
|
});
|
|
99
98
|
};
|
|
@@ -53,7 +53,7 @@ AvroQueryClient.prototype.useUpdatePrepayments = function () {
|
|
|
53
53
|
},
|
|
54
54
|
onMutate: async ({ prepayments, action }) => {
|
|
55
55
|
await queryClient.cancelQueries({ queryKey: ['prepayments'] });
|
|
56
|
-
await queryClient.cancelQueries({ queryKey: ['
|
|
56
|
+
await queryClient.cancelQueries({ queryKey: ['prepayments'] });
|
|
57
57
|
const previousPrepayments = queryClient.getQueryData(['prepayments']);
|
|
58
58
|
const previousPrepaymentObjs = prepayments.map(prepayment => queryClient.getQueryData(['prepayment', prepayment.id]));
|
|
59
59
|
const prepaymentIds = prepayments.map(prepayment => prepayment.id);
|
|
@@ -92,8 +92,7 @@ AvroQueryClient.prototype.useUpdatePrepayments = function () {
|
|
|
92
92
|
},
|
|
93
93
|
onSettled: () => {
|
|
94
94
|
queryClient.invalidateQueries({ queryKey: ['prepayments'] });
|
|
95
|
-
queryClient.invalidateQueries({ queryKey: ['
|
|
96
|
-
queryClient.invalidateQueries({ queryKey: ['company'] });
|
|
95
|
+
queryClient.invalidateQueries({ queryKey: ['companies'] });
|
|
97
96
|
},
|
|
98
97
|
});
|
|
99
98
|
};
|
|
@@ -25,7 +25,7 @@ AvroQueryClient.prototype.useReviewProposal = function (proposal_id) {
|
|
|
25
25
|
};
|
|
26
26
|
AvroQueryClient.prototype.useGetProposal = function (proposal_id) {
|
|
27
27
|
return useQuery({
|
|
28
|
-
queryKey: ['
|
|
28
|
+
queryKey: ['proposals', proposal_id],
|
|
29
29
|
queryFn: async () => {
|
|
30
30
|
const proposal = await this.get({ path: `/proposal/${proposal_id}` });
|
|
31
31
|
if (proposal && Array.isArray(proposal.tasks)) {
|
|
@@ -31,7 +31,7 @@ AvroQueryClient.prototype.useGetRoutes = function (body, total, onProgress) {
|
|
|
31
31
|
AvroQueryClient.prototype.useGetRoute = function (routeId) {
|
|
32
32
|
const queryClient = this.getQueryClient();
|
|
33
33
|
return useQuery({
|
|
34
|
-
queryKey: ['
|
|
34
|
+
queryKey: ['routes', routeId],
|
|
35
35
|
queryFn: async () => {
|
|
36
36
|
const route = await this.get({ path: `/route/${routeId}` });
|
|
37
37
|
return new Route(route);
|
|
@@ -79,8 +79,7 @@ AvroQueryClient.prototype.useCreateRoute = function () {
|
|
|
79
79
|
onSettled: (_data, _error, _variables) => {
|
|
80
80
|
queryClient.invalidateQueries({ queryKey: ['routes'] });
|
|
81
81
|
queryClient.invalidateQueries({ queryKey: ['jobs'] });
|
|
82
|
-
queryClient.invalidateQueries({ queryKey: ['
|
|
83
|
-
queryClient.invalidateQueries({ queryKey: ['company'] });
|
|
82
|
+
queryClient.invalidateQueries({ queryKey: ['companies'] });
|
|
84
83
|
},
|
|
85
84
|
});
|
|
86
85
|
};
|
|
@@ -106,11 +105,11 @@ AvroQueryClient.prototype.useUpdateRoute = function () {
|
|
|
106
105
|
});
|
|
107
106
|
},
|
|
108
107
|
onMutate: async ({ routeId, updates }) => {
|
|
109
|
-
await queryClient.cancelQueries({ queryKey: ['
|
|
108
|
+
await queryClient.cancelQueries({ queryKey: ['routes', routeId] });
|
|
110
109
|
await queryClient.cancelQueries({ queryKey: ['routes'] });
|
|
111
|
-
const previousRoute = queryClient.getQueryData(['
|
|
110
|
+
const previousRoute = queryClient.getQueryData(['routes', routeId]);
|
|
112
111
|
const previousRoutes = queryClient.getQueryData(['routes']);
|
|
113
|
-
queryClient.setQueryData(['
|
|
112
|
+
queryClient.setQueryData(['routes', routeId], (oldData) => oldData ? new Route({ ...oldData, ...updates }) : undefined);
|
|
114
113
|
queryClient.setQueriesData({ queryKey: ['routes'] }, (oldData) => {
|
|
115
114
|
if (!oldData)
|
|
116
115
|
return oldData;
|
|
@@ -130,7 +129,7 @@ AvroQueryClient.prototype.useUpdateRoute = function () {
|
|
|
130
129
|
onError: (_err, variables, context) => {
|
|
131
130
|
const { routeId } = variables;
|
|
132
131
|
if (context?.previousRoute) {
|
|
133
|
-
queryClient.setQueryData(['
|
|
132
|
+
queryClient.setQueryData(['routes', routeId], context.previousRoute);
|
|
134
133
|
}
|
|
135
134
|
if (context?.previousRoutes) {
|
|
136
135
|
queryClient.setQueryData(['routes'], context.previousRoutes);
|
|
@@ -140,8 +139,6 @@ AvroQueryClient.prototype.useUpdateRoute = function () {
|
|
|
140
139
|
const { routeId } = variables;
|
|
141
140
|
queryClient.invalidateQueries({ queryKey: ['routes'] });
|
|
142
141
|
queryClient.invalidateQueries({ queryKey: ['jobs'] });
|
|
143
|
-
queryClient.invalidateQueries({ queryKey: ['route', routeId] });
|
|
144
|
-
queryClient.invalidateQueries({ queryKey: ['job'] });
|
|
145
142
|
},
|
|
146
143
|
});
|
|
147
144
|
};
|
|
@@ -153,10 +150,10 @@ AvroQueryClient.prototype.useDeleteRoute = function () {
|
|
|
153
150
|
},
|
|
154
151
|
onMutate: async ({ routeId }) => {
|
|
155
152
|
await queryClient.cancelQueries({ queryKey: ['routes'] });
|
|
156
|
-
await queryClient.cancelQueries({ queryKey: ['
|
|
153
|
+
await queryClient.cancelQueries({ queryKey: ['routes', routeId] });
|
|
157
154
|
const previousRoutes = queryClient.getQueryData(['routes']);
|
|
158
|
-
const previousRoute = queryClient.getQueryData(['
|
|
159
|
-
queryClient.setQueryData(['
|
|
155
|
+
const previousRoute = queryClient.getQueryData(['routes', routeId]);
|
|
156
|
+
queryClient.setQueryData(['routes', routeId], undefined);
|
|
160
157
|
queryClient.setQueriesData({ queryKey: ['routes'] }, (oldData) => {
|
|
161
158
|
if (!oldData)
|
|
162
159
|
return oldData;
|
|
@@ -177,15 +174,13 @@ AvroQueryClient.prototype.useDeleteRoute = function () {
|
|
|
177
174
|
queryClient.setQueryData(['routes'], context.previousRoutes);
|
|
178
175
|
}
|
|
179
176
|
if (context?.previousRoute) {
|
|
180
|
-
queryClient.setQueryData(['
|
|
177
|
+
queryClient.setQueryData(['routes', routeId], context.previousRoute);
|
|
181
178
|
}
|
|
182
179
|
},
|
|
183
180
|
onSettled: (_data, _error, variables) => {
|
|
184
181
|
const { routeId } = variables;
|
|
185
182
|
queryClient.invalidateQueries({ queryKey: ['routes'] });
|
|
186
183
|
queryClient.invalidateQueries({ queryKey: ['jobs'] });
|
|
187
|
-
queryClient.invalidateQueries({ queryKey: ['route', routeId] });
|
|
188
|
-
queryClient.invalidateQueries({ queryKey: ['job'] });
|
|
189
184
|
},
|
|
190
185
|
});
|
|
191
186
|
};
|
|
@@ -11,7 +11,7 @@ AvroQueryClient.prototype.useCreateSkill = function () {
|
|
|
11
11
|
});
|
|
12
12
|
},
|
|
13
13
|
onSettled: () => {
|
|
14
|
-
queryClient.invalidateQueries({ queryKey: ['
|
|
14
|
+
queryClient.invalidateQueries({ queryKey: ['companies'] });
|
|
15
15
|
queryClient.invalidateQueries({ queryKey: ['skills'] });
|
|
16
16
|
},
|
|
17
17
|
});
|
|
@@ -54,10 +54,10 @@ AvroQueryClient.prototype.useUpdateSkill = function () {
|
|
|
54
54
|
},
|
|
55
55
|
onMutate: async ({ skillId, updates }) => {
|
|
56
56
|
await queryClient.cancelQueries({ queryKey: ['skills'] });
|
|
57
|
-
await queryClient.cancelQueries({ queryKey: ['
|
|
57
|
+
await queryClient.cancelQueries({ queryKey: ['skills', skillId] });
|
|
58
58
|
const previousSkills = queryClient.getQueryData(['skills']);
|
|
59
|
-
const previousSkill = queryClient.getQueryData(['
|
|
60
|
-
queryClient.setQueryData(['
|
|
59
|
+
const previousSkill = queryClient.getQueryData(['skills', skillId]);
|
|
60
|
+
queryClient.setQueryData(['skills', skillId], (oldData) => {
|
|
61
61
|
if (!oldData)
|
|
62
62
|
return oldData;
|
|
63
63
|
return { ...oldData, ...updates };
|
|
@@ -82,13 +82,12 @@ AvroQueryClient.prototype.useUpdateSkill = function () {
|
|
|
82
82
|
queryClient.setQueryData(['skills'], context.previousSkills);
|
|
83
83
|
}
|
|
84
84
|
if (context?.previousSkill) {
|
|
85
|
-
queryClient.setQueryData(['
|
|
85
|
+
queryClient.setQueryData(['skills', skillId], context.previousSkill);
|
|
86
86
|
}
|
|
87
87
|
},
|
|
88
88
|
onSettled: (_data, _error, variables) => {
|
|
89
89
|
const { skillId } = variables;
|
|
90
90
|
queryClient.invalidateQueries({ queryKey: ['skills'] });
|
|
91
|
-
queryClient.invalidateQueries({ queryKey: ['skill', skillId] });
|
|
92
91
|
},
|
|
93
92
|
});
|
|
94
93
|
};
|
|
@@ -37,7 +37,7 @@ AvroQueryClient.prototype.useCreateTeam = function () {
|
|
|
37
37
|
});
|
|
38
38
|
},
|
|
39
39
|
onSettled: () => {
|
|
40
|
-
queryClient.invalidateQueries({ queryKey: ['
|
|
40
|
+
queryClient.invalidateQueries({ queryKey: ['companies'] });
|
|
41
41
|
queryClient.invalidateQueries({ queryKey: ['teams'] });
|
|
42
42
|
},
|
|
43
43
|
});
|
|
@@ -54,10 +54,10 @@ AvroQueryClient.prototype.useUpdateTeam = function () {
|
|
|
54
54
|
},
|
|
55
55
|
onMutate: async ({ teamId, teamData }) => {
|
|
56
56
|
await queryClient.cancelQueries({ queryKey: ['teams'] });
|
|
57
|
-
await queryClient.cancelQueries({ queryKey: ['
|
|
57
|
+
await queryClient.cancelQueries({ queryKey: ['teams', teamId] });
|
|
58
58
|
const previousTeams = queryClient.getQueryData(['teams']);
|
|
59
|
-
const previousTeam = queryClient.getQueryData(['
|
|
60
|
-
queryClient.setQueryData(['
|
|
59
|
+
const previousTeam = queryClient.getQueryData(['teams', teamId]);
|
|
60
|
+
queryClient.setQueryData(['teams', teamId], (oldData) => {
|
|
61
61
|
if (!oldData)
|
|
62
62
|
return oldData;
|
|
63
63
|
return { ...oldData, ...teamData };
|
|
@@ -82,13 +82,12 @@ AvroQueryClient.prototype.useUpdateTeam = function () {
|
|
|
82
82
|
queryClient.setQueryData(['teams'], context.previousTeams);
|
|
83
83
|
}
|
|
84
84
|
if (context?.previousTeam) {
|
|
85
|
-
queryClient.setQueryData(['
|
|
85
|
+
queryClient.setQueryData(['teams', teamId], context.previousTeam);
|
|
86
86
|
}
|
|
87
87
|
},
|
|
88
88
|
onSettled: (_data, _error, variables) => {
|
|
89
89
|
const { teamId } = variables;
|
|
90
90
|
queryClient.invalidateQueries({ queryKey: ['teams'] });
|
|
91
|
-
queryClient.invalidateQueries({ queryKey: ['team', teamId] });
|
|
92
91
|
},
|
|
93
92
|
});
|
|
94
93
|
};
|
|
@@ -100,10 +99,10 @@ AvroQueryClient.prototype.useDeleteTeam = function () {
|
|
|
100
99
|
},
|
|
101
100
|
onMutate: async ({ teamId }) => {
|
|
102
101
|
await queryClient.cancelQueries({ queryKey: ['teams'] });
|
|
103
|
-
await queryClient.cancelQueries({ queryKey: ['
|
|
102
|
+
await queryClient.cancelQueries({ queryKey: ['teams', teamId] });
|
|
104
103
|
const previousRoutes = queryClient.getQueryData(['teams']);
|
|
105
|
-
const previousRoute = queryClient.getQueryData(['
|
|
106
|
-
queryClient.setQueryData(['
|
|
104
|
+
const previousRoute = queryClient.getQueryData(['teams', teamId]);
|
|
105
|
+
queryClient.setQueryData(['teams', teamId], undefined);
|
|
107
106
|
queryClient.setQueriesData({ queryKey: ['teams'] }, (oldData) => {
|
|
108
107
|
if (!oldData)
|
|
109
108
|
return oldData;
|
|
@@ -124,13 +123,12 @@ AvroQueryClient.prototype.useDeleteTeam = function () {
|
|
|
124
123
|
queryClient.setQueryData(['teams'], context.previousRoutes);
|
|
125
124
|
}
|
|
126
125
|
if (context?.previousRoute) {
|
|
127
|
-
queryClient.setQueryData(['
|
|
126
|
+
queryClient.setQueryData(['teams', teamId], context.previousRoute);
|
|
128
127
|
}
|
|
129
128
|
},
|
|
130
129
|
onSettled: (_data, _error, variables) => {
|
|
131
130
|
const { teamId } = variables;
|
|
132
131
|
queryClient.invalidateQueries({ queryKey: ['teams'] });
|
|
133
|
-
queryClient.invalidateQueries({ queryKey: ['team', teamId] });
|
|
134
132
|
},
|
|
135
133
|
});
|
|
136
134
|
};
|
|
@@ -32,7 +32,7 @@ AvroQueryClient.prototype.useGetCompanyTimecards = function (params = {}) {
|
|
|
32
32
|
};
|
|
33
33
|
AvroQueryClient.prototype.useGetTimecard = function (timecardId, enabled = true) {
|
|
34
34
|
return useQuery({
|
|
35
|
-
queryKey: ["
|
|
35
|
+
queryKey: ["timecards", timecardId],
|
|
36
36
|
queryFn: async () => {
|
|
37
37
|
const rsp = await this.get({
|
|
38
38
|
path: `/timecard/${timecardId}`,
|
|
@@ -70,7 +70,6 @@ AvroQueryClient.prototype.useUpdateTimecard = function () {
|
|
|
70
70
|
},
|
|
71
71
|
onSettled: async (_data, _err, variables) => {
|
|
72
72
|
await queryClient.invalidateQueries({ queryKey: ["timecards"] });
|
|
73
|
-
await queryClient.invalidateQueries({ queryKey: ["timecard", variables.timecardId] });
|
|
74
73
|
},
|
|
75
74
|
});
|
|
76
75
|
};
|
|
@@ -3,14 +3,14 @@ import { AvroQueryClient } from "../../client/QueryClient";
|
|
|
3
3
|
import { AuthState } from "../../types/auth";
|
|
4
4
|
AvroQueryClient.prototype.useGetUser = function (userId) {
|
|
5
5
|
return useQuery({
|
|
6
|
-
queryKey: ['
|
|
6
|
+
queryKey: ['users', userId],
|
|
7
7
|
queryFn: () => this.get({ path: `/user/${userId}` }),
|
|
8
8
|
enabled: Boolean(userId),
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
AvroQueryClient.prototype.useSearchUsers = function (searchUsername) {
|
|
12
12
|
return useQuery({
|
|
13
|
-
queryKey: ['
|
|
13
|
+
queryKey: ['users', 'search', searchUsername],
|
|
14
14
|
queryFn: () => {
|
|
15
15
|
if (!searchUsername)
|
|
16
16
|
return Promise.resolve([]);
|
|
@@ -101,26 +101,26 @@ AvroQueryClient.prototype.useUpdateUserCompany = function () {
|
|
|
101
101
|
// Optimistically update the user data and company data in the cache
|
|
102
102
|
onMutate: async (data) => {
|
|
103
103
|
await queryClient.cancelQueries({ queryKey: ['user'] });
|
|
104
|
-
await queryClient.cancelQueries({ queryKey: ['
|
|
105
|
-
const previousCompany = queryClient.getQueryData(['
|
|
104
|
+
await queryClient.cancelQueries({ queryKey: ['companies', this.companyId] });
|
|
105
|
+
const previousCompany = queryClient.getQueryData(['companies', this.companyId]);
|
|
106
106
|
if (previousCompany) {
|
|
107
107
|
let oldCompanyUser = previousCompany.users?.find((u) => u.user.id === data.user_id);
|
|
108
108
|
if (oldCompanyUser) {
|
|
109
109
|
oldCompanyUser = { ...oldCompanyUser, ...data.data };
|
|
110
110
|
const newUsers = previousCompany.users?.map((u) => u.user.id === data.user_id ? oldCompanyUser : u) ?? [];
|
|
111
|
-
queryClient.setQueryData(['
|
|
111
|
+
queryClient.setQueryData(['companies', this.companyId], { ...previousCompany, users: newUsers });
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
return { previousCompany };
|
|
115
115
|
},
|
|
116
116
|
onError: (err, _, context) => {
|
|
117
117
|
if (context?.previousCompany) {
|
|
118
|
-
queryClient.setQueryData(['
|
|
118
|
+
queryClient.setQueryData(['companies', this.companyId], context.previousCompany);
|
|
119
119
|
}
|
|
120
120
|
},
|
|
121
121
|
onSettled: (data, error, variables) => {
|
|
122
122
|
queryClient.invalidateQueries({ queryKey: ['user'] });
|
|
123
|
-
queryClient.invalidateQueries({ queryKey: ['
|
|
123
|
+
queryClient.invalidateQueries({ queryKey: ['companies', this.companyId] });
|
|
124
124
|
},
|
|
125
125
|
});
|
|
126
126
|
};
|
|
@@ -11,7 +11,7 @@ AvroQueryClient.prototype.useCreateWaiver = function () {
|
|
|
11
11
|
});
|
|
12
12
|
},
|
|
13
13
|
onSettled: () => {
|
|
14
|
-
queryClient.invalidateQueries({ queryKey: ['
|
|
14
|
+
queryClient.invalidateQueries({ queryKey: ['companies'] });
|
|
15
15
|
queryClient.invalidateQueries({ queryKey: ['waivers'] });
|
|
16
16
|
},
|
|
17
17
|
});
|
|
@@ -54,10 +54,10 @@ AvroQueryClient.prototype.useUpdateWaiver = function () {
|
|
|
54
54
|
},
|
|
55
55
|
onMutate: async ({ waiverId, updates }) => {
|
|
56
56
|
await queryClient.cancelQueries({ queryKey: ['waivers'] });
|
|
57
|
-
await queryClient.cancelQueries({ queryKey: ['
|
|
57
|
+
await queryClient.cancelQueries({ queryKey: ['waivers', waiverId] });
|
|
58
58
|
const previousWaivers = queryClient.getQueryData(['waivers']);
|
|
59
|
-
const previousWaiver = queryClient.getQueryData(['
|
|
60
|
-
queryClient.setQueryData(['
|
|
59
|
+
const previousWaiver = queryClient.getQueryData(['waivers', waiverId]);
|
|
60
|
+
queryClient.setQueryData(['waivers', waiverId], (oldData) => {
|
|
61
61
|
if (!oldData)
|
|
62
62
|
return oldData;
|
|
63
63
|
return { ...oldData, ...updates };
|
|
@@ -82,13 +82,12 @@ AvroQueryClient.prototype.useUpdateWaiver = function () {
|
|
|
82
82
|
queryClient.setQueryData(['waivers'], context.previousWaivers);
|
|
83
83
|
}
|
|
84
84
|
if (context?.previousWaiver) {
|
|
85
|
-
queryClient.setQueryData(['
|
|
85
|
+
queryClient.setQueryData(['waivers', waiverId], context.previousWaiver);
|
|
86
86
|
}
|
|
87
87
|
},
|
|
88
88
|
onSettled: (_data, _error, variables) => {
|
|
89
89
|
const { waiverId } = variables;
|
|
90
90
|
queryClient.invalidateQueries({ queryKey: ['waivers'] });
|
|
91
|
-
queryClient.invalidateQueries({ queryKey: ['waiver', waiverId] });
|
|
92
91
|
},
|
|
93
92
|
});
|
|
94
93
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { AvroQueryClientConfig, AvroQueryClient } from './client/QueryClient';
|
|
2
|
-
export { AvroQueryClientProvider, useAvroQueryClient } from './client/AvroQueryClientProvider';
|
|
2
|
+
export { AvroQueryClientProvider, useAvroQueryClient, useSocketEvent } from './client/AvroQueryClientProvider';
|
|
3
3
|
export { AuthManager } from './auth/AuthManager';
|
|
4
4
|
export { MemoryStorage, LocalStorage } from './auth/storage';
|
|
5
5
|
import './client/core/xhr';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { AvroQueryClient } from './client/QueryClient';
|
|
2
|
-
export { AvroQueryClientProvider, useAvroQueryClient } from './client/AvroQueryClientProvider';
|
|
2
|
+
export { AvroQueryClientProvider, useAvroQueryClient, useSocketEvent } from './client/AvroQueryClientProvider';
|
|
3
3
|
export { AuthManager } from './auth/AuthManager';
|
|
4
4
|
export { MemoryStorage, LocalStorage } from './auth/storage';
|
|
5
5
|
import './client/core/xhr';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@go-avro/avro-js",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.22",
|
|
4
4
|
"description": "JS client for Avro backend integration.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -50,7 +50,11 @@
|
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@tanstack/react-query": "^5.90.2",
|
|
54
53
|
"socket.io-client": "^4.8.1"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
57
|
+
"react-dom": "^18.0.0 || ^19.0.0",
|
|
58
|
+
"@tanstack/react-query": "^5.0.0"
|
|
55
59
|
}
|
|
56
60
|
}
|