import {GSBaseResult} from '@models';
import {useMutation} from '@tanstack/react-query';
import {message} from 'antd';

export function useMutateAddOrder<P>(
  fn: (params: P) => Promise<GSBaseResult>,
  onFetch: () => void,
  onClose: () => void,
) {
  const {isLoading, mutate} = useMutation({
    mutationFn: fn,
    onSuccess({status}) {
      if (status === '0000') {
        onFetch();
        onClose();
        message.success('新增成功');
      }
    },
  });

  return [isLoading, mutate] as const;
}
