import { useMutation } from 'react-query';

import { markJourneyTaskAsDone } from '../services';
import { JourneyTaskDetail } from '../types';
import { invalidateJourneyStepTasksQueries } from '../utils';

export const useMarkTaskAsDone = (
  task?: JourneyTaskDetail,
  onSuccess?: () => void,
) => {
  return useMutation({
    mutationFn: markJourneyTaskAsDone,
    onSuccess: () => {
      invalidateJourneyStepTasksQueries(task);
      onSuccess?.();
    },
  });
};
