import { useMutation } from 'react-query';

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

export const useReopenJourneyTask = (
  task?: JourneyTaskDetail,
  onSuccess?: () => void,
) => {
  return useMutation({
    mutationFn: (taskId: number) => reopenJourneyTask(taskId),
    onSuccess: () => {
      invalidateJourneyStepTasksQueries(task);
      onSuccess?.();
    },
  });
};
