import { actionPromise, actionRootCats } from '.';
import gql from '../api';

const actionChangeCategName = (_id, name) =>
  async (dispatch) => {
    await dispatch(actionPromise('newCategoryName', gql(`mutation categoryChange($category:CategoryInput){
    CategoryUpsert(category:$category){
      _id name
      }
    }`, {
      category: {
        _id,
        name
      }
    })));

    dispatch(actionRootCats());
  };

export default actionChangeCategName;
