@go-avro/avro-js 0.0.2-beta.152 → 0.0.2-beta.154

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.
@@ -307,6 +307,11 @@ declare module '../client/QueryClient' {
307
307
  logo: File | null;
308
308
  }>;
309
309
  }>>;
310
+ useCreateUserCompany(): ReturnType<typeof useMutation<{
311
+ id: string;
312
+ }, StandardError, {
313
+ user_id: string;
314
+ }>>;
310
315
  useRemoveUserCompany(): ReturnType<typeof useMutation<{
311
316
  msg: string;
312
317
  }, StandardError, {
@@ -92,6 +92,39 @@ AvroQueryClient.prototype.useUpdateCompany = function () {
92
92
  },
93
93
  });
94
94
  };
95
+ AvroQueryClient.prototype.useCreateUserCompany = function () {
96
+ const queryClient = this.getQueryClient();
97
+ return useMutation({
98
+ mutationFn: async ({ user_id }) => {
99
+ if (!user_id) {
100
+ throw new Error("Both userId and companyId are required");
101
+ }
102
+ return this.post(`/company/${this.companyId}/user/${user_id}`, JSON.stringify({ user_id: user_id }), undefined, { "Content-Type": "application/json" });
103
+ },
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) => {
108
+ if (!oldData)
109
+ return oldData;
110
+ return {
111
+ ...oldData,
112
+ users: [...(oldData.users || []), { id: user_id }],
113
+ };
114
+ });
115
+ return { previousCompany };
116
+ },
117
+ onError: (err, variables, context) => {
118
+ if (context?.previousCompany) {
119
+ queryClient.setQueryData(['company', this.companyId], context.previousCompany);
120
+ }
121
+ },
122
+ onSettled: (_data, _error, variables) => {
123
+ queryClient.invalidateQueries({ queryKey: ['company', this.companyId] });
124
+ queryClient.invalidateQueries({ queryKey: ['/company/list'] });
125
+ },
126
+ });
127
+ };
95
128
  AvroQueryClient.prototype.useRemoveUserCompany = function () {
96
129
  const queryClient = this.getQueryClient();
97
130
  return useMutation({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@go-avro/avro-js",
3
- "version": "0.0.2-beta.152",
3
+ "version": "0.0.2-beta.154",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",