MCPcopy
hub / github.com/tolgee/tolgee-platform / useApiMutation

Function useApiMutation

webapp/src/service/http/useQueryApi.ts:229–270  ·  view source on GitHub ↗
(
  props: MutationProps<Url, Method, Paths>
)

Source from the content-addressed store, hash-verified

227 ) as MutationFn;
228};
229export const useApiMutation = <
230 Url extends keyof Paths,
231 Method extends keyof Paths[Url],
232 Paths = paths
233>(
234 props: MutationProps<Url, Method, Paths>
235) => {
236 const queryClient = useQueryClient();
237 const { url, method, fetchOptions, options, invalidatePrefix } = props;
238
239 // inject custom onSuccess
240 const customOptions = getApiMutationOptions(invalidatePrefix, queryClient);
241
242 const mutation = useMutation<
243 ResponseContent<Url, Method, Paths>,
244 ApiError,
245 RequestParamsType<Url, Method, Paths>
246 >(
247 (request) =>
248 apiSchemaHttpService.schemaRequest<Url, Method, Paths>(url, method, {
249 ...fetchOptions,
250 disableAutoErrorHandle: true,
251 })(request),
252 customOptions(options as any) as any
253 );
254
255 const mutate = getMutationCallback(
256 mutation.mutate,
257 customOptions,
258 fetchOptions,
259 props
260 );
261
262 const mutateAsync = getMutationCallback(
263 mutation.mutateAsync,
264 customOptions,
265 fetchOptions,
266 props
267 );
268
269 return { ...mutation, mutate, mutateAsync };
270};
271
272export const matchUrlPrefix = (prefix: string) => {
273 return {

Callers 15

EmailNotVerifiedViewFunction · 0.90
NotificationsPopupFunction · 0.90
PasswordResetSetViewFunction · 0.90
AcceptInvitationViewFunction · 0.90
PasswordResetViewFunction · 0.90
LanguagesAddDialogFunction · 0.90
SlackConnectViewFunction · 0.90
usePutKeyFunction · 0.90
usePostKeyFunction · 0.90
useDeleteKeysFunction · 0.90

Calls 3

getApiMutationOptionsFunction · 0.85
getMutationCallbackFunction · 0.85
schemaRequestMethod · 0.80

Tested by

no test coverage detected