@go-avro/avro-js 0.0.19 → 0.0.21
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 +11 -0
- package/dist/client/AvroQueryClientProvider.js +42 -2
- package/dist/client/QueryClient.d.ts +14 -1
- package/dist/client/QueryClient.js +129 -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 +2 -2
- 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 +1 -1
|
@@ -11,4 +11,15 @@ 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
|
+
/**
|
|
15
|
+
* Subscribe to a raw socket event for UI-only side-effects (toasts,
|
|
16
|
+
* alerts, etc.) without managing on/off yourself. Query invalidation
|
|
17
|
+
* is already handled automatically — this is only for presentation.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* useSocketEvent<{ msg: string }>("scheduling_error", (data) => {
|
|
21
|
+
* toast({ title: "Error", description: data.msg });
|
|
22
|
+
* });
|
|
23
|
+
*/
|
|
24
|
+
export declare const useSocketEvent: <T = unknown>(eventName: string, callback: (data: T) => void) => void;
|
|
14
25
|
export default AvroQueryClientProvider;
|
|
@@ -1,6 +1,21 @@
|
|
|
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
|
+
/**
|
|
6
|
+
* Inner component that has access to the tanstack QueryClient via
|
|
7
|
+
* useQueryClient() and wires up socket → query invalidation.
|
|
8
|
+
*/
|
|
9
|
+
const SocketInvalidationBridge = ({ client }) => {
|
|
10
|
+
const queryClient = useQueryClient();
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
client.setupSocketInvalidation(queryClient);
|
|
13
|
+
return () => {
|
|
14
|
+
client.teardownSocketInvalidation();
|
|
15
|
+
};
|
|
16
|
+
}, [client, queryClient]);
|
|
17
|
+
return null;
|
|
18
|
+
};
|
|
4
19
|
export const AvroQueryClientProvider = ({ baseUrl, authManager, configOverrides, children, }) => {
|
|
5
20
|
const client = useMemo(() => {
|
|
6
21
|
const cfg = {
|
|
@@ -13,6 +28,7 @@ export const AvroQueryClientProvider = ({ baseUrl, authManager, configOverrides,
|
|
|
13
28
|
useEffect(() => {
|
|
14
29
|
return () => {
|
|
15
30
|
try {
|
|
31
|
+
client.teardownSocketInvalidation();
|
|
16
32
|
client.socket?.disconnect();
|
|
17
33
|
}
|
|
18
34
|
catch (e) {
|
|
@@ -20,7 +36,9 @@ export const AvroQueryClientProvider = ({ baseUrl, authManager, configOverrides,
|
|
|
20
36
|
}
|
|
21
37
|
};
|
|
22
38
|
}, [client]);
|
|
23
|
-
return (React.createElement(AvroQueryClientContext.Provider, { value: client },
|
|
39
|
+
return (React.createElement(AvroQueryClientContext.Provider, { value: client },
|
|
40
|
+
React.createElement(SocketInvalidationBridge, { client: client }),
|
|
41
|
+
children));
|
|
24
42
|
};
|
|
25
43
|
export const useAvroQueryClient = () => {
|
|
26
44
|
const ctx = useContext(AvroQueryClientContext);
|
|
@@ -29,4 +47,26 @@ export const useAvroQueryClient = () => {
|
|
|
29
47
|
}
|
|
30
48
|
return ctx;
|
|
31
49
|
};
|
|
50
|
+
/**
|
|
51
|
+
* Subscribe to a raw socket event for UI-only side-effects (toasts,
|
|
52
|
+
* alerts, etc.) without managing on/off yourself. Query invalidation
|
|
53
|
+
* is already handled automatically — this is only for presentation.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* useSocketEvent<{ msg: string }>("scheduling_error", (data) => {
|
|
57
|
+
* toast({ title: "Error", description: data.msg });
|
|
58
|
+
* });
|
|
59
|
+
*/
|
|
60
|
+
export const useSocketEvent = (eventName, callback) => {
|
|
61
|
+
const client = useAvroQueryClient();
|
|
62
|
+
const callbackRef = useRef(callback);
|
|
63
|
+
callbackRef.current = callback;
|
|
64
|
+
const stableHandler = useCallback((data) => callbackRef.current(data), []);
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
client.on(eventName, stableHandler);
|
|
67
|
+
return () => {
|
|
68
|
+
client.off(eventName, stableHandler);
|
|
69
|
+
};
|
|
70
|
+
}, [client, eventName, stableHandler]);
|
|
71
|
+
};
|
|
32
72
|
export default AvroQueryClientProvider;
|
|
@@ -166,7 +166,7 @@ declare module '../client/QueryClient' {
|
|
|
166
166
|
useGetTimecard(timecardId?: string, enabled?: boolean): UseQueryResult<Timecard, StandardError>;
|
|
167
167
|
useGetAvro(): UseQueryResult<Avro, StandardError>;
|
|
168
168
|
useSearchUsers(searchUsername: string): UseQueryResult<User[], StandardError>;
|
|
169
|
-
|
|
169
|
+
useReviewProposal(proposal_id: string): ReturnType<typeof useMutation<{
|
|
170
170
|
msg: string;
|
|
171
171
|
bill_id?: string;
|
|
172
172
|
}, StandardError, {
|
|
@@ -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,89 @@ 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
|
+
};
|
|
6
81
|
export class AvroQueryClient {
|
|
7
82
|
constructor(config) {
|
|
8
83
|
this._authState = AuthState.UNKNOWN;
|
|
9
84
|
this.companyId = undefined;
|
|
10
85
|
this.company = undefined;
|
|
11
86
|
this.authStateListeners = [];
|
|
87
|
+
this._queryClient = null;
|
|
88
|
+
this._socketInvalidationCleanup = null;
|
|
12
89
|
this.config = {
|
|
13
90
|
baseUrl: config.baseUrl,
|
|
14
91
|
authManager: config.authManager,
|
|
@@ -70,6 +147,58 @@ export class AvroQueryClient {
|
|
|
70
147
|
off(eventName, callback) {
|
|
71
148
|
this.socket?.off(eventName, callback);
|
|
72
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* Wire up automatic query invalidation for socket events.
|
|
152
|
+
* Called once from AvroQueryClientProvider when the tanstack
|
|
153
|
+
* QueryClient is available. Also handles auto-joining the
|
|
154
|
+
* company room on connect so consumer apps don't have to.
|
|
155
|
+
*/
|
|
156
|
+
setupSocketInvalidation(queryClient) {
|
|
157
|
+
// Prevent double-setup
|
|
158
|
+
if (this._queryClient)
|
|
159
|
+
return;
|
|
160
|
+
this._queryClient = queryClient;
|
|
161
|
+
const handlers = [];
|
|
162
|
+
// Register invalidation listeners for every mapped event
|
|
163
|
+
for (const [event, queryKeys] of Object.entries(SOCKET_INVALIDATION_MAP)) {
|
|
164
|
+
const handler = () => {
|
|
165
|
+
for (const key of queryKeys) {
|
|
166
|
+
queryClient.invalidateQueries({ queryKey: key });
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
this.socket.on(event, handler);
|
|
170
|
+
handlers.push({ event, handler });
|
|
171
|
+
}
|
|
172
|
+
// Auto join/leave company room
|
|
173
|
+
const joinCompanyRoom = () => {
|
|
174
|
+
if (this.companyId) {
|
|
175
|
+
this.socket.emit('join_company', { company_id: this.companyId });
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
this.socket.on('connect', joinCompanyRoom);
|
|
179
|
+
handlers.push({ event: 'connect', handler: joinCompanyRoom });
|
|
180
|
+
// If already connected, join immediately
|
|
181
|
+
if (this.socket.connected && this.companyId) {
|
|
182
|
+
joinCompanyRoom();
|
|
183
|
+
}
|
|
184
|
+
this._socketInvalidationCleanup = () => {
|
|
185
|
+
for (const { event, handler } of handlers) {
|
|
186
|
+
this.socket.off(event, handler);
|
|
187
|
+
}
|
|
188
|
+
// Leave company room on teardown
|
|
189
|
+
if (this.socket.connected && this.companyId) {
|
|
190
|
+
this.socket.emit('leave_company', { company_id: this.companyId });
|
|
191
|
+
}
|
|
192
|
+
this._queryClient = null;
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Remove all invalidation listeners. Called on provider unmount.
|
|
197
|
+
*/
|
|
198
|
+
teardownSocketInvalidation() {
|
|
199
|
+
this._socketInvalidationCleanup?.();
|
|
200
|
+
this._socketInvalidationCleanup = null;
|
|
201
|
+
}
|
|
73
202
|
get({ path, cancelToken, headers, progressUpdateCallback }) {
|
|
74
203
|
return this._xhr('GET', path, null, cancelToken, headers, true, this.config.maxRetries, progressUpdateCallback);
|
|
75
204
|
}
|
|
@@ -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
|
};
|