aboutsummaryrefslogtreecommitdiff
path: root/src/components/hooks/queries/useUpdateQuery.ts
blob: 85a94425f816825383bd098b53f5d52b9aa61941 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import { useToast } from '@umami/react-zen';
import type { ApiError } from '@/lib/types';
import { useApi } from '../useApi';
import { useModified } from '../useModified';

export function useUpdateQuery(path: string, params?: Record<string, any>) {
  const { post, useMutation } = useApi();
  const query = useMutation<any, ApiError, Record<string, any>>({
    mutationFn: (data: Record<string, any>) => post(path, { ...data, ...params }),
  });
  const { touch } = useModified();
  const { toast } = useToast();

  return { ...query, touch, toast };
}