@sudobility/shapeshyft_client 0.0.54 → 0.0.55
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/hooks/useAiExecute.d.ts.map +1 -1
- package/dist/hooks/useAiExecute.js +51 -60
- package/dist/hooks/useAiExecute.js.map +1 -1
- package/dist/hooks/useAnalytics.d.ts +6 -2
- package/dist/hooks/useAnalytics.d.ts.map +1 -1
- package/dist/hooks/useAnalytics.js +27 -33
- package/dist/hooks/useAnalytics.js.map +1 -1
- package/dist/hooks/useEndpoints.d.ts +10 -6
- package/dist/hooks/useEndpoints.d.ts.map +1 -1
- package/dist/hooks/useEndpoints.js +87 -121
- package/dist/hooks/useEndpoints.js.map +1 -1
- package/dist/hooks/useEntities.d.ts +18 -15
- package/dist/hooks/useEntities.d.ts.map +1 -1
- package/dist/hooks/useEntities.js +235 -332
- package/dist/hooks/useEntities.js.map +1 -1
- package/dist/hooks/useKeys.d.ts +9 -6
- package/dist/hooks/useKeys.d.ts.map +1 -1
- package/dist/hooks/useKeys.js +82 -117
- package/dist/hooks/useKeys.js.map +1 -1
- package/dist/hooks/useProjects.d.ts +12 -8
- package/dist/hooks/useProjects.d.ts.map +1 -1
- package/dist/hooks/useProjects.js +103 -157
- package/dist/hooks/useProjects.js.map +1 -1
- package/dist/hooks/useSettings.d.ts +6 -3
- package/dist/hooks/useSettings.d.ts.map +1 -1
- package/dist/hooks/useSettings.js +53 -56
- package/dist/hooks/useSettings.js.map +1 -1
- package/dist/hooks/useStorageConfig.d.ts +8 -5
- package/dist/hooks/useStorageConfig.d.ts.map +1 -1
- package/dist/hooks/useStorageConfig.js +93 -119
- package/dist/hooks/useStorageConfig.js.map +1 -1
- package/dist/types.d.ts +8 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +8 -6
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,395 +1,298 @@
|
|
|
1
|
-
import { useCallback, useMemo
|
|
1
|
+
import { useCallback, useMemo } from 'react';
|
|
2
|
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
2
3
|
import { ShapeshyftClient } from '../network/ShapeshyftClient';
|
|
3
|
-
|
|
4
|
+
import { QUERY_KEYS } from '../types';
|
|
5
|
+
const EMPTY_ENTITIES = [];
|
|
6
|
+
const EMPTY_MEMBERS = [];
|
|
7
|
+
const EMPTY_INVITATIONS = [];
|
|
8
|
+
export const useEntities = (networkClient, baseUrl, token, entitySlug, options) => {
|
|
9
|
+
const testMode = options?.testMode ?? false;
|
|
10
|
+
const enabled = (options?.enabled ?? true) && !!token;
|
|
11
|
+
const entityEnabled = enabled && !!entitySlug;
|
|
4
12
|
const client = useMemo(() => new ShapeshyftClient({ baseUrl, networkClient, testMode }), [baseUrl, networkClient, testMode]);
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const [myInvitations, setMyInvitations] = useState([]);
|
|
10
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
11
|
-
const [error, setError] = useState(null);
|
|
12
|
-
const refreshEntities = useCallback(async (token) => {
|
|
13
|
-
setIsLoading(true);
|
|
14
|
-
setError(null);
|
|
15
|
-
try {
|
|
13
|
+
const queryClient = useQueryClient();
|
|
14
|
+
const { data: entitiesData, isLoading: entitiesLoading, error: entitiesError, refetch: refetchEntities, } = useQuery({
|
|
15
|
+
queryKey: QUERY_KEYS.entities(),
|
|
16
|
+
queryFn: async () => {
|
|
16
17
|
const response = await client.getEntities(token);
|
|
17
|
-
if (response.success
|
|
18
|
-
|
|
18
|
+
if (!response.success || !response.data) {
|
|
19
|
+
throw new Error(response.error || 'Failed to fetch entities');
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
return response.data;
|
|
22
|
+
},
|
|
23
|
+
enabled,
|
|
24
|
+
staleTime: 5 * 60 * 1000,
|
|
25
|
+
gcTime: 30 * 60 * 1000,
|
|
26
|
+
});
|
|
27
|
+
const { data: membersData, isLoading: membersLoading, refetch: refetchMembers, } = useQuery({
|
|
28
|
+
queryKey: QUERY_KEYS.entityMembers(entitySlug ?? ''),
|
|
29
|
+
queryFn: async () => {
|
|
30
|
+
const response = await client.getEntityMembers(entitySlug, token);
|
|
31
|
+
if (!response.success || !response.data) {
|
|
32
|
+
throw new Error(response.error || 'Failed to fetch members');
|
|
22
33
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
setError(null);
|
|
36
|
-
try {
|
|
37
|
-
const response = await client.getEntity(entitySlug, token);
|
|
38
|
-
if (response.success && response.data) {
|
|
39
|
-
setCurrentEntity(response.data);
|
|
34
|
+
return response.data;
|
|
35
|
+
},
|
|
36
|
+
enabled: entityEnabled,
|
|
37
|
+
staleTime: 5 * 60 * 1000,
|
|
38
|
+
gcTime: 30 * 60 * 1000,
|
|
39
|
+
});
|
|
40
|
+
const { data: invitationsData, isLoading: invitationsLoading, refetch: refetchInvitations, } = useQuery({
|
|
41
|
+
queryKey: QUERY_KEYS.entityInvitations(entitySlug ?? ''),
|
|
42
|
+
queryFn: async () => {
|
|
43
|
+
const response = await client.getEntityInvitations(entitySlug, token);
|
|
44
|
+
if (!response.success || !response.data) {
|
|
45
|
+
throw new Error(response.error || 'Failed to fetch invitations');
|
|
40
46
|
}
|
|
41
|
-
return response;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
finally {
|
|
54
|
-
setIsLoading(false);
|
|
55
|
-
}
|
|
56
|
-
}, [client]);
|
|
57
|
-
const createEntity = useCallback(async (data, token) => {
|
|
58
|
-
setIsLoading(true);
|
|
59
|
-
setError(null);
|
|
60
|
-
try {
|
|
61
|
-
const response = await client.createEntity(data, token);
|
|
62
|
-
if (response.success) {
|
|
63
|
-
await refreshEntities(token);
|
|
47
|
+
return response.data;
|
|
48
|
+
},
|
|
49
|
+
enabled: entityEnabled,
|
|
50
|
+
staleTime: 5 * 60 * 1000,
|
|
51
|
+
gcTime: 30 * 60 * 1000,
|
|
52
|
+
});
|
|
53
|
+
const { data: myInvitationsData, isLoading: myInvitationsLoading, refetch: refetchMyInvitations, } = useQuery({
|
|
54
|
+
queryKey: QUERY_KEYS.myInvitations(),
|
|
55
|
+
queryFn: async () => {
|
|
56
|
+
const response = await client.getMyInvitations(token);
|
|
57
|
+
if (!response.success || !response.data) {
|
|
58
|
+
throw new Error(response.error || 'Failed to fetch my invitations');
|
|
64
59
|
}
|
|
65
|
-
return response;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
finally {
|
|
78
|
-
setIsLoading(false);
|
|
79
|
-
}
|
|
80
|
-
}, [client, refreshEntities]);
|
|
81
|
-
const updateEntity = useCallback(async (entitySlug, data, token) => {
|
|
82
|
-
setIsLoading(true);
|
|
83
|
-
setError(null);
|
|
84
|
-
try {
|
|
85
|
-
const response = await client.updateEntity(entitySlug, data, token);
|
|
60
|
+
return response.data;
|
|
61
|
+
},
|
|
62
|
+
enabled,
|
|
63
|
+
staleTime: 5 * 60 * 1000,
|
|
64
|
+
gcTime: 30 * 60 * 1000,
|
|
65
|
+
});
|
|
66
|
+
const createEntityMutation = useMutation({
|
|
67
|
+
mutationFn: async (data) => {
|
|
68
|
+
return client.createEntity(data, token);
|
|
69
|
+
},
|
|
70
|
+
onSuccess: response => {
|
|
86
71
|
if (response.success) {
|
|
87
|
-
|
|
72
|
+
queryClient.invalidateQueries({ queryKey: QUERY_KEYS.entities() });
|
|
88
73
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
success: false,
|
|
97
|
-
error: errorMessage,
|
|
98
|
-
timestamp: new Date().toISOString(),
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
finally {
|
|
102
|
-
setIsLoading(false);
|
|
103
|
-
}
|
|
104
|
-
}, [client, refreshEntities]);
|
|
105
|
-
const deleteEntity = useCallback(async (entitySlug, token) => {
|
|
106
|
-
setIsLoading(true);
|
|
107
|
-
setError(null);
|
|
108
|
-
try {
|
|
109
|
-
const response = await client.deleteEntity(entitySlug, token);
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
const updateEntityMutation = useMutation({
|
|
77
|
+
mutationFn: async ({ slug, data, }) => {
|
|
78
|
+
return client.updateEntity(slug, data, token);
|
|
79
|
+
},
|
|
80
|
+
onSuccess: response => {
|
|
110
81
|
if (response.success) {
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
return response;
|
|
114
|
-
}
|
|
115
|
-
catch (err) {
|
|
116
|
-
const errorMessage = err instanceof Error ? err.message : 'Failed to delete entity';
|
|
117
|
-
setError(errorMessage);
|
|
118
|
-
console.error('[useEntities] deleteEntity error:', errorMessage, err);
|
|
119
|
-
return {
|
|
120
|
-
success: false,
|
|
121
|
-
error: errorMessage,
|
|
122
|
-
timestamp: new Date().toISOString(),
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
finally {
|
|
126
|
-
setIsLoading(false);
|
|
127
|
-
}
|
|
128
|
-
}, [client, refreshEntities]);
|
|
129
|
-
const refreshMembers = useCallback(async (entitySlug, token) => {
|
|
130
|
-
setIsLoading(true);
|
|
131
|
-
setError(null);
|
|
132
|
-
try {
|
|
133
|
-
const response = await client.getEntityMembers(entitySlug, token);
|
|
134
|
-
if (response.success && response.data) {
|
|
135
|
-
setMembers(response.data);
|
|
82
|
+
queryClient.invalidateQueries({ queryKey: QUERY_KEYS.entities() });
|
|
136
83
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
console.error('[useEntities] refreshMembers error:', errorMessage, err);
|
|
145
|
-
}
|
|
146
|
-
finally {
|
|
147
|
-
setIsLoading(false);
|
|
148
|
-
}
|
|
149
|
-
}, [client]);
|
|
150
|
-
const updateMemberRole = useCallback(async (entitySlug, memberId, role, token) => {
|
|
151
|
-
setIsLoading(true);
|
|
152
|
-
setError(null);
|
|
153
|
-
try {
|
|
154
|
-
const response = await client.updateEntityMemberRole(entitySlug, memberId, role, token);
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
const deleteEntityMutation = useMutation({
|
|
87
|
+
mutationFn: async (slug) => {
|
|
88
|
+
return client.deleteEntity(slug, token);
|
|
89
|
+
},
|
|
90
|
+
onSuccess: response => {
|
|
155
91
|
if (response.success) {
|
|
156
|
-
|
|
92
|
+
queryClient.invalidateQueries({ queryKey: QUERY_KEYS.entities() });
|
|
157
93
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
finally {
|
|
171
|
-
setIsLoading(false);
|
|
172
|
-
}
|
|
173
|
-
}, [client, refreshMembers]);
|
|
174
|
-
const removeMember = useCallback(async (entitySlug, memberId, token) => {
|
|
175
|
-
setIsLoading(true);
|
|
176
|
-
setError(null);
|
|
177
|
-
try {
|
|
178
|
-
const response = await client.removeEntityMember(entitySlug, memberId, token);
|
|
179
|
-
if (response.success) {
|
|
180
|
-
await refreshMembers(entitySlug, token);
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
const updateMemberRoleMutation = useMutation({
|
|
97
|
+
mutationFn: async ({ memberId, role, }) => {
|
|
98
|
+
return client.updateEntityMemberRole(entitySlug, memberId, role, token);
|
|
99
|
+
},
|
|
100
|
+
onSuccess: response => {
|
|
101
|
+
if (response.success && entitySlug) {
|
|
102
|
+
queryClient.invalidateQueries({
|
|
103
|
+
queryKey: QUERY_KEYS.entityMembers(entitySlug),
|
|
104
|
+
});
|
|
181
105
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
finally {
|
|
195
|
-
setIsLoading(false);
|
|
196
|
-
}
|
|
197
|
-
}, [client, refreshMembers]);
|
|
198
|
-
const refreshInvitations = useCallback(async (entitySlug, token) => {
|
|
199
|
-
setIsLoading(true);
|
|
200
|
-
setError(null);
|
|
201
|
-
try {
|
|
202
|
-
const response = await client.getEntityInvitations(entitySlug, token);
|
|
203
|
-
if (response.success && response.data) {
|
|
204
|
-
setInvitations(response.data);
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
const removeMemberMutation = useMutation({
|
|
109
|
+
mutationFn: async (memberId) => {
|
|
110
|
+
return client.removeEntityMember(entitySlug, memberId, token);
|
|
111
|
+
},
|
|
112
|
+
onSuccess: response => {
|
|
113
|
+
if (response.success && entitySlug) {
|
|
114
|
+
queryClient.invalidateQueries({
|
|
115
|
+
queryKey: QUERY_KEYS.entityMembers(entitySlug),
|
|
116
|
+
});
|
|
205
117
|
}
|
|
206
|
-
|
|
207
|
-
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
const createInvitationMutation = useMutation({
|
|
121
|
+
mutationFn: async (data) => {
|
|
122
|
+
return client.createEntityInvitation(entitySlug, data, token);
|
|
123
|
+
},
|
|
124
|
+
onSuccess: response => {
|
|
125
|
+
if (response.success && entitySlug) {
|
|
126
|
+
queryClient.invalidateQueries({
|
|
127
|
+
queryKey: QUERY_KEYS.entityInvitations(entitySlug),
|
|
128
|
+
});
|
|
208
129
|
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
setIsLoading(true);
|
|
221
|
-
setError(null);
|
|
222
|
-
try {
|
|
223
|
-
const response = await client.createEntityInvitation(entitySlug, data, token);
|
|
224
|
-
if (response.success) {
|
|
225
|
-
await refreshInvitations(entitySlug, token);
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
const cancelInvitationMutation = useMutation({
|
|
133
|
+
mutationFn: async (invitationId) => {
|
|
134
|
+
return client.cancelEntityInvitation(entitySlug, invitationId, token);
|
|
135
|
+
},
|
|
136
|
+
onSuccess: response => {
|
|
137
|
+
if (response.success && entitySlug) {
|
|
138
|
+
queryClient.invalidateQueries({
|
|
139
|
+
queryKey: QUERY_KEYS.entityInvitations(entitySlug),
|
|
140
|
+
});
|
|
226
141
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
success: false,
|
|
235
|
-
error: errorMessage,
|
|
236
|
-
timestamp: new Date().toISOString(),
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
finally {
|
|
240
|
-
setIsLoading(false);
|
|
241
|
-
}
|
|
242
|
-
}, [client, refreshInvitations]);
|
|
243
|
-
const cancelInvitation = useCallback(async (entitySlug, invitationId, token) => {
|
|
244
|
-
setIsLoading(true);
|
|
245
|
-
setError(null);
|
|
246
|
-
try {
|
|
247
|
-
const response = await client.cancelEntityInvitation(entitySlug, invitationId, token);
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
const acceptInvitationMutation = useMutation({
|
|
145
|
+
mutationFn: async (invitationToken) => {
|
|
146
|
+
return client.acceptInvitation(invitationToken, token);
|
|
147
|
+
},
|
|
148
|
+
onSuccess: response => {
|
|
248
149
|
if (response.success) {
|
|
249
|
-
|
|
150
|
+
queryClient.invalidateQueries({ queryKey: QUERY_KEYS.myInvitations() });
|
|
151
|
+
queryClient.invalidateQueries({ queryKey: QUERY_KEYS.entities() });
|
|
250
152
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
success: false,
|
|
259
|
-
error: errorMessage,
|
|
260
|
-
timestamp: new Date().toISOString(),
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
finally {
|
|
264
|
-
setIsLoading(false);
|
|
265
|
-
}
|
|
266
|
-
}, [client, refreshInvitations]);
|
|
267
|
-
const refreshMyInvitations = useCallback(async (token) => {
|
|
268
|
-
setIsLoading(true);
|
|
269
|
-
setError(null);
|
|
270
|
-
try {
|
|
271
|
-
const response = await client.getMyInvitations(token);
|
|
272
|
-
if (response.success && response.data) {
|
|
273
|
-
setMyInvitations(response.data);
|
|
274
|
-
}
|
|
275
|
-
else {
|
|
276
|
-
setError(response.error || 'Failed to fetch my invitations');
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
catch (err) {
|
|
280
|
-
const errorMessage = err instanceof Error ? err.message : 'Failed to fetch my invitations';
|
|
281
|
-
setError(errorMessage);
|
|
282
|
-
console.error('[useEntities] refreshMyInvitations error:', errorMessage, err);
|
|
283
|
-
}
|
|
284
|
-
finally {
|
|
285
|
-
setIsLoading(false);
|
|
286
|
-
}
|
|
287
|
-
}, [client]);
|
|
288
|
-
const acceptInvitation = useCallback(async (invitationToken, token) => {
|
|
289
|
-
setIsLoading(true);
|
|
290
|
-
setError(null);
|
|
291
|
-
try {
|
|
292
|
-
const response = await client.acceptInvitation(invitationToken, token);
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
const declineInvitationMutation = useMutation({
|
|
156
|
+
mutationFn: async (invitationToken) => {
|
|
157
|
+
return client.declineInvitation(invitationToken, token);
|
|
158
|
+
},
|
|
159
|
+
onSuccess: response => {
|
|
293
160
|
if (response.success) {
|
|
294
|
-
|
|
295
|
-
await refreshEntities(token);
|
|
161
|
+
queryClient.invalidateQueries({ queryKey: QUERY_KEYS.myInvitations() });
|
|
296
162
|
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
const errorMessage = err instanceof Error ? err.message : 'Failed to accept invitation';
|
|
301
|
-
setError(errorMessage);
|
|
302
|
-
console.error('[useEntities] acceptInvitation error:', errorMessage, err);
|
|
303
|
-
return {
|
|
304
|
-
success: false,
|
|
305
|
-
error: errorMessage,
|
|
306
|
-
timestamp: new Date().toISOString(),
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
finally {
|
|
310
|
-
setIsLoading(false);
|
|
311
|
-
}
|
|
312
|
-
}, [client, refreshMyInvitations, refreshEntities]);
|
|
313
|
-
const declineInvitation = useCallback(async (invitationToken, token) => {
|
|
314
|
-
setIsLoading(true);
|
|
315
|
-
setError(null);
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
const getEntity = useCallback(async (slug) => {
|
|
316
166
|
try {
|
|
317
|
-
|
|
318
|
-
if (response.success) {
|
|
319
|
-
await refreshMyInvitations(token);
|
|
320
|
-
}
|
|
321
|
-
return response;
|
|
167
|
+
return await client.getEntity(slug, token);
|
|
322
168
|
}
|
|
323
169
|
catch (err) {
|
|
324
|
-
const errorMessage = err instanceof Error ? err.message : 'Failed to
|
|
325
|
-
setError(errorMessage);
|
|
326
|
-
console.error('[useEntities] declineInvitation error:', errorMessage, err);
|
|
170
|
+
const errorMessage = err instanceof Error ? err.message : 'Failed to get entity';
|
|
327
171
|
return {
|
|
328
172
|
success: false,
|
|
329
173
|
error: errorMessage,
|
|
330
174
|
timestamp: new Date().toISOString(),
|
|
331
175
|
};
|
|
332
176
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
177
|
+
}, [client, token]);
|
|
178
|
+
const createEntity = useCallback((data) => createEntityMutation.mutateAsync(data), [createEntityMutation]);
|
|
179
|
+
const updateEntity = useCallback((slug, data) => updateEntityMutation.mutateAsync({ slug, data }), [updateEntityMutation]);
|
|
180
|
+
const deleteEntity = useCallback((slug) => deleteEntityMutation.mutateAsync(slug), [deleteEntityMutation]);
|
|
181
|
+
const updateMemberRole = useCallback((memberId, role) => updateMemberRoleMutation.mutateAsync({ memberId, role }), [updateMemberRoleMutation]);
|
|
182
|
+
const removeMember = useCallback((memberId) => removeMemberMutation.mutateAsync(memberId), [removeMemberMutation]);
|
|
183
|
+
const createInvitation = useCallback((data) => createInvitationMutation.mutateAsync(data), [createInvitationMutation]);
|
|
184
|
+
const cancelInvitation = useCallback((invitationId) => cancelInvitationMutation.mutateAsync(invitationId), [cancelInvitationMutation]);
|
|
185
|
+
const acceptInvitation = useCallback((invitationToken) => acceptInvitationMutation.mutateAsync(invitationToken), [acceptInvitationMutation]);
|
|
186
|
+
const declineInvitation = useCallback((invitationToken) => declineInvitationMutation.mutateAsync(invitationToken), [declineInvitationMutation]);
|
|
187
|
+
const isLoading = entitiesLoading ||
|
|
188
|
+
membersLoading ||
|
|
189
|
+
invitationsLoading ||
|
|
190
|
+
myInvitationsLoading ||
|
|
191
|
+
createEntityMutation.isPending ||
|
|
192
|
+
updateEntityMutation.isPending ||
|
|
193
|
+
deleteEntityMutation.isPending ||
|
|
194
|
+
updateMemberRoleMutation.isPending ||
|
|
195
|
+
removeMemberMutation.isPending ||
|
|
196
|
+
createInvitationMutation.isPending ||
|
|
197
|
+
cancelInvitationMutation.isPending ||
|
|
198
|
+
acceptInvitationMutation.isPending ||
|
|
199
|
+
declineInvitationMutation.isPending;
|
|
200
|
+
const queryError = entitiesError;
|
|
201
|
+
const mutationError = createEntityMutation.error ??
|
|
202
|
+
updateEntityMutation.error ??
|
|
203
|
+
deleteEntityMutation.error ??
|
|
204
|
+
updateMemberRoleMutation.error ??
|
|
205
|
+
removeMemberMutation.error ??
|
|
206
|
+
createInvitationMutation.error ??
|
|
207
|
+
cancelInvitationMutation.error ??
|
|
208
|
+
acceptInvitationMutation.error ??
|
|
209
|
+
declineInvitationMutation.error;
|
|
210
|
+
const error = queryError instanceof Error
|
|
211
|
+
? queryError.message
|
|
212
|
+
: mutationError instanceof Error
|
|
213
|
+
? mutationError.message
|
|
214
|
+
: null;
|
|
337
215
|
const clearError = useCallback(() => {
|
|
338
|
-
|
|
339
|
-
|
|
216
|
+
createEntityMutation.reset();
|
|
217
|
+
updateEntityMutation.reset();
|
|
218
|
+
deleteEntityMutation.reset();
|
|
219
|
+
updateMemberRoleMutation.reset();
|
|
220
|
+
removeMemberMutation.reset();
|
|
221
|
+
createInvitationMutation.reset();
|
|
222
|
+
cancelInvitationMutation.reset();
|
|
223
|
+
acceptInvitationMutation.reset();
|
|
224
|
+
declineInvitationMutation.reset();
|
|
225
|
+
}, [
|
|
226
|
+
createEntityMutation,
|
|
227
|
+
updateEntityMutation,
|
|
228
|
+
deleteEntityMutation,
|
|
229
|
+
updateMemberRoleMutation,
|
|
230
|
+
removeMemberMutation,
|
|
231
|
+
createInvitationMutation,
|
|
232
|
+
cancelInvitationMutation,
|
|
233
|
+
acceptInvitationMutation,
|
|
234
|
+
declineInvitationMutation,
|
|
235
|
+
]);
|
|
340
236
|
const reset = useCallback(() => {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
237
|
+
queryClient.removeQueries({ queryKey: QUERY_KEYS.entities() });
|
|
238
|
+
queryClient.removeQueries({ queryKey: QUERY_KEYS.myInvitations() });
|
|
239
|
+
if (entitySlug) {
|
|
240
|
+
queryClient.removeQueries({
|
|
241
|
+
queryKey: QUERY_KEYS.entityMembers(entitySlug),
|
|
242
|
+
});
|
|
243
|
+
queryClient.removeQueries({
|
|
244
|
+
queryKey: QUERY_KEYS.entityInvitations(entitySlug),
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
clearError();
|
|
248
|
+
}, [queryClient, entitySlug, clearError]);
|
|
249
|
+
const currentEntity = useMemo(() => entitySlug
|
|
250
|
+
? ((entitiesData ?? []).find(e => e.entitySlug === entitySlug) ?? null)
|
|
251
|
+
: null, [entitiesData, entitySlug]);
|
|
349
252
|
return useMemo(() => ({
|
|
350
|
-
entities,
|
|
253
|
+
entities: entitiesData ?? EMPTY_ENTITIES,
|
|
351
254
|
currentEntity,
|
|
352
|
-
members,
|
|
353
|
-
invitations,
|
|
354
|
-
myInvitations,
|
|
255
|
+
members: membersData ?? EMPTY_MEMBERS,
|
|
256
|
+
invitations: invitationsData ?? EMPTY_INVITATIONS,
|
|
257
|
+
myInvitations: myInvitationsData ?? EMPTY_INVITATIONS,
|
|
355
258
|
isLoading,
|
|
356
259
|
error,
|
|
357
|
-
|
|
260
|
+
refetchEntities,
|
|
358
261
|
getEntity,
|
|
359
262
|
createEntity,
|
|
360
263
|
updateEntity,
|
|
361
264
|
deleteEntity,
|
|
362
|
-
|
|
265
|
+
refetchMembers,
|
|
363
266
|
updateMemberRole,
|
|
364
267
|
removeMember,
|
|
365
|
-
|
|
268
|
+
refetchInvitations,
|
|
366
269
|
createInvitation,
|
|
367
270
|
cancelInvitation,
|
|
368
|
-
|
|
271
|
+
refetchMyInvitations,
|
|
369
272
|
acceptInvitation,
|
|
370
273
|
declineInvitation,
|
|
371
274
|
clearError,
|
|
372
275
|
reset,
|
|
373
276
|
}), [
|
|
374
|
-
|
|
277
|
+
entitiesData,
|
|
375
278
|
currentEntity,
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
279
|
+
membersData,
|
|
280
|
+
invitationsData,
|
|
281
|
+
myInvitationsData,
|
|
379
282
|
isLoading,
|
|
380
283
|
error,
|
|
381
|
-
|
|
284
|
+
refetchEntities,
|
|
382
285
|
getEntity,
|
|
383
286
|
createEntity,
|
|
384
287
|
updateEntity,
|
|
385
288
|
deleteEntity,
|
|
386
|
-
|
|
289
|
+
refetchMembers,
|
|
387
290
|
updateMemberRole,
|
|
388
291
|
removeMember,
|
|
389
|
-
|
|
292
|
+
refetchInvitations,
|
|
390
293
|
createInvitation,
|
|
391
294
|
cancelInvitation,
|
|
392
|
-
|
|
295
|
+
refetchMyInvitations,
|
|
393
296
|
acceptInvitation,
|
|
394
297
|
declineInvitation,
|
|
395
298
|
clearError,
|