@go-avro/avro-js 0.0.112 → 0.0.113
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/QueryClient.d.ts +5 -0
- package/dist/client/QueryClient.js +10 -8
- package/dist/client/hooks/companies.js +3 -16
- package/dist/client/hooks/users.js +15 -0
- package/dist/types/api/Company.d.ts +0 -2
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -548,6 +548,11 @@ declare module '../client/QueryClient' {
|
|
|
548
548
|
data: Partial<UserCompanyAssociation>;
|
|
549
549
|
}>>;
|
|
550
550
|
useDevices(): UseQueryResult<Device[], StandardError>;
|
|
551
|
+
useGetCompanyUsers(body?: {
|
|
552
|
+
query?: string;
|
|
553
|
+
user_ids?: string[];
|
|
554
|
+
enabled?: boolean;
|
|
555
|
+
}): UseQueryResult<UserCompanyAssociation[], StandardError>;
|
|
551
556
|
useReportDevice(): ReturnType<typeof useMutation<Device, StandardError, DeviceInfo & {
|
|
552
557
|
location_status?: LocationServicesStatus;
|
|
553
558
|
}>>;
|
|
@@ -132,7 +132,10 @@ const SOCKET_EVENT_CONFIG = {
|
|
|
132
132
|
},
|
|
133
133
|
// ── Users (no single-entity socket events) ──
|
|
134
134
|
user_updated: { invalidateKeys: [['users'], ['user']] },
|
|
135
|
-
|
|
135
|
+
// Membership / permission changes.
|
|
136
|
+
update_users: { invalidateKeys: [['users'], ['user']] },
|
|
137
|
+
// Presence / location-status flips: only the member list is affected.
|
|
138
|
+
update_presence: { invalidateKeys: [['users', 'company']] },
|
|
136
139
|
// ── Jobs ──
|
|
137
140
|
create_job: {
|
|
138
141
|
entityKey: 'jobs',
|
|
@@ -513,21 +516,20 @@ export class AvroQueryClient {
|
|
|
513
516
|
const patchMemberLocation = (data) => {
|
|
514
517
|
const userId = data?.user_id;
|
|
515
518
|
if (!userId || typeof userId !== 'string' || typeof data?.latitude !== 'number') {
|
|
516
|
-
queryClient.invalidateQueries({ queryKey: ['
|
|
519
|
+
queryClient.invalidateQueries({ queryKey: ['users', 'company'] });
|
|
517
520
|
return;
|
|
518
521
|
}
|
|
519
|
-
|
|
520
|
-
if (!old || !Array.isArray(old.users))
|
|
521
|
-
return old;
|
|
522
|
+
const patchMembers = (members) => {
|
|
522
523
|
let changed = false;
|
|
523
|
-
const
|
|
524
|
+
const next = members.map((u) => {
|
|
524
525
|
if (u?.user?.id !== userId)
|
|
525
526
|
return u;
|
|
526
527
|
changed = true;
|
|
527
528
|
return { ...u, last_location: data };
|
|
528
529
|
});
|
|
529
|
-
return changed ?
|
|
530
|
-
}
|
|
530
|
+
return changed ? next : members;
|
|
531
|
+
};
|
|
532
|
+
queryClient.setQueriesData({ queryKey: ['users', 'company'] }, (old) => Array.isArray(old) ? patchMembers(old) : old);
|
|
531
533
|
};
|
|
532
534
|
for (const [event, config] of Object.entries(SOCKET_EVENT_CONFIG)) {
|
|
533
535
|
if (event === 'location_update' && isBulkEvent(config)) {
|
|
@@ -146,14 +146,8 @@ AvroQueryClient.prototype.useCreateUserCompany = function () {
|
|
|
146
146
|
queryKey: ['companies', this.companyId],
|
|
147
147
|
});
|
|
148
148
|
const previousCompany = queryClient.getQueryData(['companies', this.companyId]);
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
return oldData;
|
|
152
|
-
return {
|
|
153
|
-
...oldData,
|
|
154
|
-
users: [...(oldData.users || []), { id: user_id }],
|
|
155
|
-
};
|
|
156
|
-
});
|
|
149
|
+
// Members live in their own query now; the server's
|
|
150
|
+
// update_users event refreshes it once the add lands.
|
|
157
151
|
return { previousCompany };
|
|
158
152
|
},
|
|
159
153
|
onSuccess: () => {
|
|
@@ -180,14 +174,7 @@ AvroQueryClient.prototype.useRemoveUserCompany = function () {
|
|
|
180
174
|
queryKey: ['companies', this.companyId],
|
|
181
175
|
});
|
|
182
176
|
const previousCompany = queryClient.getQueryData(['companies', this.companyId]);
|
|
183
|
-
queryClient.
|
|
184
|
-
if (!oldData)
|
|
185
|
-
return oldData;
|
|
186
|
-
return {
|
|
187
|
-
...oldData,
|
|
188
|
-
users: oldData.users.filter((user) => user.id !== userId),
|
|
189
|
-
};
|
|
190
|
-
});
|
|
177
|
+
queryClient.setQueriesData({ queryKey: ['users', 'company'] }, (old) => old ? old.filter((member) => member.id !== userId) : old);
|
|
191
178
|
return { previousCompany };
|
|
192
179
|
},
|
|
193
180
|
onSuccess: () => {
|
|
@@ -175,3 +175,18 @@ AvroQueryClient.prototype.useDeleteSelf = function () {
|
|
|
175
175
|
},
|
|
176
176
|
});
|
|
177
177
|
};
|
|
178
|
+
/**
|
|
179
|
+
* A company's members on their own, so presence/status flips
|
|
180
|
+
* (`update_presence`) refetch this list instead of the whole company.
|
|
181
|
+
*/
|
|
182
|
+
AvroQueryClient.prototype.useGetCompanyUsers = function (body = {}) {
|
|
183
|
+
return useQuery({
|
|
184
|
+
queryKey: ['users', 'company', this.companyId, body.query ?? '', body.user_ids ?? null],
|
|
185
|
+
queryFn: () => this.post({
|
|
186
|
+
path: `/company/${this.companyId}/users`,
|
|
187
|
+
data: JSON.stringify(body),
|
|
188
|
+
headers: { 'Content-Type': 'application/json' },
|
|
189
|
+
}),
|
|
190
|
+
enabled: Boolean(this.companyId) && (body.enabled ?? true),
|
|
191
|
+
});
|
|
192
|
+
};
|
|
@@ -8,7 +8,6 @@ import { Plan } from '../../types/api/Plan';
|
|
|
8
8
|
import { PlanPayment } from '../../types/api/PlanPayment';
|
|
9
9
|
import { Session } from '../../types/api/Session';
|
|
10
10
|
import { Skill } from '../../types/api/Skill';
|
|
11
|
-
import { UserCompanyAssociation } from '../../types/api/UserCompanyAssociation';
|
|
12
11
|
import { CatalogItem } from '../../types/api/CatalogItem';
|
|
13
12
|
export interface Company {
|
|
14
13
|
id: string;
|
|
@@ -20,7 +19,6 @@ export interface Company {
|
|
|
20
19
|
catalog_items: CatalogItem[];
|
|
21
20
|
time_created: number;
|
|
22
21
|
time_updated: number | null;
|
|
23
|
-
users: UserCompanyAssociation[];
|
|
24
22
|
use_client_side_customer_start_billing: boolean;
|
|
25
23
|
use_client_side_customer_stop_billing: boolean;
|
|
26
24
|
use_client_side_employee_start_billing: boolean;
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const AVRO_JS_VERSION = "0.0.
|
|
1
|
+
export declare const AVRO_JS_VERSION = "0.0.113";
|
package/dist/version.js
CHANGED