@go-avro/avro-js 0.0.2-beta.142 → 0.0.2-beta.144
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.
|
@@ -276,6 +276,9 @@ declare module '../client/QueryClient' {
|
|
|
276
276
|
breakId: string;
|
|
277
277
|
updates: Partial<Break>;
|
|
278
278
|
}>>;
|
|
279
|
+
useUpdateSelf(): ReturnType<typeof useMutation<{
|
|
280
|
+
msg: string;
|
|
281
|
+
}, StandardError, Partial<User>>>;
|
|
279
282
|
useDeleteJob(): ReturnType<typeof useMutation<{
|
|
280
283
|
msg: string;
|
|
281
284
|
}, StandardError, {
|
|
@@ -36,6 +36,31 @@ AvroQueryClient.prototype.useCreateSelf = function () {
|
|
|
36
36
|
},
|
|
37
37
|
});
|
|
38
38
|
};
|
|
39
|
+
AvroQueryClient.prototype.useUpdateSelf = function () {
|
|
40
|
+
const queryClient = this.getQueryClient();
|
|
41
|
+
return useMutation({
|
|
42
|
+
mutationFn: async (data) => {
|
|
43
|
+
return this.put(`/user`, JSON.stringify(data), undefined, { "Content-Type": "application/json" });
|
|
44
|
+
},
|
|
45
|
+
// Optimistically update the user data in the cache
|
|
46
|
+
onMutate: async (data) => {
|
|
47
|
+
await queryClient.cancelQueries({ queryKey: ['user'] });
|
|
48
|
+
const previousUser = queryClient.getQueryData(['user']);
|
|
49
|
+
if (previousUser) {
|
|
50
|
+
queryClient.setQueryData(['user'], { ...previousUser, ...data });
|
|
51
|
+
}
|
|
52
|
+
return { previousUser };
|
|
53
|
+
},
|
|
54
|
+
onError: (err, _, context) => {
|
|
55
|
+
if (context?.previousUser) {
|
|
56
|
+
queryClient.setQueryData(['user'], context.previousUser);
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
onSettled: () => {
|
|
60
|
+
queryClient.invalidateQueries({ queryKey: ['user'] });
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
};
|
|
39
64
|
AvroQueryClient.prototype.useUpdateUserCompany = function () {
|
|
40
65
|
const queryClient = this.getQueryClient();
|
|
41
66
|
return useMutation({
|
|
@@ -46,16 +71,7 @@ AvroQueryClient.prototype.useUpdateUserCompany = function () {
|
|
|
46
71
|
onMutate: async (data) => {
|
|
47
72
|
await queryClient.cancelQueries({ queryKey: ['user'] });
|
|
48
73
|
await queryClient.cancelQueries({ queryKey: ['company', this.companyId] });
|
|
49
|
-
const previousUser = queryClient.getQueryData(['user']);
|
|
50
74
|
const previousCompany = queryClient.getQueryData(['company', this.companyId]);
|
|
51
|
-
if (previousUser) {
|
|
52
|
-
let oldUserCompany = previousUser.companies?.find(c => c.company === this.companyId);
|
|
53
|
-
if (oldUserCompany) {
|
|
54
|
-
oldUserCompany = { ...oldUserCompany, ...data.data };
|
|
55
|
-
const newCompanies = previousUser.companies?.map(c => c.company === this.companyId ? oldUserCompany : c) ?? [];
|
|
56
|
-
queryClient.setQueryData(['user'], { ...previousUser, companies: newCompanies });
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
75
|
if (previousCompany) {
|
|
60
76
|
let oldCompanyUser = previousCompany.users?.find((u) => u.user.id === data.user_id);
|
|
61
77
|
if (oldCompanyUser) {
|
|
@@ -64,14 +80,11 @@ AvroQueryClient.prototype.useUpdateUserCompany = function () {
|
|
|
64
80
|
queryClient.setQueryData(['company', this.companyId], { ...previousCompany, users: newUsers });
|
|
65
81
|
}
|
|
66
82
|
}
|
|
67
|
-
return {
|
|
83
|
+
return { previousCompany };
|
|
68
84
|
},
|
|
69
85
|
onError: (err, _, context) => {
|
|
70
|
-
if (context?.previousUser) {
|
|
71
|
-
queryClient.setQueryData(['user'], context.previousUser);
|
|
72
|
-
}
|
|
73
86
|
if (context?.previousCompany) {
|
|
74
|
-
queryClient.setQueryData(['company'], context.previousCompany);
|
|
87
|
+
queryClient.setQueryData(['company', this.companyId], context.previousCompany);
|
|
75
88
|
}
|
|
76
89
|
},
|
|
77
90
|
onSettled: (data, error, variables) => {
|
package/dist/types/api.d.ts
CHANGED
|
@@ -209,11 +209,11 @@ export interface User {
|
|
|
209
209
|
username: string;
|
|
210
210
|
name: string;
|
|
211
211
|
verified: boolean;
|
|
212
|
-
companies: UserCompanyAssociation[] | null;
|
|
213
212
|
email: string | null;
|
|
214
213
|
phone_number: string | null;
|
|
215
214
|
time_created: number;
|
|
216
215
|
time_updated: number | null;
|
|
216
|
+
share_location: boolean;
|
|
217
217
|
can_send_emails: boolean | null;
|
|
218
218
|
payment_methods: PaymentMethod[];
|
|
219
219
|
autopay_payment_types: string[];
|
|
@@ -374,7 +374,7 @@ export interface Company {
|
|
|
374
374
|
incomplete_payments: PlanPayment[];
|
|
375
375
|
overdue_threshold: number;
|
|
376
376
|
stripe_account_id: string;
|
|
377
|
-
is_restricted:
|
|
377
|
+
is_restricted: boolean;
|
|
378
378
|
disabled_reason: string;
|
|
379
379
|
completed_onboarding: boolean;
|
|
380
380
|
restricted_soon: boolean;
|