@go-avro/avro-js 0.0.2-beta.153 → 0.0.2-beta.155
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.
|
@@ -310,7 +310,8 @@ declare module '../client/QueryClient' {
|
|
|
310
310
|
useCreateUserCompany(): ReturnType<typeof useMutation<{
|
|
311
311
|
id: string;
|
|
312
312
|
}, StandardError, {
|
|
313
|
-
|
|
313
|
+
user_id: string;
|
|
314
|
+
data: Partial<UserCompanyAssociation>;
|
|
314
315
|
}>>;
|
|
315
316
|
useRemoveUserCompany(): ReturnType<typeof useMutation<{
|
|
316
317
|
msg: string;
|
|
@@ -95,41 +95,34 @@ AvroQueryClient.prototype.useUpdateCompany = function () {
|
|
|
95
95
|
AvroQueryClient.prototype.useCreateUserCompany = function () {
|
|
96
96
|
const queryClient = this.getQueryClient();
|
|
97
97
|
return useMutation({
|
|
98
|
-
mutationFn: async ({
|
|
99
|
-
|
|
100
|
-
const companyId = userCompanyData.company;
|
|
101
|
-
if (!userId || !companyId) {
|
|
98
|
+
mutationFn: async ({ user_id, data }) => {
|
|
99
|
+
if (!user_id) {
|
|
102
100
|
throw new Error("Both userId and companyId are required");
|
|
103
101
|
}
|
|
104
|
-
return this.post(`/company/${companyId}/user/${
|
|
102
|
+
return this.post(`/company/${this.companyId}/user/${user_id}`, JSON.stringify(data), undefined, { "Content-Type": "application/json" });
|
|
105
103
|
},
|
|
106
|
-
onMutate: async ({
|
|
107
|
-
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
const previousCompany = queryClient.getQueryData(['company', companyId]);
|
|
111
|
-
queryClient.setQueryData(['company', companyId], (oldData) => {
|
|
104
|
+
onMutate: async ({ user_id }) => {
|
|
105
|
+
await queryClient.cancelQueries({ queryKey: ['company', this.companyId] });
|
|
106
|
+
const previousCompany = queryClient.getQueryData(['company', this.companyId]);
|
|
107
|
+
queryClient.setQueryData(['company', this.companyId], (oldData) => {
|
|
112
108
|
if (!oldData)
|
|
113
109
|
return oldData;
|
|
114
110
|
return {
|
|
115
111
|
...oldData,
|
|
116
|
-
users: [...(oldData.users || []), { id:
|
|
112
|
+
users: [...(oldData.users || []), { id: user_id }],
|
|
117
113
|
};
|
|
118
114
|
});
|
|
119
115
|
return { previousCompany };
|
|
120
116
|
},
|
|
121
117
|
onError: (err, variables, context) => {
|
|
122
|
-
const { userCompanyData } = variables;
|
|
123
|
-
const { company } = userCompanyData;
|
|
124
118
|
if (context?.previousCompany) {
|
|
125
|
-
queryClient.setQueryData(['company',
|
|
119
|
+
queryClient.setQueryData(['company', this.companyId], context.previousCompany);
|
|
126
120
|
}
|
|
127
121
|
},
|
|
128
122
|
onSettled: (_data, _error, variables) => {
|
|
129
|
-
|
|
130
|
-
const { company } = userCompanyData;
|
|
131
|
-
queryClient.invalidateQueries({ queryKey: ['company', company] });
|
|
123
|
+
queryClient.invalidateQueries({ queryKey: ['company', this.companyId] });
|
|
132
124
|
queryClient.invalidateQueries({ queryKey: ['/company/list'] });
|
|
125
|
+
queryClient.invalidateQueries({ queryKey: ['company', 'current'] });
|
|
133
126
|
},
|
|
134
127
|
});
|
|
135
128
|
};
|