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

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
+ userCompanyData: Partial<UserCompanyAssociation>;
314
+ }>>;
310
315
  useRemoveUserCompany(): ReturnType<typeof useMutation<{
311
316
  msg: string;
312
317
  }, StandardError, {
@@ -92,6 +92,47 @@ 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 ({ userCompanyData }) => {
99
+ const userId = userCompanyData.user?.id;
100
+ const companyId = userCompanyData.company;
101
+ if (!userId || !companyId) {
102
+ throw new Error("Both userId and companyId are required");
103
+ }
104
+ return this.post(`/company/${companyId}/user/${userId}`, JSON.stringify({ user_id: userId }), undefined, { "Content-Type": "application/json" });
105
+ },
106
+ onMutate: async ({ userCompanyData }) => {
107
+ const userId = userCompanyData.user?.id;
108
+ const companyId = userCompanyData.company;
109
+ await queryClient.cancelQueries({ queryKey: ['company', companyId] });
110
+ const previousCompany = queryClient.getQueryData(['company', companyId]);
111
+ queryClient.setQueryData(['company', companyId], (oldData) => {
112
+ if (!oldData)
113
+ return oldData;
114
+ return {
115
+ ...oldData,
116
+ users: [...(oldData.users || []), { id: userId }],
117
+ };
118
+ });
119
+ return { previousCompany };
120
+ },
121
+ onError: (err, variables, context) => {
122
+ const { userCompanyData } = variables;
123
+ const { company } = userCompanyData;
124
+ if (context?.previousCompany) {
125
+ queryClient.setQueryData(['company', company], context.previousCompany);
126
+ }
127
+ },
128
+ onSettled: (_data, _error, variables) => {
129
+ const { userCompanyData } = variables;
130
+ const { company } = userCompanyData;
131
+ queryClient.invalidateQueries({ queryKey: ['company', company] });
132
+ queryClient.invalidateQueries({ queryKey: ['/company/list'] });
133
+ },
134
+ });
135
+ };
95
136
  AvroQueryClient.prototype.useRemoveUserCompany = function () {
96
137
  const queryClient = this.getQueryClient();
97
138
  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.153",
4
4
  "description": "JS client for Avro backend integration.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",